-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.js
56 lines (47 loc) · 1.1 KB
/
main.js
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// @ts-check
import { app, BrowserWindow, protocol } from "electron";
import { readFile } from "node:fs/promises";
import { resolve } from "node:path";
import { Agent } from "undici";
function createWindow() {
const win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
preload: resolve("preload.js"),
},
});
win.loadURL("https://127.0.0.1:8080");
// win.loadURL("https://developer.mozilla.org");
}
Promise.all([
app.whenReady(),
readFile("cert/ca.crt"),
readFile("cert/client.crt"),
readFile("cert/client.key"),
]).then(([_, ca, cert, key]) => {
const agent = new Agent({
connect: {
ca,
cert,
key,
},
});
protocol.handle("https", (request) => {
const url = new URL(request.url);
return fetch(request, {
dispatcher: url.hostname === "127.0.0.1" ? agent : undefined,
});
});
createWindow();
app.on("activate", () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
});
app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.quit();
}
});