From 04591e605c9a07e1afb61e3dcda199da85e603f9 Mon Sep 17 00:00:00 2001 From: Core <64542347+coredev-uk@users.noreply.github.com> Date: Tue, 15 Feb 2022 14:35:56 +0000 Subject: [PATCH 01/17] Removed Discord clear on pause --- src/main/base/store.ts | 1 - src/main/plugins/discordrpc.ts | 98 ++++++++++++--------------- src/renderer/views/pages/settings.ejs | 8 --- 3 files changed, 42 insertions(+), 65 deletions(-) diff --git a/src/main/base/store.ts b/src/main/base/store.ts index da89a70a..4256ea9f 100644 --- a/src/main/base/store.ts +++ b/src/main/base/store.ts @@ -9,7 +9,6 @@ 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 3b11557e..0fde49b9 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,29 +158,15 @@ 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) { - if (DiscordRichPresence._store.general.discord_rpc_clear_on_pause) { - this._client.clearActivity() + 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; } @@ -207,21 +193,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/views/pages/settings.ejs b/src/renderer/views/pages/settings.ejs index 23292ff0..24fff74a 100644 --- a/src/renderer/views/pages/settings.ejs +++ b/src/renderer/views/pages/settings.ejs @@ -558,14 +558,6 @@ -
-
- {{$root.getLz('settings.option.connectivity.discordRPC.clearOnPause')}} -
-
- -
-
{{$root.getLz('settings.option.connectivity.lastfmScrobble')}} From ad86f58e47c783a6444accca8d070e8f458c4f06 Mon Sep 17 00:00:00 2001 From: Core <64542347+coredev-uk@users.noreply.github.com> Date: Tue, 15 Feb 2022 14:53:51 +0000 Subject: [PATCH 02/17] Linux frame --- src/main/base/browserwindow.ts | 3 ++- src/renderer/style.less | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/base/browserwindow.ts b/src/main/base/browserwindow.ts index cbe6547d..6eca794f 100644 --- a/src/main/base/browserwindow.ts +++ b/src/main/base/browserwindow.ts @@ -87,7 +87,7 @@ export class BrowserWindow { y: undefined, minWidth: 900, minHeight: 390, - frame: false, + frame: (process.platform === "linux"), title: "Cider", vibrancy: "fullscreen-ui", transparent: process.platform === "darwin", @@ -129,6 +129,7 @@ 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/renderer/style.less b/src/renderer/style.less index 85949811..7ca4b38d 100644 --- a/src/renderer/style.less +++ b/src/renderer/style.less @@ -3120,7 +3120,7 @@ body.no-gpu { } } -body[platform='darwin'] { +body[platform='darwin'], body[platform='linux'] { #window-controls-container { display: none; } From 2f3fda5235fa69e7155ab20b09e2143f694f8b74 Mon Sep 17 00:00:00 2001 From: Core <64542347+coredev-uk@users.noreply.github.com> Date: Tue, 15 Feb 2022 17:11:04 +0000 Subject: [PATCH 03/17] Fix --- src/renderer/style.less | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/renderer/style.less b/src/renderer/style.less index 7ca4b38d..f768e36d 100644 --- a/src/renderer/style.less +++ b/src/renderer/style.less @@ -3120,7 +3120,7 @@ body.no-gpu { } } -body[platform='darwin'], body[platform='linux'] { +body[platform='darwin'] { #window-controls-container { display: none; } @@ -3132,5 +3132,9 @@ body[platform='darwin'], body[platform='linux'] { } } +body[platform='linux'] #window-controls-container { + display: none; +} + @import url("less/compact.less"); From 09825e93d3c6c5b36f87954ec385d11cc07d8a9e Mon Sep 17 00:00:00 2001 From: Core <64542347+coredev-uk@users.noreply.github.com> Date: Thu, 17 Feb 2022 00:19:14 +0000 Subject: [PATCH 04/17] Created audio controls menu --- src/i18n/README.md | 6 ++ src/i18n/en_US.jsonc | 3 + src/main/base/browserwindow.ts | 1 + src/renderer/style.less | 20 +++++ src/renderer/views/app/panels.ejs | 3 + src/renderer/views/app/sidebar.ejs | 2 +- .../views/components/audio-controls.ejs | 87 +++++++++++++++++++ .../views/components/audio-settings.ejs | 9 ++ src/renderer/views/components/fullscreen.ejs | 2 +- src/renderer/views/pages/settings.ejs | 10 +++ 10 files changed, 141 insertions(+), 2 deletions(-) create mode 100644 src/renderer/views/components/audio-controls.ejs diff --git a/src/i18n/README.md b/src/i18n/README.md index f474d134..6552894c 100644 --- a/src/i18n/README.md +++ b/src/i18n/README.md @@ -116,3 +116,9 @@ Update 12/02/2022 12:00 UTC * `settings.notyf.visual.theme.install.error`: Added for `en_US`. * `term.defaultPresets`: Added for `en_US`. * `term.userPresets`: Added for `en_US`. + +Update 16/02/2022 21:45 UTC + +* `term.audioControls`: Added for `en_US`. +* `settings.option.audio.volumeStep`: Added for `en_US`. +* `settings.option.audio.maxVolume`: Added for `en_US`.` \ No newline at end of file diff --git a/src/i18n/en_US.jsonc b/src/i18n/en_US.jsonc index 6f09a2fc..037cbe9c 100644 --- a/src/i18n/en_US.jsonc +++ b/src/i18n/en_US.jsonc @@ -109,6 +109,7 @@ "term.fullscreenView": "Fullscreen View", "term.defaultView": "Default View", "term.audioSettings": "Audio Settings", + "term.audioControls": "Audio Controls", "term.clearAll": "Clear All", "term.recentStations": "Recent Stations", "term.language": "Language", @@ -251,6 +252,8 @@ // Settings - Audio "settings.header.audio": "Audio", "settings.header.audio.description": "Adjust the audio settings for Cider.", + "settings.option.audio.volumeStep": "Volume Step", + "settings.option.audio.maxVolume": "Max Volume", "settings.option.audio.quality": "Audio Quality", // Dropdown "settings.header.audio.quality.hireslossless": "Hi-Res Lossless", "settings.header.audio.quality.hireslossless.description": "up to 24-bit/192 kHz", diff --git a/src/main/base/browserwindow.ts b/src/main/base/browserwindow.ts index cbe6547d..a586b662 100644 --- a/src/main/base/browserwindow.ts +++ b/src/main/base/browserwindow.ts @@ -53,6 +53,7 @@ export class BrowserWindow { "components/sidebar-playlist", "components/spatial-properties", "components/audio-settings", + "components/audio-controls", "components/qrcode-modal", "components/equalizer", "components/add-to-playlist", diff --git a/src/renderer/style.less b/src/renderer/style.less index 9df52a9b..4b4d957c 100644 --- a/src/renderer/style.less +++ b/src/renderer/style.less @@ -3134,5 +3134,25 @@ body[platform='darwin'] { } } +.percent { + display: inline-block; + position: relative; +} + +.percent::after { + position: relative; + right: 2em; + transition: all .05s ease-in-out; +} + +.percent:hover::after, +.percent:focus-within::after { + right: 3.5em; +} + +.percent::after { + content: '%'; +} + @import url("less/compact.less"); diff --git a/src/renderer/views/app/panels.ejs b/src/renderer/views/app/panels.ejs index af2b76f9..85227a31 100644 --- a/src/renderer/views/app/panels.ejs +++ b/src/renderer/views/app/panels.ejs @@ -16,6 +16,9 @@ + + + diff --git a/src/renderer/views/app/sidebar.ejs b/src/renderer/views/app/sidebar.ejs index 4cae1592..fbad26eb 100644 --- a/src/renderer/views/app/sidebar.ejs +++ b/src/renderer/views/app/sidebar.ejs @@ -152,7 +152,7 @@
- diff --git a/src/renderer/views/components/audio-controls.ejs b/src/renderer/views/components/audio-controls.ejs new file mode 100644 index 00000000..57a174e6 --- /dev/null +++ b/src/renderer/views/components/audio-controls.ejs @@ -0,0 +1,87 @@ + + + \ No newline at end of file diff --git a/src/renderer/views/components/audio-settings.ejs b/src/renderer/views/components/audio-settings.ejs index 512db50e..aadab781 100644 --- a/src/renderer/views/components/audio-settings.ejs +++ b/src/renderer/views/components/audio-settings.ejs @@ -17,6 +17,11 @@
<%- include("../svg/speaker.svg") %>
{{app.getLz('settings.option.audio.enableAdvancedFunctionality.audioSpatialization')}}
+
@@ -46,6 +51,10 @@ notyf.error(app.getLz('spatial.notTurnedOn')) } }, + openAudioControls() { + app.modals.audioControls = true + app.modals.audioSettings = false + } } }); \ No newline at end of file diff --git a/src/renderer/views/components/fullscreen.ejs b/src/renderer/views/components/fullscreen.ejs index 733a4b0c..6572ff97 100644 --- a/src/renderer/views/components/fullscreen.ejs +++ b/src/renderer/views/components/fullscreen.ejs @@ -80,7 +80,7 @@
-
diff --git a/src/renderer/views/pages/settings.ejs b/src/renderer/views/pages/settings.ejs index 23292ff0..32a50e46 100644 --- a/src/renderer/views/pages/settings.ejs +++ b/src/renderer/views/pages/settings.ejs @@ -42,6 +42,16 @@ +
+
+ {{$root.getLz('term.audioControls')}} +
+
+ +
+
{{$root.getLz('settings.option.audio.seamlessTransition')}} From 64c7d53f075d27d00b28d5aae1dca0bb3a1a6a7c Mon Sep 17 00:00:00 2001 From: Core <64542347+coredev-uk@users.noreply.github.com> Date: Thu, 17 Feb 2022 00:19:32 +0000 Subject: [PATCH 05/17] Added start-renderer command for easier testing --- package.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/package.json b/package.json index f2eaa78d..06b287ac 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,10 @@ "start:win32": "yarn build && set ELECTRON_ENABLE_LOGGING=true && electron ./build/index.js --enable-accelerated-mjpeg-decode --enable-accelerated-video --disable-gpu-driver-bug-workarounds --ignore-gpu-blacklist --enable-native-gpu-memory-buffers", "start:linux": "yarn build && ELECTRON_ENABLE_LOGGING=true && electron ./build/index.js --enable-accelerated-mjpeg-decode --enable-accelerated-video --disable-gpu-driver-bug-workarounds --ignore-gpu-blacklist --enable-native-gpu-memory-buffers", "start:darwin": "yarn build && ELECTRON_ENABLE_LOGGING=true && electron ./build/index.js --enable-accelerated-mjpeg-decode --enable-accelerated-video --disable-gpu-driver-bug-workarounds --ignore-gpu-blacklist --enable-native-gpu-memory-buffers", + "start-renderer": "run-script-os", + "start-renderer:win32": "set ELECTRON_ENABLE_LOGGING=true && electron ./build/index.js --enable-accelerated-mjpeg-decode --enable-accelerated-video --disable-gpu-driver-bug-workarounds --ignore-gpu-blacklist --enable-native-gpu-memory-buffers", + "start-renderer:linux": "ELECTRON_ENABLE_LOGGING=true && electron ./build/index.js --enable-accelerated-mjpeg-decode --enable-accelerated-video --disable-gpu-driver-bug-workarounds --ignore-gpu-blacklist --enable-native-gpu-memory-buffers", + "start-renderer:darwin": "ELECTRON_ENABLE_LOGGING=true && electron ./build/index.js --enable-accelerated-mjpeg-decode --enable-accelerated-video --disable-gpu-driver-bug-workarounds --ignore-gpu-blacklist --enable-native-gpu-memory-buffers", "pack": "electron-builder --dir", "dist": "yarn build && electron-builder", "dist:macarm": "yarn build && electron-builder --mac --arm64", From a02b633f49b94b05a925d65fb2bda0f267c0096a Mon Sep 17 00:00:00 2001 From: Core <64542347+coredev-uk@users.noreply.github.com> Date: Thu, 17 Feb 2022 00:20:18 +0000 Subject: [PATCH 06/17] shitty floats shitty shitty --- src/renderer/index.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/renderer/index.js b/src/renderer/index.js index c2aee7ac..7daf7bb8 100644 --- a/src/renderer/index.js +++ b/src/renderer/index.js @@ -233,6 +233,7 @@ const app = new Vue({ qrcode: false, equalizer: false, audioSettings: false, + audioControls: false, showPlaylist: false, }, socialBadges: { @@ -272,7 +273,7 @@ const app = new Vue({ artistPage: () => { document.getElementById("app-content").scrollTo(0, 0); app.resetState() - }, + } }, methods: { songLinkShare(amUrl) { @@ -3321,7 +3322,7 @@ const app = new Vue({ console.log('setting max volume') } else { console.log('volume up') - app.mk.volume += app.cfg.audio.volumeStep; + app.mk.volume = ((app.mk.volume * 100) + (app.cfg.audio.volumeStep * 100)) / 100 } }, volumeDown() { @@ -3330,11 +3331,11 @@ const app = new Vue({ console.log('setting volume to 0') } else { console.log('volume down') - app.mk.volume -= app.cfg.audio.volumeStep; + app.mk.volume = ((app.mk.volume * 100) - (app.cfg.audio.volumeStep * 100)) / 100 } }, volumeWheel(event) { - app.checkScrollDirectionIsUp(event) ? app.volumeUp() : app.volumeDown() + app.checkScrollDirectionIsUp(event) ? this.volumeUp() : this.volumeDown() }, muteButtonPressed() { if (this.cfg.audio.muted) { 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 07/17] 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 08/17] 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 09/17] 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 10/17] 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, () => { From 7f5ad08da37f6db33c941159ae24c3e0b005ca6d Mon Sep 17 00:00:00 2001 From: Core <64542347+coredev-uk@users.noreply.github.com> Date: Thu, 17 Feb 2022 01:16:31 +0000 Subject: [PATCH 11/17] Revert "Merge branch 'ciderapp:develop' into develop" This reverts commit 20fd0c05da981a82b786254f0f1bbaa39c9d3fa0, reversing changes made to 4937e29fcfccc2e7bdbd1f8c0afdd6ce22b85af3. --- src/main/base/browserwindow.ts | 3 +- src/main/base/store.ts | 1 - src/main/index.ts | 4 -- src/main/plugins/discordrpc.ts | 98 ++++++++++++--------------- src/renderer/style.less | 4 ++ src/renderer/views/pages/settings.ejs | 8 --- 6 files changed, 48 insertions(+), 70 deletions(-) diff --git a/src/main/base/browserwindow.ts b/src/main/base/browserwindow.ts index a586b662..f44c468e 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: false, + frame: (process.platform === "linux"), title: "Cider", vibrancy: "fullscreen-ui", transparent: process.platform === "darwin", @@ -130,6 +130,7 @@ 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 da89a70a..4256ea9f 100644 --- a/src/main/base/store.ts +++ b/src/main/base/store.ts @@ -9,7 +9,6 @@ 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/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/discordrpc.ts b/src/main/plugins/discordrpc.ts index 3b11557e..0fde49b9 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,29 +158,15 @@ 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) { - if (DiscordRichPresence._store.general.discord_rpc_clear_on_pause) { - this._client.clearActivity() + 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; } @@ -207,21 +193,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 4b4d957c..d5e9f8a8 100644 --- a/src/renderer/style.less +++ b/src/renderer/style.less @@ -3134,6 +3134,10 @@ 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 32a50e46..69cb70f8 100644 --- a/src/renderer/views/pages/settings.ejs +++ b/src/renderer/views/pages/settings.ejs @@ -568,14 +568,6 @@
-
-
- {{$root.getLz('settings.option.connectivity.discordRPC.clearOnPause')}} -
-
- -
-
{{$root.getLz('settings.option.connectivity.lastfmScrobble')}} From 1ad805c04e8dfe0c7dd43c0b4e8ea906602bd6a8 Mon Sep 17 00:00:00 2001 From: vapormusic Date: Thu, 17 Feb 2022 09:22:36 +0700 Subject: [PATCH 12/17] lastfm changes --- src/main/plugins/lastfm.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/plugins/lastfm.ts b/src/main/plugins/lastfm.ts index 5e871f3b..fbeb2b40 100644 --- a/src/main/plugins/lastfm.ts +++ b/src/main/plugins/lastfm.ts @@ -257,20 +257,22 @@ export default class LastFMPlugin { * @param attributes Music Attributes (attributes.status = current state) */ onPlaybackStateDidChange(attributes: object): void { - this.updateNowPlayingSong(attributes) - this.scrobbleSong(attributes) + this.updateNowPlayingSong(attributes) + // this.scrobbleSong(attributes) } /** * Runs on song change * @param attributes Music Attributes */ - lfmItemChange(attributes: object): void { + lfmItemChange(attributes: any): void { + attributes.status = true if (!this._store.lastfm.filterLoop){ this._lastfm.cachedNowPlayingAttributes = false; - this._lastfm.cachedAttributes = false} + this._lastfm.cachedAttributes = false + } this.updateNowPlayingSong(attributes) - this.scrobbleSong(attributes) + this.scrobbleSong(attributes) } } 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 13/17] 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; From 0fb6802ff35ad9cfd03e3ce50f4de768cdba750c Mon Sep 17 00:00:00 2001 From: Core <64542347+coredev-uk@users.noreply.github.com> Date: Thu, 17 Feb 2022 03:02:16 +0000 Subject: [PATCH 14/17] Revert "Merge remote-tracking branch 'origin/develop' into develop" This reverts commit 5b360e74faf937a6e54fda80e5851fc36707a528, reversing changes made to 548688341d953bd5cfe5f27b32a60fcc8b338c08. --- src/main/plugins/lastfm.ts | 77 ++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 40 deletions(-) diff --git a/src/main/plugins/lastfm.ts b/src/main/plugins/lastfm.ts index c5222203..ea66bb2c 100644 --- a/src/main/plugins/lastfm.ts +++ b/src/main/plugins/lastfm.ts @@ -79,47 +79,46 @@ export default class LastFMPlugin { } private scrobbleSong(attributes: any) { - if (this._timer) clearTimeout(this._timer); + if(this._timer) clearTimeout(this._timer); var self = this; this._timer = setTimeout(async () => { - const currentAttributes = attributes; + const currentAttributes = attributes; - if (!self._lastfm || self._lastfm.cachedAttributes === attributes) { - return - } + if (!self._lastfm || self._lastfm.cachedAttributes === attributes) { + return + } - if (self._lastfm.cachedAttributes) { - if (self._lastfm.cachedAttributes.playParams.id === attributes.playParams.id) return; - } + if (self._lastfm.cachedAttributes) { + if (self._lastfm.cachedAttributes.playParams.id === attributes.playParams.id) return; + } - const artist = await this.getPrimaryArtist(attributes) + const artist = await this.getPrimaryArtist(attributes) - if (currentAttributes.status && currentAttributes === attributes) { - if (fs.existsSync(this.sessionPath)) { - // Scrobble playing song. - if (attributes.status === true) { - self._lastfm.track.scrobble({ - 'artist': artist, - 'track': attributes.name, - 'album': attributes.albumName, - 'albumArtist': artist, - 'timestamp': new Date().getTime() / 1000 - }, function (err: any, scrobbled: any) { - if (err) { - return console.error('[LastFM] An error occurred while scrobbling', err); - } + if (currentAttributes.status && currentAttributes === attributes) { + if (fs.existsSync(this.sessionPath)) { + // Scrobble playing song. + if (attributes.status === true) { + self._lastfm.track.scrobble({ + 'artist': artist, + 'track': attributes.name, + 'album': attributes.albumName, + 'albumArtist': artist, + 'timestamp': new Date().getTime() / 1000 + }, function (err: any, scrobbled: any) { + if (err) { + return console.error('[LastFM] An error occurred while scrobbling', err); + } - console.log('[LastFM] Successfully scrobbled: ', scrobbled); - }); - self._lastfm.cachedAttributes = attributes - } - } else { - self.authenticate(); + console.log('[LastFM] Successfully scrobbled: ', scrobbled); + }); + self._lastfm.cachedAttributes = attributes } } else { - return console.log('[LastFM] Did not add ', attributes.name, '—', artist, 'because now playing a other song.'); + self.authenticate(); } - }, Math.round(attributes.durationInMillis * (self._store.lastfm.scrobble_after / 100))); + } else { + return console.log('[LastFM] Did not add ', attributes.name, '—', artist, 'because now playing a other song.'); + }},Math.round(attributes.durationInMillis * (self._store.lastfm.scrobble_after / 100))); } private async updateNowPlayingSong(attributes: any) { @@ -156,7 +155,7 @@ export default class LastFMPlugin { } } - private async getPrimaryArtist(attributes: any) { + private async getPrimaryArtist (attributes: any) { const songId = attributes.playParams.catalogId || attributes.playParams.id if (!this._store.lastfm.enabledRemoveFeaturingArtists || !songId) return attributes.artistName; @@ -259,21 +258,19 @@ export default class LastFMPlugin { */ onPlaybackStateDidChange(attributes: object): void { this.updateNowPlayingSong(attributes) - // this.scrobbleSong(attributes) + this.scrobbleSong(attributes) } /** * Runs on song change * @param attributes Music Attributes */ - lfmItemChange(attributes: any): void { - attributes.status = true - if (!this._store.lastfm.filterLoop) { + nowPlayingItemDidChangeLastFM(attributes: object): void { + if (!this._store.lastfm.filterLoop){ this._lastfm.cachedNowPlayingAttributes = false; - this._lastfm.cachedAttributes = false - } - this.updateNowPlayingSong(attributes) - this.scrobbleSong(attributes) + this._lastfm.cachedAttributes = false} + this.updateNowPlayingSong(attributes) + this.scrobbleSong(attributes) } } From 35aa69c2d67f7c883b18c62e033a620d2a89c7ad Mon Sep 17 00:00:00 2001 From: Core <64542347+coredev-uk@users.noreply.github.com> Date: Thu, 17 Feb 2022 03:06:27 +0000 Subject: [PATCH 15/17] Revert "Revert "Merge remote-tracking branch 'origin/develop' into develop"" This reverts commit 0fb6802ff35ad9cfd03e3ce50f4de768cdba750c. --- src/main/plugins/lastfm.ts | 77 ++++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 37 deletions(-) diff --git a/src/main/plugins/lastfm.ts b/src/main/plugins/lastfm.ts index ea66bb2c..c5222203 100644 --- a/src/main/plugins/lastfm.ts +++ b/src/main/plugins/lastfm.ts @@ -79,46 +79,47 @@ export default class LastFMPlugin { } private scrobbleSong(attributes: any) { - if(this._timer) clearTimeout(this._timer); + if (this._timer) clearTimeout(this._timer); var self = this; this._timer = setTimeout(async () => { - const currentAttributes = attributes; + const currentAttributes = attributes; - if (!self._lastfm || self._lastfm.cachedAttributes === attributes) { - return - } + if (!self._lastfm || self._lastfm.cachedAttributes === attributes) { + return + } - if (self._lastfm.cachedAttributes) { - if (self._lastfm.cachedAttributes.playParams.id === attributes.playParams.id) return; - } + if (self._lastfm.cachedAttributes) { + if (self._lastfm.cachedAttributes.playParams.id === attributes.playParams.id) return; + } - const artist = await this.getPrimaryArtist(attributes) + const artist = await this.getPrimaryArtist(attributes) - if (currentAttributes.status && currentAttributes === attributes) { - if (fs.existsSync(this.sessionPath)) { - // Scrobble playing song. - if (attributes.status === true) { - self._lastfm.track.scrobble({ - 'artist': artist, - 'track': attributes.name, - 'album': attributes.albumName, - 'albumArtist': artist, - 'timestamp': new Date().getTime() / 1000 - }, function (err: any, scrobbled: any) { - if (err) { - return console.error('[LastFM] An error occurred while scrobbling', err); - } + if (currentAttributes.status && currentAttributes === attributes) { + if (fs.existsSync(this.sessionPath)) { + // Scrobble playing song. + if (attributes.status === true) { + self._lastfm.track.scrobble({ + 'artist': artist, + 'track': attributes.name, + 'album': attributes.albumName, + 'albumArtist': artist, + 'timestamp': new Date().getTime() / 1000 + }, function (err: any, scrobbled: any) { + if (err) { + return console.error('[LastFM] An error occurred while scrobbling', err); + } - console.log('[LastFM] Successfully scrobbled: ', scrobbled); - }); - self._lastfm.cachedAttributes = attributes + console.log('[LastFM] Successfully scrobbled: ', scrobbled); + }); + self._lastfm.cachedAttributes = attributes + } + } else { + self.authenticate(); } } else { - self.authenticate(); + return console.log('[LastFM] Did not add ', attributes.name, '—', artist, 'because now playing a other song.'); } - } else { - return console.log('[LastFM] Did not add ', attributes.name, '—', artist, 'because now playing a other song.'); - }},Math.round(attributes.durationInMillis * (self._store.lastfm.scrobble_after / 100))); + }, Math.round(attributes.durationInMillis * (self._store.lastfm.scrobble_after / 100))); } private async updateNowPlayingSong(attributes: any) { @@ -155,7 +156,7 @@ export default class LastFMPlugin { } } - private async getPrimaryArtist (attributes: any) { + private async getPrimaryArtist(attributes: any) { const songId = attributes.playParams.catalogId || attributes.playParams.id if (!this._store.lastfm.enabledRemoveFeaturingArtists || !songId) return attributes.artistName; @@ -258,19 +259,21 @@ export default class LastFMPlugin { */ onPlaybackStateDidChange(attributes: object): void { this.updateNowPlayingSong(attributes) - this.scrobbleSong(attributes) + // this.scrobbleSong(attributes) } /** * Runs on song change * @param attributes Music Attributes */ - nowPlayingItemDidChangeLastFM(attributes: object): void { - if (!this._store.lastfm.filterLoop){ + lfmItemChange(attributes: any): void { + attributes.status = true + if (!this._store.lastfm.filterLoop) { this._lastfm.cachedNowPlayingAttributes = false; - this._lastfm.cachedAttributes = false} - this.updateNowPlayingSong(attributes) - this.scrobbleSong(attributes) + this._lastfm.cachedAttributes = false + } + this.updateNowPlayingSong(attributes) + this.scrobbleSong(attributes) } } From 4bed3ca783bba29ceba97091e3618a31b0c9b6ac Mon Sep 17 00:00:00 2001 From: Core <64542347+coredev-uk@users.noreply.github.com> Date: Thu, 17 Feb 2022 03:06:30 +0000 Subject: [PATCH 16/17] Revert "Merge branch 'develop' of https://github.com/ciderapp/Cider into develop" This reverts commit bd3a2b6172097dbbffaf8e5d7b477ae0a340c71e, reversing changes made to 0fb6802ff35ad9cfd03e3ce50f4de768cdba750c. --- 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 6001dc1a1e2fa07c1ecfc7d350fecfe89811a73d Mon Sep 17 00:00:00 2001 From: Core <64542347+coredev-uk@users.noreply.github.com> Date: Thu, 17 Feb 2022 03:07:58 +0000 Subject: [PATCH 17/17] and git can go in the bin too --- src/main/plugins/lastfm.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/plugins/lastfm.ts b/src/main/plugins/lastfm.ts index c5222203..a7433b8b 100644 --- a/src/main/plugins/lastfm.ts +++ b/src/main/plugins/lastfm.ts @@ -266,7 +266,7 @@ export default class LastFMPlugin { * Runs on song change * @param attributes Music Attributes */ - lfmItemChange(attributes: any): void { + nowPlayingItemDidChangeLastFM(attributes: any): void { attributes.status = true if (!this._store.lastfm.filterLoop) { this._lastfm.cachedNowPlayingAttributes = false;