forked from lexogrine/hud-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrenderer.ts
80 lines (64 loc) · 2.13 KB
/
renderer.ts
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 fs from 'fs';
import { loadConfig } from './server/api/config';
const isDev = process.env.DEV === "true";
export const createMainWindow = async (forceDev = false) => {
let win: BrowserWindow | null;
const cookieFile = path.join(app.getPath('userData'), 'databases', 'cookie');
const cookie = fs.readFileSync(cookieFile, 'utf8');
try {
const cookies = JSON.parse(cookie);
if(Array.isArray(cookies)){
for(const cookie of cookies){
cookie.url = 'https://hmapi.lexogrine.com/';
await session.defaultSession.cookies.set(cookie);
}
}
} catch(e) { }
if (app) {
app.on("window-all-closed", app.quit);
app.on("before-quit", async () => {
const cookies = await session.defaultSession.cookies.get({url: 'https://hmapi.lexogrine.com/'});
fs.writeFileSync(cookieFile, JSON.stringify(cookies), 'utf8');
if (!win) return;
win.removeAllListeners("close");
win.close();
});
}
win = new BrowserWindow({
height: 700,
show: false,
frame:false,
titleBarStyle:"hidden",
//resizable: isDev,
title: "HUD Manager",
icon: path.join(__dirname, 'assets/icon.png'),
webPreferences: {
nodeIntegration: true,
backgroundThrottling: false,
devTools: isDev || forceDev
},
minWidth: 775,
minHeight:700,
width: 1010,
});
win.once("ready-to-show", () => {
if (win) {
win.show();
}
});
// win.setMenu(null);
const config = await loadConfig();
win.setMenuBarVisibility(false);
const startUrl =`http://localhost:${config.port}/`;
win.webContents.on('new-window', (e, url) => {
e.preventDefault();
shell.openExternal(url);
});
win.loadURL(`${isDev ? `http://localhost:3000/?port=${config.port}` : startUrl}`);
win.on("close", () => {
win = null;
app.quit();
});
}