Selaa lähdekoodia

限制一个窗口

wallace5303 4 vuotta sitten
vanhempi
commit
b0942284a0
2 muutettua tiedostoa jossa 16 lisäystä ja 1 poistoa
  1. 15 0
      main.js
  2. 1 1
      package.json

+ 15 - 0
main.js

@@ -30,6 +30,21 @@ eggConfig.env = ENV
 const eLogger = require('./electron/lib/eLogger').get()
 
 async function initialize () {
+
+  // 限制一个窗口
+  const gotTheLock = app.requestSingleInstanceLock()
+  if (!gotTheLock) {
+    helper.appQuit()
+  }
+  app.on('second-instance', (event) => {
+    if (MAIN_WINDOW) {
+      if (MAIN_WINDOW.isMinimized()) {
+        MAIN_WINDOW.restore()
+      }
+      MAIN_WINDOW.focus()
+    }
+  })
+
   app.whenReady().then(() => {
     createWindow()
     app.on('activate', function () {

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "electron-egg",
-  "version": "1.16.1",
+  "version": "1.16.2",
   "description": "A fast, desktop software development framework",
   "main": "main.js",
   "scripts": {