-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.ts
More file actions
115 lines (98 loc) · 3.19 KB
/
main.ts
File metadata and controls
115 lines (98 loc) · 3.19 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import { app, BrowserWindow, ipcMain, safeStorage, shell } from "electron";
import { join, relative } from "path";
import { theme } from "./src/theme";
import packageJson from "./package.json";
let win: BrowserWindow;
app.setAppUserModelId("com.muffoi.botcord");
const userDataDirName = app.isPackaged ? packageJson.productName : `${packageJson.productName}_dev`;
app.setPath("userData", join(app.getPath("userData"), "..", userDataDirName));
function createWindow () {
win = new BrowserWindow({
webPreferences: {
nodeIntegration: true,
sandbox: false,
contextIsolation: false,
devTools: !app.isPackaged,
additionalArguments: [JSON.stringify({
appData: app.getPath("userData"),
isPackaged: app.isPackaged,
title: packageJson.productName
})]
},
autoHideMenuBar: true,
title: packageJson.productName,
icon: join(__dirname, "resources", "icon.ico"),
backgroundColor: theme.background
})
let allowed = [
"src\\info.html"
]
win.webContents.setWindowOpenHandler(({url}) => {
if(allowed.includes(
relative(
__dirname,
url.match(/^file:\/\/\/(.*)/)?.[1] || ""
)
)) {
return {
action: "allow",
overrideBrowserWindowOptions: {
titleBarStyle: "default",
fullscreenable: false,
resizable: false,
autoHideMenuBar: true,
maximizable: false,
minimizable: false,
backgroundColor: theme.background,
icon: join(__dirname, "resources", "icon.ico"),
webPreferences: {
devTools: !app.isPackaged
}
}
}
} else {
shell.openExternal(url);
return {
action: "deny"
}
}
});
win.webContents.on("did-create-window", (window) => {
window.webContents.setWindowOpenHandler(({url}) => {
shell.openExternal(url);
return {
action: "deny"
}
})
});
win.removeMenu();
if(!app.isPackaged) win.webContents.openDevTools({ mode: "undocked" });
win.loadFile(join(__dirname, "src", "index.html"));
/* win.on("unresponsive", ()=>{
dialog.showErrorBox("Not Responding", "App window has gone unresponsive");
}) */
}
app.whenReady().then(() => {
createWindow();
ipcMain.handle("encode", (_e, data) => {
return safeStorage.encryptString(data);
})
ipcMain.handle("decode", (_e, data) => {
return safeStorage.decryptString(data);
})
ipcMain.on("restartWindow", () => {
win.close();
createWindow();
});
app.on("activate", () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
})
})
// app.on("window-all-closed", () => {
// if (process.platform !== "darwin") {
// app.quit();
// }
// })
app.on("window-all-closed", app.quit);