-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.ts
More file actions
111 lines (96 loc) · 2.46 KB
/
Copy pathmain.ts
File metadata and controls
111 lines (96 loc) · 2.46 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
const { app, BrowserWindow } = require("electron");
const path = require("path");
const iconPath =
process.platform !== "darwin"
? "public/images/icons/fav.ico"
: "public/images/icons/fav.ico";
function createLoadingScreen() {
const loadingScreen = new BrowserWindow({
width: 400,
height: 200,
frame: false,
transparent: true,
alwaysOnTop: true,
webPreferences: {
nodeIntegration: true,
},
icon: path.join(__dirname, iconPath),
});
loadingScreen.loadFile("loading.html");
return loadingScreen;
}
function createMainWindow() {
const mainWindow = new BrowserWindow({
width: 900,
height: 600,
show: false,
focusable: false,
titleBarStyle: 'hidden',
trafficLightPosition: {
x: 14,
y: 8,
},
icon: `${__dirname}/public/images/icons/152.png`,
});
mainWindow.loadURL(
process.env.NODE_ENV !== "production"
? "http://localhost:3000/?appSt=true"
: process.env.NEXT_PUBLIC_SITE_URL
);
// drag(mainWindow, {
// dragArea: 'header'
// })
// mainWindow.webContents.openDevTools();
mainWindow.setTitle(process.env.NEXT_PUBLIC_APP_TITLE || "");
mainWindow.webContents.on("page-title-updated", (event, title) => {
mainWindow.setTitle(title);
});
mainWindow.on("page-title-set", (event, title) => {
if (title === "") {
const fallbackTitle = process.env.NEXT_PUBLIC_APP_TITLE || "";
if (fallbackTitle) {
mainWindow.setTitle(fallbackTitle);
}
}
});
return mainWindow;
}
app.whenReady().then(() => {
const loadingScreen = createLoadingScreen();
const mainWindow = createMainWindow();
let loadTime = Date.now();
let loaded = false;
mainWindow.on("ready-to-show", () => {
loaded = true;
const remainingTime = 3000 - (Date.now() - loadTime);
setTimeout(
() => {
loadingScreen.hide();
mainWindow.show();
},
remainingTime > 0 ? remainingTime : 0
);
});
mainWindow.on("closed", () => {
app.quit();
});
mainWindow.webContents.on("did-finish-load", () => {
if (!loaded) {
const remainingTime = 3000 - (Date.now() - loadTime);
setTimeout(
() => {
loadingScreen.hide();
mainWindow.show();
},
remainingTime > 0 ? remainingTime : 0
);
}
});
// Show the loading screen initially
loadingScreen.show();
});
app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.quit();
}
});