From 548688341d953bd5cfe5f27b32a60fcc8b338c08 Mon Sep 17 00:00:00 2001 From: Core <64542347+coredev-uk@users.noreply.github.com> Date: Thu, 17 Feb 2022 02:56:41 +0000 Subject: [PATCH] i hate lastfm like really really hate it --- src/main/index.ts | 6 +++--- src/main/plugins/lastfm.ts | 2 +- src/preload/cider-preload.js | 25 ++++++++++++++++--------- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/main/index.ts b/src/main/index.ts index 9e0d53d9..daeb3eeb 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -69,9 +69,9 @@ ipcMain.on('nowPlayingItemDidChange', (_event, attributes) => { CiderPlug.callPlugins('onNowPlayingItemDidChange', attributes); }); -ipcMain.on('lfmItemChange', (_event, attributes) => { - CiderPlug.callPlugins('lfmItemChange', attributes); -}); +ipcMain.on('nowPlayingItemDidChangeLastFM', (_event, attributes) => { + CiderPlug.callPlugin('lastfm', 'nowPlayingItemDidChangeLastFM', attributes); +}) app.on('before-quit', () => { CiderPlug.callPlugins('onBeforeQuit'); diff --git a/src/main/plugins/lastfm.ts b/src/main/plugins/lastfm.ts index 5e871f3b..ea66bb2c 100644 --- a/src/main/plugins/lastfm.ts +++ b/src/main/plugins/lastfm.ts @@ -265,7 +265,7 @@ export default class LastFMPlugin { * Runs on song change * @param attributes Music Attributes */ - lfmItemChange(attributes: object): void { + nowPlayingItemDidChangeLastFM(attributes: object): void { if (!this._store.lastfm.filterLoop){ this._lastfm.cachedNowPlayingAttributes = false; this._lastfm.cachedAttributes = false} diff --git a/src/preload/cider-preload.js b/src/preload/cider-preload.js index 47441d25..50e4d1ee 100644 --- a/src/preload/cider-preload.js +++ b/src/preload/cider-preload.js @@ -7,9 +7,10 @@ let cache = {playParams: {id: 0}, status: null, remainingTime: 0}, 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()); + const attributes = MusicKitInterop.getAttributes() + if (MusicKitInterop.filterTrack(attributes, true, false)) { + global.ipcRenderer.send('playbackStateDidChange', attributes) + ipcRenderer.send('wsapi-updatePlaybackState', attributes); // if (typeof _plugins != "undefined") { // _plugins.execute("OnPlaybackStateChanged", {Attributes: MusicKitInterop.getAttributes()}) // } @@ -23,12 +24,18 @@ const MusicKitInterop = { /** 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()); + const attributes = MusicKitInterop.getAttributes() + const trackFilter = MusicKitInterop.filterTrack(attributes, false, true) + + if (trackFilter) { + global.ipcRenderer.send('nowPlayingItemDidChange', attributes); } - global.ipcRenderer.send('nowPlayingItemDidChange', MusicKitInterop.getAttributes()); + // LastFM's Custom Call + // await MusicKitInterop.modifyNamesOnLocale(); + if (trackFilter || !app.cfg.lastfm.filterLoop) { + global.ipcRenderer.send('nowPlayingItemDidChangeLastFM', attributes); + } }); MusicKit.getInstance().addEventListener(MusicKit.Events.authorizationStatusDidChange, () => { @@ -69,7 +76,7 @@ const MusicKitInterop = { const attributes = (nowPlayingItem != null ? nowPlayingItem.attributes : {}); attributes.status = isPlayingExport ?? false; - attributes.name = attributes?.name ?? 'No Title Found'; + 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'}; @@ -98,7 +105,7 @@ const MusicKitInterop = { }, filterTrack: function (a, playbackCheck, mediaCheck) { - if (a.title === "No Title Found" || a.playParams.id === "no-id-found") { + if (a.name === 'no-title-found' || a.playParams.id === "no-id-found") { return; } else if (mediaCheck && a.playParams.id === cache.playParams.id) { return;