mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-13 19:31:46 +00:00
use Electron with ToastXML instead of SnoreToast
* Add support for protocol commands * Remove node-notifier dependency
This commit is contained in:
36
index.js
36
index.js
@ -14,6 +14,7 @@ const { isTesting } = require("./utils/testing");
|
||||
const { setUpTray } = require("./tray");
|
||||
const { setupSongInfo } = require("./providers/song-info");
|
||||
const { setupAppControls, restart } = require("./providers/app-controls");
|
||||
const { APP_PROTOCOL, setupProtocolHandler, handleProtocol } = require("./providers/protocol-handler");
|
||||
|
||||
// Catch errors and log them
|
||||
unhandled({
|
||||
@ -29,17 +30,9 @@ const app = electron.app;
|
||||
let mainWindow;
|
||||
autoUpdater.autoDownload = false;
|
||||
|
||||
if(config.get("options.singleInstanceLock")){
|
||||
const gotTheLock = app.requestSingleInstanceLock();
|
||||
if (!gotTheLock) app.quit();
|
||||
|
||||
app.on('second-instance', () => {
|
||||
if (!mainWindow) return;
|
||||
if (mainWindow.isMinimized()) mainWindow.restore();
|
||||
if (!mainWindow.isVisible()) mainWindow.show();
|
||||
mainWindow.focus();
|
||||
});
|
||||
}
|
||||
const gotTheLock = app.requestSingleInstanceLock();
|
||||
if (!gotTheLock) app.quit();
|
||||
|
||||
app.commandLine.appendSwitch(
|
||||
"js-flags",
|
||||
@ -354,7 +347,7 @@ app.on("ready", () => {
|
||||
// Clear cache after 20s
|
||||
const clearCacheTimeout = setTimeout(() => {
|
||||
if (is.dev()) {
|
||||
console.log("Clearing app cache.");
|
||||
console.log("Clearing app cache.");
|
||||
}
|
||||
electron.session.defaultSession.clearCache();
|
||||
clearTimeout(clearCacheTimeout);
|
||||
@ -363,9 +356,6 @@ app.on("ready", () => {
|
||||
|
||||
// Register appID on 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";
|
||||
app.setAppUserModelId(appID);
|
||||
const appLocation = process.execPath;
|
||||
@ -391,7 +381,6 @@ app.on("ready", () => {
|
||||
cwd: path.dirname(appLocation),
|
||||
description: "YouTube Music Desktop App - including custom plugins",
|
||||
appUserModelId: appID,
|
||||
toastActivatorClsid
|
||||
}
|
||||
);
|
||||
}
|
||||
@ -402,6 +391,23 @@ app.on("ready", () => {
|
||||
setApplicationMenu(mainWindow);
|
||||
setUpTray(app, mainWindow);
|
||||
|
||||
setupProtocolHandler(mainWindow);
|
||||
|
||||
app.on('second-instance', (_event, commandLine, _workingDirectory) => {
|
||||
const uri = `${APP_PROTOCOL}://`;
|
||||
const protocolArgv = commandLine.find(arg => arg.startsWith(uri));
|
||||
if (protocolArgv) {
|
||||
const command = protocolArgv.slice(uri.length, -1);
|
||||
if (is.dev()) console.debug(`Received command over protocol: "${command}"`);
|
||||
handleProtocol(command);
|
||||
return;
|
||||
}
|
||||
if (!mainWindow) return;
|
||||
if (mainWindow.isMinimized()) mainWindow.restore();
|
||||
if (!mainWindow.isVisible()) mainWindow.show();
|
||||
mainWindow.focus();
|
||||
});
|
||||
|
||||
// Autostart at login
|
||||
app.setLoginItemSettings({
|
||||
openAtLogin: config.get("options.startAtLogin"),
|
||||
|
||||
Reference in New Issue
Block a user