-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathmain.cjs
More file actions
79 lines (69 loc) · 1.87 KB
/
main.cjs
File metadata and controls
79 lines (69 loc) · 1.87 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
const { app, BrowserWindow, session, ipcMain, shell } = require("electron");
const url = require("url");
const isDev = require("electron-is-dev");
const path = require("path");
const createWindow = () => {
const win = new BrowserWindow({
show: false,
icon: "./dist/logo.png",
frame: false,
minHeight: 600,
minWidth: 850,
webPreferences: {
allowRunningInsecureContent: true,
preload: path.join(__dirname, "preload.js"),
devTools: isDev,
},
});
session.defaultSession.webRequest.onHeadersReceived((details, callback) => {
callback({
responseHeaders: {
...details.responseHeaders,
"Content-Security-Policy": ["default-src 'self' 'unsafe-eval' data:"],
},
});
});
win.removeMenu();
win.loadURL(
url.format({
pathname: path.join(__dirname, "dist/index.html"),
protocol: "file:",
slashes: true,
})
);
win.maximize();
win.show();
if (isDev) {
win.openDevTools();
}
};
app.whenReady().then(() => {
if (isDev) {
console.log(`You are running the electron app on dev.`);
console.log(`Live changes is not handled`);
console.log(`Each change requires new build`);
console.log(
`Use npm run dev command and once you are happy with the result`
);
console.log(`then build and then run this command again`);
}
createWindow();
app.on("activate", () => {
if (BrowserWindow.getAllWindows().length === 0) createWindow();
});
});
app.on("window-all-closed", () => {
if (process.platform !== "darwin") app.quit();
});
ipcMain.handle("minimize", () => {
BrowserWindow.getFocusedWindow().minimize();
});
ipcMain.handle("maximize", () => {
BrowserWindow.getFocusedWindow().maximize();
});
ipcMain.handle("close", () => {
BrowserWindow.getFocusedWindow().close();
});
ipcMain.handle("open", (event, link) => {
shell.openExternal(link);
});