Moved discord and lastfm config to connectivity

This commit is contained in:
Core 2022-06-22 23:34:54 +01:00
parent e3225e9ad5
commit 2abefe21a0
No known key found for this signature in database
GPG key ID: FE9BF1B547F8F3C6
4 changed files with 66 additions and 64 deletions

View file

@ -12,15 +12,6 @@ export class Store {
}, },
"general": { "general": {
"close_button_hide": false, "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 "language": "en_US", // electron.app.getLocale().replace('-', '_') this can be used in future
"playbackNotifications": true, "playbackNotifications": true,
"resumeOnStartupBehavior": "local", "resumeOnStartupBehavior": "local",
@ -114,6 +105,27 @@ export class Store {
}, },
"showLovedTracksInline": true "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": { "home": {
"followedArtists": [], "followedArtists": [],
"favoriteItems": [] "favoriteItems": []
@ -219,16 +231,6 @@ export class Store {
"enable_qq": false, "enable_qq": false,
"enable_yt": false, "enable_yt": false,
}, },
"lastfm": {
"enabled": false,
"scrobble_after": 50,
"filter_loop": false,
"secrets": {
"username": "",
"key": ""
}
},
"advanced": { "advanced": {
"AudioContext": false, "AudioContext": false,
"experiments": [], "experiments": [],
@ -246,13 +248,13 @@ export class Store {
} }
private migrations: any = { private migrations: any = {
'>=1.4.3': (store: ElectronStore) => { '>=1.4.3': (store: ElectronStore) => {
if (typeof store.get('general.discordrpc') == 'number' || typeof store.get('general.discordrpc') == 'string') { if (typeof store.get('connectivity.discord_rpc') == 'number' || typeof store.get('connectivity.discord_rpc') == 'string') {
store.delete('general.discordrpc'); store.delete('connectivity.discord_rpc');
} }
}, },
} }
private schema: ElectronStore.Schema<any> = { private schema: ElectronStore.Schema<any> = {
"general.discordrpc": { "connectivity.discord_rpc": {
type: 'object' type: 'object'
}, },
} }

View file

@ -74,7 +74,7 @@ export default class DiscordRPC {
console.log(`[DiscordRPC][reload] Reloading DiscordRPC.`); console.log(`[DiscordRPC][reload] Reloading DiscordRPC.`);
this._client.destroy() 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(() => { .then(() => {
this.ready = true this.ready = true
this._utils.getWindow().webContents.send("rpcReloaded", this._client.user) this._utils.getWindow().webContents.send("rpcReloaded", this._client.user)
@ -125,7 +125,7 @@ export default class DiscordRPC {
* @private * @private
*/ */
private connect() { private connect() {
if (!this._utils.getStoreValue("general.discordrpc.enabled")) { if (!this._utils.getStoreValue("connectivity.discord_rpc.enabled")) {
return; return;
} }
@ -143,7 +143,7 @@ export default class DiscordRPC {
}) })
// Login to Discord // 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(() => { .then(() => {
this.ready = true this.ready = true
}) })
@ -161,8 +161,8 @@ export default class DiscordRPC {
// Check if show buttons is (true) or (false) // Check if show buttons is (true) or (false)
let activity: Object = { let activity: Object = {
details: this._utils.getStoreValue("general.discordrpc.details_format"), details: this._utils.getStoreValue("connectivity.discord_rpc.details_format"),
state: this._utils.getStoreValue("general.discordrpc.state_format"), state: this._utils.getStoreValue("connectivity.discord_rpc.state_format"),
largeImageKey: attributes?.artwork?.url?.replace('{w}', '1024').replace('{h}', '1024'), largeImageKey: attributes?.artwork?.url?.replace('{w}', '1024').replace('{h}', '1024'),
largeImageText: attributes.albumName, largeImageText: attributes.albumName,
instance: false // Whether the activity is in a game session instance: false // Whether the activity is in a game session
@ -177,7 +177,7 @@ export default class DiscordRPC {
} }
// Set the activity // 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() this._client.clearActivity()
} else if (activity && this._activityCache !== activity) { } else if (activity && this._activityCache !== activity) {
this._client.setActivity(activity) this._client.setActivity(activity)
@ -191,7 +191,7 @@ export default class DiscordRPC {
private filterActivity(activity: any, attributes: any): Object { private filterActivity(activity: any, attributes: any): Object {
// Add the buttons if people want them // 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 = [ activity.buttons = [
{label: 'Listen on Cider', url: attributes.url.cider}, {label: 'Listen on Cider', url: attributes.url.cider},
{label: 'View on Apple Music', url: attributes.url.appleMusic} {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 // 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.startTimestamp = Date.now() - (attributes?.durationInMillis - attributes?.remainingTime)
activity.endTimestamp = attributes.endTime activity.endTimestamp = attributes.endTime
} }
// If the user wants to keep the activity when paused // 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.smallImageKey = attributes.status ? 'play' : 'pause';
activity.smallImageText = attributes.status ? 'Playing' : 'Paused'; activity.smallImageText = attributes.status ? 'Playing' : 'Paused';
} }

View file

@ -54,7 +54,7 @@ export default class lastfm {
}) })
this._utils.getIPCMain().on('lastfm:nowPlayingChange', (event: any, attributes: any) => { 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) this.onNowPlayingItemDidChange(attributes)
}) })
} }
@ -96,8 +96,8 @@ export default class lastfm {
'secret': api.secret, 'secret': api.secret,
}); });
if (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("lastfm.secrets.username"), this._utils.getStoreValue("lastfm.secrets.key")); this._lfm.setSessionCredentials(this._utils.getStoreValue("connectivity.lastfm.secrets.username"), this._utils.getStoreValue("connectivity.lastfm.secrets.key"));
this._authenticated = true; this._authenticated = true;
} else { } else {
this.authenticateLastFM(token) this.authenticateLastFM(token)
@ -170,7 +170,7 @@ export default class lastfm {
* @private * @private
*/ */
private scrobbleTrack(attributes: any): void { 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) { if (this._scrobbleDelay) {
clearTimeout(this._scrobbleDelay); clearTimeout(this._scrobbleDelay);
@ -204,11 +204,11 @@ export default class lastfm {
this._scrobbleCache = scrobble 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 { 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 = { const nowPlaying = {
'artist': attributes.lfmTrack.artist.name, 'artist': attributes.lfmTrack.artist.name,

View file

@ -967,18 +967,18 @@
</div> </div>
<div class="md-option-segment md-option-segment_auto"> <div class="md-option-segment md-option-segment_auto">
<label> <label>
<input type="checkbox" v-model="app.cfg.general.discordrpc.enabled" switch/> <input type="checkbox" v-model="app.cfg.connectivity.discord_rpc.enabled" switch/>
</label> </label>
</div> </div>
</div> </div>
<div class="md-option-line" v-show="app.cfg.general.discordrpc.enabled != false"> <div class="md-option-line" v-show="app.cfg.connectivity.discord_rpc.enabled != false">
<div class="md-option-segment"> <div class="md-option-segment">
{{$root.getLz('settings.option.connectivity.discordRPC.clientName')}} {{$root.getLz('settings.option.connectivity.discordRPC.clientName')}}
</div> </div>
<div class="md-option-segment md-option-segment_auto"> <div class="md-option-segment md-option-segment_auto">
<label> <label>
<select class="md-select" v-model="app.cfg.general.discordrpc.client"> <select class="md-select" v-model="app.cfg.connectivity.discord_rpc.client">
<option value="Cider">{{$root.getLz('app.name')}}</option> <option value="Cider">{{$root.getLz('app.name')}}</option>
<option value="AppleMusic">{{$root.getLz('term.appleMusic')}} <option value="AppleMusic">{{$root.getLz('term.appleMusic')}}
</option> </option>
@ -987,40 +987,40 @@
</div> </div>
</div> </div>
<div class="md-option-line" v-show="app.cfg.general.discordrpc.enabled != false"> <div class="md-option-line" v-show="app.cfg.connectivity.discord_rpc.enabled != false">
<div class="md-option-segment"> <div class="md-option-segment">
{{$root.getLz('settings.option.connectivity.discordRPC.clearOnPause')}} {{$root.getLz('settings.option.connectivity.discordRPC.clearOnPause')}}
</div> </div>
<div class="md-option-segment md-option-segment_auto"> <div class="md-option-segment md-option-segment_auto">
<label> <label>
<input type="checkbox" v-model="app.cfg.general.discordrpc.clear_on_pause" switch/> <input type="checkbox" v-model="app.cfg.connectivity.discord_rpc.clear_on_pause" switch/>
</label> </label>
</div> </div>
</div> </div>
<div class="md-option-line" v-show="app.cfg.general.discordrpc.enabled != false"> <div class="md-option-line" v-show="app.cfg.connectivity.discord_rpc.enabled != false">
<div class="md-option-segment"> <div class="md-option-segment">
{{$root.getLz('settings.option.connectivity.discordRPC.hideButtons')}} {{$root.getLz('settings.option.connectivity.discordRPC.hideButtons')}}
</div> </div>
<div class="md-option-segment md-option-segment_auto"> <div class="md-option-segment md-option-segment_auto">
<label> <label>
<input type="checkbox" v-model="app.cfg.general.discordrpc.hide_buttons" switch/> <input type="checkbox" v-model="app.cfg.connectivity.discord_rpc.hide_buttons" switch/>
</label> </label>
</div> </div>
</div> </div>
<div class="md-option-line" v-show="app.cfg.general.discordrpc.enabled != false"> <div class="md-option-line" v-show="app.cfg.connectivity.discord_rpc.enabled != false">
<div class="md-option-segment"> <div class="md-option-segment">
{{$root.getLz('settings.option.connectivity.discordRPC.hideTimestamp')}} {{$root.getLz('settings.option.connectivity.discordRPC.hideTimestamp')}}
</div> </div>
<div class="md-option-segment md-option-segment_auto"> <div class="md-option-segment md-option-segment_auto">
<label> <label>
<input type="checkbox" v-model="app.cfg.general.discordrpc.hide_timestamp" switch/> <input type="checkbox" v-model="app.cfg.connectivity.discord_rpc.hide_timestamp" switch/>
</label> </label>
</div> </div>
</div> </div>
<div class="md-option-line" v-show="app.cfg.general.discordrpc.enabled != false"> <div class="md-option-line" v-show="app.cfg.connectivity.discord_rpc.enabled != false">
<div class="md-option-segment"> <div class="md-option-segment">
{{$root.getLz('settings.option.connectivity.discordRPC.detailsFormat')}}<br/> {{$root.getLz('settings.option.connectivity.discordRPC.detailsFormat')}}<br/>
<small>{{$root.getLz('term.variables')}}: {artist}, {composer}, {title}, {album}, <small>{{$root.getLz('term.variables')}}: {artist}, {composer}, {title}, {album},
@ -1028,12 +1028,12 @@
</div> </div>
<div class="md-option-segment md-option-segment_auto"> <div class="md-option-segment md-option-segment_auto">
<label> <label>
<input type="text" v-model="app.cfg.general.discordrpc.details_format"/> <input type="text" v-model="app.cfg.connectivity.discord_rpc.details_format"/>
</label> </label>
</div> </div>
</div> </div>
<div class="md-option-line" v-show="app.cfg.general.discordrpc.enabled != false"> <div class="md-option-line" v-show="app.cfg.connectivity.discord_rpc.enabled != false">
<div class="md-option-segment"> <div class="md-option-segment">
{{$root.getLz('settings.option.connectivity.discordRPC.stateFormat')}} {{$root.getLz('settings.option.connectivity.discordRPC.stateFormat')}}
<small>{{$root.getLz('term.variables')}}: {artist}, {composer}, {title}, {album}, <small>{{$root.getLz('term.variables')}}: {artist}, {composer}, {title}, {album},
@ -1041,12 +1041,12 @@
</div> </div>
<div class="md-option-segment md-option-segment_auto"> <div class="md-option-segment md-option-segment_auto">
<label> <label>
<input type="text" v-model="app.cfg.general.discordrpc.state_format"/> <input type="text" v-model="app.cfg.connectivity.discord_rpc.state_format"/>
</label> </label>
</div> </div>
</div> </div>
<div class="md-option-line" v-show="app.cfg.general.discordrpc.enabled != false"> <div class="md-option-line" v-show="app.cfg.connectivity.discord_rpc.enabled != false">
<div class="md-option-segment"> <div class="md-option-segment">
{{$root.getLz('settings.option.connectivity.discordRPC.reload')}} {{$root.getLz('settings.option.connectivity.discordRPC.reload')}}
</div> </div>
@ -1063,30 +1063,30 @@
{{$root.getLz('settings.option.connectivity.lastfmScrobble')}} {{$root.getLz('settings.option.connectivity.lastfmScrobble')}}
</div> </div>
<div class="md-option-segment md-option-segment_auto"> <div class="md-option-segment md-option-segment_auto">
<button class="md-btn" id="lfmConnect" @click="app.cfg.lastfm.enabled ? lfmDisconnect() : lfmAuthorize()"> <button class="md-btn" id="lfmConnect" @click="app.cfg.connectivity.lastfm.enabled ? lfmDisconnect() : lfmAuthorize()">
{{$root.getLz(`term.${$root.cfg.lastfm.enabled ? "disconnect" : "connect"}`)}}<br> {{$root.getLz(`term.${$root.cfg.connectivity.lastfm.enabled ? "disconnect" : "connect"}`)}}<br>
<small>{{app.cfg.lastfm.enabled ? `${$root.getLz('term.authed')}: ${$root.cfg.lastfm.secrets.username}` : '' }}</small> <small>{{app.cfg.connectivity.lastfm.enabled ? `${$root.getLz('term.authed')}: ${$root.cfg.connectivity.lastfm.secrets.username}` : '' }}</small>
</button> </button>
</div> </div>
</div> </div>
<div class="md-option-line" v-show="app.cfg.lastfm.enabled"> <div class="md-option-line" v-show="app.cfg.connectivity.lastfm.enabled">
<div class="md-option-segment"> <div class="md-option-segment">
{{$root.getLz('settings.option.connectivity.lastfmScrobble.delay')}} {{$root.getLz('settings.option.connectivity.lastfmScrobble.delay')}}
</div> </div>
<div class="md-option-segment md-option-segment_auto"> <div class="md-option-segment md-option-segment_auto">
<label> <label>
<input type="number" min="50" max="100" v-model="app.cfg.lastfm.scrobble_after"/> <input type="number" min="50" max="100" v-model="app.cfg.connectivity.lastfm.scrobble_after"/>
</label> </label>
</div> </div>
</div> </div>
<div class="md-option-line" v-show="app.cfg.lastfm.enabled"> <div class="md-option-line" v-show="app.cfg.connectivity.lastfm.enabled">
<div class="md-option-segment"> <div class="md-option-segment">
{{$root.getLz('settings.option.connectivity.lastfmScrobble.filterLoop')}} {{$root.getLz('settings.option.connectivity.lastfmScrobble.filterLoop')}}
<small>{{$root.getLz('settings.option.connectivity.lastfmScrobble.filterLoop.description')}}</small> <small>{{$root.getLz('settings.option.connectivity.lastfmScrobble.filterLoop.description')}}</small>
</div> </div>
<div class="md-option-segment md-option-segment_auto"> <div class="md-option-segment md-option-segment_auto">
<label> <label>
<input type="checkbox" v-model="app.cfg.lastfm.filter_loop" switch/> <input type="checkbox" v-model="app.cfg.connectivity.lastfm.filter_loop" switch/>
</label> </label>
</div> </div>
</div> </div>
@ -1493,9 +1493,9 @@
ipcRenderer.send('reloadRPC') ipcRenderer.send('reloadRPC')
}, },
lfmDisconnect() { lfmDisconnect() {
app.cfg.lastfm.enabled = false; app.cfg.connectivity.lastfm.enabled = false;
app.cfg.lastfm.secrets.username = ""; app.cfg.connectivity.lastfm.secrets.username = "";
app.cfg.lastfm.secrets.key = ""; app.cfg.connectivity.lastfm.secrets.key = "";
ipcRenderer.send('lastfm:disconnect'); ipcRenderer.send('lastfm:disconnect');
}, },
async lfmAuthorize() { async lfmAuthorize() {
@ -1511,9 +1511,9 @@
}, 20000); }, 20000);
ipcRenderer.once('lastfm:authenticated', (_e, session) => { ipcRenderer.once('lastfm:authenticated', (_e, session) => {
app.cfg.lastfm.secrets.username = session.username app.cfg.connectivity.lastfm.secrets.username = session.username
app.cfg.lastfm.secrets.key = session.key app.cfg.connectivity.lastfm.secrets.key = session.key
app.cfg.lastfm.enabled = true app.cfg.connectivity.lastfm.enabled = true
app.notyf.success(app.getLz('settings.notyf.connectivity.lastfmScrobble.connectSuccess')); app.notyf.success(app.getLz('settings.notyf.connectivity.lastfmScrobble.connectSuccess'));
}) })