From 720970b2e2daee14251c4d9706081e29ea5c0a45 Mon Sep 17 00:00:00 2001 From: Core Date: Wed, 31 Aug 2022 12:44:38 +0100 Subject: [PATCH] lastfm annoying --- src/main/plugins/lastfm.ts | 23 +++++++---------------- src/preload/cider-preload.js | 4 +++- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/src/main/plugins/lastfm.ts b/src/main/plugins/lastfm.ts index be8380d5..ce8a98bf 100644 --- a/src/main/plugins/lastfm.ts +++ b/src/main/plugins/lastfm.ts @@ -29,7 +29,9 @@ export default class lastfm { onReady(_win: Electron.BrowserWindow): void { this.initializeLastFM("", this._apiCredentials); + } + onRendererReady(): void { // Register the ipcMain handlers this._utils.getIPCMain().handle("lastfm:url", (event: any) => { console.debug(`[${lastfm.name}:url] Called.`); @@ -52,28 +54,17 @@ export default class lastfm { this.updateNowPlayingTrack(attributes); }); + this._utils.getIPCMain().on("lastfm:FilteredNowPlayingItemDidChange", (event: any, attributes: any) => { + if (this._utils.getStoreValue("general.privateEnabled")) return; + this.updateNowPlayingTrack(attributes); + }); + this._utils.getIPCMain().on("lastfm:scrobbleTrack", (event: any, attributes: any) => { if (this._utils.getStoreValue("general.privateEnabled")) return; this.scrobbleTrack(attributes); }); } - /** - * Runs on playback State Change - * @param attributes Music Attributes (attributes.status = current state) - */ - onPlaybackStateDidChange(attributes: object): void {} - - /** - * Runs on song change - * @param attributes Music Attributes - * @param scrobble - */ - onNowPlayingItemDidChange(attributes: any, scrobble = false): void { - if (this._utils.getStoreValue("general.privateEnabled")) return; - this.updateNowPlayingTrack(attributes); - } - /** * Initialize LastFM * @param token diff --git a/src/preload/cider-preload.js b/src/preload/cider-preload.js index c1fc7c6a..6f8505eb 100644 --- a/src/preload/cider-preload.js +++ b/src/preload/cider-preload.js @@ -38,8 +38,10 @@ const MusicKitInterop = { const attributes = MusicKitInterop.getAttributes(); attributes.primaryArtist = app.cfg.connectivity.lastfm.remove_featured ? await this.fetchPrimaryArtist() : attributes.artistName; + global.ipcRenderer.send("nowPlayingItemDidChange", attributes); + if (MusicKitInterop.filterTrack(attributes, false, true)) { - global.ipcRenderer.send("nowPlayingItemDidChange", attributes); + global.ipcRenderer.send("lastfm:FilteredNowPlayingItemDidChange", attributes); } else if (attributes.name !== "no-title-found" && attributes.playParams.id !== "no-id-found") { global.ipcRenderer.send("lastfm:nowPlayingChange", attributes); }