Browse Source

启动时只允许单实例。 #130 #142

oldj 8 years ago
parent
commit
d7ff89ba2b
2 changed files with 16 additions and 1 deletions
  1. 15 0
      app/main.js
  2. 1 1
      app/version.js

+ 15 - 0
app/main.js

@@ -81,6 +81,21 @@ function createWindow() {
     require('./bg/events').init(app, contents);
 }
 
+const should_quit = app.makeSingleInstance((commandLine, workingDirectory) => {
+    // Someone tried to run a second instance, we should focus our window.
+    if (mainWindow) {
+        if (mainWindow.isMinimized()) {
+            mainWindow.restore();
+        }
+        mainWindow.show();
+        // mainWindow.focus();
+    }
+});
+
+if (should_quit) {
+    app.quit();
+}
+
 // This method will be called when Electron has finished
 // initialization and is ready to create browser windows.
 // Some APIs can only be used after this event occurs.

+ 1 - 1
app/version.js

@@ -1 +1 @@
-exports.version = [3,2,2,4246];
+exports.version = [3,2,2,4247];