From 2827dfb36dc95dafe980ca75db8b677f30b92c34 Mon Sep 17 00:00:00 2001 From: Core <64542347+coredev-uk@users.noreply.github.com> Date: Wed, 15 Jun 2022 22:11:54 +0100 Subject: [PATCH] renderer side of lastfm updated --- src/i18n/README.md | 3 +++ src/i18n/en_US.json | 1 + src/i18n/source/en_US.json | 1 + src/main/plugins/lastfm.ts | 12 ++++++++++- src/renderer/views/pages/settings.ejs | 29 ++++++++------------------- 5 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/i18n/README.md b/src/i18n/README.md index a21bf49e..575da984 100644 --- a/src/i18n/README.md +++ b/src/i18n/README.md @@ -448,3 +448,6 @@ Update 10/06/2022 20:00 UTC * `settings.option.visual.purplePodcastPlaybackBar`: Added to `en_US` +Update 15/06/2022 20:00 UTC + +* `settings.notyf.connectivity.lastfmScrobble.connectError`: Added to `en_US` \ No newline at end of file diff --git a/src/i18n/en_US.json b/src/i18n/en_US.json index 692e86c2..06a09bdf 100644 --- a/src/i18n/en_US.json +++ b/src/i18n/en_US.json @@ -539,6 +539,7 @@ "settings.option.connectivity.lastfmScrobble.nowPlaying": "Enable Last.fm Now Playing", "settings.option.connectivity.lastfmScrobble.removeFeatured": "Remove featuring artists from song title (Last.fm)", "settings.option.connectivity.lastfmScrobble.filterLoop": "Filter looped track (Last.fm)", + "settings.notyf.connectivity.lastfmScrobble.connectError": "Last.fm Connection Timed Out", "settings.header.debug": "Debug", "settings.option.debug.copy_log": "Copy logs to clipboard", "settings.option.debug.openAppData": "Open Cider Folder", diff --git a/src/i18n/source/en_US.json b/src/i18n/source/en_US.json index e202b0bf..3a05d741 100644 --- a/src/i18n/source/en_US.json +++ b/src/i18n/source/en_US.json @@ -527,6 +527,7 @@ "settings.option.connectivity.lastfmScrobble.nowPlaying": "Enable Last.fm Now Playing", "settings.option.connectivity.lastfmScrobble.removeFeatured": "Remove featuring artists from song title (Last.fm)", "settings.option.connectivity.lastfmScrobble.filterLoop": "Filter looped track (Last.fm)", + "settings.notyf.connectivity.lastfmScrobble.connectError": "Last.fm Connection Timed Out", "settings.header.debug": "Debug", "settings.option.debug.copy_log": "Copy logs to clipboard", "settings.option.debug.openAppData": "Open Cider Folder", diff --git a/src/main/plugins/lastfm.ts b/src/main/plugins/lastfm.ts index c49b0b2d..4960781d 100644 --- a/src/main/plugins/lastfm.ts +++ b/src/main/plugins/lastfm.ts @@ -52,6 +52,15 @@ export default class lastfm { // console.debug('lastfm:auth', event, token) this.authenticateLastFM(token) }) + + this._utils.getIPCMain().on('lastfm:disconnect', (event: any) => { + this._lfm.setSessionCredentials(null, null); + this._authenticated = false; + this._utils.setStoreValue('lastfm.enabled', false) + this._utils.setStoreValue('lastfm.secrets.username', "") + this._utils.setStoreValue('lastfm.secrets.key', "") + console.debug('[lastfm] [disconnect] Disconnected') + }) } /** @@ -110,10 +119,11 @@ export default class lastfm { console.error(err); return; } - this._utils.setStoreValue("lastfm.secrets.token", token) this._utils.setStoreValue('lastfm.secrets.username', session.username); this._utils.setStoreValue('lastfm.secrets.key', session.key); + this._utils.setStoreValue('lastfm.enabled', true) this._authenticated = true; + console.debug(`[${lastfm.name}] [authenticate] Authenticated as ${session.username}`) }); } diff --git a/src/renderer/views/pages/settings.ejs b/src/renderer/views/pages/settings.ejs index 1cca7314..8e0d45aa 100644 --- a/src/renderer/views/pages/settings.ejs +++ b/src/renderer/views/pages/settings.ejs @@ -1063,8 +1063,11 @@ {{$root.getLz('settings.option.connectivity.lastfmScrobble')}}
(Authed: ${app.cfg.lastfm.auth_token})
`; - element.onclick = app.LastFMDeauthorize; - } - } }, methods: { windowBgStyleChange() { @@ -1474,14 +1469,10 @@ reloadDiscordRPC() { ipcRenderer.send('reloadRPC') }, - lfmDisconnect(event) { - ipcRenderer.invoke('setStoreValue', 'lastfm.enabled', false).catch((e) => console.error(e)); - ipcRenderer.invoke('setStoreValue', 'lastfm.secrets.session', {}).catch((e) => console.error(e)); - event.target.innerHTML = app.getLz('term.connect'); - event.target.onclick = this.lfmAuthorize; + lfmDisconnect() { + ipcRenderer.send('lastfm:disconnect'); }, async lfmAuthorize(event) { - console.debug("[lastfm:authorize] Token received.") window.open(await ipcRenderer.invoke('lastfm:url')); event.target.innerText = app.getLz('term.connecting') + '...'; @@ -1489,15 +1480,11 @@ setTimeout(() => { if (event.target.innerText === app.getLz('term.connecting') + '...') { event.target.innerText = app.getLz('term.connect'); + app.notyf.error(app.getLz('settings.notyf.connectivity.lastfmScrobble.connectError')); console.warn('[lastfm:authorize] Last.fm authorization timed out.'); } }, 20000); - ipcRenderer.on('lastfm:renderer-auth', function (event, session) { - element.innerHTML = `${app.getLz('term.disconnect')}\n(${app.getLz('term.authed')}: ${session.username})
`; - element.onclick = this.lfmDisconnect; - }); - }, } })