Better
This commit is contained in:
@@ -19,7 +19,11 @@ class Pruner {
|
||||
}
|
||||
|
||||
stopWorker() {
|
||||
clearTimeout(this.timer);
|
||||
if (this.timer) {
|
||||
clearTimeout(this.timer);
|
||||
this.timer = null;
|
||||
}
|
||||
console.log("[VersionChecker] Stopped pruner checker");
|
||||
}
|
||||
|
||||
async prune() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* VersionChecker polls the /v1/version endpoint to detect server restarts
|
||||
* VersionChecker polls the /v1/config endpoint to detect new server versions
|
||||
* or configuration changes, prompting users to refresh the page.
|
||||
*/
|
||||
|
||||
@@ -9,7 +9,8 @@ class VersionChecker {
|
||||
constructor() {
|
||||
this.initialConfigHash = null;
|
||||
this.listener = null;
|
||||
this.intervalId = null;
|
||||
console.log("XXXXXXxxxx set listener null");
|
||||
this.timer = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -18,73 +19,52 @@ class VersionChecker {
|
||||
*/
|
||||
startWorker() {
|
||||
// Store initial config hash from the config loaded at page load
|
||||
this.initialConfigHash = window.config?.config_hash || null;
|
||||
|
||||
if (!this.initialConfigHash) {
|
||||
console.log("[VersionChecker] No initial config_hash found, version checking disabled");
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("[VersionChecker] Starting version checker with initial hash:", this.initialConfigHash);
|
||||
|
||||
// Start polling
|
||||
this.intervalId = setInterval(() => this.checkVersion(), CHECK_INTERVAL);
|
||||
this.initialConfigHash = window.config?.config_hash || "";
|
||||
console.log("[VersionChecker] Starting version checker");
|
||||
this.timer = setInterval(() => this.checkVersion(), CHECK_INTERVAL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the version checker worker.
|
||||
*/
|
||||
stopWorker() {
|
||||
if (this.intervalId) {
|
||||
clearInterval(this.intervalId);
|
||||
this.intervalId = null;
|
||||
if (this.timer) {
|
||||
clearInterval(this.timer);
|
||||
this.timer = null;
|
||||
}
|
||||
console.log("[VersionChecker] Stopped version checker");
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a listener that will be called when a version change is detected.
|
||||
* @param {function} listener - Callback function that receives no arguments
|
||||
*/
|
||||
registerListener(listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the listener.
|
||||
*/
|
||||
resetListener() {
|
||||
this.listener = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the current version from the server and compares it with the initial config hash.
|
||||
*/
|
||||
async checkVersion() {
|
||||
if (!this.initialConfigHash) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`${window.config?.base_url || ""}/v1/version`);
|
||||
const response = await fetch(`${window.config?.base_url || ""}/v1/config`);
|
||||
if (!response.ok) {
|
||||
console.log("[VersionChecker] Failed to fetch version:", response.status);
|
||||
console.log("[VersionChecker] Failed to fetch config:", response.status);
|
||||
return;
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
const currentHash = data.config_hash;
|
||||
|
||||
console.log("[VersionChecker] Checked version, initial:", this.initialConfigHash, "current:", currentHash);
|
||||
|
||||
if (currentHash && currentHash !== this.initialConfigHash) {
|
||||
console.log("[VersionChecker] Config hash changed, notifying listener");
|
||||
console.log("[VersionChecker] Version or config changed, showing banner");
|
||||
if (this.listener) {
|
||||
this.listener();
|
||||
}
|
||||
} else {
|
||||
console.log("[VersionChecker] No version change detected");
|
||||
}
|
||||
} catch (error) {
|
||||
console.log("[VersionChecker] Error checking version:", error);
|
||||
console.log("[VersionChecker] Error checking config:", error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
import {
|
||||
Drawer,
|
||||
ListItemButton,
|
||||
ListItemIcon,
|
||||
ListItemText,
|
||||
Toolbar,
|
||||
Divider,
|
||||
List,
|
||||
Alert,
|
||||
AlertTitle,
|
||||
Badge,
|
||||
Box,
|
||||
Button,
|
||||
CircularProgress,
|
||||
Divider,
|
||||
Drawer,
|
||||
IconButton,
|
||||
Link,
|
||||
List,
|
||||
ListItemButton,
|
||||
ListItemIcon,
|
||||
ListItemText,
|
||||
ListSubheader,
|
||||
Portal,
|
||||
Toolbar,
|
||||
Tooltip,
|
||||
Typography,
|
||||
Box,
|
||||
IconButton,
|
||||
Button,
|
||||
useTheme,
|
||||
} from "@mui/material";
|
||||
import * as React from "react";
|
||||
import { useCallback, useContext, useState } from "react";
|
||||
import { useContext, useState } from "react";
|
||||
import ChatBubbleOutlineIcon from "@mui/icons-material/ChatBubbleOutline";
|
||||
import Person from "@mui/icons-material/Person";
|
||||
import SettingsIcon from "@mui/icons-material/Settings";
|
||||
@@ -93,9 +93,9 @@ const NavList = (props) => {
|
||||
const [subscribeDialogOpen, setSubscribeDialogOpen] = useState(false);
|
||||
const [versionChanged, setVersionChanged] = useState(false);
|
||||
|
||||
const handleVersionChange = useCallback(() => {
|
||||
const handleVersionChange = () => {
|
||||
setVersionChanged(true);
|
||||
}, []);
|
||||
};
|
||||
|
||||
useVersionChangeListener(handleVersionChange);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user