
* Added update check if using MSS or MAS builds. need help implementing * fix locale / allow pl to show before list loading is fully done * oops * Also copy blockmap for partial download `[2022-02-15 17:28:30.126] [error] Cannot download differentially, fallback to full download: Error: Cannot download "https://478-429851205-gh.circle-artifacts.com/0/%7E/Cider/dist/artifacts/Cider-Setup-1.1.428.exe.blockmap", status 404: Not Found at ClientRequest.<anonymous> (C:\Program Files\Cider\resources\app.asar\node_modules\builder-util-runtime\src\httpExecutor.ts:288:11) at ClientRequest.emit (node:events:394:28) at ClientRequest.emit (node:domain:475:12) at SimpleURLLoaderWrapper.<anonymous> (node:electron/js2c/browser_init:105:6829) at SimpleURLLoaderWrapper.emit (node:events:394:28) at SimpleURLLoaderWrapper.emit (node:domain:475:12)` * more lang fix * Removed Discord clear on pause * Linux frame * fix #459 * Fix * exposed --songProgressColor and --songProgressBackground * revert * Revert "revert" This reverts commit24313b53cf
. * ok? * Revert "ok?" This reverts commit9218ccc887
. * ok * fix adding/remove mvs from library * Created audio controls menu * Added start-renderer command for easier testing * shitty floats shitty shitty * LastFM can be unique and have its own call * Revert "LastFM can be unique and have its own call" This reverts commitd36e1b19f6
. * Revert "Merge branch 'develop' into develop" This reverts commit5fa345e6c8
, reversing changes made toa02b633f49
. * Revert "Revert "LastFM can be unique and have its own call"" This reverts commitf156083d48
. * lastfm changes Co-authored-by: child_duckling <19170969+quacksire@users.noreply.github.com> Co-authored-by: vapormusic <vietanhfat@gmail.com> Co-authored-by: JYW0803 <74043061+JYW0803@users.noreply.github.com> Co-authored-by: Core <64542347+coredev-uk@users.noreply.github.com> Co-authored-by: booploops <49113086+booploops@users.noreply.github.com>
148 lines
6.1 KiB
JavaScript
148 lines
6.1 KiB
JavaScript
global.ipcRenderer = require('electron').ipcRenderer;
|
|
console.log('Loaded Preload')
|
|
|
|
let cache = {playParams: {id: 0}, status: null, remainingTime: 0},
|
|
playbackCache = {status: null, time: Date.now()};
|
|
|
|
const MusicKitInterop = {
|
|
init: function () {
|
|
MusicKit.getInstance().addEventListener(MusicKit.Events.playbackStateDidChange, () => {
|
|
if (MusicKitInterop.filterTrack(MusicKitInterop.getAttributes(), true, false)) {
|
|
global.ipcRenderer.send('playbackStateDidChange', MusicKitInterop.getAttributes())
|
|
ipcRenderer.send('wsapi-updatePlaybackState', MusicKitInterop.getAttributes());
|
|
// if (typeof _plugins != "undefined") {
|
|
// _plugins.execute("OnPlaybackStateChanged", {Attributes: MusicKitInterop.getAttributes()})
|
|
// }
|
|
}
|
|
});
|
|
|
|
/** wsapi */
|
|
MusicKit.getInstance().addEventListener(MusicKit.Events.playbackProgressDidChange, () => {
|
|
ipcRenderer.send('wsapi-updatePlaybackState', MusicKitInterop.getAttributes());
|
|
});
|
|
/** wsapi */
|
|
|
|
MusicKit.getInstance().addEventListener(MusicKit.Events.nowPlayingItemDidChange, async () => {
|
|
// await MusicKitInterop.modifyNamesOnLocale();
|
|
if (MusicKitInterop.filterTrack(MusicKitInterop.getAttributes(), false, true) || !app.cfg.lastfm.filterLoop) {
|
|
global.ipcRenderer.send('lfmItemChange', MusicKitInterop.getAttributes());
|
|
}
|
|
|
|
global.ipcRenderer.send('nowPlayingItemDidChange', MusicKitInterop.getAttributes());
|
|
});
|
|
|
|
MusicKit.getInstance().addEventListener(MusicKit.Events.authorizationStatusDidChange, () => {
|
|
global.ipcRenderer.send('authorizationStatusDidChange', MusicKit.getInstance().authorizationStatus)
|
|
})
|
|
|
|
MusicKit.getInstance().addEventListener(MusicKit.Events.mediaPlaybackError, (e) => {
|
|
console.warn(`[mediaPlaybackError] ${e}`);
|
|
})
|
|
},
|
|
async modifyNamesOnLocale() {
|
|
if (app.mklang == '' || app.mklang == null) {
|
|
return;
|
|
}
|
|
const mk = MusicKit.getInstance()
|
|
const nowPlayingItem = mk.nowPlayingItem;
|
|
if ((nowPlayingItem?._songId ?? nowPlayingItem?.songId) == null){
|
|
return;
|
|
}
|
|
const id = nowPlayingItem?._songId ?? (nowPlayingItem?.songId ?? nowPlayingItem?.id)
|
|
if (id != null && id != -1) {
|
|
try{
|
|
const query = await mk.api.v3.music(`/v1${(((nowPlayingItem?._songId ?? nowPlayingItem?.songId) != null) && ((nowPlayingItem?._songId ?? nowPlayingItem?.songId) != -1)) ? `/catalog/${mk.storefrontId}/` : `/me/library/`}songs/${id}?l=${app.mklang}`);
|
|
if (query?.data?.data[0]){
|
|
let attrs = query?.data?.data[0]?.attributes;
|
|
if (attrs?.name) { nowPlayingItem.attributes.name = attrs?.name ?? ''}
|
|
if (attrs?.albumName) { nowPlayingItem.attributes.albumName = attrs?.albumName ?? ''}
|
|
if (attrs?.artistName) { nowPlayingItem.attributes.artistName = attrs?.artistName ?? ''}
|
|
|
|
}} catch (e) { return;}
|
|
} else {return;}
|
|
},
|
|
getAttributes: function () {
|
|
const mk = MusicKit.getInstance()
|
|
const nowPlayingItem = mk.nowPlayingItem;
|
|
const isPlayingExport = mk.isPlaying;
|
|
const remainingTimeExport = mk.currentPlaybackTimeRemaining;
|
|
const attributes = (nowPlayingItem != null ? nowPlayingItem.attributes : {});
|
|
|
|
attributes.status = isPlayingExport ?? false;
|
|
attributes.name = attributes?.name ?? 'No Title Found';
|
|
attributes.artwork = attributes?.artwork ?? {url: ''};
|
|
attributes.artwork.url = (attributes?.artwork?.url ?? '').replace(`{f}`, "png");
|
|
attributes.playParams = attributes?.playParams ?? {id: 'no-id-found'};
|
|
attributes.playParams.id = attributes?.playParams?.id ?? 'no-id-found';
|
|
attributes.url = {
|
|
cider: `cider://play/s/${nowPlayingItem?._songId ?? (nowPlayingItem?.songId ??'no-id-found')}`,
|
|
appleMusic: attributes.websiteUrl ? attributes.websiteUrl : `https://music.apple.com/${mk.storefrontId}/song/${nowPlayingItem?._songId ?? (nowPlayingItem?.songId ??'no-id-found')}`
|
|
}
|
|
if (attributes.playParams.id === 'no-id-found') {
|
|
attributes.playParams.id = nowPlayingItem?.id ?? 'no-id-found';
|
|
}
|
|
attributes.albumName = attributes?.albumName ?? '';
|
|
attributes.artistName = attributes?.artistName ?? '';
|
|
attributes.genreNames = attributes?.genreNames ?? [];
|
|
attributes.remainingTime = remainingTimeExport
|
|
? remainingTimeExport * 1000
|
|
: 0;
|
|
attributes.durationInMillis = attributes?.durationInMillis ?? 0;
|
|
attributes.startTime = Date.now();
|
|
attributes.endTime = Math.round(
|
|
attributes?.playParams?.id === cache.playParams.id
|
|
? Date.now() + attributes?.remainingTime
|
|
: attributes?.startTime + attributes?.durationInMillis
|
|
);
|
|
return attributes;
|
|
},
|
|
|
|
filterTrack: function (a, playbackCheck, mediaCheck) {
|
|
if (a.title === "No Title Found" || a.playParams.id === "no-id-found") {
|
|
return;
|
|
} else if (mediaCheck && a.playParams.id === cache.playParams.id) {
|
|
return;
|
|
} else if (playbackCheck && a.status === playbackCache.status) {
|
|
return;
|
|
} else if (playbackCheck && !a.status && a.remainingTime === playbackCache.time) { /* Pretty much have to do this to prevent multiple runs when a song starts playing */
|
|
return;
|
|
}
|
|
cache = a;
|
|
if (playbackCheck) playbackCache = {status: a.status, time: a.remainingTime};
|
|
return true;
|
|
},
|
|
|
|
play: () => {
|
|
MusicKit.getInstance().play().then(r => console.log(`[MusicKitInterop.play] ${r}`));
|
|
},
|
|
|
|
pause: () => {
|
|
MusicKit.getInstance().pause();
|
|
},
|
|
|
|
playPause: () => {
|
|
if (MusicKit.getInstance().isPlaying) {
|
|
MusicKit.getInstance().pause();
|
|
} else if (MusicKit.getInstance().nowPlayingItem != null) {
|
|
MusicKit.getInstance().play().then(r => console.log(`[MusicKitInterop.playPause] Playing ${r}`));
|
|
}
|
|
},
|
|
|
|
next: () => {
|
|
if (MusicKit.getInstance().queue.nextPlayableItemIndex != -1 && MusicKit.getInstance().queue.nextPlayableItemIndex != null)
|
|
MusicKit.getInstance().changeToMediaAtIndex(MusicKit.getInstance().queue.nextPlayableItemIndex);
|
|
// MusicKit.getInstance().skipToNextItem().then(r => console.log(`[MusicKitInterop.next] Skipping to Next ${r}`));
|
|
},
|
|
|
|
previous: () => {
|
|
if (MusicKit.getInstance().queue.previousPlayableItemIndex != -1 && MusicKit.getInstance().queue.previousPlayableItemIndex != null)
|
|
MusicKit.getInstance().changeToMediaAtIndex(MusicKit.getInstance().queue.previousPlayableItemIndex);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
process.once('loaded', () => {
|
|
console.log("Setting ipcRenderer")
|
|
global.MusicKitInterop = MusicKitInterop;
|
|
});
|