Fixed multiple instances of RPS RPS-16

This commit is contained in:
Patrick Fic
2020-10-26 11:23:09 -07:00
parent 6359641b8c
commit 3c98097a78

View File

@@ -95,7 +95,6 @@ var menu = Menu.buildFromTemplate([
let mainWindow;
let tray = null;
function createWindow() {
makeSingleInstance();
// Create the browser window.
Menu.setApplicationMenu(menu);
mainWindow = new BrowserWindow({
@@ -112,44 +111,62 @@ function createWindow() {
preload: path.join(__dirname, "preload.js"), // use a preload script
},
});
// and load the index.html of the app.
// win.loadFile("index.html");
mainWindow.loadURL(
isDev
? "http://localhost:3000"
: `file://${path.join(__dirname, "/../build/index.html")}`
);
// mainWindow.on("close", function (event) {
// event.preventDefault();
// mainWindow.hide();
// tray = createTray();
// });
mainWindow.on("minimize", function (event) {
event.preventDefault();
mainWindow.hide();
tray = createTray();
});
ipcMain.on(ipcTypes.quit, (event, arg) => {
app.isQuiting = true;
const gotTheLock = app.requestSingleInstanceLock();
if (!gotTheLock) {
app.quit();
});
} else {
app.on("second-instance", (event, commandLine, workingDirectory) => {
// Someone tried to run a second instance, we should focus our window.
if (mainWindow) {
if (mainWindow.isMinimized()) mainWindow.restore();
mainWindow.focus();
}
});
// Open the DevTools.
if (isDev) {
mainWindow.webContents.openDevTools({
// mode: "detach"
// and load the index.html of the app.
// win.loadFile("index.html");
mainWindow.loadURL(
isDev
? "http://localhost:3000"
: `file://${path.join(__dirname, "/../build/index.html")}`
);
// mainWindow.on("close", function (event) {
// event.preventDefault();
// mainWindow.hide();
// if (!tray) {
// tray = createTray();
// }
// });
mainWindow.on("minimize", function (event) {
event.preventDefault();
mainWindow.hide();
if (!tray) {
tray = createTray();
}
});
ipcMain.on(ipcTypes.quit, (event, arg) => {
app.isQuiting = true;
app.quit();
});
// Open the DevTools.
if (isDev) {
mainWindow.webContents.openDevTools({
// mode: "detach"
});
}
mainWindow.maximize();
autoUpdater.checkForUpdatesAndNotify();
globalShortcut.register("CommandOrControl+Shift+I", () => {
mainWindow.webContents.toggleDevTools();
});
}
mainWindow.maximize();
autoUpdater.checkForUpdatesAndNotify();
globalShortcut.register("CommandOrControl+Shift+I", () => {
mainWindow.webContents.toggleDevTools();
});
}
exports.mainWindow = mainWindow;
@@ -192,21 +209,6 @@ app.on("activate", () => {
}
});
// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.
function makeSingleInstance() {
if (process.mas) return;
app.requestSingleInstanceLock();
app.on("second-instance", () => {
if (mainWindow) {
if (mainWindow.isMinimized()) mainWindow.restore();
mainWindow.focus();
}
});
}
function createTray() {
let appIcon = new Tray(path.join(__dirname, "../src/assets/logo192.png"));
const contextMenu = Menu.buildFromTemplate([