diff --git a/.npmrc b/.npmrc index 3253b35..24032ed 100644 --- a/.npmrc +++ b/.npmrc @@ -1,5 +1,5 @@ build_from_source=true runtime=electron -target=9.2.1 +target=11.2.1 toolset=v142 disturl=https://electronjs.org/headers diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 6c60e01..d0e61ac 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -4,7 +4,7 @@ "name": "Win32", "includePath": [ "${workspaceFolder}/node_modules/node-addon-api", - "${env:HOME}/AppData/Local/node-gyp/Cache/9.2.1/include/node" + "${env:HOME}/AppData/Local/node-gyp/Cache/11.2.1/include/node" ], "defines": [ "_DEBUG", diff --git a/README.md b/README.md index 8a8a877..8c8686c 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ npm test # 编译然后跑测试 ## 加密 -先生成密钥保存在本地的文件中,方便 JS 打包脚本导入和 C++ include 内联。 +以 AES-256-CBC 为例,先生成密钥保存在本地的文件中,方便 JS 打包脚本导入和 C++ include 内联。 ``` js // 这个脚本不会被打包进客户端,本地开发用 @@ -219,9 +219,9 @@ static Napi::Value _runScript(Napi::Env& env, const char* script) { `node-addon-api` v3 以上可以直接使用: ``` cpp -Napi::Value Napi::Env::RunScript(const char* utf8script) -Napi::Value Napi::Env::RunScript(const std::string& utf8script) -Napi::Value Napi::Env::RunScript(Napi::String script) +Napi::Value Napi::Env::RunScript(const char* utf8script); +Napi::Value Napi::Env::RunScript(const std::string& utf8script); +Napi::Value Napi::Env::RunScript(Napi::String script); ``` 然后就可以愉快地 JS in C++ 了。 @@ -391,7 +391,7 @@ require('./main.node') ``` js for (let i = 0; i < process.argv.length; i++) { - if (process.argv[i].indexOf('--inspect') !== -1 || process.argv[i].indexOf('--remote-debugging-port') !== -1) { + if (process.argv[i].startsWith('--inspect') || process.argv[i].startsWith('--remote-debugging-port')) { throw new Error('Not allow debugging this program.') } } @@ -474,6 +474,7 @@ new BrowserWindow({ // ... webPreferences: { nodeIntegration: true, // 渲染进程要使用 require + contextIsolation: false, // Electron 12 开始默认值为 true,要关掉 devTools: false // 关掉开发者工具,因为开发者工具可以看到渲染进程的代码 } }) diff --git a/app/check.js b/app/check.js index 5fad72b..f417b1c 100644 --- a/app/check.js +++ b/app/check.js @@ -1,6 +1,6 @@ for (let i = 0; i < process.argv.length; i++) { const arg = process.argv[i] - if (arg && arg.indexOf('--inspect') !== -1 || arg.indexOf('--remote-debugging-port') !== -1) { + if (arg.startsWith('--inspect') || arg.startsWith('--remote-debugging-port')) { throw new Error('Not allow debugging this program.') } } diff --git a/app/win.js b/app/win.js index 9dd73a8..e9f52d2 100644 --- a/app/win.js +++ b/app/win.js @@ -108,6 +108,8 @@ WindowManager.createMainWindow = function () { show: false, webPreferences: { nodeIntegration: true, + enableRemoteModule: false, + contextIsolation: false, devTools: false } } diff --git a/package.json b/package.json index 96296b3..0925cfd 100644 --- a/package.json +++ b/package.json @@ -1,14 +1,14 @@ { "name": "electron-asar-encrypt-demo", - "version": "0.1.4", + "version": "0.1.5", "description": "electron-asar-encrypt-demo", "main": "pack.js", "scripts": { "keygen": "node ./script/keygen", "install": "node ./script/keygen", "postinstall": "node ./script/postinstall.js", - "build": "node ./script/js2c&&node-gyp configure --target=9.2.1 --disturl=https://electronjs.org/headers&&node-gyp build", - "build:debug": "node ./script/js2c&&node-gyp configure --target=9.2.1 --disturl=https://electronjs.org/headers&&node-gyp build --debug", + "build": "node ./script/js2c&&node-gyp configure --target=11.2.1 --disturl=https://electronjs.org/headers&&node-gyp build", + "build:debug": "node ./script/js2c&&node-gyp configure --target=11.2.1 --disturl=https://electronjs.org/headers&&node-gyp build --debug", "asar": "node ./script/pack", "test": "npm run keygen&&npm run build&&npm run asar&&node ./script/test", "dist": "node ./script/dist.js", @@ -23,9 +23,9 @@ "@tybys/cross-zip": "^3.1.0", "asar": "^3.0.3", "asar-node": "^2.1.3", - "electron": "9.2.1", + "electron": "11.2.1", "fs-extra": "^9.0.1", - "node-addon-api": "3.0.2", + "node-addon-api": "3.1.0", "node-gyp": "^5.1.1", "terser": "^4.7.0" } diff --git a/script/dist.js b/script/dist.js index a6df28b..48f5bda 100644 --- a/script/dist.js +++ b/script/dist.js @@ -1,3 +1,4 @@ const cz = require('@tybys/cross-zip') const getPath = require('./path.js') +require('fs').copyFileSync(getPath('./src/key.txt'), getPath(`test/key-${process.platform}-${process.arch}.txt`)) cz.zipSync(getPath('test'), getPath(`dist/electron-encrypted-${process.platform}-${process.arch}.zip`))