-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathweb.js
More file actions
99 lines (86 loc) · 3 KB
/
web.js
File metadata and controls
99 lines (86 loc) · 3 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
let compactSidebar = false
let currentPage = "home"
function updateSidebar() {
if (document.getElementById(currentPage)) {
document.getElementById(currentPage).setAttribute("class", "active");
}
}
function toggleSidebar() {
const sidebar = document.getElementById("sidebar");
if (!sidebar) return;
if (compactSidebar == true) {
compactSidebar = false;
sidebar.style.width = "var(--sidebar-width)";
sidebar.classList.remove('compact');
sidebar.classList.add('extended');
} else {
compactSidebar = true;
sidebar.style.width = "56px";
sidebar.classList.remove('extended');
sidebar.classList.add('compact');
}
}
if (document.getElementById('close-button')) {
document.getElementById('close-button').addEventListener('click', () => {
window.api.sendWindowControl('close');
});
}
if (document.getElementById('max-button')) {
document.getElementById('max-button').addEventListener('click', () => {
window.api.sendWindowControl('maximize');
});
}
if (document.getElementById('min-button')) {
document.getElementById('min-button').addEventListener('click', () => {
window.api.sendWindowControl('minimize');
});
}
if (window.api?.isElectron) {
console.log("Electron");
} else {
console.log("Browser");
const tb = document.querySelector(".titlebar");
if (tb) tb.setAttribute("style", "display: none; opacity: 0%;");
}
if (document.getElementById("sidebar")) {
toggleSidebar();
}
let connectionCheckInterval;
let connectionAttempts = 0;
function showLoadingScreen() {
const loadingScreen = document.getElementById('loading-screen');
const downtimeScreen = document.getElementById('downtime-screen');
if (loadingScreen) loadingScreen.style.display = 'flex';
if (downtimeScreen) downtimeScreen.style.display = 'none';
}
function showDowntimeScreen() {
const loadingScreen = document.getElementById('loading-screen');
const downtimeScreen = document.getElementById('downtime-screen');
if (loadingScreen) loadingScreen.style.display = 'none';
if (downtimeScreen) downtimeScreen.style.display = 'flex';
}
function hideAllScreens() {
const loadingScreen = document.getElementById('loading-screen');
const downtimeScreen = document.getElementById('downtime-screen');
if (loadingScreen) loadingScreen.style.display = 'none';
if (downtimeScreen) downtimeScreen.style.display = 'none';
}
function checkConnection() {
if (window.ws && window.ws.readyState === WebSocket.OPEN) {
hideAllScreens();
connectionAttempts = 0;
} else if (window.ws && window.ws.readyState === WebSocket.CONNECTING) {
showLoadingScreen();
} else {
connectionAttempts++;
if (connectionAttempts > 5) {
showDowntimeScreen();
} else {
showLoadingScreen();
}
}
}
if (document.getElementById('loading-screen')) {
showLoadingScreen();
connectionCheckInterval = setInterval(checkConnection, 500);
}