Skip to content

Commit e74917c

Browse files
authored
Merge pull request #176 from electron-vite/v0.15.3
V0.15.3
2 parents ca4adf1 + ffd14a4 commit e74917c

File tree

4 files changed

+36
-5
lines changed

4 files changed

+36
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.15.3 (2023-11-07)
2+
3+
- 20907ef chore: recover `v0.15.1`
4+
15
## 0.15.2 (2023-11-06)
26

37
- 9719203 chore: better exit `electron` logic

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,3 +323,10 @@ Modules in `node_modules` are not bundled during development, it's fast!
323323
│ const log = require('electron-log') │
324324
┗—————————————————————————————————————┛
325325
```
326+
327+
## FAQ
328+
329+
- `electron` does not exit correctly | 使用ctrl + c 停止代码,electron后台不关闭 | [#122](https://github.com/electron-vite/vite-plugin-electron/pull/122), [#168](https://github.com/electron-vite/vite-plugin-electron/issues/168)
330+
331+
* Add `tree-kill` into you dependencies, `npm i -D tree-kill`.
332+

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vite-plugin-electron",
3-
"version": "0.15.2",
3+
"version": "0.15.3",
44
"description": "Electron 🔗 Vite",
55
"main": "./dist/index.js",
66
"types": "./dist/index.d.ts",

src/index.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export async function startup(argv = ['.', '--no-sandbox']) {
121121
const electron = await import('electron')
122122
const electronPath = <any>(electron.default ?? electron)
123123

124-
startup.exit()
124+
await startup.exit()
125125

126126
// Start Electron.app
127127
process.electronApp = spawn(electronPath, argv, { stdio: 'inherit' })
@@ -131,14 +131,34 @@ export async function startup(argv = ['.', '--no-sandbox']) {
131131

132132
if (!startup.hookedProcessExit) {
133133
startup.hookedProcessExit = true
134-
process.once('exit', startup.exit)
134+
process.once('exit', () => {
135+
startup.exit()
136+
// When the process exits, `tree-kill` does not have enough time to complete execution, so `electronApp` needs to be killed immediately.
137+
process.electronApp.kill()
138+
})
135139
}
136140
}
137141
startup.hookedProcessExit = false
138142
startup.exit = async () => {
139143
if (process.electronApp) {
140144
process.electronApp.removeAllListeners()
141-
// SIGINT can be sent to the process tree #122
142-
process.electronApp.kill('SIGINT')
145+
146+
await import('tree-kill')
147+
.then(m => m.default(
148+
process.electronApp.pid!,
149+
error => error && process.electronApp.kill(),
150+
))
151+
.catch(e => {
152+
process.electronApp.kill()
153+
154+
if (e.code === 'ERR_MODULE_NOT_FOUND') {
155+
console.log(
156+
'[vite-plugin-electron]',
157+
'Please install tree-kill to exit all associated processes, run "npm i tree-kill -D".',
158+
)
159+
} else {
160+
console.error(e)
161+
}
162+
})
143163
}
144164
}

0 commit comments

Comments
 (0)