Skip to content

Commit

Permalink
electron 11
Browse files Browse the repository at this point in the history
  • Loading branch information
toyobayashi committed Feb 8, 2021
1 parent df2749d commit 74c6381
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ npm test # 编译然后跑测试

## 加密

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

``` js
// 这个脚本不会被打包进客户端,本地开发用
Expand Down Expand Up @@ -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++ 了。
Expand Down Expand Up @@ -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.')
}
}
Expand Down Expand Up @@ -474,6 +474,7 @@ new BrowserWindow({
// ...
webPreferences: {
nodeIntegration: true, // 渲染进程要使用 require
contextIsolation: false, // Electron 12 开始默认值为 true,要关掉
devTools: false // 关掉开发者工具,因为开发者工具可以看到渲染进程的代码
}
})
Expand Down
2 changes: 1 addition & 1 deletion app/check.js
Original file line number Diff line number Diff line change
@@ -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.')
}
}
2 changes: 2 additions & 0 deletions app/win.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ WindowManager.createMainWindow = function () {
show: false,
webPreferences: {
nodeIntegration: true,
enableRemoteModule: false,
contextIsolation: false,
devTools: false
}
}
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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"
}
Expand Down
1 change: 1 addition & 0 deletions script/dist.js
Original file line number Diff line number Diff line change
@@ -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`))

0 comments on commit 74c6381

Please sign in to comment.