mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-10 10:11:46 +00:00
Fix discord clearActivity, menu
The callback sends multiple events, in particular two pause when going to the next song, so the timeout wasn't properly cleared. Add menu buttons for the two options
This commit is contained in:
@ -16,6 +16,10 @@ module.exports = (win, {activityTimoutEnabled, activityTimoutTime}) => {
|
||||
win.once("ready-to-show", () => {
|
||||
rpc.once("ready", () => {
|
||||
// Register the callback
|
||||
//
|
||||
// We get multiple events
|
||||
// Next song: PAUSE(n), PAUSE(n+1), PLAY(n+1)
|
||||
// Skip time: PAUSE(N), PLAY(N)
|
||||
registerCallback((songInfo) => {
|
||||
if (songInfo.title.length === 0 && songInfo.artist.length === 0) {
|
||||
return;
|
||||
@ -31,16 +35,17 @@ module.exports = (win, {activityTimoutEnabled, activityTimoutTime}) => {
|
||||
].join(' || '),
|
||||
};
|
||||
|
||||
// stop the clear activity timout
|
||||
clearTimeout(clearActivity);
|
||||
|
||||
if (songInfo.isPaused) {
|
||||
// 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||10000);
|
||||
clearActivity = setTimeout(() => rpc.clearActivity().catch(console.error), activityTimoutTime || 10000);
|
||||
} 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;
|
||||
@ -48,7 +53,7 @@ module.exports = (win, {activityTimoutEnabled, activityTimoutTime}) => {
|
||||
songStartTime + songInfo.songDuration * 1000;
|
||||
}
|
||||
|
||||
rpc.setActivity(activityInfo);
|
||||
rpc.setActivity(activityInfo).catch(console.error);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
21
plugins/discord/menu.js
Normal file
21
plugins/discord/menu.js
Normal file
@ -0,0 +1,21 @@
|
||||
const { setOptions } = require("../../config/plugins");
|
||||
const { edit } = require("../../config");
|
||||
|
||||
module.exports = (win, options) => [
|
||||
{
|
||||
label: "Clear activity after timeout",
|
||||
type: "checkbox",
|
||||
checked: options.activityTimoutEnabled,
|
||||
click: (item) => {
|
||||
options.activityTimoutEnabled = item.checked;
|
||||
setOptions('discord', options);
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "Set timeout time in config",
|
||||
click: () => {
|
||||
// open config.json
|
||||
edit();
|
||||
},
|
||||
},
|
||||
];
|
||||
Reference in New Issue
Block a user