Merge pull request #192 from semvis123/master

Added Discord timeout
This commit is contained in:
th-ch
2021-03-24 22:38:56 +01:00
committed by GitHub
2 changed files with 13 additions and 1 deletions

View File

@ -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
},
},
};

View File

@ -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;