Browse Source

[ADD] autolaunch

Gogs 6 years ago
parent
commit
7e8fb437e8
1 changed files with 30 additions and 0 deletions
  1. 30 0
      src/index.js

+ 30 - 0
src/index.js

@@ -12,10 +12,28 @@ let settings = readSettings()
 // const isDevMode = process.execPath.match(/[\\/]electron/)
 const isDevMode = settings.appMode === 'development'
 
+const AppAutolaunch = new Autolaunch({
+    name: 'Servidor de Impresión',
+    isHidden: true
+})
+
 if (isDevMode) {
     enableLiveReload()
 }
 
+const isSecondInstance = app.makeSingleInstance(() => {
+    if (win) {
+        if (win.isMinimized()) {
+            win.restore()
+            win.focus()
+        }
+    }
+})
+
+if (isSecondInstance) {
+    app.quit()
+}
+
 /**
  * 
  */
@@ -44,6 +62,18 @@ const createWindow = async () => {
         win.webContents.openDevTools()
     }
 
+    AppAutolaunch.enable()
+
+    AppAutolaunch.isEnabled().then(enable => {
+        if (enable) {
+            return
+        }
+
+        AppAutolaunch.enable()
+    }).catch(e => {
+        console.log(e)
+    })
+
     win.once('ready-to-show', () => {
         win.show()
     })