This commit is contained in:
Mateusz Gruszczyński committed 2026-10-11 12:21:26 +02:00
1 parent 0facfe6f5c
commit 95c55da2ee
39 files changed
+715 -151

No files matched your search

+49 -13
View File
@@ -21,9 +21,10 @@ const rustProxyRefresh = (() => {
const tasks = new Map();
let ready = false, options = { ...REFRESH_DEFAULTS }, panel = currentPanel;
let settingsTab = "listeners", watchingVisibility = false;
let sessionReady = true, visibleResumeHandled = false;
const visible = () => !document.hidden;
function allowed(task) {
return ready && authenticated && visible() && options.live_enabled &&
return ready && authenticated && sessionReady && visible() && options.live_enabled &&
task.interval() > 0 && (!task.active || task.active());
}
function clear(task, abort = false) {
@@ -39,7 +40,7 @@ const rustProxyRefresh = (() => {
task.timer = setTimeout(() => { task.timer = null; void execute(task, false); }, delay);
}
function execute(task, manual) {
if (!authenticated || (!manual && !allowed(task))) return Promise.resolve();
if (!authenticated || !sessionReady || (!manual && !allowed(task))) return Promise.resolve();
if (task.inFlight) {
if (manual) task.queued = true;
return task.inFlight;
@@ -92,22 +93,56 @@ const rustProxyRefresh = (() => {
}
task.seconds = seconds;
}
if (ready && authenticated && visible() && options.live_enabled) startLive();
if (ready && authenticated && sessionReady && visible() && options.live_enabled) startLive();
else stopLive();
}
function onVisibility() { sync(); if (visible() && ready && authenticated) void revalidateSession(); }
function start() {
ready = true; panel = currentPanel;
settingsTab = window.rustProxySettings?.current?.() || "listeners";
if (!watchingVisibility) { document.addEventListener("visibilitychange", onVisibility); watchingVisibility = true; }
sync();
}
function stop() {
ready = false;
function suspendForSessionValidation() {
sessionReady = false;
for (const task of tasks.values()) {
clear(task, true); task.queued = false; task.enabled = false;
}
if (watchingVisibility) { document.removeEventListener("visibilitychange", onVisibility); watchingVisibility = false; }
sync();
}
function completeSessionValidation(success) {
sessionReady = !!success;
sync();
}
function requestSessionResume() {
if (!ready || !authenticated || !visible() || visibleResumeHandled) return;
visibleResumeHandled = true;
void revalidateSession();
}
function onVisibility() {
if (visible()) requestSessionResume();
else { visibleResumeHandled = false; sync(); }
}
function onPageHide() {
visibleResumeHandled = false;
suspendForSessionValidation();
}
function onPageShow(event) { if (event.persisted) requestSessionResume(); }
function start() {
ready = true; sessionReady = true; visibleResumeHandled = false; panel = currentPanel;
settingsTab = window.rustProxySettings?.current?.() || "listeners";
if (!watchingVisibility) {
document.addEventListener("visibilitychange", onVisibility);
window.addEventListener("pagehide", onPageHide);
window.addEventListener("pageshow", onPageShow);
watchingVisibility = true;
}
sync();
}
function stop() {
ready = false; sessionReady = false; visibleResumeHandled = false;
for (const task of tasks.values()) {
clear(task, true); task.queued = false; task.enabled = false;
}
if (watchingVisibility) {
document.removeEventListener("visibilitychange", onVisibility);
window.removeEventListener("pagehide", onPageHide);
window.removeEventListener("pageshow", onPageShow);
watchingVisibility = false;
}
stopLive();
}
function update(value) { options = normalizeRefreshPreferences(value); sync(); }
@@ -151,6 +186,7 @@ const rustProxyRefresh = (() => {
register("tunnels", { interval: () => 2, active: () => !!$("tunnels-dialog")?.open,
run: async context => { await loadTunnels(context); } });
return { register, manual, start, stop, sync, update, setPanel, setSettingsTab,
suspendForSessionValidation, completeSessionValidation,
current: () => ({ ...options }), diagnostics: () => [...tasks.values()].map(t => ({ id: t.id, enabled: t.enabled, inFlight: !!t.inFlight, scheduled: t.timer !== null })) };
})();
window.rustProxyRefresh = rustProxyRefresh;