-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathlinkStatsWindow.ts
More file actions
64 lines (55 loc) · 1.79 KB
/
linkStatsWindow.ts
File metadata and controls
64 lines (55 loc) · 1.79 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
import { BrowserWindow, ipcMain } from "electron"
import path from "path"
const VITE_DEV_SERVER_URL = process.env["VITE_DEV_SERVER_URL"]
let linkStatsWin: BrowserWindow | null = null
export function openLinkStatsWindow() {
if (linkStatsWin === null) {
linkStatsWin = new BrowserWindow({
width: 500,
height: 300,
frame: true,
icon: path.join(process.env.VITE_PUBLIC, "app_icon.ico"),
show: false,
title: "Connection Stats",
webPreferences: {
preload: path.join(__dirname, "preload.js"),
contextIsolation: true,
},
fullscreen: false,
fullscreenable: false,
})
}
if (VITE_DEV_SERVER_URL) {
linkStatsWin?.loadURL(VITE_DEV_SERVER_URL + "linkStats.html")
} else {
linkStatsWin?.loadFile(path.join(process.env.DIST, "linkStats.html"))
}
linkStatsWin.on("close", () => {
linkStatsWin = null
})
linkStatsWin.setMenuBarVisibility(false)
linkStatsWin.show()
}
export function closeLinkStatsWindow() {
destroyLinkStatsWindow()
}
export function destroyLinkStatsWindow() {
linkStatsWin?.close()
linkStatsWin = null
}
export default function registerLinkStatsIPC() {
ipcMain.removeHandler("app:open-link-stats-window")
ipcMain.removeHandler("app:close-link-stats-window")
ipcMain.removeHandler("app:update-link-stats")
ipcMain.handle("app:open-link-stats-window", () => {
openLinkStatsWindow()
})
ipcMain.handle("app:close-link-stats-window", () => closeLinkStatsWindow())
ipcMain.handle("app:update-link-stats", (_, linkStats) => {
linkStatsWin?.webContents.send("app:send-link-stats", linkStats)
const uptimeFormatted = new Date(Math.round(linkStats.uptime) * 1000)
.toISOString()
.substring(11, 19)
linkStatsWin?.setTitle(`Connection Stats | Uptime: ${uptimeFormatted}`)
})
}