fix unPause option compatibility

This commit is contained in:
Araxeus
2021-04-09 03:15:57 +03:00
parent 095196785a
commit 9c0a633677
4 changed files with 22 additions and 8 deletions

View File

@ -45,7 +45,7 @@ const defaultConfig = {
enabled: false, enabled: false,
urgency: "normal", urgency: "normal",
unpauseNotification: false, unpauseNotification: false,
interactive: true //has effect only on Windows 8+ interactive: false //has effect only on Windows 8+
} }
}, },
}; };

View File

@ -27,7 +27,7 @@ module.exports = (win, options) => {
const isInteractive = is.windows() && options.interactive; const isInteractive = is.windows() && options.interactive;
//setup interactive notifications for windows //setup interactive notifications for windows
if (isInteractive) { if (isInteractive) {
setupInteractive(win); setupInteractive(win, options.unpauseNotification);
} }
const registerCallback = getSongInfo(win); const registerCallback = getSongInfo(win);
let oldNotification; let oldNotification;

View File

@ -4,10 +4,14 @@ const notifier = require("node-notifier");
//store song controls reference on launch //store song controls reference on launch
let controls; let controls;
module.exports.setupInteractive = (win) => { let onPause;
//save controls
//Save controls and onPause option
module.exports.setupInteractive = (win, unpauseNotification) => {
const { playPause, next, previous } = getSongControls(win); const { playPause, next, previous } = getSongControls(win);
controls = { playPause, next, previous }; controls = { playPause, next, previous };
onPause = unpauseNotification;
} }
//delete old notification //delete old notification
@ -24,10 +28,13 @@ function Delete() {
} }
//New notification //New notification
module.exports.notifyInteractive = (songInfo) => { module.exports.notifyInteractive = function sendToaster(songInfo) {
console.log("called toaster");
Delete(); Delete();
console.log("deleted");
//download image and get path //download image and get path
let imgSrc = notificationImage(songInfo, true); let imgSrc = notificationImage(songInfo, true);
console.log("got image");
toDelete = { toDelete = {
//app id undefined - will break buttons //app id undefined - will break buttons
title: songInfo.title || "Playing", title: songInfo.title || "Playing",
@ -41,6 +48,7 @@ module.exports.notifyInteractive = (songInfo) => {
], ],
sound: false, sound: false,
}; };
console.log("sending notification");
//send notification //send notification
notifier.notify( notifier.notify(
toDelete, toDelete,
@ -59,12 +67,18 @@ module.exports.notifyInteractive = (songInfo) => {
return; return;
case icons.play.normalize(): case icons.play.normalize():
controls.playPause(); controls.playPause();
toDelete = undefined; // dont delete notification on play/pause // dont delete notification on play/pause
toDelete = undefined;
//manually send notification if not sending automatically
if (!onPause) {
songInfo.isPaused = false;
sendToaster(songInfo);
}
return; return;
case icons.pause.normalize(): case icons.pause.normalize():
controls.playPause(); controls.playPause();
songInfo.isPaused = true; songInfo.isPaused = true;
toDelete = undefined; // it gets deleted automatically toDelete = undefined;
sendToaster(songInfo); sendToaster(songInfo);
return; return;
//Native datatype //Native datatype

View File

@ -1,9 +1,9 @@
const { setOptions } = require("../../config/plugins"); const { setOptions } = require("../../config/plugins");
const path = require("path"); const path = require("path");
const { app } = require("electron"); const { app } = require("electron");
const icon = path.join(__dirname, "assets", "youtube-music.png");
const fs = require("fs"); const fs = require("fs");
const icon = "assets/youtube-music.png";
const tempIcon = path.join(app.getPath("userData"), "tempIcon.png"); const tempIcon = path.join(app.getPath("userData"), "tempIcon.png");
module.exports.urgencyLevels = [ module.exports.urgencyLevels = [