Browse Source

auto launch

gaoshuaixing 4 years ago
parent
commit
250b0a732d
1 changed files with 28 additions and 0 deletions
  1. 28 0
      electron/lib/autoLaunch.js

+ 28 - 0
electron/lib/autoLaunch.js

@@ -0,0 +1,28 @@
+const { app } = require('electron');
+const { LOGIN_SETTING_OPTIONS } = require('./constant').AutoLaunch;
+
+class AutoLaunch {
+  enable () {
+    const enabled = app.getLoginItemSettings(LOGIN_SETTING_OPTIONS).openAtLogin;
+    if (enabled) {
+      return true;
+    }
+    app.setLoginItemSettings({
+      ...LOGIN_SETTING_OPTIONS,
+      openAtLogin: true
+    })
+    return true;
+  }
+  
+  disable () {
+    app.setLoginItemSettings({ openAtLogin: false })
+    return true;
+  }
+
+  isEnabled () {
+    const enabled = app.getLoginItemSettings(LOGIN_SETTING_OPTIONS).openAtLogin;
+    return enabled;
+  }
+}
+
+module.exports = AutoLaunch;