forked from codinit-dev/codinit-dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreload.ts
More file actions
35 lines (29 loc) · 789 Bytes
/
Copy pathreload.ts
File metadata and controls
35 lines (29 loc) · 789 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { app } from 'electron';
import path from 'node:path';
import { promises as fs } from 'node:fs';
// Reload on change.
let isQuited = false;
const abort = new AbortController();
const { signal } = abort;
export async function reloadOnChange() {
const dir = path.join(app.getAppPath(), 'build', 'electron');
try {
const watcher = fs.watch(dir, { signal, recursive: true });
// eslint-disable-next-line @typescript-eslint/no-unused-vars
for await (const _event of watcher) {
if (!isQuited) {
isQuited = true;
app.relaunch();
app.quit();
}
}
} catch (err) {
if (!(err instanceof Error)) {
throw err;
}
if (err.name === 'AbortError') {
console.log('abort watching:', dir);
return;
}
}
}