mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-10 10:11:46 +00:00
Merge pull request #578 from Araxeus/single-instance-lock-option
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 = "";
|
||||
|
||||
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(
|
||||
"js-flags",
|
||||
// WebAssembly flags
|
||||
@ -54,10 +70,6 @@ require("electron-debug")({
|
||||
showDevTools: false //disable automatic devTools on new window
|
||||
});
|
||||
|
||||
// Prevent window being garbage collected
|
||||
let mainWindow;
|
||||
autoUpdater.autoDownload = false;
|
||||
|
||||
let icon = "assets/youtube-music.png";
|
||||
if (process.platform == "win32") {
|
||||
icon = "assets/generated/icon.ico";
|
||||
|
||||
29
menu.js
29
menu.js
@ -87,6 +87,19 @@ const mainMenuTemplate = (win) => {
|
||||
config.setMenuOption("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()
|
||||
? [
|
||||
{
|
||||
@ -166,14 +179,14 @@ const mainMenuTemplate = (win) => {
|
||||
{
|
||||
label: "Advanced options",
|
||||
submenu: [
|
||||
{
|
||||
label: "Proxy",
|
||||
type: "checkbox",
|
||||
checked: !!config.get("options.proxy"),
|
||||
click: (item) => {
|
||||
setProxy(item, win);
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "Proxy",
|
||||
type: "checkbox",
|
||||
checked: !!config.get("options.proxy"),
|
||||
click: (item) => {
|
||||
setProxy(item, win);
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "Disable hardware acceleration",
|
||||
type: "checkbox",
|
||||
|
||||
Reference in New Issue
Block a user