ソースを参照

security check

gaoshuaixing 4 年 前
コミット
f9d2ad5cbe
7 ファイル変更50 行追加4 行削除
  1. 12 0
      electron/lib/helper.js
  2. 6 0
      electron/lib/lanucher.js
  3. 22 0
      electron/lib/security.js
  4. 2 2
      electron/lib/tray.js
  5. 4 0
      electron/preferences.js
  6. 3 2
      main.js
  7. 1 0
      update.md

+ 12 - 0
electron/lib/helper.js

@@ -0,0 +1,12 @@
+'use strict';
+
+const { app } = require('electron');
+
+/**
+ * application quit
+ * @return {undefined}
+ */
+exports.appQuit = function () {
+	MAIN_WINDOW.destroy();
+	app.quit();
+}

+ 6 - 0
electron/lib/lanucher.js

@@ -6,6 +6,12 @@ const {app} = require('electron');
 
 exports = module.exports;
 
+/**
+ * egg server start
+ * 
+ * @param {Object} argv
+ * @return {Promise}
+ */
 exports.start = function (argv) {
     const { env } = process;
 

+ 22 - 0
electron/lib/security.js

@@ -0,0 +1,22 @@
+'use strict';
+
+const helper = require('./helper');
+const eLogger = require('./eLogger').get();
+
+/**
+ * security check
+ */
+exports.setup = function () {
+	eLogger.info('[security] [setup] process.argv:', process.argv);
+	const runWithDebug = process.argv.find(function(e){
+		let isHasDebug = e.includes("--inspect") || e.includes("--inspect-brk") || e.includes("--remote-debugging-port");
+		return isHasDebug;
+	})
+
+	if (runWithDebug) {
+		eLogger.info('[security] [setup] runWithDebug:', runWithDebug);
+    helper.appQuit();
+	}
+}
+
+exports = module.exports;

+ 2 - 2
electron/lib/tray.js

@@ -3,6 +3,7 @@
 const {app, Tray, Menu} = require('electron');
 const path = require('path');
 const pkg = require('../../package.json');
+const helper = require('./helper');
 
 exports.setup = function () {
   MAIN_WINDOW.on('close', (event) => {
@@ -16,8 +17,7 @@ exports.setup = function () {
   let trayMenuTemplate = [{
     label: '退出',
     click: function () {
-      MAIN_WINDOW.destroy();
-      app.quit()
+      helper.appQuit();
     }
   }]
   let iconPath = path.join(app.getAppPath(), '/asset/images/tray_logo.png');

+ 4 - 0
electron/preferences.js

@@ -5,6 +5,7 @@ const config = require('./config');
 const shortcut = require('./lib/shortcut');
 const tray = require('./lib/tray');
 const awaken = require('./lib/awaken');
+const security = require('./lib/security');
 
 module.exports = () => {
   // shortcut
@@ -16,6 +17,9 @@ module.exports = () => {
   // awaken 
   awaken.setup();
 
+  // security 
+  security.setup();
+
   // check update
   const updateConfig = config.get('autoUpdate');
   if ((is.windows() && updateConfig.windows) || (is.macOS() && updateConfig.macOS)

+ 3 - 2
main.js

@@ -6,6 +6,7 @@ const electronConfig = require('./electron/config')
 const storage = require('./electron/lib/storage')
 const preferences = require('./electron/preferences')
 const pkg = require('./package.json');
+const helper = require('./electron/lib/helper');
 
 // main window
 global.MAIN_WINDOW = null
@@ -48,8 +49,8 @@ async function initialize () {
   
   app.on('window-all-closed', function () {
     if (process.platform !== 'darwin') {
-      console.log('window-all-closed quit')
-      app.quit()
+      eLogger.info('[main] [initialize] window-all-closed quit')
+      helper.appQuit()
     }
   })
 }

+ 1 - 0
update.md

@@ -2,6 +2,7 @@
 1. 修复自动更新
 2. 支持将任意网站打包成桌面软件
 3. 优化启动时白屏问题
+4. 安全检查,防止inspect debug
 
 ## 1.12.0
 1. 崩溃上报