mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-16 20:52:06 +00:00
minify
This commit is contained in:
@ -3,7 +3,7 @@ const is = require("electron-is");
|
|||||||
const getSongInfo = require("../../providers/song-info");
|
const getSongInfo = require("../../providers/song-info");
|
||||||
const { notificationImage } = require("./utils");
|
const { notificationImage } = require("./utils");
|
||||||
|
|
||||||
const { setup, notifyInteractive } = require("./interactive")
|
const { setupInteractive, notifyInteractive } = require("./interactive")
|
||||||
|
|
||||||
const notify = (info, options) => {
|
const notify = (info, options) => {
|
||||||
|
|
||||||
@ -24,9 +24,10 @@ const notify = (info, options) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
module.exports = (win, options) => {
|
module.exports = (win, options) => {
|
||||||
|
const isInteractive = is.windows() && options.interactive;
|
||||||
//setup interactive notifications for windows
|
//setup interactive notifications for windows
|
||||||
if (is.windows()) {
|
if (isInteractive) {
|
||||||
setup(win);
|
setupInteractive(win);
|
||||||
}
|
}
|
||||||
const registerCallback = getSongInfo(win);
|
const registerCallback = getSongInfo(win);
|
||||||
let oldNotification;
|
let oldNotification;
|
||||||
@ -45,7 +46,7 @@ module.exports = (win, options) => {
|
|||||||
// If url isn"t the same as last one - send notification
|
// If url isn"t the same as last one - send notification
|
||||||
if (songInfo.url !== oldURL) {
|
if (songInfo.url !== oldURL) {
|
||||||
oldURL = songInfo.url;
|
oldURL = songInfo.url;
|
||||||
if (is.windows() && options.interactive) {
|
if (isInteractive) {
|
||||||
notifyInteractive(songInfo);
|
notifyInteractive(songInfo);
|
||||||
} else {
|
} else {
|
||||||
// Close the old notification
|
// Close the old notification
|
||||||
|
|||||||
@ -2,40 +2,29 @@ const { notificationImage, icons } = require("./utils");
|
|||||||
const getSongControls = require('../../providers/song-controls');
|
const getSongControls = require('../../providers/song-controls');
|
||||||
const notifier = require("node-notifier");
|
const notifier = require("node-notifier");
|
||||||
|
|
||||||
//store song controls
|
//store song controls reference on launch
|
||||||
let controls;
|
let controls;
|
||||||
|
module.exports.setupInteractive = (win) => {
|
||||||
|
//save controls
|
||||||
|
const { playPause, next, previous } = getSongControls(win);
|
||||||
|
controls = { playPause, next, previous };
|
||||||
|
}
|
||||||
|
|
||||||
//delete old notification
|
//delete old notification
|
||||||
let toDelete;
|
let toDelete;
|
||||||
function Delete() {
|
function Delete() {
|
||||||
if (toDelete === undefined) {
|
if (toDelete !== undefined) {
|
||||||
return;
|
const removeNotif = Object.assign(toDelete, {
|
||||||
|
remove: toDelete.id
|
||||||
|
})
|
||||||
|
notifier.notify(removeNotif)
|
||||||
|
|
||||||
|
toDelete = undefined;
|
||||||
}
|
}
|
||||||
const removeNotif = Object.assign(toDelete, {
|
|
||||||
remove: toDelete.id
|
|
||||||
})
|
|
||||||
notifier.notify(removeNotif)
|
|
||||||
|
|
||||||
toDelete = undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Setup on launch
|
|
||||||
module.exports.setup = (win) => {
|
|
||||||
//save controls
|
|
||||||
const { playPause, next, previous } = getSongControls(win);
|
|
||||||
controls = { playPause, next, previous };
|
|
||||||
//setup global listeners
|
|
||||||
notifier.on("dismissed", () => { Delete(); });
|
|
||||||
notifier.on("timeout", () => { Delete(); });
|
|
||||||
|
|
||||||
//remove all listeners on close
|
|
||||||
win.on("closed", () => {
|
|
||||||
notifier.removeAllListeners();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//New notification
|
//New notification
|
||||||
module.exports.notifyInteractive = function sendToaster(songInfo) {
|
module.exports.notifyInteractive = (songInfo) => {
|
||||||
Delete();
|
Delete();
|
||||||
//download image and get path
|
//download image and get path
|
||||||
let imgSrc = notificationImage(songInfo, true);
|
let imgSrc = notificationImage(songInfo, true);
|
||||||
@ -61,6 +50,7 @@ module.exports.notifyInteractive = function sendToaster(songInfo) {
|
|||||||
console.log(`ERROR = ${err}\n DATA = ${data}`);
|
console.log(`ERROR = ${err}\n DATA = ${data}`);
|
||||||
}
|
}
|
||||||
switch (data) {
|
switch (data) {
|
||||||
|
//buttons
|
||||||
case icons.previous.normalize():
|
case icons.previous.normalize():
|
||||||
controls.previous();
|
controls.previous();
|
||||||
return;
|
return;
|
||||||
@ -76,6 +66,11 @@ module.exports.notifyInteractive = function sendToaster(songInfo) {
|
|||||||
songInfo.isPaused = true;
|
songInfo.isPaused = true;
|
||||||
toDelete = undefined; // it gets deleted automatically
|
toDelete = undefined; // it gets deleted automatically
|
||||||
sendToaster(songInfo);
|
sendToaster(songInfo);
|
||||||
|
return;
|
||||||
|
//Native datatype
|
||||||
|
case "dismissed":
|
||||||
|
case "timeout":
|
||||||
|
Delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user