This repository has been archived by the owner on Jun 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
executable file
·57 lines (50 loc) · 1.53 KB
/
main.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
import { BrowserWindow, app } from 'electron';
import { Preferences } from './preferences';
export const preferences = new Preferences({
configName: 'serverman-preferences',
defaults: {
dimensions: {
height: 600,
width: 800,
x: undefined,
y: undefined,
},
},
});
class Main {
static mainWindow: Electron.BrowserWindow;
static application: Electron.App;
static BrowserWindow;
private static onWindowAllClosed() {
if (process.platform !== 'darwin') {
Main.application.quit();
}
}
private static onClose() {
// Dereference the window object.
Main.mainWindow = null;
}
private static onReady() {
let { height, width } = preferences.get('dimensions');
Main.mainWindow = new Main.BrowserWindow({ width: width, height: height });
Main.mainWindow.setMenu(null);
Main.mainWindow.webContents.openDevTools();
Main.mainWindow.loadURL('file://' + __dirname + '/index.html');
Main.mainWindow.on('closed', Main.onClose);
Main.mainWindow.on('resize', () => {
let bounds = Main.mainWindow.getBounds();
preferences.set('dimensions', bounds);
});
}
static main(app: Electron.App, browserWindow: typeof BrowserWindow) {
// we pass the Electron.App object and the
// Electron.BrowserWindow into this function
// so this class has no dependencies. This
// makes the code easier to write tests for
Main.BrowserWindow = browserWindow;
Main.application = app;
Main.application.on('window-all-closed', Main.onWindowAllClosed);
Main.application.on('ready', Main.onReady);
}
}
Main.main(app, BrowserWindow);