diff --git a/.gitignore b/.gitignore index d0dbab5..125f97c 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,7 @@ ossutil* ossutil_output app.asar pvl +out #tool .vscode/ diff --git a/app/app.js b/app/app.js index 6359562..bcad5dc 100644 --- a/app/app.js +++ b/app/app.js @@ -59,7 +59,7 @@ angular label: v.label }); }); - var lang = localStorage.getItem('lang') || langList[0].lang; + var lang = localStorage.getItem('lang') || (langList[0] && langList[0].lang); $rootScope.langSettings = { langList: langList, diff --git a/app/components/services/cipher.js b/app/components/services/cipher.js index 0f3e808..7fa0de3 100644 --- a/app/components/services/cipher.js +++ b/app/components/services/cipher.js @@ -1,33 +1,31 @@ angular.module('web').factory('Cipher', function() { var crypto = require('crypto'); - var ALGORITHM = 'aes192'; - var KEY = 'x82m#*lx8vv'; + var ALGORITHM = 'aes-256-cbc'; + // var KEY = 'x82m#*lx8vv'; + var KEY = Buffer.from('x82m#*lx8vvy93n#*my9wwz04o#*nz0x'); + var IV = Buffer.from('*my9wwz04o#*nz0x'); return { cipher: cipher, decipher: decipher }; - function cipher(buf, key, algorithm) { - if (!(buf instanceof Buffer)) { - buf = new Buffer(buf); - } - + function cipher(buf, key, algorithm, iv) { var encrypted = ''; - var cip = crypto.createCipher(algorithm || ALGORITHM, key || KEY); + var cip = crypto.createCipheriv(algorithm || ALGORITHM, key || KEY, iv || IV); encrypted += cip.update(buf, 'utf8', 'hex'); - encrypted += cip['final']('hex'); + encrypted += cip.final('hex'); return encrypted; } - function decipher(encrypted, key, algorithm) { + function decipher(encrypted, key, algorithm, iv) { var decrypted = ''; - var decipher = crypto.createDecipher(algorithm || ALGORITHM, key || KEY); + var decipher = crypto.createDecipheriv(algorithm || ALGORITHM, key || KEY, iv || IV); - decrypted += decipher.update(encrypted, 'hex', 'utf8'); - decrypted += decipher['final']('utf8'); + decrypted += decipher.update(Buffer.from(encrypted, 'hex'), null, 'utf8'); + decrypted += decipher.final('utf8'); return decrypted; } diff --git a/app/components/services/dialog.s.js b/app/components/services/dialog.s.js index 5b15c3d..642f6d5 100644 --- a/app/components/services/dialog.s.js +++ b/app/components/services/dialog.s.js @@ -3,7 +3,7 @@ angular .factory('Dialog', [ '$uibModal', function($modal) { - var dialog = require('electron').remote.dialog; + var dialog = require('electron').dialog; return { alert: alert, diff --git a/forge.config.js b/forge.config.js new file mode 100644 index 0000000..fa4a113 --- /dev/null +++ b/forge.config.js @@ -0,0 +1,44 @@ +const { FusesPlugin } = require('@electron-forge/plugin-fuses'); +const { FuseV1Options, FuseVersion } = require('@electron/fuses'); + +module.exports = { + packagerConfig: { + asar: true, + }, + rebuildConfig: {}, + makers: [ + { + name: '@electron-forge/maker-squirrel', + config: {}, + }, + { + name: '@electron-forge/maker-zip', + platforms: ['darwin'], + }, + { + name: '@electron-forge/maker-deb', + config: {}, + }, + { + name: '@electron-forge/maker-rpm', + config: {}, + }, + ], + plugins: [ + { + name: '@electron-forge/plugin-auto-unpack-natives', + config: {}, + }, + // Fuses are used to enable/disable various Electron functionality + // at package time, before code signing the application + new FusesPlugin({ + version: FuseVersion.V1, + [FuseV1Options.RunAsNode]: false, + [FuseV1Options.EnableCookieEncryption]: true, + [FuseV1Options.EnableNodeOptionsEnvironmentVariable]: false, + [FuseV1Options.EnableNodeCliInspectArguments]: false, + [FuseV1Options.EnableEmbeddedAsarIntegrityValidation]: true, + [FuseV1Options.OnlyLoadAppFromAsar]: true, + }), + ], +}; diff --git a/main.js b/main.js index 62c7ae3..d7530d0 100644 --- a/main.js +++ b/main.js @@ -1,4 +1,5 @@ var electron = require("electron"); +const server = require('./server.js'); // Module to control application life. // use self signed certificate for Apsara Stack @@ -23,18 +24,19 @@ log.transports.console.level = false; ///***************************************** //静态服务 var PORTS = [7123, 7124, 7125, 7126]; - -for (var port of PORTS) { - try { - //var subp = require('child_process').fork('./server.js',[port]); - require("./server.js").listen(port); - console.log("listening on port " + port); - break; - } catch (e) { - console.log(e); - } +try { + // var subp = require('child_process').fork('./server.js',[port]); + server.listen(PORTS[0]); + console.log("listening on port " + PORTS[0]); + // break; +} catch (e) { + console.log(e); } +// for (var port of PORTS) { + +// } + app.commandLine.appendSwitch("ignore-certificate-errors"); ///***************************************** @@ -57,7 +59,7 @@ if (process.platform == "darwin") { ); } -function createWindow() { +function createWindow () { var opt = { width: 1221, height: 700, @@ -67,6 +69,9 @@ function createWindow() { icon: custom.logo_ico || path.join(__dirname, "icons", "icon.ico"), webPreferences: { + nodeIntegration: true, // 允许在渲染器进程中使用 Node.js API + contextIsolation: false, // 需要配合 nodeIntegration 使用 + enableRemoteModule: true, // 允许使用 remote 模块 plugins: true, }, }; @@ -112,7 +117,7 @@ ipcMain.on("asynchronous", (event, data) => { switch (data.key) { case "getStaticServerPort": //在main process里向web page发出message - event.sender.send("asynchronous-reply", { key: data.key, port: port }); + event.sender.send("asynchronous-reply", { key: data.key, port: 7123 }); break; case "openDevTools": process.env["DEBUG"] = 'ali-oss'; @@ -145,7 +150,7 @@ ipcMain.on("asynchronous", (event, data) => { } }); -function moveFile(from, to, fn) { +function moveFile (from, to, fn) { if (process.platform != "win32") { fs.rename(from, to, fn); return; @@ -179,23 +184,20 @@ function moveFile(from, to, fn) { } //singleton -var shouldQuit = app.makeSingleInstance((commandLine, workingDirectory) => { - // Someone tried to run a second instance, we should focus our window. - if (win) { - if (win.isMinimized()) win.restore(); - win.focus(); - } -}); +app.requestSingleInstanceLock({}); +// console.log('shouldQuit', shouldQuit); +// var shouldQuit = false; -if (shouldQuit) { - app.quit(); - process.exit(0); -} +// if (shouldQuit) { +// app.quit(); +// process.exit(0); +// } // 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. -app.on("ready", createWindow); +// app.on("ready", createWindow); +app.whenReady().then(() => createWindow()); // Quit when all windows are closed. app.on("window-all-closed", () => { @@ -228,7 +230,7 @@ app.on( // In this file you can include the rest of your app's specific main process // code. You can also put them in separate files and require them here. -function getMenuTemplate() { +function getMenuTemplate () { var name = app.getName(); return [ { diff --git a/package.json b/package.json index a058cf1..09561cb 100644 --- a/package.json +++ b/package.json @@ -12,13 +12,24 @@ "watch": "./node_modules/.bin/gulp watch --custom=$custom", "build": "./node_modules/.bin/gulp build --custom=$custom", "rcedit": "cp tools/rcedit-x64.exe node_modules/rcedit/bin/rcedit.exe", - "lint": "eslint --fix app" + "lint": "eslint --fix app", + "start": "electron-forge start", + "package": "electron-forge package", + "make": "electron-forge make" }, "engines": { - "node": "8.2.1" + "node": ">=8.2.1" }, "devDependencies": { "@alicloud/eslint-config": "^1.2.23", + "@electron-forge/cli": "^7.4.0", + "@electron-forge/maker-deb": "^7.4.0", + "@electron-forge/maker-rpm": "^7.4.0", + "@electron-forge/maker-squirrel": "^7.4.0", + "@electron-forge/maker-zip": "^7.4.0", + "@electron-forge/plugin-auto-unpack-natives": "^7.4.0", + "@electron-forge/plugin-fuses": "^7.4.0", + "@electron/fuses": "^1.8.0", "angular": "1.5.8", "angular-bootstrap-contextmenu": "^1.1.0", "angular-sanitize": "1.5.8", @@ -36,8 +47,8 @@ "commander": "~2.9.0", "cross-env": "^3.1.4", "del": "^4.1.1", - "electron": "1.8.4", - "electron-packager": "7.1.0", + "electron": "latest", + "electron-packager": "latest", "eslint": "^7.1.0", "font-awesome": "^4.7.0", "gulp": "~3.5.5", @@ -67,11 +78,12 @@ "ali-oss": "^6.13.2", "aliyun-sdk": "^1.12.3", "clipboard": "^1.7.1", - "electron-log": "1.3.0", + "electron-log": "latest", + "electron-squirrel-startup": "^1.0.1", "emoji-regex": "^9.0.0", - "koa": "^2.3.0", - "koa-convert": "^1.2.0", - "koa-static-server": "^1.2.1", + "koa": "latest", + "koa-convert": "latest", + "koa-static-server": "latest", "mime": "^1.3.6", "nodemailer": "4.0.1", "nodemailer-smtp-transport": "2.7.4",