-
Notifications
You must be signed in to change notification settings - Fork 3
/
window.js
87 lines (69 loc) · 2.09 KB
/
window.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
84
85
86
87
const { app, BrowserWindow } = require("electron");
const ElectronStore = require("electron-store");
const { ipcMain } = require("electron");
module.exports = {
createMainWindow() {
const store = new ElectronStore();
let lastWindowState = store.get("lastWindowState");
if (!lastWindowState) {
lastWindowState = {
x: 0,
y: 0,
width: 800,
height: 600,
maximized: false,
};
store.set("lastWindowState", lastWindowState);
}
let win = new BrowserWindow({
title: "Electron image viewer",
icon: "images/icon.png",
position: "center",
x: lastWindowState.x,
y: lastWindowState.y,
width: lastWindowState.width,
height: lastWindowState.height,
overlayScrollbars: true,
resizable: true,
toolbar: true,
transparent: false,
fullscreen: false,
frame: false,
show: false,
});
win.setMenu(null);
if (lastWindowState.maximized) {
win.maximize();
}
win.on("close", () => {
const maximized = win.isMaximized();
// avoid setting width and height to screen w/h values
win.unmaximize();
const bounds = win.getBounds();
const { x, y, width, height } = bounds;
const windowState = {
maximized,
width,
height,
x,
y,
};
store.set("lastWindowState", windowState);
});
win.on("unresponsive", (e) => console.log(e));
win.webContents.on("crashed", (e) => console.log(e));
process.on("uncaughtException", (e) => console.log(e));
win.webContents.on("did-finish-load", () => win.show());
win.on("maximize", () => win.webContents.send("maximize"));
win.on("unmaximize", () => win.webContents.send("unmaximize"));
ipcMain.on("maximize", () => win.maximize());
ipcMain.on("unmaximize", () => win.unmaximize());
win.on("closed", () => setTimeout(() => (win = null), 250));
ipcMain.on("quit", () => {
win.closeDevTools();
app.quit();
});
win.loadURL("file://" + __dirname + "/app/index.html");
return win;
}
};