-
Notifications
You must be signed in to change notification settings - Fork 1
/
createWindow.js
59 lines (50 loc) 路 1.42 KB
/
createWindow.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
import { BrowserWindow } from "electron";
import * as path from "path";
import { format as formatUrl } from "url";
import { callRenderer } from "electron-better-ipc";
const isDevelopment = process.env.NODE_ENV !== "production";
export const createMainWindow = mainWindow => {
const window = new BrowserWindow({
width: 1024,
height: 768,
minWidth: 1024,
minHeight: 768,
/*
only setting minWidth or minHeight doesn't work, have to set width & height too
also setting one of minWidth or minHeight doesn't work, have to set both minWidth & minHeight
*/
title: "WIP Desktop",
frame: false,
icon: path.join(__dirname, "../../build/icon.png"),
});
if (isDevelopment) {
window.webContents.openDevTools();
}
if (isDevelopment) {
window.loadURL(`http://localhost:${process.env.ELECTRON_WEBPACK_WDS_PORT}`);
} else {
window.loadURL(
formatUrl({
pathname: path.join(__dirname, "../renderer/index.html"),
protocol: "file",
slashes: true,
})
);
}
window.on("closed", () => {
mainWindow = null;
});
window.webContents.on("devtools-opened", () => {
window.focus();
setImmediate(() => {
window.focus();
});
});
window.on("blur", async () => {
await callRenderer(window, "window-blur", "true");
});
window.on("focus", async () => {
await callRenderer(window, "window-blur", "false");
});
return window;
};