Skip to content

Commit ca4adf1

Browse files
authored
Merge pull request #175 from electron-vite/v0.15.2
V0.15.2
2 parents 1a90409 + 2958538 commit ca4adf1

File tree

4 files changed

+9
-29
lines changed

4 files changed

+9
-29
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.2 (2023-11-06)
2+
3+
- 9719203 chore: better exit `electron` logic
4+
15
## 0.15.1 (2023-11-06)
26

37
- 2119108 fix: correct use `tree-kill`

README.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -323,10 +323,3 @@ 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.1",
3+
"version": "0.15.2",
44
"description": "Electron 🔗 Vite",
55
"main": "./dist/index.js",
66
"types": "./dist/index.d.ts",

src/index.ts

Lines changed: 4 additions & 21 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-
await startup.exit()
124+
startup.exit()
125125

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

132132
if (!startup.hookedProcessExit) {
133133
startup.hookedProcessExit = true
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-
})
134+
process.once('exit', startup.exit)
139135
}
140136
}
141137
startup.hookedProcessExit = false
142138
startup.exit = async () => {
143139
if (process.electronApp) {
144140
process.electronApp.removeAllListeners()
145-
146-
await import('tree-kill')
147-
.then(m => m.default(process.electronApp.pid!))
148-
.catch(e => {
149-
process.electronApp.kill()
150-
151-
if (e.code === 'ERR_MODULE_NOT_FOUND') {
152-
console.log(
153-
'[vite-plugin-electron]',
154-
'Please install tree-kill to exit all associated processes, run "npm i tree-kill -D".',
155-
)
156-
} else {
157-
console.error(e)
158-
}
159-
})
141+
// SIGINT can be sent to the process tree #122
142+
process.electronApp.kill('SIGINT')
160143
}
161144
}

0 commit comments

Comments
 (0)