use snoretoast CLSID

This commit is contained in:
Araxeus
2023-01-07 04:36:24 +02:00
parent fcb92fda84
commit 3412b3504f
2 changed files with 12 additions and 4 deletions

View File

@ -363,6 +363,9 @@ app.on("ready", () => {
// Register appID on windows // Register appID on windows
if (is.windows()) { if (is.windows()) {
// Depends on SnoreToast version https://github.com/KDE/snoretoast/blob/master/CMakeLists.txt#L5
const toastActivatorClsid = "eb1fdd5b-8f70-4b5a-b230-998a2dc19303";
const appID = "com.github.th-ch.youtube-music"; const appID = "com.github.th-ch.youtube-music";
app.setAppUserModelId(appID); app.setAppUserModelId(appID);
const appLocation = process.execPath; const appLocation = process.execPath;
@ -372,7 +375,11 @@ app.on("ready", () => {
const shortcutPath = path.join(appData, "Microsoft", "Windows", "Start Menu", "Programs", "YouTube Music.lnk"); const shortcutPath = path.join(appData, "Microsoft", "Windows", "Start Menu", "Programs", "YouTube Music.lnk");
try { // check if shortcut is registered and valid try { // check if shortcut is registered and valid
const shortcutDetails = electron.shell.readShortcutLink(shortcutPath); // throw error if doesn't exist yet const shortcutDetails = electron.shell.readShortcutLink(shortcutPath); // throw error if doesn't exist yet
if (shortcutDetails.target !== appLocation || shortcutDetails.appUserModelId !== appID) { if (
shortcutDetails.target !== appLocation ||
shortcutDetails.appUserModelId !== appID ||
shortcutDetails.toastActivatorClsid !== toastActivatorClsid
) {
throw "needUpdate"; throw "needUpdate";
} }
} catch (error) { // if not valid -> Register shortcut } catch (error) { // if not valid -> Register shortcut
@ -381,9 +388,10 @@ app.on("ready", () => {
error === "needUpdate" ? "update" : "create", error === "needUpdate" ? "update" : "create",
{ {
target: appLocation, target: appLocation,
cwd: appLocation.slice(0, appLocation.lastIndexOf(path.sep)), cwd: path.dirname(appLocation),
description: "YouTube Music Desktop App - including custom plugins", description: "YouTube Music Desktop App - including custom plugins",
appUserModelId: appID appUserModelId: appID,
toastActivatorClsid
} }
); );
} }

View File

@ -51,7 +51,7 @@ function sendToaster(songInfo) {
//download image and get path //download image and get path
let imgSrc = notificationImage(songInfo, true); let imgSrc = notificationImage(songInfo, true);
toDelete = { toDelete = {
appID: is.dev() ? undefined : "com.github.th-ch.youtube-music", appID: "com.github.th-ch.youtube-music",
title: songInfo.title || "Playing", title: songInfo.title || "Playing",
message: songInfo.artist, message: songInfo.artist,
id: parseInt(Math.random() * 1000000, 10), id: parseInt(Math.random() * 1000000, 10),