Skip to content

Commit

Permalink
Merge pull request #176 from electron-vite/v0.15.3
Browse files Browse the repository at this point in the history
V0.15.3
  • Loading branch information
caoxiemeihao authored Nov 7, 2023
2 parents ca4adf1 + ffd14a4 commit e74917c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.15.3 (2023-11-07)

- 20907ef chore: recover `v0.15.1`

## 0.15.2 (2023-11-06)

- 9719203 chore: better exit `electron` logic
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -323,3 +323,10 @@ Modules in `node_modules` are not bundled during development, it's fast!
│ const log = require('electron-log') │
┗—————————————————————————————————————┛
```
## FAQ
- `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)
* Add `tree-kill` into you dependencies, `npm i -D tree-kill`.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vite-plugin-electron",
"version": "0.15.2",
"version": "0.15.3",
"description": "Electron 🔗 Vite",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
28 changes: 24 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export async function startup(argv = ['.', '--no-sandbox']) {
const electron = await import('electron')
const electronPath = <any>(electron.default ?? electron)

startup.exit()
await startup.exit()

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

if (!startup.hookedProcessExit) {
startup.hookedProcessExit = true
process.once('exit', startup.exit)
process.once('exit', () => {
startup.exit()
// When the process exits, `tree-kill` does not have enough time to complete execution, so `electronApp` needs to be killed immediately.
process.electronApp.kill()
})
}
}
startup.hookedProcessExit = false
startup.exit = async () => {
if (process.electronApp) {
process.electronApp.removeAllListeners()
// SIGINT can be sent to the process tree #122
process.electronApp.kill('SIGINT')

await import('tree-kill')
.then(m => m.default(
process.electronApp.pid!,
error => error && process.electronApp.kill(),
))
.catch(e => {
process.electronApp.kill()

if (e.code === 'ERR_MODULE_NOT_FOUND') {
console.log(
'[vite-plugin-electron]',
'Please install tree-kill to exit all associated processes, run "npm i tree-kill -D".',
)
} else {
console.error(e)
}
})
}
}

0 comments on commit e74917c

Please sign in to comment.