Initial upload to Gitea
This commit is contained in:
1 parent
78193254ad
commit
8478998cae
1485 files changed
+461025
-42348
No files matched your search
+22
-12
@@ -64,7 +64,12 @@
|
||||
}
|
||||
|
||||
function onResourceData(data) {
|
||||
if (!data || data.server !== bot) return;
|
||||
// Unsubscribe on hide is asynchronous server-side, so an in-flight
|
||||
// room event can still land afterwards; ignore everything while the
|
||||
// tab is hidden (the show path re-subscribes and the server
|
||||
// immediately replays the watcher's last snapshot).
|
||||
if (document.visibilityState === 'hidden') return;
|
||||
if (!data || String(data.server || '').trim().toLowerCase() !== String(bot || '').trim().toLowerCase()) return;
|
||||
const isRunning = data.status === 'running' || data.status === 'online';
|
||||
|
||||
if (data.memory && isRunning) {
|
||||
@@ -125,17 +130,19 @@
|
||||
const network = data.network || null;
|
||||
const inboundBytes = readNetworkBytes(network, ['inboundBytes', 'rxBytes', 'receivedBytes']);
|
||||
const outboundBytes = readNetworkBytes(network, ['outboundBytes', 'txBytes', 'transmittedBytes']);
|
||||
if (inboundBytes !== null) {
|
||||
lastNetworkInboundBytes = Math.max(lastNetworkInboundBytes, inboundBytes);
|
||||
if (inboundBytes !== null && isRunning) {
|
||||
lastNetworkInboundBytes = inboundBytes;
|
||||
if (resNetworkInboundLabel) resNetworkInboundLabel.textContent = formatBytes(lastNetworkInboundBytes);
|
||||
} else if (resNetworkInboundLabel) {
|
||||
resNetworkInboundLabel.textContent = '—';
|
||||
lastNetworkInboundBytes = 0;
|
||||
resNetworkInboundLabel.textContent = isRunning ? '0 B' : '—';
|
||||
}
|
||||
if (outboundBytes !== null) {
|
||||
lastNetworkOutboundBytes = Math.max(lastNetworkOutboundBytes, outboundBytes);
|
||||
if (outboundBytes !== null && isRunning) {
|
||||
lastNetworkOutboundBytes = outboundBytes;
|
||||
if (resNetworkOutboundLabel) resNetworkOutboundLabel.textContent = formatBytes(lastNetworkOutboundBytes);
|
||||
} else if (resNetworkOutboundLabel) {
|
||||
resNetworkOutboundLabel.textContent = '—';
|
||||
lastNetworkOutboundBytes = 0;
|
||||
resNetworkOutboundLabel.textContent = isRunning ? '0 B' : '—';
|
||||
}
|
||||
|
||||
if (data.uptime && data.uptime > 0 && isRunning) {
|
||||
@@ -172,29 +179,32 @@
|
||||
}
|
||||
}
|
||||
|
||||
// The resources:data handler is registered exactly once. The old path
|
||||
// re-registered it on every reconnect (subscribed survived disconnects
|
||||
// while the listener was added again), so each event was processed N+1
|
||||
// times in long-lived tabs; subscribed now only gates the server-side
|
||||
// room join.
|
||||
socket.on('resources:data', onResourceData);
|
||||
|
||||
let subscribed = false;
|
||||
|
||||
function subscribe() {
|
||||
if (subscribed) return;
|
||||
subscribed = true;
|
||||
socket.on('resources:data', onResourceData);
|
||||
socket.emit('resources:subscribe', { server: bot });
|
||||
}
|
||||
|
||||
function unsubscribe() {
|
||||
if (!subscribed) return;
|
||||
subscribed = false;
|
||||
socket.off('resources:data', onResourceData);
|
||||
socket.emit('resources:unsubscribe', { server: bot });
|
||||
stopUptimeCounter();
|
||||
}
|
||||
|
||||
socket.on('connect', () => {
|
||||
if (subscribed) {
|
||||
if (subscribed || document.visibilityState !== 'hidden') {
|
||||
subscribed = false;
|
||||
subscribe();
|
||||
} else if (document.visibilityState !== 'hidden') {
|
||||
subscribe();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user