Skip to content

Commit 1a90409

Browse files
authored
Merge pull request #174 from electron-vite/v0.15.1
V0.15.1
2 parents e345d78 + ecbb69f commit 1a90409

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
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.1 (2023-11-06)
2+
3+
- 2119108 fix: correct use `tree-kill`
4+
15
## 0.15.0 (2023-11-06)
26

37
- 234be07 fix: `tree-kill` doesn't work

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.0",
3+
"version": "0.15.1",
44
"description": "Electron 🔗 Vite",
55
"main": "./dist/index.js",
66
"types": "./dist/index.d.ts",

src/index.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,29 +129,33 @@ export async function startup(argv = ['.', '--no-sandbox']) {
129129
// Exit command after Electron.app exits
130130
process.electronApp.once('exit', process.exit)
131131

132-
if (!startup.hookProcessExit) {
133-
startup.hookProcessExit = true
134-
process.once('exit', startup.exit)
132+
if (!startup.hookedProcessExit) {
133+
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+
})
135139
}
136140
}
137-
startup.hookProcessExit = false
141+
startup.hookedProcessExit = false
138142
startup.exit = async () => {
139143
if (process.electronApp) {
140144
process.electronApp.removeAllListeners()
141145

142-
import('tree-kill')
146+
await import('tree-kill')
143147
.then(m => m.default(process.electronApp.pid!))
144148
.catch(e => {
149+
process.electronApp.kill()
150+
145151
if (e.code === 'ERR_MODULE_NOT_FOUND') {
146152
console.log(
147153
'[vite-plugin-electron]',
148-
'install tree-kill to exit all associated processes, place run "npm i tree-kill".',
154+
'Please install tree-kill to exit all associated processes, run "npm i tree-kill -D".',
149155
)
150156
} else {
151157
console.error(e)
152158
}
153159
})
154-
155-
process.electronApp.kill() // `tree-kill` doesn't work locally on my Mac(2023-11-06) 🤔
156160
}
157161
}

0 commit comments

Comments
 (0)