mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-28 02:11:40 +00:00
Force reload after restart and switch URL after IP change (#2278)
## Description Forces a reload after restarting PhotonVision, restarting the coprocessor, performing an offline update, or nuking the install. We wait until we are reconnected to the coprocessor to reload, this is accomplished by the addition of a status API endpoint. This is being implemented due to issues experienced when the webpage is not updated (particularly during offline updates). --- Using the same statusCheck, we also wait until a new IP is available, then change to it, after changing our static IP. --- closes #2169 closes #903 ## Meta Merge checklist: - [x] Pull Request title is [short, imperative summary](https://cbea.ms/git-commit/) of proposed changes - [x] The description documents the _what_ and _why_ - [ ] If this PR changes behavior or adds a feature, user documentation is updated - [ ] If this PR touches photon-serde, all messages have been regenerated and hashes have not changed unexpectedly - [ ] If this PR touches configuration, this is backwards compatible with settings back to v2025.3.2 - [ ] If this PR touches pipeline settings or anything related to data exchange, the frontend typing is updated - [ ] If this PR addresses a bug, a regression test for it is added
This commit is contained in:
@@ -6,6 +6,49 @@ export const resolutionsAreEqual = (a: Resolution, b: Resolution) => {
|
||||
return a.height === b.height && a.width === b.width;
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks the status of the backend by polling the "/status" endpoint.
|
||||
*
|
||||
* This function will repeatedly attempt to send a GET request to the backend
|
||||
* until a successful response is received or the specified timeout is reached.
|
||||
*
|
||||
* @param timeout - The maximum time in milliseconds to wait for a successful response.
|
||||
* @param ip - Optional IP address of the backend server. If not provided, the default endpoint is used. This is meant for the case where the backend is running on a different IP than the frontend.
|
||||
* @returns A promise that resolves to a boolean indicating whether the backend is responsive (true) or not (false).
|
||||
*/
|
||||
export const statusCheck = async (timeout: number, ip?: string): Promise<boolean> => {
|
||||
// Poll the backend until it's responsive or we hit the timeout
|
||||
let pollLimit = Math.floor(timeout / 100);
|
||||
while (pollLimit > 0) {
|
||||
try {
|
||||
pollLimit--;
|
||||
await axios.get(ip ? `http://${ip}/status` : "/status");
|
||||
return true;
|
||||
} catch {
|
||||
// Backend not ready yet, wait and retry
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Forces a page reload after a brief delay and a status check.
|
||||
*/
|
||||
export const forceReloadPage = async () => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
|
||||
useStateStore().showSnackbarMessage({
|
||||
message: "Reloading the page to apply changes...",
|
||||
color: "success"
|
||||
});
|
||||
|
||||
await statusCheck(20000);
|
||||
|
||||
window.location.reload();
|
||||
};
|
||||
|
||||
export const getResolutionString = (resolution: Resolution): string => `${resolution.width}x${resolution.height}`;
|
||||
|
||||
export const parseJsonFile = async <T extends Record<string, any>>(file: File): Promise<T> => {
|
||||
|
||||
Reference in New Issue
Block a user