mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 10:31:47 +00:00
add single instance lock option
This commit is contained in:
20
index.js
20
index.js
@ -26,6 +26,22 @@ unhandled({
|
|||||||
process.env.NODE_OPTIONS = "";
|
process.env.NODE_OPTIONS = "";
|
||||||
|
|
||||||
const app = electron.app;
|
const app = electron.app;
|
||||||
|
// Prevent window being garbage collected
|
||||||
|
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();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
app.commandLine.appendSwitch(
|
app.commandLine.appendSwitch(
|
||||||
"js-flags",
|
"js-flags",
|
||||||
// WebAssembly flags
|
// WebAssembly flags
|
||||||
@ -54,10 +70,6 @@ require("electron-debug")({
|
|||||||
showDevTools: false //disable automatic devTools on new window
|
showDevTools: false //disable automatic devTools on new window
|
||||||
});
|
});
|
||||||
|
|
||||||
// Prevent window being garbage collected
|
|
||||||
let mainWindow;
|
|
||||||
autoUpdater.autoDownload = false;
|
|
||||||
|
|
||||||
let icon = "assets/youtube-music.png";
|
let icon = "assets/youtube-music.png";
|
||||||
if (process.platform == "win32") {
|
if (process.platform == "win32") {
|
||||||
icon = "assets/generated/icon.ico";
|
icon = "assets/generated/icon.ico";
|
||||||
|
|||||||
13
menu.js
13
menu.js
@ -87,6 +87,19 @@ const mainMenuTemplate = (win) => {
|
|||||||
config.set("options.removeUpgradeButton", item.checked);
|
config.set("options.removeUpgradeButton", item.checked);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: "Single instance lock",
|
||||||
|
type: "checkbox",
|
||||||
|
checked: config.get("options.singleInstanceLock"),
|
||||||
|
click: (item) => {
|
||||||
|
config.set("options.singleInstanceLock", item.checked);
|
||||||
|
if (item.checked && !app.hasSingleInstanceLock()) {
|
||||||
|
app.requestSingleInstanceLock();
|
||||||
|
} else if (!item.checked && app.hasSingleInstanceLock()) {
|
||||||
|
app.releaseSingleInstanceLock();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
...(is.windows() || is.linux()
|
...(is.windows() || is.linux()
|
||||||
? [
|
? [
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user