From b9dbd8bd4def9e9f43f25946228ed495f3365417 Mon Sep 17 00:00:00 2001 From: Constantin Piber Date: Mon, 11 Oct 2021 15:02:24 +0200 Subject: [PATCH] Allow disable listen along (#426) --- config/defaults.js | 3 ++- config/store.js | 5 +++++ plugins/discord/back.js | 10 +++++----- plugins/discord/menu.js | 9 +++++++++ 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/config/defaults.js b/config/defaults.js index f0533241..552a4995 100644 --- a/config/defaults.js +++ b/config/defaults.js @@ -45,7 +45,8 @@ const defaultConfig = { discord: { enabled: false, activityTimoutEnabled: true, // if enabled, the discord rich presence gets cleared when music paused after the time specified below - activityTimoutTime: 10 * 60 * 1000 // 10 minutes + activityTimoutTime: 10 * 60 * 1000, // 10 minutes + listenAlong: true, // add a "listen along" button to rich presence }, notifications: { enabled: false, diff --git a/config/store.js b/config/store.js index 9c0de1e4..f66c1f9a 100644 --- a/config/store.js +++ b/config/store.js @@ -3,6 +3,11 @@ const Store = require("electron-store"); const defaults = require("./defaults"); const migrations = { + ">=1.13.0": (store) => { + if (store.get("plugins.discord.listenAlong") === undefined) { + store.set("plugins.discord.listenAlong", true); + } + }, ">=1.11.0": (store) => { if (store.get("options.resumeOnStart") === undefined) { store.set("options.resumeOnStart", true); diff --git a/plugins/discord/back.js b/plugins/discord/back.js index 478af101..3c3ab5fd 100644 --- a/plugins/discord/back.js +++ b/plugins/discord/back.js @@ -70,7 +70,7 @@ let clearActivity; */ let updateActivity; -module.exports = (win, {activityTimoutEnabled, activityTimoutTime}) => { +module.exports = (win, {activityTimoutEnabled, activityTimoutTime, listenAlong}) => { window = win; // We get multiple events // Next song: PAUSE(n), PAUSE(n+1), PLAY(n+1) @@ -106,11 +106,11 @@ module.exports = (win, {activityTimoutEnabled, activityTimoutTime}) => { largeImageKey: "logo", largeImageText: [ songInfo.uploadDate, - songInfo.views.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") + " views" + songInfo.views.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") + " views", ].join(' || '), - buttons: [ + buttons: listenAlong ? [ { label: "Listen Along", url: songInfo.url }, - ], + ] : undefined, }; if (songInfo.isPaused) { @@ -119,7 +119,7 @@ module.exports = (win, {activityTimoutEnabled, activityTimoutTime}) => { activityInfo.smallImageText = "idle/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; diff --git a/plugins/discord/menu.js b/plugins/discord/menu.js index 3e8d97e9..9750dabe 100644 --- a/plugins/discord/menu.js +++ b/plugins/discord/menu.js @@ -29,6 +29,15 @@ module.exports = (win, options, refreshMenu) => { setOptions('discord', options); }, }, + { + label: "Listen Along", + type: "checkbox", + checked: options.listenAlong, + click: (item) => { + options.listenAlong = item.checked; + setOptions('discord', options); + }, + }, { label: "Set timeout time in config", // open config.json