-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
83 lines (67 loc) · 1.94 KB
/
main.js
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
const {app, BrowserWindow, nativeImage} = require('electron');
const store = new (require('electron-store'))();
let mainWindow;
function windowStateKeeper(windowName) {
let window;
// default values
let windowState = {
x: undefined,
y: undefined,
width: 1024,
height: 768
};
function setBounds() {
if (store.has(`windowState.${windowName}`)) {
windowState = store.get(`windowState.${windowName}`);
}
}
function saveState() {
if (!windowState.isMaximized) {
windowState = window.getBounds();
}
windowState.isMaximized = window.isMaximized();
store.set(`windowState.${windowName}`, windowState);
}
function track(win) {
window = win;
['resize', 'move', 'close'].forEach(event => {
win.on(event, saveState);
});
}
setBounds();
return ({
x: windowState.x,
y: windowState.y,
width: windowState.width,
height: windowState.height,
isMaximized: windowState.isMaximized,
track
});
}
function createWindow() {
const mainWindowStateKeeper = windowStateKeeper('main');
mainWindow = new BrowserWindow({
icon: nativeImage.createFromPath(__dirname + '/spritemate/dist/img/favicon/android-chrome-256x256.png'),
x: mainWindowStateKeeper.x,
y: mainWindowStateKeeper.y,
width: mainWindowStateKeeper.width,
height: mainWindowStateKeeper.height
});
mainWindow.loadFile('spritemate/dist/index.html');
mainWindow.setMenu(null);
mainWindow.on('closed', function () {
mainWindow = null
});
mainWindowStateKeeper.track(mainWindow);
}
app.on('ready', createWindow);
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') {
app.quit()
}
});
app.on('activate', function () {
if (mainWindow === null) {
createWindow()
}
});