Skip to content

Commit 74c6381

Browse files
committed
electron 11
1 parent df2749d commit 74c6381

7 files changed

Lines changed: 17 additions & 13 deletions

File tree

.npmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
build_from_source=true
22
runtime=electron
3-
target=9.2.1
3+
target=11.2.1
44
toolset=v142
55
disturl=https://electronjs.org/headers

.vscode/c_cpp_properties.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"name": "Win32",
55
"includePath": [
66
"${workspaceFolder}/node_modules/node-addon-api",
7-
"${env:HOME}/AppData/Local/node-gyp/Cache/9.2.1/include/node"
7+
"${env:HOME}/AppData/Local/node-gyp/Cache/11.2.1/include/node"
88
],
99
"defines": [
1010
"_DEBUG",

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ npm test # 编译然后跑测试
1818

1919
## 加密
2020

21-
先生成密钥保存在本地的文件中,方便 JS 打包脚本导入和 C++ include 内联。
21+
以 AES-256-CBC 为例,先生成密钥保存在本地的文件中,方便 JS 打包脚本导入和 C++ include 内联。
2222

2323
``` js
2424
// 这个脚本不会被打包进客户端,本地开发用
@@ -219,9 +219,9 @@ static Napi::Value _runScript(Napi::Env& env, const char* script) {
219219
`node-addon-api` v3 以上可以直接使用:
220220
221221
``` cpp
222-
Napi::Value Napi::Env::RunScript(const char* utf8script)
223-
Napi::Value Napi::Env::RunScript(const std::string& utf8script)
224-
Napi::Value Napi::Env::RunScript(Napi::String script)
222+
Napi::Value Napi::Env::RunScript(const char* utf8script);
223+
Napi::Value Napi::Env::RunScript(const std::string& utf8script);
224+
Napi::Value Napi::Env::RunScript(Napi::String script);
225225
```
226226
227227
然后就可以愉快地 JS in C++ 了。
@@ -391,7 +391,7 @@ require('./main.node')
391391
392392
``` js
393393
for (let i = 0; i < process.argv.length; i++) {
394-
if (process.argv[i].indexOf('--inspect') !== -1 || process.argv[i].indexOf('--remote-debugging-port') !== -1) {
394+
if (process.argv[i].startsWith('--inspect') || process.argv[i].startsWith('--remote-debugging-port')) {
395395
throw new Error('Not allow debugging this program.')
396396
}
397397
}
@@ -474,6 +474,7 @@ new BrowserWindow({
474474
// ...
475475
webPreferences: {
476476
nodeIntegration: true, // 渲染进程要使用 require
477+
contextIsolation: false, // Electron 12 开始默认值为 true,要关掉
477478
devTools: false // 关掉开发者工具,因为开发者工具可以看到渲染进程的代码
478479
}
479480
})

app/check.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
for (let i = 0; i < process.argv.length; i++) {
22
const arg = process.argv[i]
3-
if (arg && arg.indexOf('--inspect') !== -1 || arg.indexOf('--remote-debugging-port') !== -1) {
3+
if (arg.startsWith('--inspect') || arg.startsWith('--remote-debugging-port')) {
44
throw new Error('Not allow debugging this program.')
55
}
66
}

app/win.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ WindowManager.createMainWindow = function () {
108108
show: false,
109109
webPreferences: {
110110
nodeIntegration: true,
111+
enableRemoteModule: false,
112+
contextIsolation: false,
111113
devTools: false
112114
}
113115
}

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"name": "electron-asar-encrypt-demo",
3-
"version": "0.1.4",
3+
"version": "0.1.5",
44
"description": "electron-asar-encrypt-demo",
55
"main": "pack.js",
66
"scripts": {
77
"keygen": "node ./script/keygen",
88
"install": "node ./script/keygen",
99
"postinstall": "node ./script/postinstall.js",
10-
"build": "node ./script/js2c&&node-gyp configure --target=9.2.1 --disturl=https://electronjs.org/headers&&node-gyp build",
11-
"build:debug": "node ./script/js2c&&node-gyp configure --target=9.2.1 --disturl=https://electronjs.org/headers&&node-gyp build --debug",
10+
"build": "node ./script/js2c&&node-gyp configure --target=11.2.1 --disturl=https://electronjs.org/headers&&node-gyp build",
11+
"build:debug": "node ./script/js2c&&node-gyp configure --target=11.2.1 --disturl=https://electronjs.org/headers&&node-gyp build --debug",
1212
"asar": "node ./script/pack",
1313
"test": "npm run keygen&&npm run build&&npm run asar&&node ./script/test",
1414
"dist": "node ./script/dist.js",
@@ -23,9 +23,9 @@
2323
"@tybys/cross-zip": "^3.1.0",
2424
"asar": "^3.0.3",
2525
"asar-node": "^2.1.3",
26-
"electron": "9.2.1",
26+
"electron": "11.2.1",
2727
"fs-extra": "^9.0.1",
28-
"node-addon-api": "3.0.2",
28+
"node-addon-api": "3.1.0",
2929
"node-gyp": "^5.1.1",
3030
"terser": "^4.7.0"
3131
}

script/dist.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
const cz = require('@tybys/cross-zip')
22
const getPath = require('./path.js')
3+
require('fs').copyFileSync(getPath('./src/key.txt'), getPath(`test/key-${process.platform}-${process.arch}.txt`))
34
cz.zipSync(getPath('test'), getPath(`dist/electron-encrypted-${process.platform}-${process.arch}.zip`))

0 commit comments

Comments
 (0)