From a9f5f376d0ccf796ac1e0d22306556f6833e6bba Mon Sep 17 00:00:00 2001 From: Noah <95990495+xn-oah@users.noreply.github.com> Date: Sun, 13 Feb 2022 15:59:53 -0600 Subject: [PATCH 1/2] fixed clientID --- plugins/discord/back.js | 49 ++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/plugins/discord/back.js b/plugins/discord/back.js index 0e1b72fa..c4c37a48 100644 --- a/plugins/discord/back.js +++ b/plugins/discord/back.js @@ -5,7 +5,7 @@ const { dialog, app } = require("electron"); const registerCallback = require("../../providers/song-info"); // Application ID registered by @xn-oah -const clientId = "937234785716285471"; +const clientId = "942539762227630162"; /** * @typedef {Object} Info @@ -30,14 +30,13 @@ const resetInfo = () => { info.ready = false; clearTimeout(clearActivity); if (dev()) console.log("discord disconnected"); - refreshCallbacks.forEach(cb => cb()); + refreshCallbacks.forEach((cb) => cb()); }; let window; const connect = (showErr = false) => { if (info.rpc) { - if (dev()) - console.log('Attempted to connect with active RPC object'); + if (dev()) console.log("Attempted to connect with active RPC object"); return; } @@ -48,19 +47,24 @@ const connect = (showErr = false) => { info.rpc.once("connected", () => { if (dev()) console.log("discord connected"); - refreshCallbacks.forEach(cb => cb()); + refreshCallbacks.forEach((cb) => cb()); }); info.rpc.once("ready", () => { info.ready = true; - if (info.lastSongInfo) updateActivity(info.lastSongInfo) + if (info.lastSongInfo) updateActivity(info.lastSongInfo); }); info.rpc.once("disconnected", resetInfo); // Startup the rpc client - info.rpc.login({ clientId }).catch(err => { + info.rpc.login({ clientId }).catch((err) => { resetInfo(); if (dev()) console.error(err); - if (showErr) dialog.showMessageBox(window, { title: 'Connection failed', message: err.message || String(err), type: 'error' }); + if (showErr) + dialog.showMessageBox(window, { + title: "Connection failed", + message: err.message || String(err), + type: "error", + }); }); }; @@ -70,12 +74,15 @@ let clearActivity; */ let updateActivity; -module.exports = (win, { activityTimoutEnabled, activityTimoutTime, listenAlong }) => { +module.exports = ( + win, + { activityTimoutEnabled, activityTimoutTime, listenAlong } +) => { window = win; // We get multiple events // Next song: PAUSE(n), PAUSE(n+1), PLAY(n+1) // Skip time: PAUSE(N), PLAY(N) - updateActivity = songInfo => { + updateActivity = (songInfo) => { if (songInfo.title.length === 0 && songInfo.artist.length === 0) { return; } @@ -91,7 +98,11 @@ module.exports = (win, { activityTimoutEnabled, activityTimoutTime, listenAlong } // clear directly if timeout is 0 - if (songInfo.isPaused && activityTimoutEnabled && activityTimoutTime === 0) { + if ( + songInfo.isPaused && + activityTimoutEnabled && + activityTimoutTime === 0 + ) { info.rpc.clearActivity().catch(console.error); return; } @@ -105,9 +116,9 @@ module.exports = (win, { activityTimoutEnabled, activityTimoutTime, listenAlong state: songInfo.artist, largeImageKey: songInfo.imageSrc, largeImageText: songInfo.album, - buttons: listenAlong ? [ - { label: "Listen Along", url: songInfo.url }, - ] : undefined, + buttons: listenAlong + ? [{ label: "Listen Along", url: songInfo.url }] + : undefined, }; if (songInfo.isPaused) { @@ -116,13 +127,15 @@ module.exports = (win, { activityTimoutEnabled, activityTimoutTime, listenAlong activityInfo.smallImageText = "Paused"; // Set start the timer so the activity gets cleared after a while if enabled if (activityTimoutEnabled) - clearActivity = setTimeout(() => info.rpc.clearActivity().catch(console.error), activityTimoutTime ?? 10000); + clearActivity = setTimeout( + () => info.rpc.clearActivity().catch(console.error), + activityTimoutTime ?? 10000 + ); } else { // Add the start and end time of the song const songStartTime = Date.now() - songInfo.elapsedSeconds * 1000; activityInfo.startTimestamp = songStartTime; - activityInfo.endTimestamp = - songStartTime + songInfo.songDuration * 1000; + activityInfo.endTimestamp = songStartTime + songInfo.songDuration * 1000; } info.rpc.setActivity(activityInfo).catch(console.error); @@ -133,7 +146,7 @@ module.exports = (win, { activityTimoutEnabled, activityTimoutTime, listenAlong registerCallback(updateActivity); connect(); }); - app.on('window-all-closed', module.exports.clear) + app.on("window-all-closed", module.exports.clear); }; module.exports.clear = () => { From 6aa789fb6a6723c0aba9f4b6fc991fd417640b08 Mon Sep 17 00:00:00 2001 From: Noah <95990495+xn-oah@users.noreply.github.com> Date: Sun, 13 Feb 2022 16:02:50 -0600 Subject: [PATCH 2/2] fixed clientID --- plugins/discord/back.js | 47 +++++++++++++++-------------------------- 1 file changed, 17 insertions(+), 30 deletions(-) diff --git a/plugins/discord/back.js b/plugins/discord/back.js index c4c37a48..da25b1ef 100644 --- a/plugins/discord/back.js +++ b/plugins/discord/back.js @@ -30,13 +30,14 @@ const resetInfo = () => { info.ready = false; clearTimeout(clearActivity); if (dev()) console.log("discord disconnected"); - refreshCallbacks.forEach((cb) => cb()); + refreshCallbacks.forEach(cb => cb()); }; let window; const connect = (showErr = false) => { if (info.rpc) { - if (dev()) console.log("Attempted to connect with active RPC object"); + if (dev()) + console.log('Attempted to connect with active RPC object'); return; } @@ -47,24 +48,19 @@ const connect = (showErr = false) => { info.rpc.once("connected", () => { if (dev()) console.log("discord connected"); - refreshCallbacks.forEach((cb) => cb()); + refreshCallbacks.forEach(cb => cb()); }); info.rpc.once("ready", () => { info.ready = true; - if (info.lastSongInfo) updateActivity(info.lastSongInfo); + if (info.lastSongInfo) updateActivity(info.lastSongInfo) }); info.rpc.once("disconnected", resetInfo); // Startup the rpc client - info.rpc.login({ clientId }).catch((err) => { + info.rpc.login({ clientId }).catch(err => { resetInfo(); if (dev()) console.error(err); - if (showErr) - dialog.showMessageBox(window, { - title: "Connection failed", - message: err.message || String(err), - type: "error", - }); + if (showErr) dialog.showMessageBox(window, { title: 'Connection failed', message: err.message || String(err), type: 'error' }); }); }; @@ -74,15 +70,12 @@ let clearActivity; */ let updateActivity; -module.exports = ( - win, - { activityTimoutEnabled, activityTimoutTime, listenAlong } -) => { +module.exports = (win, { activityTimoutEnabled, activityTimoutTime, listenAlong }) => { window = win; // We get multiple events // Next song: PAUSE(n), PAUSE(n+1), PLAY(n+1) // Skip time: PAUSE(N), PLAY(N) - updateActivity = (songInfo) => { + updateActivity = songInfo => { if (songInfo.title.length === 0 && songInfo.artist.length === 0) { return; } @@ -98,11 +91,7 @@ module.exports = ( } // clear directly if timeout is 0 - if ( - songInfo.isPaused && - activityTimoutEnabled && - activityTimoutTime === 0 - ) { + if (songInfo.isPaused && activityTimoutEnabled && activityTimoutTime === 0) { info.rpc.clearActivity().catch(console.error); return; } @@ -116,9 +105,9 @@ module.exports = ( state: songInfo.artist, largeImageKey: songInfo.imageSrc, largeImageText: songInfo.album, - buttons: listenAlong - ? [{ label: "Listen Along", url: songInfo.url }] - : undefined, + buttons: listenAlong ? [ + { label: "Listen Along", url: songInfo.url }, + ] : undefined, }; if (songInfo.isPaused) { @@ -127,15 +116,13 @@ module.exports = ( activityInfo.smallImageText = "Paused"; // Set start the timer so the activity gets cleared after a while if enabled if (activityTimoutEnabled) - clearActivity = setTimeout( - () => info.rpc.clearActivity().catch(console.error), - activityTimoutTime ?? 10000 - ); + clearActivity = setTimeout(() => info.rpc.clearActivity().catch(console.error), activityTimoutTime ?? 10000); } else { // Add the start and end time of the song const songStartTime = Date.now() - songInfo.elapsedSeconds * 1000; activityInfo.startTimestamp = songStartTime; - activityInfo.endTimestamp = songStartTime + songInfo.songDuration * 1000; + activityInfo.endTimestamp = + songStartTime + songInfo.songDuration * 1000; } info.rpc.setActivity(activityInfo).catch(console.error); @@ -146,7 +133,7 @@ module.exports = ( registerCallback(updateActivity); connect(); }); - app.on("window-all-closed", module.exports.clear); + app.on('window-all-closed', module.exports.clear) }; module.exports.clear = () => {