mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-15 12:21:47 +00:00
Center Icon on ALL notifications
Delete notification on windowclosed Refactor notifications.utils.setOption
This commit is contained in:
@ -12,6 +12,10 @@ module.exports.setupInteractive = (win, unpauseNotification) => {
|
|||||||
controls = { playPause, next, previous };
|
controls = { playPause, next, previous };
|
||||||
|
|
||||||
onPause = unpauseNotification;
|
onPause = unpauseNotification;
|
||||||
|
|
||||||
|
win.webContents.on("closed", () => {
|
||||||
|
Delete()
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
//delete old notification
|
//delete old notification
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
const { urgencyLevels, setUrgency, setUnpause, setInteractive } = require("./utils");
|
const { urgencyLevels, setOption } = require("./utils");
|
||||||
const is = require("electron-is");
|
const is = require("electron-is");
|
||||||
|
|
||||||
module.exports = (win, options) => [
|
module.exports = (win, options) => [
|
||||||
@ -8,21 +8,21 @@ module.exports = (win, options) => [
|
|||||||
label: level.name,
|
label: level.name,
|
||||||
type: "radio",
|
type: "radio",
|
||||||
checked: options.urgency === level.value,
|
checked: options.urgency === level.value,
|
||||||
click: () => setUrgency(options, level.value)
|
click: () => setOption(options, "urgency", level.value)
|
||||||
})),
|
})),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "Show notification on unpause",
|
label: "Show notification on unpause",
|
||||||
type: "checkbox",
|
type: "checkbox",
|
||||||
checked: options.unpauseNotification,
|
checked: options.unpauseNotification,
|
||||||
click: (item) => setUnpause(options, item.checked)
|
click: (item) => setOption(options, "unpauseNotification", item.checked)
|
||||||
},
|
},
|
||||||
...(is.windows() ?
|
...(is.windows() ?
|
||||||
[{
|
[{
|
||||||
label: "Interactive Notifications",
|
label: "Interactive Notifications",
|
||||||
type: "checkbox",
|
type: "checkbox",
|
||||||
checked: options.interactive,
|
checked: options.interactive,
|
||||||
click: (item) => setInteractive(options, item.checked)
|
click: (item) => setOption(options, "interactive", item.checked)
|
||||||
}] :
|
}] :
|
||||||
[])
|
[])
|
||||||
];
|
];
|
||||||
|
|||||||
@ -6,52 +6,51 @@ const fs = require("fs");
|
|||||||
const icon = "assets/youtube-music.png";
|
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 = [
|
|
||||||
{ name: "Low", value: "low" },
|
|
||||||
{ name: "Normal", value: "normal" },
|
|
||||||
{ name: "High", value: "critical" },
|
|
||||||
];
|
|
||||||
module.exports.setUrgency = (options, level) => {
|
|
||||||
options.urgency = level;
|
|
||||||
setOption(options);
|
|
||||||
};
|
|
||||||
module.exports.setUnpause = (options, value) => {
|
|
||||||
options.unpauseNotification = value;
|
|
||||||
setOption(options);
|
|
||||||
};
|
|
||||||
module.exports.setInteractive = (options, value) => {
|
|
||||||
options.interactive = value;
|
|
||||||
setOption(options);
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports.notificationImage = function (songInfo, saveIcon = false) {
|
|
||||||
//return local path to temp icon
|
|
||||||
if (saveIcon && !!songInfo.image) {
|
|
||||||
try {
|
|
||||||
fs.writeFileSync(tempIcon,
|
|
||||||
songInfo.image
|
|
||||||
.resize({ height: 256, width: 256 })
|
|
||||||
.toPNG()
|
|
||||||
);
|
|
||||||
} catch (err) {
|
|
||||||
console.log(`Error downloading song icon:\n${err.toString()}`)
|
|
||||||
return icon;
|
|
||||||
}
|
|
||||||
return tempIcon;
|
|
||||||
}
|
|
||||||
//else: return image
|
|
||||||
return songInfo.image
|
|
||||||
? songInfo.image.resize({ height: 256, width: 256 })
|
|
||||||
: icon
|
|
||||||
};
|
|
||||||
|
|
||||||
let setOption = options => {
|
|
||||||
setOptions("notifications", options)
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.icons = {
|
module.exports.icons = {
|
||||||
play: "\u{1405}", // ᐅ
|
play: "\u{1405}", // ᐅ
|
||||||
pause: "\u{2016}", // ‖
|
pause: "\u{2016}", // ‖
|
||||||
next: "\u{1433}", // ᐳ
|
next: "\u{1433}", // ᐳ
|
||||||
previous: "\u{1438}" // ᐸ
|
previous: "\u{1438}" // ᐸ
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports.setOption = (options, option, value) => {
|
||||||
|
options[option] = value;
|
||||||
|
setOptions("notifications", options)
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.urgencyLevels = [
|
||||||
|
{ name: "Low", value: "low" },
|
||||||
|
{ name: "Normal", value: "normal" },
|
||||||
|
{ name: "High", value: "critical" },
|
||||||
|
];
|
||||||
|
|
||||||
|
module.exports.notificationImage = function (songInfo, saveIcon = false) {
|
||||||
|
//return local path to temp icon
|
||||||
|
if (saveIcon && !!songInfo.image) {
|
||||||
|
try {
|
||||||
|
fs.writeFileSync(tempIcon,
|
||||||
|
centerNativeImage(songInfo.image)
|
||||||
|
.toPNG()
|
||||||
|
);
|
||||||
|
} catch (err) {
|
||||||
|
console.log(`Error writing song icon to disk:\n${err.toString()}`)
|
||||||
|
return icon;
|
||||||
|
}
|
||||||
|
return tempIcon;
|
||||||
|
}
|
||||||
|
//else: return image
|
||||||
|
return songInfo.image
|
||||||
|
? centerNativeImage(songInfo.image)
|
||||||
|
: icon
|
||||||
|
};
|
||||||
|
|
||||||
|
function centerNativeImage(nativeImage) {
|
||||||
|
const tempImage = nativeImage.resize({ height: 256 });
|
||||||
|
const margin = Math.max((tempImage.getSize().width - 256), 0);
|
||||||
|
|
||||||
|
return tempImage.crop({
|
||||||
|
x: Math.round(margin / 2),
|
||||||
|
y: 0,
|
||||||
|
width: 256, height: 256
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user