Skip to content

Commit

Permalink
Merge pull request #192 from semvis123/master
Browse files Browse the repository at this point in the history
Added Discord timeout
  • Loading branch information
th-ch authored Mar 24, 2021
2 parents c926db7 + ca8d62d commit 304ad6e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions config/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
},
};

Expand Down
10 changes: 9 additions & 1 deletion plugins/discord/back.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down

0 comments on commit 304ad6e

Please sign in to comment.