From ca8d62d4e26d28927c5b6c552578eb6a8a639c7e Mon Sep 17 00:00:00 2001 From: Sem Visscher Date: Wed, 17 Mar 2021 10:22:19 +0100 Subject: [PATCH] Added Discord timeout --- config/defaults.js | 4 ++++ plugins/discord/back.js | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/config/defaults.js b/config/defaults.js index 6238e114..855b1964 100644 --- a/config/defaults.js +++ b/config/defaults.js @@ -35,6 +35,10 @@ const defaultConfig = { ffmpegArgs: [], // e.g. ["-b:a", "192k"] for an audio bitrate of 192kb/s downloadFolder: undefined, // Custom download folder (absolute path) }, + discord: { + activityTimoutEnabled: true, // if enabled, the discord rich presence gets cleared when music paused after the time specified below + activityTimoutTime: 10 * 60 * 1000 // 10 minutes + }, }, }; diff --git a/plugins/discord/back.js b/plugins/discord/back.js index 3e4ab629..0ebcc624 100644 --- a/plugins/discord/back.js +++ b/plugins/discord/back.js @@ -9,7 +9,9 @@ const rpc = new Discord.Client({ // Application ID registered by @semvis123 const clientId = "790655993809338398"; -module.exports = (win) => { +let clearActivity; + +module.exports = (win, {activityTimoutEnabled, activityTimoutTime}) => { const registerCallback = getSongInfo(win); // If the page is ready, register the callback @@ -29,7 +31,13 @@ module.exports = (win) => { // Add an idle icon to show that the song is paused activityInfo.smallImageKey = "idle"; activityInfo.smallImageText = "idle/paused"; + // Set start the timer so the activity gets cleared after a while if enabled + if (activityTimoutEnabled) + clearActivity = setTimeout(()=>rpc.clearActivity(), activityTimoutTime||10,000); + } else { + // stop the clear activity timout + clearTimeout(clearActivity); // Add the start and end time of the song const songStartTime = Date.now() - songInfo.elapsedSeconds * 1000; activityInfo.startTimestamp = songStartTime;