-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelectron.ts
76 lines (65 loc) · 1.43 KB
/
electron.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
/* eslint-disable no-console */
import { app, BrowserWindow, ipcMain } from 'electron';
import path from 'path';
import './huds';
export const isDev = process.env.VITE_DEV === 'true';
const createMainWindow = () => {
let win: BrowserWindow | null;
if (app) {
app.on('window-all-closed', app.quit);
app.on('before-quit', async () => {
if (!win) return;
win.removeAllListeners('close');
win.close();
});
}
win = new BrowserWindow({
height: 435,
show: false,
frame: false,
titleBarStyle: 'hidden',
//resizable: isDev,
title: 'Lexogrine HUD Viewer',
icon: path.join(__dirname, 'assets/icon.png'),
webPreferences: {
backgroundThrottling: false,
nodeIntegration: true,
preload: path.join(__dirname, 'preload.js')
//devTools: isDev
},
minWidth: 775,
minHeight: 435,
width: 775
});
ipcMain.on('min', () => {
win!.minimize();
});
ipcMain.on('max', () => {
if (win!.isMaximized()) {
win!.restore();
} else {
win!.maximize();
}
});
ipcMain.on('close', () => {
win!.close();
});
win.once('ready-to-show', () => {
if (win) {
win!.show();
}
});
// win.setMenu(null);
win.setMenuBarVisibility(!isDev);
win.loadURL(isDev ? 'http://localhost:3001' : `file://${__dirname}/dist/build/index.html`);
win.on('close', () => {
win = null;
app.quit();
});
};
const lock = app.requestSingleInstanceLock();
if (!lock) {
app.quit();
} else {
app.on('ready', createMainWindow);
}