Browse Source

代码优化

gaoshuaixing 4 years ago
parent
commit
0d44673870

+ 0 - 1
app.js

@@ -3,7 +3,6 @@
  * @param app
  */
 'use strict';
-global.CODE = require('./app/const/statusCode');
 
 class AppBootHook {
   constructor(app) {

+ 0 - 6
app/config/openAuthConfig.js

@@ -1,6 +0,0 @@
-'use strict';
-module.exports = {
-  authInfo: {
-    key: 'Tsld2o4elg',
-  },
-};

+ 0 - 0
app/const/common.js


+ 35 - 0
app/controller/v1/example.js

@@ -146,6 +146,41 @@ class ExampleController extends BaseController {
 
     self.sendSuccess(data);
   }
+
+  async autoLaunchEnable() {
+    const { service } = this;
+
+    await service.example.autoLaunchEnable();
+    const data = {
+      isEnabled: true
+    };
+
+    this.sendSuccess(data);
+  }
+  
+  async autoLaunchDisable() {
+    const { service } = this;
+    
+    await service.example.autoLaunchDisable();
+    const data = {
+      isEnabled: false
+    };
+
+    this.sendSuccess(data);
+  }
+
+  async autoLaunchIsEnabled() {
+    const { service } = this;
+
+    const data = {
+      isEnabled: null
+    };
+
+    const isEnabled = await service.example.autoLaunchIsEnabled();
+    data.isEnabled = isEnabled;
+
+    this.sendSuccess(data);
+  }
 }
 
 module.exports = ExampleController;

+ 0 - 43
app/controller/v1/setting.js

@@ -1,43 +0,0 @@
-'use strict';
-
-const BaseController = require('../base');
-
-class SettingController extends BaseController {
-
-  async autoLaunchEnable() {
-    const { service } = this;
-
-    await service.setting.autoLaunchEnable();
-    const data = {
-      isEnabled: true
-    };
-
-    this.sendSuccess(data);
-  }
-  
-  async autoLaunchDisable() {
-    const { service } = this;
-    
-    await service.setting.autoLaunchDisable();
-    const data = {
-      isEnabled: false
-    };
-
-    this.sendSuccess(data);
-  }
-
-  async autoLaunchIsEnabled() {
-    const { service } = this;
-
-    const data = {
-      isEnabled: null
-    };
-
-    const isEnabled = await service.setting.autoLaunchIsEnabled();
-    data.isEnabled = isEnabled;
-
-    this.sendSuccess(data);
-  }
-}
-
-module.exports = SettingController;

+ 6 - 0
app/router/example.js

@@ -23,4 +23,10 @@ module.exports = app => {
   router.post('/api/v1/example/getTestData', controller.v1.example.getTestData);
   // set shortcut
   router.post('/api/v1/example/setShortcut', controller.v1.example.setShortcut);
+  // open launch
+  router.post('/api/v1/example/autoLaunchEnable', controller.v1.example.autoLaunchEnable);
+  // close launch 
+  router.post('/api/v1/example/autoLaunchDisable', controller.v1.example.autoLaunchDisable);
+  // is launch 
+  router.post('/api/v1/example/autoLaunchIsEnabled', controller.v1.example.autoLaunchIsEnabled);
 };

+ 0 - 4
app/router/index.js

@@ -8,13 +8,9 @@ module.exports = app => {
   // home
   router.get('/', controller.v1.home.index);
 
-  // hello
-  //router.get('/', controller.v1.home.hello);
-
   // html
   router.get('/home', controller.v1.home.index);
 
   // 引入其他路由
   require('./example')(app);
-  require('./setting')(app);
 };

+ 0 - 14
app/router/setting.js

@@ -1,14 +0,0 @@
-'use strict';
-
-/**
- * @param {Egg.Application} app - egg application
- */
-module.exports = app => {
-  const { router, controller } = app;
-  // open launch
-  router.post('/api/v1/setting/autoLaunchEnable', controller.v1.setting.autoLaunchEnable);
-  // close launch 
-  router.post('/api/v1/setting/autoLaunchDisable', controller.v1.setting.autoLaunchDisable);
-  // is launch 
-  router.post('/api/v1/setting/autoLaunchIsEnabled', controller.v1.setting.autoLaunchIsEnabled);
-};

+ 18 - 0
app/service/example.js

@@ -59,6 +59,24 @@ class ExampleService extends BaseService {
 
     return res;
   }
+
+  async autoLaunchEnable() {
+    const callResult = await this.ipcCall('example.autoLaunchEnable');
+
+    return callResult.data;
+  }
+
+  async autoLaunchDisable() {
+    const callResult = await this.ipcCall('example.autoLaunchDisable');
+
+    return callResult.data;
+  }
+
+  async autoLaunchIsEnabled() {
+    const callResult = await this.ipcCall('example.autoLaunchIsEnabled');
+
+    return callResult.data;
+  }
 }
 
 module.exports = ExampleService;

