Skip to content

Commit 632205b

Browse files
committed
feat: add autoRunRenderer option to UserConfig
1 parent 32992ad commit 632205b

File tree

6 files changed

+22
-2
lines changed

6 files changed

+22
-2
lines changed

README-zh-CN.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ export declare interface UserConfig {
117117
* 启动app时同步检测程序是否被篡改
118118
*/
119119
syncValidationChanges?: boolean
120+
/**
121+
* 是否自动启动渲染进程,设置为false后可以使用 __runRenderer() 方法手动启动
122+
* @default true
123+
*/
124+
autoRunRenderer?: boolean
120125
}
121126
```
122127

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ export declare interface UserConfig {
117117
* Synchronously detect whether the program has been tampered with when starting the app
118118
*/
119119
syncValidationChanges?: boolean
120+
/**
121+
* Automatically run the renderer process after the main process is started. After setting it to false, you can use the __runRenderer() method to start it manually.
122+
* @default true
123+
*/
124+
autoRunRenderer?: boolean
120125
}
121126
```
122127

src/config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ export declare interface UserConfig {
115115
* Synchronously detect whether the program has been tampered with when starting the app
116116
*/
117117
syncValidationChanges?: boolean
118+
/**
119+
* Automatically run the renderer process after the main process is started
120+
* @default true
121+
*/
122+
autoRunRenderer?: boolean
118123
}
119124

120125
export function defineConfig(arg: UserConfigExport) {

src/default-config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export function mergeDefaultConfig(
2222
output: '',
2323
},
2424
syncValidationChanges: false,
25+
autoRunRenderer: true,
2526
})
2627
}
2728

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export async function run(context: AfterPackContext, options: RunOptions = {}) {
7575
// 往main.js添加preload.js
7676
const preloadJsPath = path.join(__dirname, 'preload.js').replace(/\\/g, '/')
7777
let code = await fs.promises.readFile(mainJsPath, 'utf-8')
78-
code = `const __encryptorConfig = require('${preloadJsPath}').encryptorConfig;${code}`
78+
code = `const { encryptorConfig: __encryptorConfig, runRenderer: __runRenderer } = require('${preloadJsPath}');${code}`
7979
await fs.promises.writeFile(mainJsPath, code, 'utf-8')
8080

8181
const cwd = process.cwd()

src/preload.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ if (!__encryptorConfig.noRegisterSchemes)
3232
app.whenReady().then(() => {
3333
wacthClientModify()
3434

35+
if (__encryptorConfig.autoRunRenderer) runRenderer()
36+
})
37+
38+
export function runRenderer() {
3539
let rendererPath = ''
3640
if (__encryptorConfig.renderer.output) {
3741
rendererPath = path.join(execDir, __encryptorConfig.renderer.output)
@@ -58,7 +62,7 @@ app.whenReady().then(() => {
5862
callback({ data: undefined })
5963
}
6064
})
61-
})
65+
}
6266

6367
function verifyModifySync() {
6468
const appAsarDir = path.join(execDir, 'resources', 'app.asar')

0 commit comments

Comments
 (0)