Skip to content

Commit 4489a40

Browse files
committed
Merge branch 'master' of github.com:th-ch/youtube-music into snyk-upgrade-ce2777733d9dee231391c0a822c24a84
# By Araxeus (5) and others # Via GitHub (5) and TC (2) * 'master' of github.com:th-ch/youtube-music: Bump electron to 12.0.8 fix: upgrade ytdl-core from 4.5.0 to 4.7.0 fix: upgrade @ffmpeg/core from 0.8.5 to 0.9.0 fix notificationOnUnpause option fix: upgrade filenamify from 4.2.0 to 4.3.0 switch to `registerCallback()` on song info fix: upgrade ytpl from 2.1.1 to 2.2.0 lint refactor notifications plugin setup SongInfo **once**
2 parents c5f84b5 + 28aa1c0 commit 4489a40

File tree

12 files changed

+80
-91
lines changed

12 files changed

+80
-91
lines changed

index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const { setApplicationMenu } = require("./menu");
1111
const { fileExists, injectCSS } = require("./plugins/utils");
1212
const { isTesting } = require("./utils/testing");
1313
const { setUpTray } = require("./tray");
14+
const { setupSongInfo } = require("./providers/song-info");
1415

1516
// Catch errors and log them
1617
unhandled({
@@ -157,6 +158,7 @@ function createMainWindow() {
157158
}
158159

159160
app.once("browser-window-created", (event, win) => {
161+
setupSongInfo(win);
160162
loadPlugins(win);
161163

162164
win.webContents.on("did-fail-load", (

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
},
6565
"dependencies": {
6666
"@cliqz/adblocker-electron": "^1.20.5",
67-
"@ffmpeg/core": "^0.8.5",
67+
"@ffmpeg/core": "^0.9.0",
6868
"@ffmpeg/ffmpeg": "^0.9.7",
6969
"YoutubeNonStop": "git://github.com/lawfx/YoutubeNonStop.git#v0.9.0",
7070
"async-mutex": "^0.3.1",
@@ -78,15 +78,15 @@
7878
"electron-store": "^7.0.3",
7979
"electron-unhandled": "^3.0.2",
8080
"electron-updater": "^4.3.8",
81-
"filenamify": "^4.2.0",
81+
"filenamify": "^4.3.0",
8282
"md5": "^2.3.0",
8383
"node-fetch": "^2.6.1",
8484
"node-notifier": "^9.0.1",
85-
"ytdl-core": "^4.5.0",
86-
"ytpl": "^2.1.1"
85+
"ytdl-core": "^4.7.0",
86+
"ytpl": "^2.2.0"
8787
},
8888
"devDependencies": {
89-
"electron": "^12.0.7",
89+
"electron": "^12.0.8",
9090
"electron-builder": "^22.10.5",
9191
"electron-devtools-installer": "^3.1.1",
9292
"electron-icon-maker": "0.0.5",

plugins/discord/back.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const Discord = require("discord-rpc");
22

3-
const getSongInfo = require("../../providers/song-info");
3+
const registerCallback = require("../../providers/song-info");
44

55
const rpc = new Discord.Client({
66
transport: "ipc",
@@ -12,8 +12,6 @@ const clientId = "790655993809338398";
1212
let clearActivity;
1313

1414
module.exports = (win, {activityTimoutEnabled, activityTimoutTime}) => {
15-
const registerCallback = getSongInfo(win);
16-
1715
// If the page is ready, register the callback
1816
win.once("ready-to-show", () => {
1917
rpc.once("ready", () => {

plugins/downloader/back.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const { join } = require("path");
44
const ID3Writer = require("browser-id3-writer");
55
const { dialog, ipcMain } = require("electron");
66

7-
const getSongInfo = require("../../providers/song-info");
7+
const registerCallback = require("../../providers/song-info");
88
const { injectCSS, listenAction } = require("../utils");
99
const { cropMaxWidth } = require("./utils");
1010
const { ACTIONS, CHANNEL } = require("./actions.js");
@@ -25,7 +25,6 @@ let nowPlayingMetadata = {};
2525

2626
function handle(win) {
2727
injectCSS(win.webContents, join(__dirname, "style.css"));
28-
const registerCallback = getSongInfo(win);
2928
registerCallback((info) => {
3029
nowPlayingMetadata = info;
3130
});

plugins/downloader/menu.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ const { existsSync, mkdirSync } = require("fs");
22
const { join } = require("path");
33
const { URL } = require("url");
44

5-
const { dialog, ipcMain } = require("electron");
5+
const { dialog } = require("electron");
66
const is = require("electron-is");
77
const ytpl = require("ytpl");
88
const chokidar = require('chokidar');
99

1010
const { setOptions } = require("../../config/plugins");
11-
const getSongInfo = require("../../providers/song-info");
11+
const registerCallback = require("../../providers/song-info");
1212
const { sendError } = require("./back");
1313
const { defaultMenuDownloadLabel, getFolder } = require("./utils");
1414

@@ -18,7 +18,6 @@ let callbackIsRegistered = false;
1818

1919
module.exports = (win, options) => {
2020
if (!callbackIsRegistered) {
21-
const registerCallback = getSongInfo(win);
2221
registerCallback((info) => {
2322
metadataURL = info.url;
2423
});

plugins/last-fm/back.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const fetch = require('node-fetch');
22
const md5 = require('md5');
33
const { shell } = require('electron');
44
const { setOptions } = require('../../config/plugins');
5-
const getSongInfo = require('../../providers/song-info');
5+
const registerCallback = require('../../providers/song-info');
66
const defaultConfig = require('../../config/defaults');
77

88
const createFormData = params => {
@@ -128,9 +128,7 @@ const setNowPlaying = (songInfo, config) => {
128128
// this will store the timeout that will trigger addScrobble
129129
let scrobbleTimer = undefined;
130130

131-
const lastfm = async (win, config) => {
132-
const registerCallback = getSongInfo(win);
133-
131+
const lastfm = async (_win, config) => {
134132
if (!config.api_root) {
135133
// settings are not present, creating them with the default values
136134
config = defaultConfig.plugins['last-fm'];

plugins/notifications/back.js

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
const { Notification } = require("electron");
22
const is = require("electron-is");
3-
const getSongInfo = require("../../providers/song-info");
3+
const registerCallback = require("../../providers/song-info");
44
const { notificationImage } = require("./utils");
55

6-
const { setupInteractive, notifyInteractive } = require("./interactive")
6+
const setupInteractive = require("./interactive")
77

88
const notify = (info, options) => {
99

@@ -23,38 +23,24 @@ const notify = (info, options) => {
2323
return currentNotification;
2424
};
2525

26-
module.exports = (win, options) => {
27-
const isInteractive = is.windows() && options.interactive;
28-
//setup interactive notifications for windows
29-
if (isInteractive) {
30-
setupInteractive(win, options.unpauseNotification);
31-
}
32-
const registerCallback = getSongInfo(win);
26+
const setup = (options) => {
3327
let oldNotification;
34-
let oldURL = "";
35-
win.once("ready-to-show", () => {
36-
// Register the callback for new song information
37-
registerCallback(songInfo => {
38-
// on pause - reset url? and skip notification
39-
if (songInfo.isPaused) {
40-
//reset oldURL if unpause notification option is on
41-
if (options.unpauseNotification) {
42-
oldURL = "";
43-
}
44-
return;
45-
}
46-
// If url isn't the same as last one - send notification
47-
if (songInfo.url !== oldURL) {
48-
oldURL = songInfo.url;
49-
if (isInteractive) {
50-
notifyInteractive(songInfo);
51-
} else {
52-
// Close the old notification
53-
oldNotification?.close();
54-
// This fixes a weird bug that would cause the notification to be updated instead of showing
55-
setTimeout(() => { oldNotification = notify(songInfo, options) }, 10);
56-
}
57-
}
58-
});
28+
let currentUrl;
29+
30+
registerCallback(songInfo => {
31+
if (!songInfo.isPaused && (songInfo.url !== currentUrl || options.unpauseNotification)) {
32+
// Close the old notification
33+
oldNotification?.close();
34+
currentUrl = songInfo.url;
35+
// This fixes a weird bug that would cause the notification to be updated instead of showing
36+
setTimeout(() => { oldNotification = notify(songInfo, options) }, 10);
37+
}
5938
});
39+
}
40+
41+
module.exports = (win, options) => {
42+
// Register the callback for new song information
43+
is.windows() && options.interactive ?
44+
setupInteractive(win, options.unpauseNotification) :
45+
setup(options);
6046
};

plugins/notifications/interactive.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
11
const { notificationImage, icons } = require("./utils");
22
const getSongControls = require('../../providers/song-controls');
3+
const registerCallback = require("../../providers/song-info");
34
const notifier = require("node-notifier");
45

56
//store song controls reference on launch
67
let controls;
7-
let notificationOnPause;
8+
let notificationOnUnpause;
89

9-
//Save controls and onPause option
10-
module.exports.setupInteractive = (win, unpauseNotification) => {
10+
module.exports = (win, unpauseNotification) => {
11+
//Save controls and onPause option
1112
const { playPause, next, previous } = getSongControls(win);
1213
controls = { playPause, next, previous };
14+
notificationOnUnpause = unpauseNotification;
1315

14-
notificationOnPause = unpauseNotification;
16+
let currentUrl;
17+
18+
// Register songInfoCallback
19+
registerCallback(songInfo => {
20+
if (!songInfo.isPaused && (songInfo.url !== currentUrl || notificationOnUnpause)) {
21+
currentUrl = songInfo.url;
22+
sendToaster(songInfo);
23+
}
24+
});
1525

1626
win.webContents.once("closed", () => {
1727
deleteNotification()
@@ -33,7 +43,7 @@ function deleteNotification() {
3343
}
3444

3545
//New notification
36-
module.exports.notifyInteractive = function sendToaster(songInfo) {
46+
function sendToaster(songInfo) {
3747
deleteNotification();
3848
//download image and get path
3949
let imgSrc = notificationImage(songInfo, true);
@@ -71,7 +81,7 @@ module.exports.notifyInteractive = function sendToaster(songInfo) {
7181
// dont delete notification on play/pause
7282
toDelete = undefined;
7383
//manually send notification if not sending automatically
74-
if (!notificationOnPause) {
84+
if (!notificationOnUnpause) {
7585
songInfo.isPaused = false;
7686
sendToaster(songInfo);
7787
}

plugins/taskbar-mediacontrol/back.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
const getSongControls = require('../../providers/song-controls');
2-
const getSongInfo = require('../../providers/song-info');
2+
const registerCallback = require('../../providers/song-info');
33
const path = require('path');
44

55
let controls;
66
let currentSongInfo;
77

88
module.exports = win => {
9-
const registerCallback = getSongInfo(win);
109
const { playPause, next, previous } = getSongControls(win);
1110
controls = { playPause, next, previous };
1211

plugins/touchbar/back.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const {
77
TouchBarScrubber,
88
} = TouchBar;
99

10-
const getSongInfo = require("../../providers/song-info");
10+
const registerCallback = require("../../providers/song-info");
1111
const getSongControls = require("../../providers/song-controls");
1212

1313
// Songtitle label
@@ -59,7 +59,6 @@ const touchBar = new TouchBar({
5959
});
6060

6161
module.exports = (win) => {
62-
const registerCallback = getSongInfo(win);
6362
const { playPause, next, previous, like, dislike } = getSongControls(win);
6463

6564
// If the page is ready, register the callback

0 commit comments

Comments
 (0)