From 79227b6e651a536dfb024d3153f58ac67c397775 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 14 Nov 2020 15:18:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=93=E5=BC=80=E9=BB=98=E8=AE=A4=E6=9C=80?= =?UTF-8?q?=E5=A4=A7=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/index.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/main/index.js b/src/main/index.js index c68b758..7f9e79f 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -2,9 +2,10 @@ const { app, BrowserWindow, protocol, ipcMain, dialog } = require('electron') const path = require('path') +let mainWindow; function createWindow() { // Create the browser window. - const mainWindow = new BrowserWindow({ + mainWindow = new BrowserWindow({ width: 1080, height: 600, webPreferences: { @@ -25,12 +26,13 @@ function createWindow() { // and load the index.html of the app. // mainWindow.loadFile('./dist/index.html') // mainWindow.loadURL('http://47.104.91.134:9000'); - // mainWindow.loadURL('http://47.104.91.134:9000', { "extraHeaders": "pragma: no-cache\n" }); - mainWindow.loadURL('http://localhost:8081'); + mainWindow.loadURL('http://47.104.91.134:9000', { "extraHeaders": "pragma: no-cache\n" }); + // mainWindow.loadURL('http://localhost:8081'); // 隐藏菜单栏 mainWindow.setMenuBarVisibility(false); // Open the DevTools. - mainWindow.webContents.openDevTools() + // mainWindow.webContents.openDevTools() + mainWindow.maximize(); } // This method will be called when Electron has finished @@ -63,6 +65,20 @@ app.on('window-all-closed', function () { if (process.platform !== 'darwin') app.quit() }) +const gotTheLock = app.requestSingleInstanceLock() +if (!gotTheLock) { + app.quit() +} else { + app.on('second-instance', (event, commandLine, workingDirectory) => { + // 当运行第二个实例时,将会聚焦到mainWindow这个窗口 + if (mainWindow) { + if (mainWindow.isMinimized()) mainWindow.restore() + mainWindow.focus() + mainWindow.show() + } + }) +} + // 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.