+ 0 - 26
app/service/setting.js

@@ -1,26 +0,0 @@
-'use strict';
-
-const BaseService = require('./base');
-
-class SettingService extends BaseService {
-
-  async autoLaunchEnable() {
-    const callResult = await this.ipcCall('base.autoLaunchEnable');
-
-    return callResult.data;
-  }
-
-  async autoLaunchDisable() {
-    const callResult = await this.ipcCall('base.autoLaunchDisable');
-
-    return callResult.data;
-  }
-
-  async autoLaunchIsEnabled() {
-    const callResult = await this.ipcCall('base.autoLaunchIsEnabled');
-
-    return callResult.data;
-  }
-}
-
-module.exports = SettingService;

+ 0 - 21
electron/apis/base.js

@@ -1,21 +0,0 @@
-'use strict'
-
-const AutoLaunchManager = require('../lib/autoLaunch')
-
-exports.autoLaunchEnable = function () {
-  const autoLaunchManager = new AutoLaunchManager()
-  const enable = autoLaunchManager.enable()
-  return enable
-}
-
-exports.autoLaunchDisable = function () {
-  const autoLaunchManager = new AutoLaunchManager()
-  const disable = autoLaunchManager.disable()
-  return disable
-}
-
-exports.autoLaunchIsEnabled = function () {
-  const autoLaunchManager = new AutoLaunchManager()
-  const isEnable = autoLaunchManager.isEnabled()
-  return isEnable
-}

+ 21 - 5
electron/apis/example.js

@@ -1,11 +1,9 @@
 'use strict';
 
 const path = require('path');
-const {
-  app,
-  webContents,
-  shell
-} = require('electron');
+
+const {app, webContents, shell} = require('electron');
+const AutoLaunchManager = require('../lib/autoLaunch');
 const shortcut = require('../lib/shortcut');
 
 exports.getPath = function () {
@@ -36,6 +34,24 @@ exports.setShortcut = function (shortcutObj) {
   return true;
 }
 
+exports.autoLaunchEnable = function () {
+  const autoLaunchManager = new AutoLaunchManager()
+  const enable = autoLaunchManager.enable()
+  return enable
+}
+
+exports.autoLaunchDisable = function () {
+  const autoLaunchManager = new AutoLaunchManager()
+  const disable = autoLaunchManager.disable()
+  return disable
+}
+
+exports.autoLaunchIsEnabled = function () {
+  const autoLaunchManager = new AutoLaunchManager()
+  const isEnable = autoLaunchManager.isEnabled()
+  return isEnable
+}
+
 function getElectronPath(filepath) {
   //filepath = path.resolve(filepath);
   filepath = filepath.replace("resources", "");

+ 3 - 3
frontend/src/api/main.js

@@ -7,9 +7,9 @@ const mainApi = {
   uploadFile: '/api/v1/example/uploadFile',
   executeJS: '/api/v1/example/executeJS',
   setShortcut: '/api/v1/example/setShortcut',
-  autoLaunchEnable: '/api/v1/setting/autoLaunchEnable',
-  autoLaunchDisable: '/api/v1/setting/autoLaunchDisable',
-  autoLaunchIsEnabled: '/api/v1/setting/autoLaunchIsEnabled'
+  autoLaunchEnable: '/api/v1/example/autoLaunchEnable',
+  autoLaunchDisable: '/api/v1/example/autoLaunchDisable',
+  autoLaunchIsEnabled: '/api/v1/example/autoLaunchIsEnabled'
 }
 
 /**