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.