diff --git a/src/main/base/store.ts b/src/main/base/store.ts index 9bfb548f..7556e44e 100644 --- a/src/main/base/store.ts +++ b/src/main/base/store.ts @@ -12,15 +12,6 @@ export class Store { }, "general": { "close_button_hide": false, - "discordrpc": { - "enabled": true, - "client": "Cider", - "clear_on_pause": true, - "hide_buttons": false, - "hide_timestamp": false, - "state_format": "by {artist}", - "details_format": "{title}", - }, "language": "en_US", // electron.app.getLocale().replace('-', '_') this can be used in future "playbackNotifications": true, "resumeOnStartupBehavior": "local", @@ -114,6 +105,27 @@ export class Store { }, "showLovedTracksInline": true }, + "connectivity": { + "discord_rpc": { + "enabled": true, + "client": "Cider", + "clear_on_pause": true, + "hide_buttons": false, + "hide_timestamp": false, + "state_format": "by {artist}", + "details_format": "{title}", + }, + "lastfm": { + "enabled": false, + "scrobble_after": 50, + "filter_loop": false, + "secrets": { + "username": "", + "key": "" + } + + }, + }, "home": { "followedArtists": [], "favoriteItems": [] @@ -219,16 +231,6 @@ export class Store { "enable_qq": false, "enable_yt": false, }, - "lastfm": { - "enabled": false, - "scrobble_after": 50, - "filter_loop": false, - "secrets": { - "username": "", - "key": "" - } - - }, "advanced": { "AudioContext": false, "experiments": [], @@ -246,13 +248,13 @@ export class Store { } private migrations: any = { '>=1.4.3': (store: ElectronStore) => { - if (typeof store.get('general.discordrpc') == 'number' || typeof store.get('general.discordrpc') == 'string') { - store.delete('general.discordrpc'); + if (typeof store.get('connectivity.discord_rpc') == 'number' || typeof store.get('connectivity.discord_rpc') == 'string') { + store.delete('connectivity.discord_rpc'); } }, } private schema: ElectronStore.Schema = { - "general.discordrpc": { + "connectivity.discord_rpc": { type: 'object' }, } diff --git a/src/main/plugins/discordrpc.ts b/src/main/plugins/discordrpc.ts index 9cc7baf1..cdd78144 100644 --- a/src/main/plugins/discordrpc.ts +++ b/src/main/plugins/discordrpc.ts @@ -74,7 +74,7 @@ export default class DiscordRPC { console.log(`[DiscordRPC][reload] Reloading DiscordRPC.`); this._client.destroy() - this._client.endlessLogin({clientId: this._utils.getStoreValue("general.discordrpc.client") === "Cider" ? '911790844204437504' : '886578863147192350'}) + this._client.endlessLogin({clientId: this._utils.getStoreValue("connectivity.discord_rpc.client") === "Cider" ? '911790844204437504' : '886578863147192350'}) .then(() => { this.ready = true this._utils.getWindow().webContents.send("rpcReloaded", this._client.user) @@ -125,7 +125,7 @@ export default class DiscordRPC { * @private */ private connect() { - if (!this._utils.getStoreValue("general.discordrpc.enabled")) { + if (!this._utils.getStoreValue("connectivity.discord_rpc.enabled")) { return; } @@ -143,7 +143,7 @@ export default class DiscordRPC { }) // Login to Discord - this._client.endlessLogin({clientId: this._utils.getStoreValue("general.discordrpc.client") === "Cider" ? '911790844204437504' : '886578863147192350'}) + this._client.endlessLogin({clientId: this._utils.getStoreValue("connectivity.discord_rpc.client") === "Cider" ? '911790844204437504' : '886578863147192350'}) .then(() => { this.ready = true }) @@ -161,8 +161,8 @@ export default class DiscordRPC { // Check if show buttons is (true) or (false) let activity: Object = { - details: this._utils.getStoreValue("general.discordrpc.details_format"), - state: this._utils.getStoreValue("general.discordrpc.state_format"), + details: this._utils.getStoreValue("connectivity.discord_rpc.details_format"), + state: this._utils.getStoreValue("connectivity.discord_rpc.state_format"), largeImageKey: attributes?.artwork?.url?.replace('{w}', '1024').replace('{h}', '1024'), largeImageText: attributes.albumName, instance: false // Whether the activity is in a game session @@ -177,7 +177,7 @@ export default class DiscordRPC { } // Set the activity - if (!attributes.status && this._utils.getStoreValue("general.discordrpc.clear_on_pause")) { + if (!attributes.status && this._utils.getStoreValue("connectivity.discord_rpc.clear_on_pause")) { this._client.clearActivity() } else if (activity && this._activityCache !== activity) { this._client.setActivity(activity) @@ -191,7 +191,7 @@ export default class DiscordRPC { private filterActivity(activity: any, attributes: any): Object { // Add the buttons if people want them - if (!this._utils.getStoreValue("general.discordrpc.hide_buttons")) { + if (!this._utils.getStoreValue("connectivity.discord_rpc.hide_buttons")) { activity.buttons = [ {label: 'Listen on Cider', url: attributes.url.cider}, {label: 'View on Apple Music', url: attributes.url.appleMusic} @@ -199,13 +199,13 @@ export default class DiscordRPC { } // Add the timestamp if its playing and people want them - if (!this._utils.getStoreValue("general.discordrpc.hide_timestamp") && attributes.status) { + if (!this._utils.getStoreValue("connectivity.discord_rpc.hide_timestamp") && attributes.status) { activity.startTimestamp = Date.now() - (attributes?.durationInMillis - attributes?.remainingTime) activity.endTimestamp = attributes.endTime } // If the user wants to keep the activity when paused - if (!this._utils.getStoreValue("general.discordrpc.clear_on_pause")) { + if (!this._utils.getStoreValue("connectivity.discord_rpc.clear_on_pause")) { activity.smallImageKey = attributes.status ? 'play' : 'pause'; activity.smallImageText = attributes.status ? 'Playing' : 'Paused'; } diff --git a/src/main/plugins/lastfm.ts b/src/main/plugins/lastfm.ts index bf0b88e5..c25ba860 100644 --- a/src/main/plugins/lastfm.ts +++ b/src/main/plugins/lastfm.ts @@ -54,7 +54,7 @@ export default class lastfm { }) this._utils.getIPCMain().on('lastfm:nowPlayingChange', (event: any, attributes: any) => { - if (this._utils.getStoreValue("lastfm.filter_loop")) return; + if (this._utils.getStoreValue("connectivity.lastfm.filter_loop")) return; this.onNowPlayingItemDidChange(attributes) }) } @@ -96,8 +96,8 @@ export default class lastfm { 'secret': api.secret, }); - if (this._utils.getStoreValue("lastfm.secrets.username") && this._utils.getStoreValue("lastfm.secrets.key")) { - this._lfm.setSessionCredentials(this._utils.getStoreValue("lastfm.secrets.username"), this._utils.getStoreValue("lastfm.secrets.key")); + if (this._utils.getStoreValue("connectivity.lastfm.secrets.username") && this._utils.getStoreValue("connectivity.lastfm.secrets.key")) { + this._lfm.setSessionCredentials(this._utils.getStoreValue("connectivity.lastfm.secrets.username"), this._utils.getStoreValue("connectivity.lastfm.secrets.key")); this._authenticated = true; } else { this.authenticateLastFM(token) @@ -170,7 +170,7 @@ export default class lastfm { * @private */ private scrobbleTrack(attributes: any): void { - if (!this._authenticated || !attributes || (this._utils.getStoreValue("lastfm.filter_loop") && this._scrobbleCache.track === attributes.lfmTrack.name)) return; + if (!this._authenticated || !attributes || (this._utils.getStoreValue("connectivity.lastfm.filter_loop") && this._scrobbleCache.track === attributes.lfmTrack.name)) return; if (this._scrobbleDelay) { clearTimeout(this._scrobbleDelay); @@ -204,11 +204,11 @@ export default class lastfm { this._scrobbleCache = scrobble } }); - }, Math.round(attributes.durationInMillis * Math.min((this._utils.getStoreValue("lastfm.scrobble_after") / 100), 0.8))) + }, Math.round(attributes.durationInMillis * Math.min((this._utils.getStoreValue("connectivity.lastfm.scrobble_after") / 100), 0.8))) } private updateNowPlayingTrack(attributes: any): void { - if (!this._authenticated || !attributes || (this._utils.getStoreValue("lastfm.filter_loop") && this._nowPlayingCache.track === attributes.lfmTrack.name)) return; + if (!this._authenticated || !attributes || (this._utils.getStoreValue("connectivity.lastfm.filter_loop") && this._nowPlayingCache.track === attributes.lfmTrack.name)) return; const nowPlaying = { 'artist': attributes.lfmTrack.artist.name, diff --git a/src/renderer/views/pages/settings.ejs b/src/renderer/views/pages/settings.ejs index 176ed381..523193c6 100644 --- a/src/renderer/views/pages/settings.ejs +++ b/src/renderer/views/pages/settings.ejs @@ -967,18 +967,18 @@
-
+
{{$root.getLz('settings.option.connectivity.discordRPC.clientName')}}
-
+
{{$root.getLz('settings.option.connectivity.discordRPC.clearOnPause')}}
-
+
{{$root.getLz('settings.option.connectivity.discordRPC.hideButtons')}}
-
+
{{$root.getLz('settings.option.connectivity.discordRPC.hideTimestamp')}}
-
+
{{$root.getLz('settings.option.connectivity.discordRPC.detailsFormat')}}
{{$root.getLz('term.variables')}}: {artist}, {composer}, {title}, {album}, @@ -1028,12 +1028,12 @@
-
+
{{$root.getLz('settings.option.connectivity.discordRPC.stateFormat')}} {{$root.getLz('term.variables')}}: {artist}, {composer}, {title}, {album}, @@ -1041,12 +1041,12 @@
-
+
{{$root.getLz('settings.option.connectivity.discordRPC.reload')}}
@@ -1063,30 +1063,30 @@ {{$root.getLz('settings.option.connectivity.lastfmScrobble')}}
-
-
+
{{$root.getLz('settings.option.connectivity.lastfmScrobble.delay')}}
-
+
{{$root.getLz('settings.option.connectivity.lastfmScrobble.filterLoop')}} {{$root.getLz('settings.option.connectivity.lastfmScrobble.filterLoop.description')}}
@@ -1493,9 +1493,9 @@ ipcRenderer.send('reloadRPC') }, lfmDisconnect() { - app.cfg.lastfm.enabled = false; - app.cfg.lastfm.secrets.username = ""; - app.cfg.lastfm.secrets.key = ""; + app.cfg.connectivity.lastfm.enabled = false; + app.cfg.connectivity.lastfm.secrets.username = ""; + app.cfg.connectivity.lastfm.secrets.key = ""; ipcRenderer.send('lastfm:disconnect'); }, async lfmAuthorize() { @@ -1511,9 +1511,9 @@ }, 20000); ipcRenderer.once('lastfm:authenticated', (_e, session) => { - app.cfg.lastfm.secrets.username = session.username - app.cfg.lastfm.secrets.key = session.key - app.cfg.lastfm.enabled = true + app.cfg.connectivity.lastfm.secrets.username = session.username + app.cfg.connectivity.lastfm.secrets.key = session.key + app.cfg.connectivity.lastfm.enabled = true app.notyf.success(app.getLz('settings.notyf.connectivity.lastfmScrobble.connectSuccess')); })