From 8284b56075baf819ec89884530ff2022cf94bdfb Mon Sep 17 00:00:00 2001 From: Araxeus Date: Mon, 10 May 2021 20:40:25 +0300 Subject: [PATCH 1/7] set appID on windows --- index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/index.js b/index.js index 81fd45b505..1e1af39152 100644 --- a/index.js +++ b/index.js @@ -255,6 +255,10 @@ app.on("ready", () => { }, 20000); } + if (is.windows()) { + app.setAppUserModelId("com.github.th-ch.youtube-music"); + } + mainWindow = createMainWindow(); setApplicationMenu(mainWindow); if (config.get("options.restartOnConfigChanges")) { From 93d4d3c976ec5b945cc0d122c506805c0502423c Mon Sep 17 00:00:00 2001 From: Araxeus Date: Mon, 10 May 2021 22:13:45 +0300 Subject: [PATCH 2/7] writeShortcut on windows --- index.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 1e1af39152..278d51c434 100644 --- a/index.js +++ b/index.js @@ -255,8 +255,18 @@ app.on("ready", () => { }, 20000); } - if (is.windows()) { - app.setAppUserModelId("com.github.th-ch.youtube-music"); + if (!is.dev() && is.windows()) { + const appID = "com.github.th-ch.youtube-music"; + electron.shell.writeShortcutLink( + path.join(app.getPath("appData"), 'Microsoft', 'Windows', 'Start Menu', 'Programs', 'YouTube Music.lnk'), + 'update', + { + target: process.execPath, + description: "YouTube Music Desktop App - including custom plugins", + appUserModelId: appID + } + ); + app.setAppUserModelId(appID); } mainWindow = createMainWindow(); From 8cca9f3eeb048ce27de8c06dc541b1bfc9e5c18b Mon Sep 17 00:00:00 2001 From: Araxeus Date: Mon, 10 May 2021 23:23:17 +0300 Subject: [PATCH 3/7] create shortcut only if needed --- index.js | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 278d51c434..399c8a3f4d 100644 --- a/index.js +++ b/index.js @@ -255,17 +255,29 @@ app.on("ready", () => { }, 20000); } + // Register shortcut & appID on windows if (!is.dev() && is.windows()) { const appID = "com.github.th-ch.youtube-music"; - electron.shell.writeShortcutLink( - path.join(app.getPath("appData"), 'Microsoft', 'Windows', 'Start Menu', 'Programs', 'YouTube Music.lnk'), - 'update', - { - target: process.execPath, - description: "YouTube Music Desktop App - including custom plugins", - appUserModelId: appID + const shortcutPath = path.join(app.getPath("appData"), "Microsoft", "Windows", "Start Menu", "Programs", "YouTube Music.lnk"); + const appLocation = process.execPath; + try { // check if shortcut is registered and valid + const shortcutDetails = electron.shell.readShortcutLink(shortcutPath); // throw error if doesn't exist yet + if (shortcutDetails.target !== appLocation || shortcutDetails.appUserModelId !== appID) { + throw undefined; } - ); + } 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); } From 78a7dcb7e8f60a992b2b9c9e39a7a45147966b1b Mon Sep 17 00:00:00 2001 From: Araxeus Date: Mon, 10 May 2021 23:46:56 +0300 Subject: [PATCH 4/7] lint --- index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 399c8a3f4d..851b26f9eb 100644 --- a/index.js +++ b/index.js @@ -263,12 +263,12 @@ app.on("ready", () => { try { // check if shortcut is registered and valid const shortcutDetails = electron.shell.readShortcutLink(shortcutPath); // throw error if doesn't exist yet if (shortcutDetails.target !== appLocation || shortcutDetails.appUserModelId !== appID) { - throw undefined; + throw "needUpdate"; } - } catch { // if not valid -> Register shortcut + } catch (error) { // if not valid -> Register shortcut electron.shell.writeShortcutLink( shortcutPath, - "create", + error === "needUpdate" ? "update" : "create", { target: appLocation, cwd: appLocation.slice(0, appLocation.lastIndexOf(path.sep)), From cb5ef1d6e58fcbef1b6120b9ea030892dce40791 Mon Sep 17 00:00:00 2001 From: Araxeus Date: Tue, 11 May 2021 00:15:54 +0300 Subject: [PATCH 5/7] check that app is installed / unpacked --- index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 851b26f9eb..c053e5e0fe 100644 --- a/index.js +++ b/index.js @@ -255,11 +255,12 @@ app.on("ready", () => { }, 20000); } + const appLocation = process.execPath; + // Register shortcut & appID on windows - if (!is.dev() && is.windows()) { + if (is.windows() && !is.dev() && !appLocation.startsWith(path.join(app.getPath("appData"), "..", "Local", "Temp"))) { const appID = "com.github.th-ch.youtube-music"; const shortcutPath = path.join(app.getPath("appData"), "Microsoft", "Windows", "Start Menu", "Programs", "YouTube Music.lnk"); - const appLocation = process.execPath; try { // check if shortcut is registered and valid const shortcutDetails = electron.shell.readShortcutLink(shortcutPath); // throw error if doesn't exist yet if (shortcutDetails.target !== appLocation || shortcutDetails.appUserModelId !== appID) { From d6150302225701a56dfcfafa6ff127edc10bf4a9 Mon Sep 17 00:00:00 2001 From: Araxeus Date: Tue, 11 May 2021 00:34:40 +0300 Subject: [PATCH 6/7] register appID on windows reguardless of shortcut --- index.js | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/index.js b/index.js index c053e5e0fe..4c33d75041 100644 --- a/index.js +++ b/index.js @@ -255,31 +255,32 @@ app.on("ready", () => { }, 20000); } - const appLocation = process.execPath; - - // Register shortcut & appID on windows - if (is.windows() && !is.dev() && !appLocation.startsWith(path.join(app.getPath("appData"), "..", "Local", "Temp"))) { + // Register appID on windows + if (is.windows()) { + const appLocation = process.execPath; const appID = "com.github.th-ch.youtube-music"; - const shortcutPath = path.join(app.getPath("appData"), "Microsoft", "Windows", "Start Menu", "Programs", "YouTube Music.lnk"); - try { // check if shortcut is registered and valid - const shortcutDetails = electron.shell.readShortcutLink(shortcutPath); // throw error if doesn't exist yet - if (shortcutDetails.target !== appLocation || shortcutDetails.appUserModelId !== appID) { - throw "needUpdate"; - } - } catch (error) { // if not valid -> Register shortcut - electron.shell.writeShortcutLink( - shortcutPath, - error === "needUpdate" ? "update" : "create", - { - target: appLocation, - cwd: appLocation.slice(0, appLocation.lastIndexOf(path.sep)), - description: "YouTube Music Desktop App - including custom plugins", - appUserModelId: appID + app.setAppUserModelId(appID); + // check shortcut validity if not in dev mode / running portable app + if (!is.dev() && !appLocation.startsWith(path.join(app.getPath("appData"), "..", "Local", "Temp"))) { + const shortcutPath = path.join(app.getPath("appData"), "Microsoft", "Windows", "Start Menu", "Programs", "YouTube Music.lnk"); + try { // check if shortcut is registered and valid + const shortcutDetails = electron.shell.readShortcutLink(shortcutPath); // throw error if doesn't exist yet + if (shortcutDetails.target !== appLocation || shortcutDetails.appUserModelId !== appID) { + throw "needUpdate"; } - ); + } catch (error) { // if not valid -> Register shortcut + electron.shell.writeShortcutLink( + shortcutPath, + error === "needUpdate" ? "update" : "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); } mainWindow = createMainWindow(); From cb6a5a478eafab5104200bbfc56c4d9ee7bfca60 Mon Sep 17 00:00:00 2001 From: Araxeus Date: Tue, 11 May 2021 16:47:51 +0300 Subject: [PATCH 7/7] lint --- index.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 4c33d75041..83f8d59f07 100644 --- a/index.js +++ b/index.js @@ -257,12 +257,13 @@ app.on("ready", () => { // Register appID on windows if (is.windows()) { - const appLocation = process.execPath; const appID = "com.github.th-ch.youtube-music"; app.setAppUserModelId(appID); + const appLocation = process.execPath; + const appData = app.getPath("appData"); // check shortcut validity if not in dev mode / running portable app - if (!is.dev() && !appLocation.startsWith(path.join(app.getPath("appData"), "..", "Local", "Temp"))) { - const shortcutPath = path.join(app.getPath("appData"), "Microsoft", "Windows", "Start Menu", "Programs", "YouTube Music.lnk"); + if (!is.dev() && !appLocation.startsWith(path.join(appData, "..", "Local", "Temp"))) { + const shortcutPath = path.join(appData, "Microsoft", "Windows", "Start Menu", "Programs", "YouTube Music.lnk"); try { // check if shortcut is registered and valid const shortcutDetails = electron.shell.readShortcutLink(shortcutPath); // throw error if doesn't exist yet if (shortcutDetails.target !== appLocation || shortcutDetails.appUserModelId !== appID) {