From 183bad43f662ffc294be57548720eb09c9fa0cbb Mon Sep 17 00:00:00 2001 From: Constantin Piber Date: Sun, 15 Aug 2021 12:20:37 +0200 Subject: [PATCH 01/12] 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 --- plugins/discord/back.js | 13 +++++++++---- plugins/discord/menu.js | 21 +++++++++++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 plugins/discord/menu.js diff --git a/plugins/discord/back.js b/plugins/discord/back.js index c6faadd7..2f75c430 100644 --- a/plugins/discord/back.js +++ b/plugins/discord/back.js @@ -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); }); }); diff --git a/plugins/discord/menu.js b/plugins/discord/menu.js new file mode 100644 index 00000000..d0af48e8 --- /dev/null +++ b/plugins/discord/menu.js @@ -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(); + }, + }, +]; From 39014572180798772c0a9a464c2bf43fb7d417ce Mon Sep 17 00:00:00 2001 From: Constantin Piber Date: Tue, 17 Aug 2021 10:09:11 +0200 Subject: [PATCH 02/12] Discord add menu button for clearing activity --- plugins/discord/back.js | 2 ++ plugins/discord/menu.js | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/plugins/discord/back.js b/plugins/discord/back.js index 2f75c430..57d9902a 100644 --- a/plugins/discord/back.js +++ b/plugins/discord/back.js @@ -61,3 +61,5 @@ module.exports = (win, {activityTimoutEnabled, activityTimoutTime}) => { rpc.login({ clientId }).catch(console.error); }); }; + +module.exports.clear = () => rpc.clearActivity(); diff --git a/plugins/discord/menu.js b/plugins/discord/menu.js index d0af48e8..96e25e8c 100644 --- a/plugins/discord/menu.js +++ b/plugins/discord/menu.js @@ -1,7 +1,14 @@ const { setOptions } = require("../../config/plugins"); const { edit } = require("../../config"); +const { clear } = require("./back"); module.exports = (win, options) => [ + { + label: "Clear activity", + click: () => { + clear(); + }, + }, { label: "Clear activity after timeout", type: "checkbox", From 36bc9c62b0e964dd8cbc1ad964ae570c0fe7566a Mon Sep 17 00:00:00 2001 From: Constantin Piber Date: Wed, 18 Aug 2021 21:39:40 +0200 Subject: [PATCH 03/12] Discord timeout 0 clear activity directly --- plugins/discord/back.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugins/discord/back.js b/plugins/discord/back.js index 57d9902a..c0808e4e 100644 --- a/plugins/discord/back.js +++ b/plugins/discord/back.js @@ -38,6 +38,12 @@ module.exports = (win, {activityTimoutEnabled, activityTimoutTime}) => { // stop the clear activity timout clearTimeout(clearActivity); + // clear directly if timeout is 0 + if (songInfo.isPaused && activityTimoutEnabled && activityTimoutTime === 0) { + rpc.clearActivity().catch(console.error); + return; + } + if (songInfo.isPaused) { // Add an idle icon to show that the song is paused activityInfo.smallImageKey = "idle"; From b5fd6b4969a318b3738583e7f33eb2c0cf295237 Mon Sep 17 00:00:00 2001 From: Constantin Piber Date: Fri, 27 Aug 2021 16:32:55 +0200 Subject: [PATCH 04/12] Discord add reconnecting functionality Clear rpc on disconnect Add menu button to reconnect --- plugins/discord/back.js | 183 +++++++++++++++++++++++++++------------- plugins/discord/menu.js | 52 +++++++----- providers/song-info.js | 11 +++ 3 files changed, 168 insertions(+), 78 deletions(-) diff --git a/plugins/discord/back.js b/plugins/discord/back.js index c0808e4e..7ba1ea1a 100644 --- a/plugins/discord/back.js +++ b/plugins/discord/back.js @@ -1,71 +1,140 @@ const Discord = require("discord-rpc"); +const { dev } = require("electron-is") const registerCallback = require("../../providers/song-info"); -const rpc = new Discord.Client({ - transport: "ipc", -}); - // Application ID registered by @semvis123 const clientId = "790655993809338398"; -let clearActivity; +/** + * @typedef {Object} Info + * @property {import('discord-rpc').Client} rpc + * @property {boolean} ready + * @property {import('../../providers/song-info').SongInfo} lastSongInfo + */ +/** + * @type {Info} + */ +const info = { + rpc: null, + ready: false, + lastSongInfo: null, +}; +/** + * @type {(() => void)[]} + */ +const refreshCallbacks = []; +const resetInfo = () => { + info.rpc = null; + info.ready = false; + clearTimeout(clearActivity); + if (dev()) console.log("discord disconnected"); + refreshCallbacks.forEach(cb => cb()); +}; -module.exports = (win, {activityTimoutEnabled, activityTimoutTime}) => { - // If the page is ready, register the callback - 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; - } - // Song information changed, so lets update the rich presence - const activityInfo = { - details: songInfo.title, - state: songInfo.artist, - largeImageKey: "logo", - largeImageText: [ - songInfo.uploadDate, - songInfo.views.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") + " views" - ].join(' || '), - }; +const connect = () => { + if (info.rpc) { + if (dev()) + console.log('Attempted to connect with active RPC object'); + return; + } - // stop the clear activity timout - clearTimeout(clearActivity); + info.rpc = new Discord.Client({ + transport: "ipc", + }); + info.ready = false; - // clear directly if timeout is 0 - if (songInfo.isPaused && activityTimoutEnabled && activityTimoutTime === 0) { - rpc.clearActivity().catch(console.error); - return; - } + info.rpc.once("connected", () => { + if (dev()) console.log("discord connected"); + refreshCallbacks.forEach(cb => cb()); + }); + info.rpc.once("ready", () => { + info.ready = true; + if (info.lastSongInfo) updateActivity(info.lastSongInfo) + }); + info.rpc.once("disconnected", resetInfo); - 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().catch(console.error), activityTimoutTime || 10000); - } else { - // Add the start and end time of the song - const songStartTime = Date.now() - songInfo.elapsedSeconds * 1000; - activityInfo.startTimestamp = songStartTime; - activityInfo.endTimestamp = - songStartTime + songInfo.songDuration * 1000; - } - - rpc.setActivity(activityInfo).catch(console.error); - }); - }); - - // Startup the rpc client - rpc.login({ clientId }).catch(console.error); + // Startup the rpc client + info.rpc.login({ clientId }).catch(err => { + resetInfo(); + if (dev()) console.error(err); }); }; -module.exports.clear = () => rpc.clearActivity(); +let clearActivity; +/** + * @type {import('../../providers/song-info').songInfoCallback} + */ +let updateActivity; + +module.exports = (win, {activityTimoutEnabled, activityTimoutTime}) => { + // We get multiple events + // Next song: PAUSE(n), PAUSE(n+1), PLAY(n+1) + // Skip time: PAUSE(N), PLAY(N) + updateActivity = songInfo => { + if (songInfo.title.length === 0 && songInfo.artist.length === 0) { + return; + } + info.lastSongInfo = songInfo; + + // stop the clear activity timout + clearTimeout(clearActivity); + + // stop early if discord connection is not ready + // do this after clearTimeout to avoid unexpected clears + if (!info.rpc || !info.ready) { + return; + } + + // clear directly if timeout is 0 + if (songInfo.isPaused && activityTimoutEnabled && activityTimoutTime === 0) { + info.rpc.clearActivity().catch(console.error); + return; + } + + // Song information changed, so lets update the rich presence + const activityInfo = { + details: songInfo.title, + state: songInfo.artist, + largeImageKey: "logo", + largeImageText: [ + songInfo.uploadDate, + songInfo.views.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") + " views" + ].join(' || '), + }; + + 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(() => 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; + activityInfo.startTimestamp = songStartTime; + activityInfo.endTimestamp = + songStartTime + songInfo.songDuration * 1000; + } + + info.rpc.setActivity(activityInfo).catch(console.error); + }; + + // If the page is ready, register the callback + win.once("ready-to-show", () => { + registerCallback(updateActivity); + connect(); + }); +}; + +module.exports.clear = () => { + if (info.rpc) info.rpc.clearActivity(); + clearTimeout(clearActivity); +}; +module.exports.connect = connect; +module.exports.registerRefresh = (cb) => refreshCallbacks.push(cb); +/** + * @type {Info} + */ +module.exports.info = Object.defineProperties({}, Object.keys(info).reduce((o, k) => ({ ...o, [k]: { enumerable: true, get: () => info[k] } }), {})); diff --git a/plugins/discord/menu.js b/plugins/discord/menu.js index 96e25e8c..3e8d97e9 100644 --- a/plugins/discord/menu.js +++ b/plugins/discord/menu.js @@ -1,28 +1,38 @@ const { setOptions } = require("../../config/plugins"); const { edit } = require("../../config"); -const { clear } = require("./back"); +const { clear, info, connect, registerRefresh } = require("./back"); -module.exports = (win, options) => [ - { - label: "Clear activity", - click: () => { - clear(); +let hasRegisterred = false; + +module.exports = (win, options, refreshMenu) => { + if (!hasRegisterred) { + registerRefresh(refreshMenu); + hasRegisterred = true; + } + + return [ + { + label: info.rpc !== null ? "Connected" : "Reconnect", + enabled: info.rpc === null, + click: connect, }, - }, - { - label: "Clear activity after timeout", - type: "checkbox", - checked: options.activityTimoutEnabled, - click: (item) => { - options.activityTimoutEnabled = item.checked; - setOptions('discord', options); + { + label: "Clear activity", + click: clear, }, - }, - { - label: "Set timeout time in config", - click: () => { + { + 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", // open config.json - edit(); + click: edit, }, - }, -]; + ]; +}; diff --git a/providers/song-info.js b/providers/song-info.js index 08eaf944..11b2abeb 100644 --- a/providers/song-info.js +++ b/providers/song-info.js @@ -40,6 +40,9 @@ const getArtist = async (win) => { } // Fill songInfo with empty values +/** + * @typedef {songInfo} SongInfo + */ const songInfo = { title: "", artist: "", @@ -71,6 +74,14 @@ const handleData = async (responseText, win) => { const callbacks = []; // This function will allow plugins to register callback that will be triggered when data changes +/** + * @callback songInfoCallback + * @param {songInfo} songInfo + * @returns {void} + */ +/** + * @param {songInfoCallback} callback + */ const registerCallback = (callback) => { callbacks.push(callback); }; From ef66612cc87e749f702a96248099d7178cad8ae7 Mon Sep 17 00:00:00 2001 From: Constantin Piber Date: Fri, 27 Aug 2021 17:07:23 +0200 Subject: [PATCH 05/12] Discord show error dialog on reconnect error --- plugins/discord/back.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugins/discord/back.js b/plugins/discord/back.js index 6a8dd007..8f0cc614 100644 --- a/plugins/discord/back.js +++ b/plugins/discord/back.js @@ -1,5 +1,6 @@ const Discord = require("discord-rpc"); -const { dev } = require("electron-is") +const { dev } = require("electron-is"); +const { dialog } = require("electron"); const registerCallback = require("../../providers/song-info"); @@ -32,7 +33,8 @@ const resetInfo = () => { refreshCallbacks.forEach(cb => cb()); }; -const connect = () => { +let window; +const connect = (showErr = false) => { if (info.rpc) { if (dev()) console.log('Attempted to connect with active RPC object'); @@ -58,6 +60,7 @@ const connect = () => { info.rpc.login({ clientId }).catch(err => { resetInfo(); if (dev()) console.error(err); + if (showErr) dialog.showMessageBox(window, { title: 'Connection failed', message: err.message || String(err), type: 'error' }); }); }; @@ -68,6 +71,7 @@ let clearActivity; let updateActivity; module.exports = (win, {activityTimoutEnabled, activityTimoutTime}) => { + window = win; // We get multiple events // Next song: PAUSE(n), PAUSE(n+1), PLAY(n+1) // Skip time: PAUSE(N), PLAY(N) From ea2d33c3cfbaa952dac9b21ce8dfbaf72f0e14f2 Mon Sep 17 00:00:00 2001 From: snyk-bot Date: Tue, 21 Sep 2021 03:24:11 +0000 Subject: [PATCH 06/12] fix: upgrade async-mutex from 0.3.1 to 0.3.2 Snyk has created this PR to upgrade async-mutex from 0.3.1 to 0.3.2. See this package in npm: See this project in Snyk: https://app.snyk.io/org/th-ch/project/81809c53-bb7b-46b9-a0d7-806d45d74ac6?utm_source=github&utm_medium=upgrade-pr --- package.json | 2 +- yarn.lock | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 6920b186..0151ddc7 100644 --- a/package.json +++ b/package.json @@ -68,7 +68,7 @@ "@ffmpeg/core": "^0.10.0", "@ffmpeg/ffmpeg": "^0.10.0", "YoutubeNonStop": "git://github.com/lawfx/YoutubeNonStop.git#v0.9.0", - "async-mutex": "^0.3.1", + "async-mutex": "^0.3.2", "browser-id3-writer": "^4.4.0", "chokidar": "^3.5.2", "custom-electron-titlebar": "^3.2.7", diff --git a/yarn.lock b/yarn.lock index 743fcc50..0bed6c60 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1913,12 +1913,12 @@ async-exit-hook@^2.0.1: resolved "https://registry.yarnpkg.com/async-exit-hook/-/async-exit-hook-2.0.1.tgz#8bd8b024b0ec9b1c01cccb9af9db29bd717dfaf3" integrity sha512-NW2cX8m1Q7KPA7a5M2ULQeZ2wR5qI5PAbw5L0UOMxdioVk9PMZ0h1TmyZEkPYrCvYjDlFICusOu1dlEKAAeXBw== -async-mutex@^0.3.1: - version "0.3.1" - resolved "https://registry.yarnpkg.com/async-mutex/-/async-mutex-0.3.1.tgz#7033af665f1c7cebed8b878267a43ba9e77c5f67" - integrity sha512-vRfQwcqBnJTLzVQo72Sf7KIUbcSUP5hNchx6udI1U6LuPQpfePgdjJzlCe76yFZ8pxlLjn9lwcl/Ya0TSOv0Tw== +async-mutex@^0.3.2: + version "0.3.2" + resolved "https://registry.yarnpkg.com/async-mutex/-/async-mutex-0.3.2.tgz#1485eda5bda1b0ec7c8df1ac2e815757ad1831df" + integrity sha512-HuTK7E7MT7jZEh1P9GtRW9+aTWiDWWi9InbZ5hjxrnRa39KS4BW04+xLBhYNS2aXhHUIKZSw3gj4Pn1pj+qGAA== dependencies: - tslib "^2.1.0" + tslib "^2.3.1" async@0.9.x: version "0.9.2" @@ -8943,10 +8943,10 @@ tslib@^1.8.1: resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00" integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg== -tslib@^2.1.0: - version "2.1.0" - resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.1.0.tgz#da60860f1c2ecaa5703ab7d39bc05b6bf988b97a" - integrity sha512-hcVC3wYEziELGGmEEXue7D75zbwIIVUMWAVbHItGPx0ziyXxrOMQx4rQEVEV45Ut/1IotuEvwqPopzIOkDMf0A== +tslib@^2.3.1: + version "2.3.1" + resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.3.1.tgz#e8a335add5ceae51aa261d32a490158ef042ef01" + integrity sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw== tsutils@^3.21.0: version "3.21.0" From f2039e29e7aabd6fe1f69fbb7c054ee539f07327 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 21 Sep 2021 21:12:33 +0000 Subject: [PATCH 07/12] build(deps): bump tmpl from 1.0.4 to 1.0.5 Bumps [tmpl](https://github.com/daaku/nodejs-tmpl) from 1.0.4 to 1.0.5. - [Release notes](https://github.com/daaku/nodejs-tmpl/releases) - [Commits](https://github.com/daaku/nodejs-tmpl/commits/v1.0.5) --- updated-dependencies: - dependency-name: tmpl dependency-type: indirect ... Signed-off-by: dependabot[bot] --- yarn.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yarn.lock b/yarn.lock index 743fcc50..1025e2bd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8826,9 +8826,9 @@ tmp@^0.2.0: rimraf "^3.0.0" tmpl@1.0.x: - version "1.0.4" - resolved "https://registry.yarnpkg.com/tmpl/-/tmpl-1.0.4.tgz#23640dd7b42d00433911140820e5cf440e521dd1" - integrity sha1-I2QN17QtAEM5ERQIIOXPRA5SHdE= + version "1.0.5" + resolved "https://registry.yarnpkg.com/tmpl/-/tmpl-1.0.5.tgz#8683e0b902bb9c20c4f726e3c0b69f36518c07cc" + integrity sha512-3f0uOEAQwIqGuWW2MVzYg8fV/QNnc/IpuJNG837rLuczAaLVHslWHZQj4IGiEl5Hs3kkbhwL9Ab7Hrsmuj+Smw== to-absolute-glob@^2.0.2: version "2.0.2" From 157ae05f80a25612a2861fe9c9e6a101f22bbbd8 Mon Sep 17 00:00:00 2001 From: snyk-bot Date: Mon, 27 Sep 2021 19:13:33 +0000 Subject: [PATCH 08/12] fix: upgrade node-fetch from 2.6.1 to 2.6.2 Snyk has created this PR to upgrade node-fetch from 2.6.1 to 2.6.2. See this package in npm: See this project in Snyk: https://app.snyk.io/org/th-ch/project/81809c53-bb7b-46b9-a0d7-806d45d74ac6?utm_source=github&utm_medium=referral&page=upgrade-pr --- package.json | 2 +- yarn.lock | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 6920b186..7fcc987f 100644 --- a/package.json +++ b/package.json @@ -83,7 +83,7 @@ "filenamify": "^4.3.0", "md5": "^2.3.0", "mpris-service": "^2.1.2", - "node-fetch": "^2.6.1", + "node-fetch": "^2.6.2", "node-notifier": "^9.0.1", "ytdl-core": "^4.9.1", "ytpl": "^2.2.3" diff --git a/yarn.lock b/yarn.lock index 743fcc50..b194c7e3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6784,6 +6784,13 @@ node-fetch@^2.6.1: resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052" integrity sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw== +node-fetch@^2.6.2: + version "2.6.5" + resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.5.tgz#42735537d7f080a7e5f78b6c549b7146be1742fd" + integrity sha512-mmlIVHJEu5rnIxgEgez6b9GgWXbkZj5YZ7fx+2r94a2E+Uirsp6HsPTPlomfdHtpt/B0cdKviwkoaM6pyvUOpQ== + dependencies: + whatwg-url "^5.0.0" + node-int64@^0.4.0: version "0.4.0" resolved "https://registry.yarnpkg.com/node-int64/-/node-int64-0.4.0.tgz#87a9065cdb355d3182d8f94ce11188b825c68a3b" @@ -8909,6 +8916,11 @@ tr46@^2.0.2: dependencies: punycode "^2.1.1" +tr46@~0.0.3: + version "0.0.3" + resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a" + integrity sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o= + trim-newlines@^3.0.0: version "3.0.1" resolved "https://registry.yarnpkg.com/trim-newlines/-/trim-newlines-3.0.1.tgz#260a5d962d8b752425b32f3a7db0dcacd176c144" @@ -9308,6 +9320,11 @@ webdriverio@^6.9.1: serialize-error "^8.0.0" webdriver "6.12.1" +webidl-conversions@^3.0.0: + version "3.0.1" + resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871" + integrity sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE= + webidl-conversions@^5.0.0: version "5.0.0" resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-5.0.0.tgz#ae59c8a00b121543a2acc65c0434f57b0fc11aff" @@ -9330,6 +9347,14 @@ whatwg-mimetype@^2.3.0: resolved "https://registry.yarnpkg.com/whatwg-mimetype/-/whatwg-mimetype-2.3.0.tgz#3d4b1e0312d2079879f826aff18dbeeca5960fbf" integrity sha512-M4yMwr6mAnQz76TbJm914+gPpB/nCwvZbJU28cUD6dR004SAxDLOOSUaB1JDRqLtaOV/vi0IC5lEAGFgrjGv/g== +whatwg-url@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-5.0.0.tgz#966454e8765462e37644d3626f6742ce8b70965d" + integrity sha1-lmRU6HZUYuN2RNNib2dCzotwll0= + dependencies: + tr46 "~0.0.3" + webidl-conversions "^3.0.0" + whatwg-url@^8.0.0: version "8.4.0" resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-8.4.0.tgz#50fb9615b05469591d2b2bd6dfaed2942ed72837" From 587818b91ed0730bb75c421f27405a3e1038c4e4 Mon Sep 17 00:00:00 2001 From: Constantin Piber Date: Tue, 5 Oct 2021 10:10:36 +0200 Subject: [PATCH 09/12] Add type, clear on close --- plugins/discord/back.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugins/discord/back.js b/plugins/discord/back.js index 8f0cc614..478af101 100644 --- a/plugins/discord/back.js +++ b/plugins/discord/back.js @@ -97,7 +97,10 @@ module.exports = (win, {activityTimoutEnabled, activityTimoutTime}) => { } // Song information changed, so lets update the rich presence + // @see https://discord.com/developers/docs/topics/gateway#activity-object + // not all options are transfered through https://github.com/discordjs/RPC/blob/6f83d8d812c87cb7ae22064acd132600407d7d05/src/client.js#L518-530 const activityInfo = { + type: 2, // Listening, addressed in https://github.com/discordjs/RPC/pull/149 details: songInfo.title, state: songInfo.artist, largeImageKey: "logo", @@ -133,6 +136,7 @@ module.exports = (win, {activityTimoutEnabled, activityTimoutTime}) => { registerCallback(updateActivity); connect(); }); + win.on("close", () => module.exports.clear()); }; module.exports.clear = () => { From b9dbd8bd4def9e9f43f25946228ed495f3365417 Mon Sep 17 00:00:00 2001 From: Constantin Piber Date: Mon, 11 Oct 2021 15:02:24 +0200 Subject: [PATCH 10/12] 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 From 1908921ae639846e5ba001e7534bc506784e0824 Mon Sep 17 00:00:00 2001 From: snyk-bot Date: Mon, 11 Oct 2021 21:23:58 +0000 Subject: [PATCH 11/12] fix: upgrade @cliqz/adblocker-electron from 1.22.5 to 1.22.6 Snyk has created this PR to upgrade @cliqz/adblocker-electron from 1.22.5 to 1.22.6. See this package in npm: See this project in Snyk: https://app.snyk.io/org/th-ch/project/81809c53-bb7b-46b9-a0d7-806d45d74ac6?utm_source=github&utm_medium=referral&page=upgrade-pr --- package.json | 2 +- yarn.lock | 62 ++++++++++++++++++++++++++-------------------------- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/package.json b/package.json index 6920b186..b0b6a118 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,7 @@ "npm": "Please use yarn and not npm" }, "dependencies": { - "@cliqz/adblocker-electron": "^1.22.5", + "@cliqz/adblocker-electron": "^1.22.6", "@ffmpeg/core": "^0.10.0", "@ffmpeg/ffmpeg": "^0.10.0", "YoutubeNonStop": "git://github.com/lawfx/YoutubeNonStop.git#v0.9.0", diff --git a/yarn.lock b/yarn.lock index 743fcc50..fa7d74db 100644 --- a/yarn.lock +++ b/yarn.lock @@ -439,45 +439,45 @@ resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39" integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw== -"@cliqz/adblocker-content@^1.22.5": - version "1.22.5" - resolved "https://registry.yarnpkg.com/@cliqz/adblocker-content/-/adblocker-content-1.22.5.tgz#84a82a630b3824623fff203ffaa9f4831f902eaa" - integrity sha512-79UAWMLZ5Na3FJey/RkYbUcPsmRbfkWq7LzUVffRR+yL8B24P6ptd+T7/qBFAULbJ0unp1DBtJ/i1P1QOPktXw== +"@cliqz/adblocker-content@^1.22.7": + version "1.22.7" + resolved "https://registry.yarnpkg.com/@cliqz/adblocker-content/-/adblocker-content-1.22.7.tgz#02bfa1775d8be1efa82e9d5802cc17cfa9dc0712" + integrity sha512-pAGxQ7sKCk7r0g/d7vyxY1MhkLfxfwMzd4WPL9234HmU/blCGCg1QL8wkjLTNYJERXZ+xoJ2dqMOisR/nE0ypA== dependencies: - "@cliqz/adblocker-extended-selectors" "^1.22.5" + "@cliqz/adblocker-extended-selectors" "^1.22.7" -"@cliqz/adblocker-electron-preload@^1.22.5": - version "1.22.5" - resolved "https://registry.yarnpkg.com/@cliqz/adblocker-electron-preload/-/adblocker-electron-preload-1.22.5.tgz#3a9067279bdab0fd5e6d147b5a36c15c2273c83d" - integrity sha512-O0Baz5SXT4cSGkwcmPiTFWmeLGFYy/vQxRsh2C8sJzkmCj8593rHOVgvVUL4M9o1wKTh+RycmWpoi6dWu75mZw== +"@cliqz/adblocker-electron-preload@^1.22.7": + version "1.22.7" + resolved "https://registry.yarnpkg.com/@cliqz/adblocker-electron-preload/-/adblocker-electron-preload-1.22.7.tgz#1de6c4c3e66d566149cf60785b85d6f3fdb9a9ea" + integrity sha512-1eUQvmmDd5Wi0ka48SRggd80ZBilnA7uRePni/cVGfH5LSecCs5WoIpEhuoc1G333DXeBv9W0sRc1wVlKBsszg== dependencies: - "@cliqz/adblocker-content" "^1.22.5" + "@cliqz/adblocker-content" "^1.22.7" -"@cliqz/adblocker-electron@^1.22.5": - version "1.22.5" - resolved "https://registry.yarnpkg.com/@cliqz/adblocker-electron/-/adblocker-electron-1.22.5.tgz#3b45851d47c1835bb7f6476f4e29ae43606c90cf" - integrity sha512-yAfbPszTT5ZDIA4PfPwoImdUJLhAMXZg9G2wfpZP3uadMZHS6E1wJaufjMelDDo/UL5xjH/Mi4ZCRmGZPhZ7Wg== +"@cliqz/adblocker-electron@^1.22.6": + version "1.22.7" + resolved "https://registry.yarnpkg.com/@cliqz/adblocker-electron/-/adblocker-electron-1.22.7.tgz#bd29cf47835bc5c0c4d146333de3944096d23b4d" + integrity sha512-/O5Dskkr7R/8RKOby04VZ7HbnU/OD6Kk+raLxyP858FOYccHOnBjkAcUcUzun2x0UXmHX9Cus8SJ3h8GbrG7ZA== dependencies: - "@cliqz/adblocker" "^1.22.5" - "@cliqz/adblocker-electron-preload" "^1.22.5" + "@cliqz/adblocker" "^1.22.7" + "@cliqz/adblocker-electron-preload" "^1.22.7" tldts-experimental "^5.6.21" -"@cliqz/adblocker-extended-selectors@^1.22.5": - version "1.22.5" - resolved "https://registry.yarnpkg.com/@cliqz/adblocker-extended-selectors/-/adblocker-extended-selectors-1.22.5.tgz#228fdec6a58e313225a0be4266529f495432db0e" - integrity sha512-5HTrNq1TaTXpTOddBo7z7GMEE7r44J6HusMVaDmbMpoA115YoQJyMfD82OYgoddj4Zdvp63/pjP+MBlE0WZyJg== +"@cliqz/adblocker-extended-selectors@^1.22.7": + version "1.22.7" + resolved "https://registry.yarnpkg.com/@cliqz/adblocker-extended-selectors/-/adblocker-extended-selectors-1.22.7.tgz#ca0f219d773af5e8013287e5ddd8b00761359d87" + integrity sha512-eHZWYJsgPZPaiLyQtZF7phDFoEqAzk54eno0P+Daal+QwiNixobsk3V4Uh1AVGFcmFEG/Z2CbC/vdWSHpSlImw== -"@cliqz/adblocker@^1.22.5": - version "1.22.5" - resolved "https://registry.yarnpkg.com/@cliqz/adblocker/-/adblocker-1.22.5.tgz#26e675078db9d9854f295a87e969db0c95a15764" - integrity sha512-hQSyedelwG2+D6RDorJkarIUd9mln5IyxnRKO4ADGXvdQhZ5G/E90bTyJ2apDBdnvaUwXpmhhXs2cK12HhN14g== +"@cliqz/adblocker@^1.22.7": + version "1.22.7" + resolved "https://registry.yarnpkg.com/@cliqz/adblocker/-/adblocker-1.22.7.tgz#e2ee745c663ad6862e627de240973bdb4f1dc100" + integrity sha512-DxHlLJmV1q05F1I6BORqvBaOc43Vqts8c+vZdsjYdfiwfrPtuVRFYVTwZeMlZHBhmWx4HyxnfFakzJ8hw/B09A== dependencies: - "@cliqz/adblocker-content" "^1.22.5" - "@cliqz/adblocker-extended-selectors" "^1.22.5" + "@cliqz/adblocker-content" "^1.22.7" + "@cliqz/adblocker-extended-selectors" "^1.22.7" "@remusao/guess-url-type" "^1.1.2" "@remusao/small" "^1.1.2" "@remusao/smaz" "^1.7.1" - "@types/chrome" "^0.0.154" + "@types/chrome" "^0.0.157" "@types/firefox-webext-browser" "^82.0.0" tldts-experimental "^5.6.21" @@ -1208,10 +1208,10 @@ "@types/node" "*" "@types/responselike" "*" -"@types/chrome@^0.0.154": - version "0.0.154" - resolved "https://registry.yarnpkg.com/@types/chrome/-/chrome-0.0.154.tgz#7992e97364f4447e961028ad07ac843d0b052c2d" - integrity sha512-6QmP744MeMUZUIUHED4d4L2la5dIF1e6bcrkGF4yGQTyO94ER+r++Ss165wkzA5cAGUYt8kToDa6L9xtNqVMxg== +"@types/chrome@^0.0.157": + version "0.0.157" + resolved "https://registry.yarnpkg.com/@types/chrome/-/chrome-0.0.157.tgz#5a50bd378f4f632383c6ebbc34c88fb87d501f58" + integrity sha512-q5SSmA9nKaDzFi8QkJW9kW8MYwWg9O7PKPUdBxsz+3rPcIF1Kxw0Bexpd70Uq1mU6PN4DBp4qKMXQDybUeiI9w== dependencies: "@types/filesystem" "*" "@types/har-format" "*" From 3ec49bca742f7cdecec946b7f4ab4725f793071a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 12 Oct 2021 22:10:41 +0000 Subject: [PATCH 12/12] build(deps-dev): bump electron from 12.0.8 to 12.1.0 Bumps [electron](https://github.com/electron/electron) from 12.0.8 to 12.1.0. - [Release notes](https://github.com/electron/electron/releases) - [Changelog](https://github.com/electron/electron/blob/main/docs/breaking-changes.md) - [Commits](https://github.com/electron/electron/compare/v12.0.8...v12.1.0) --- updated-dependencies: - dependency-name: electron dependency-type: direct:development ... Signed-off-by: dependabot[bot] --- package.json | 2 +- yarn.lock | 15 +++++---------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 6920b186..63e0977b 100644 --- a/package.json +++ b/package.json @@ -89,7 +89,7 @@ "ytpl": "^2.2.3" }, "devDependencies": { - "electron": "^12.0.8", + "electron": "^12.1.0", "electron-builder": "^22.10.5", "electron-devtools-installer": "^3.1.1", "electron-icon-maker": "0.0.5", diff --git a/yarn.lock b/yarn.lock index 743fcc50..225e289b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1316,12 +1316,7 @@ resolved "https://registry.yarnpkg.com/@types/minimist/-/minimist-1.2.1.tgz#283f669ff76d7b8260df8ab7a4262cc83d988256" integrity sha512-fZQQafSREFyuZcdWFAExYjBiCL7AUCdgsk80iO0q4yihYYdcIiH28CcuPTGFgLOCC8RlW49GSQxdHwZP+I7CNg== -"@types/node@*": - version "14.14.25" - resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.25.tgz#15967a7b577ff81383f9b888aa6705d43fbbae93" - integrity sha512-EPpXLOVqDvisVxtlbvzfyqSsFeQxltFbluZNRndIb8tr9KiBnYNLzrc1N3pyKUCww2RNrfHDViqDWWE1LCJQtQ== - -"@types/node@^14.6.2": +"@types/node@*", "@types/node@^14.6.2": version "14.14.44" resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.44.tgz#df7503e6002847b834371c004b372529f3f85215" integrity sha512-+gaugz6Oce6ZInfI/tK4Pq5wIIkJMEJUu92RB3Eu93mtj4wjjjz9EB5mLp5s1pSsLXdC/CPut/xF20ZzAQJbTA== @@ -3511,10 +3506,10 @@ electron-updater@^4.4.6: lodash.isequal "^4.5.0" semver "^7.3.5" -electron@^12.0.8: - version "12.0.8" - resolved "https://registry.yarnpkg.com/electron/-/electron-12.0.8.tgz#e52583b2b4f1eaa6fbb0e3666b9907f99f1f24c7" - integrity sha512-bN2wYNnnma7ugBsiwysO1LI6oTTV1lDHOXuWip+OGjDUiz0IiJmZ+r0gAIMMeypVohZh7AA1ftnKad7tJ8sH4A== +electron@^12.1.0: + version "12.1.0" + resolved "https://registry.yarnpkg.com/electron/-/electron-12.1.0.tgz#615a7f9dbb2fc79cc72361fba9f39d005c697bca" + integrity sha512-joQlYI/nTIrTUldO3GENZ2j225eKar9nTQBSEwSUSWN4h65QGDmXNQ7dbWPmLlkUQWtHhz8lXhFk30OLG9ZjLw== dependencies: "@electron/get" "^1.0.1" "@types/node" "^14.6.2"