create shortcut only if needed

This commit is contained in:
Araxeus
2021-05-10 23:23:17 +03:00
parent 93d4d3c976
commit 8cca9f3eeb

View File

@ -255,17 +255,29 @@ app.on("ready", () => {
}, 20000); }, 20000);
} }
// Register shortcut & appID on windows
if (!is.dev() && is.windows()) { if (!is.dev() && is.windows()) {
const appID = "com.github.th-ch.youtube-music"; const appID = "com.github.th-ch.youtube-music";
electron.shell.writeShortcutLink( const shortcutPath = path.join(app.getPath("appData"), "Microsoft", "Windows", "Start Menu", "Programs", "YouTube Music.lnk");
path.join(app.getPath("appData"), 'Microsoft', 'Windows', 'Start Menu', 'Programs', 'YouTube Music.lnk'), const appLocation = process.execPath;
'update', try { // check if shortcut is registered and valid
{ const shortcutDetails = electron.shell.readShortcutLink(shortcutPath); // throw error if doesn't exist yet
target: process.execPath, if (shortcutDetails.target !== appLocation || shortcutDetails.appUserModelId !== appID) {
description: "YouTube Music Desktop App - including custom plugins", throw undefined;
appUserModelId: appID
} }
); } catch { // if not valid -> Register shortcut
electron.shell.writeShortcutLink(
shortcutPath,
"create",
{
target: appLocation,
cwd: appLocation.slice(0, appLocation.lastIndexOf(path.sep)),
description: "YouTube Music Desktop App - including custom plugins",
appUserModelId: appID
}
);
}
// set appID
app.setAppUserModelId(appID); app.setAppUserModelId(appID);
} }