From d36e1b19f65259743d07001db4942fe3932608de Mon Sep 17 00:00:00 2001 From: Core <64542347+coredev-uk@users.noreply.github.com> Date: Thu, 17 Feb 2022 00:58:48 +0000 Subject: [PATCH 1/4] LastFM can be unique and have its own call --- src/main/index.ts | 4 ++++ src/main/plugins/lastfm.ts | 2 +- src/preload/cider-preload.js | 4 +++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/index.ts b/src/main/index.ts index 7038f483..9e0d53d9 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -69,6 +69,10 @@ ipcMain.on('nowPlayingItemDidChange', (_event, attributes) => { CiderPlug.callPlugins('onNowPlayingItemDidChange', attributes); }); +ipcMain.on('lfmItemChange', (_event, attributes) => { + CiderPlug.callPlugins('lfmItemChange', attributes); +}); + app.on('before-quit', () => { CiderPlug.callPlugins('onBeforeQuit'); console.warn(`${app.getName()} exited.`); diff --git a/src/main/plugins/lastfm.ts b/src/main/plugins/lastfm.ts index 6110ad31..5e871f3b 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 */ - onNowPlayingItemDidChange(attributes: object): void { + lfmItemChange(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 bf6f2924..47441d25 100644 --- a/src/preload/cider-preload.js +++ b/src/preload/cider-preload.js @@ -25,8 +25,10 @@ const MusicKitInterop = { MusicKit.getInstance().addEventListener(MusicKit.Events.nowPlayingItemDidChange, async () => { // await MusicKitInterop.modifyNamesOnLocale(); if (MusicKitInterop.filterTrack(MusicKitInterop.getAttributes(), false, true) || !app.cfg.lastfm.filterLoop) { - global.ipcRenderer.send('nowPlayingItemDidChange', MusicKitInterop.getAttributes()); + global.ipcRenderer.send('lfmItemChange', MusicKitInterop.getAttributes()); } + + global.ipcRenderer.send('nowPlayingItemDidChange', MusicKitInterop.getAttributes()); }); MusicKit.getInstance().addEventListener(MusicKit.Events.authorizationStatusDidChange, () => { From f156083d48f866fcd69d590794a33e0b25c8d95d Mon Sep 17 00:00:00 2001 From: Core <64542347+coredev-uk@users.noreply.github.com> Date: Thu, 17 Feb 2022 01:01:17 +0000 Subject: [PATCH 2/4] Revert "LastFM can be unique and have its own call" This reverts commit d36e1b19f65259743d07001db4942fe3932608de. --- src/main/index.ts | 4 ---- src/main/plugins/lastfm.ts | 2 +- src/preload/cider-preload.js | 4 +--- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/main/index.ts b/src/main/index.ts index 9e0d53d9..7038f483 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -69,10 +69,6 @@ ipcMain.on('nowPlayingItemDidChange', (_event, attributes) => { CiderPlug.callPlugins('onNowPlayingItemDidChange', attributes); }); -ipcMain.on('lfmItemChange', (_event, attributes) => { - CiderPlug.callPlugins('lfmItemChange', attributes); -}); - app.on('before-quit', () => { CiderPlug.callPlugins('onBeforeQuit'); console.warn(`${app.getName()} exited.`); diff --git a/src/main/plugins/lastfm.ts b/src/main/plugins/lastfm.ts index 5e871f3b..6110ad31 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 { + onNowPlayingItemDidChange(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..bf6f2924 100644 --- a/src/preload/cider-preload.js +++ b/src/preload/cider-preload.js @@ -25,10 +25,8 @@ const MusicKitInterop = { 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()); } - - global.ipcRenderer.send('nowPlayingItemDidChange', MusicKitInterop.getAttributes()); }); MusicKit.getInstance().addEventListener(MusicKit.Events.authorizationStatusDidChange, () => { From 604ef16db857dcf82467b41bcbfaee1eb6198607 Mon Sep 17 00:00:00 2001 From: Core <64542347+coredev-uk@users.noreply.github.com> Date: Thu, 17 Feb 2022 01:05:52 +0000 Subject: [PATCH 3/4] Revert "Merge branch 'develop' into develop" This reverts commit 5fa345e6c8107a5256649c6e15450add001afb56, reversing changes made to a02b633f49b94b05a925d65fb2bda0f267c0096a. --- src/main/base/browserwindow.ts | 3 +- src/main/base/store.ts | 1 + src/main/plugins/discordrpc.ts | 98 +++++++++++++++------------ src/renderer/style.less | 4 -- src/renderer/views/pages/settings.ejs | 8 +++ 5 files changed, 66 insertions(+), 48 deletions(-) diff --git a/src/main/base/browserwindow.ts b/src/main/base/browserwindow.ts index f44c468e..a586b662 100644 --- a/src/main/base/browserwindow.ts +++ b/src/main/base/browserwindow.ts @@ -88,7 +88,7 @@ export class BrowserWindow { y: undefined, minWidth: 900, minHeight: 390, - frame: (process.platform === "linux"), + frame: false, title: "Cider", vibrancy: "fullscreen-ui", transparent: process.platform === "darwin", @@ -130,7 +130,6 @@ export class BrowserWindow { this.startWebServer(); BrowserWindow.win = new bw(this.options); - BrowserWindow.win.setMenuBarVisibility(false) const ws = new wsapi(BrowserWindow.win) ws.InitWebSockets() // and load the renderer. diff --git a/src/main/base/store.ts b/src/main/base/store.ts index 4256ea9f..da89a70a 100644 --- a/src/main/base/store.ts +++ b/src/main/base/store.ts @@ -9,6 +9,7 @@ export class Store { "close_button_hide": false, "open_on_startup": false, "discord_rpc": 1, // 0 = disabled, 1 = enabled as Cider, 2 = enabled as Apple Music + "discord_rpc_clear_on_pause": true, "language": "en_US", // electron.app.getLocale().replace('-', '_') this can be used in future "playbackNotifications": true, "update_branch": "main" diff --git a/src/main/plugins/discordrpc.ts b/src/main/plugins/discordrpc.ts index 0fde49b9..3b11557e 100644 --- a/src/main/plugins/discordrpc.ts +++ b/src/main/plugins/discordrpc.ts @@ -8,8 +8,8 @@ export default class DiscordRichPresence { * Private variables for interaction in plugins */ private static _store: any; - private _app: any; - private _attributes: any; + private _app : any; + private _attributes : any; private static _connection: boolean = false; /** @@ -76,10 +76,10 @@ export default class DiscordRichPresence { // Login to Discord this._client.login({clientId}) - .then(() => { - DiscordRichPresence._connection = true; - }) - .catch((e: any) => console.error(`[DiscordRichPresence][connect] ${e}`)); + .then(() => { + DiscordRichPresence._connection = true; + }) + .catch((e: any) => console.error(`[DiscordRichPresence][connect] ${e}`)); } /** @@ -94,43 +94,43 @@ export default class DiscordRichPresence { }).catch((e: any) => console.error(`[DiscordRPC][disconnect] ${e}`)); } - /** - * Filter the Discord activity object - */ - private filterActivity(activity: any, attributes: any): Object { - - // Checks if the name is greater than 128 because some songs can be that long + /** + * Filter the Discord activity object + */ + private filterActivity(activity: any, attributes: any): Object { + + // Checks if the name is greater than 128 because some songs can be that long if (activity.details && activity.details.length > 128) { activity.details = activity.details.substring(0, 125) + '...' } - // Check large image - if (activity.largeImageKey == null || activity.largeImageKey === "" || activity.largeImageKey.length > 256) { + // Check large image + if (activity.largeImageKey == null || activity.largeImageKey === "" || activity.largeImageKey.length > 256) { activity.largeImageKey = "cider"; } - // Timestamp - if (new Date(attributes.endTime).getTime() < 0) { - delete activity.startTime - delete activity.endTime - } + // Timestamp + if (new Date(attributes.endTime).getTime() < 0) { + delete activity.startTime + delete activity.endTime + } - // not sure - if (!attributes.artistName) { - delete activity.state; - } + // not sure + if (!attributes.artistName) { + delete activity.state; + } - if (!activity.largeImageText || activity.largeImageText.length < 2) { + if (!activity.largeImageText || activity.largeImageText.length < 2) { delete activity.largeImageText } - activity.buttons.forEach((key: { label: string, url: string }, _v: Number) => { - if (key.url.includes('undefined') || key.url.includes('no-id-found')) { + activity.buttons.forEach((key: {label: string, url: string}, _v: Number) => { + if (key.url.includes('undefined') || key.url.includes('no-id-found')) { activity.buttons.splice(key, 1); - } - }) - return activity - } + } + }) + return activity + } /** * Sets the activity of the client @@ -158,15 +158,29 @@ export default class DiscordRichPresence { ] }; - this._activity = this.filterActivity(this._activity, attributes) + this._activity = this.filterActivity(this._activity, attributes) // Check if its pausing (false) or playing (true) if (!attributes.status) { - this._client.clearActivity() + if (DiscordRichPresence._store.general.discord_rpc_clear_on_pause) { + this._client.clearActivity() .catch((e: any) => console.error(`[DiscordRichPresence][clearActivity] ${e}`)); + } else { + this._activity.smallImageKey = 'pause'; + this._activity.smallImageText = 'Paused'; + delete this._activity.endTimestamp; + delete this._activity.startTimestamp; + this._client.setActivity(this._activity) + .catch((e: any) => console.error(`[DiscordRichPresence][setActivity] ${e}`)); + } } else if (this._activity && this._activityCache !== this._activity && this._activity.details) { + if (!DiscordRichPresence._store.general.discord_rpc_clear_on_pause) { + this._activity.smallImageKey = 'play'; + this._activity.smallImageText = 'Playing'; + } + this._client.setActivity(this._activity) - .catch((e: any) => console.error(`[DiscordRichPresence][updateActivity] ${e}`)); + .catch((e: any) => console.error(`[DiscordRichPresence][updateActivity] ${e}`)); this._activityCache = this._activity; } @@ -193,21 +207,21 @@ export default class DiscordRichPresence { this.connect((DiscordRichPresence._store.general.discord_rpc == 1) ? '911790844204437504' : '886578863147192350'); console.debug(`[Plugin][${this.name}] Ready.`); ipcMain.on('updateRPCImage', (_event, imageurl) => { - fetch('https://api.cider.sh/v1/images', { + fetch('https://api.cider.sh/v1/images' ,{ method: 'POST', - body: JSON.stringify({url: imageurl}), - headers: { + body: JSON.stringify({url : imageurl}), + headers: { 'Content-Type': 'application/json', 'User-Agent': _win.webContents.getUserAgent() }, }) - .then(res => res.json()) - .then(function (json) { - self._attributes["artwork"]["url"] = json.url - self.updateActivity(self._attributes) - }) - + .then(res => res.json()) + .then(function(json){ + self._attributes["artwork"]["url"] = json.url + self.updateActivity(self._attributes) + }) + }) } diff --git a/src/renderer/style.less b/src/renderer/style.less index d5e9f8a8..4b4d957c 100644 --- a/src/renderer/style.less +++ b/src/renderer/style.less @@ -3134,10 +3134,6 @@ body[platform='darwin'] { } } -body[platform='linux'] #window-controls-container { - display: none; -} - .percent { display: inline-block; position: relative; diff --git a/src/renderer/views/pages/settings.ejs b/src/renderer/views/pages/settings.ejs index 69cb70f8..32a50e46 100644 --- a/src/renderer/views/pages/settings.ejs +++ b/src/renderer/views/pages/settings.ejs @@ -568,6 +568,14 @@ +
+
+ {{$root.getLz('settings.option.connectivity.discordRPC.clearOnPause')}} +
+
+ +
+
{{$root.getLz('settings.option.connectivity.lastfmScrobble')}} From cb82ff482d0c918a17cdd3f7c9f8558e8848e763 Mon Sep 17 00:00:00 2001 From: Core <64542347+coredev-uk@users.noreply.github.com> Date: Thu, 17 Feb 2022 01:06:47 +0000 Subject: [PATCH 4/4] Revert "Revert "LastFM can be unique and have its own call"" This reverts commit f156083d48f866fcd69d590794a33e0b25c8d95d. --- src/main/index.ts | 4 ++++ src/main/plugins/lastfm.ts | 2 +- src/preload/cider-preload.js | 4 +++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/index.ts b/src/main/index.ts index 7038f483..9e0d53d9 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -69,6 +69,10 @@ ipcMain.on('nowPlayingItemDidChange', (_event, attributes) => { CiderPlug.callPlugins('onNowPlayingItemDidChange', attributes); }); +ipcMain.on('lfmItemChange', (_event, attributes) => { + CiderPlug.callPlugins('lfmItemChange', attributes); +}); + app.on('before-quit', () => { CiderPlug.callPlugins('onBeforeQuit'); console.warn(`${app.getName()} exited.`); diff --git a/src/main/plugins/lastfm.ts b/src/main/plugins/lastfm.ts index 6110ad31..5e871f3b 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 */ - onNowPlayingItemDidChange(attributes: object): void { + lfmItemChange(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 bf6f2924..47441d25 100644 --- a/src/preload/cider-preload.js +++ b/src/preload/cider-preload.js @@ -25,8 +25,10 @@ const MusicKitInterop = { MusicKit.getInstance().addEventListener(MusicKit.Events.nowPlayingItemDidChange, async () => { // await MusicKitInterop.modifyNamesOnLocale(); if (MusicKitInterop.filterTrack(MusicKitInterop.getAttributes(), false, true) || !app.cfg.lastfm.filterLoop) { - global.ipcRenderer.send('nowPlayingItemDidChange', MusicKitInterop.getAttributes()); + global.ipcRenderer.send('lfmItemChange', MusicKitInterop.getAttributes()); } + + global.ipcRenderer.send('nowPlayingItemDidChange', MusicKitInterop.getAttributes()); }); MusicKit.getInstance().addEventListener(MusicKit.Events.authorizationStatusDidChange, () => {