diff --git a/src/renderer/views/components/settings-window.ejs b/src/renderer/views/components/settings-window.ejs index 6c784a72..013e1b72 100644 --- a/src/renderer/views/components/settings-window.ejs +++ b/src/renderer/views/components/settings-window.ejs @@ -994,18 +994,18 @@
(Authed: ${app.cfg.lastfm.auth_token})
`; - element.onclick = app.LastFMDeauthorize; - } - } - }, methods: { close() { this.$root.modals.settings = false @@ -1554,6 +1547,41 @@ }, reloadDiscordRPC() { ipcRenderer.send('reloadRPC') + }, + lfmDisconnect() { + this.$root.cfg.connectivity.lastfm.enabled = false; + this.$root.cfg.connectivity.lastfm.secrets.username = ""; + this.$root.cfg.connectivity.lastfm.secrets.key = ""; + ipcRenderer.send('lastfm:disconnect'); + }, + async lfmAuthorize() { + this.lastfmConnecting = true; + window.open(await ipcRenderer.invoke('lastfm:url')); + app.notyf.success(app.getLz('settings.notyf.connectivity.lastfmScrobble.connecting')); + + /* Just a timeout for the button */ + setTimeout(() => { + if (!this.$root.cfg.connectivity.lastfm.enabled) { + app.notyf.error(app.getLz('settings.notyf.connectivity.lastfmScrobble.connectError')); + console.warn('[lastfm:authorize] Last.fm authorization timed out.'); + this.lastfmConnecting = false; + } + }, 20000); + + ipcRenderer.once('lastfm:authenticated', (_e, session) => { + this.$root.cfg.connectivity.lastfm.secrets.username = session.username + this.$root.cfg.connectivity.lastfm.secrets.key = session.key + this.$root.cfg.connectivity.lastfm.enabled = true + this.lastfmConnecting = false; + app.notyf.success(app.getLz('settings.notyf.connectivity.lastfmScrobble.connectSuccess')); + }) + }, + filterChange(e) { + this.$root.cfg.connectivity.lastfm.filter_types[e.target.value] = e.target.checked; + }, + submitToken() { + const token = document.getElementById('lfmToken').value; + ipcRenderer.send('lastfm:auth', token); } } })