forked from Txio-labs/txio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
80 lines (69 loc) · 1.83 KB
/
Copy pathindex.js
File metadata and controls
80 lines (69 loc) · 1.83 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { app, BrowserWindow, shell, session } from "electron"
import path from "path"
import { fileURLToPath } from "url"
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const PACKAGED_ORIGIN = "file://"
const CSP = [
"default-src 'self'",
"script-src 'self' 'unsafe-inline' 'unsafe-eval'",
"style-src 'self' 'unsafe-inline'",
"img-src 'self' data: blob: https:",
"font-src 'self' data:",
"connect-src 'self' https: wss:",
"frame-src 'self' https:",
"object-src 'none'",
"base-uri 'self'",
"form-action 'self'",
].join("; ")
const createWindow = () => {
const win = new BrowserWindow({
width: 1200,
height: 800,
icon: path.join(__dirname, "assets/logo/512x512.png"),
webPreferences: {
sandbox: true,
contextIsolation: true,
nodeIntegration: false,
webSecurity: true,
},
})
win.webContents.setWindowOpenHandler(({ url }) => {
try {
const parsed = new URL(url)
if (parsed.protocol === "http:" || parsed.protocol === "https:") {
shell.openExternal(url)
}
} catch {
// ignore invalid URLs
}
return { action: "deny" }
})
win.webContents.on("will-navigate", (event, url) => {
if (!url.startsWith(PACKAGED_ORIGIN)) {
event.preventDefault()
}
})
win.loadFile(path.join(__dirname, "../dist/index.html"))
}
app.whenReady().then(() => {
session.defaultSession.webRequest.onHeadersReceived((details, callback) => {
callback({
responseHeaders: {
...details.responseHeaders,
"Content-Security-Policy": [CSP],
},
})
})
createWindow()
app.on("activate", () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})
})
app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.quit()
}
})