Compare commits

..

2 Commits

Author SHA1 Message Date
Marc Brooks bfe7e3d59b
Merge f23480792b into 7f2dcc84b4 2025-11-10 12:59:03 +01:00
Marc Brooks 7f2dcc84b4
fix: don't reload page if we didn't attempt an upgrade. (#955) 2025-11-10 12:58:57 +01:00
2 changed files with 23 additions and 12 deletions

View File

@ -603,6 +603,9 @@ export interface UpdateState {
updateErrorMessage: string | null;
setUpdateErrorMessage: (errorMessage: string) => void;
shouldReload: boolean;
setShouldReload: (reloadRequired: boolean) => void;
}
export const useUpdateStore = create<UpdateState>(set => ({
@ -640,6 +643,9 @@ export const useUpdateStore = create<UpdateState>(set => ({
updateErrorMessage: null,
setUpdateErrorMessage: (errorMessage: string) =>
set({ updateErrorMessage: errorMessage }),
shouldReload: false,
setShouldReload: (reloadRequired: boolean) => set({ shouldReload: reloadRequired }),
}));
export type UsbConfigModalViews = "updateUsbConfig" | "updateUsbConfigSuccess";
@ -850,12 +856,12 @@ export interface MacrosState {
loadMacros: () => Promise<void>;
saveMacros: (macros: KeySequence[]) => Promise<void>;
sendFn:
| ((
method: string,
params: unknown,
callback?: ((resp: JsonRpcResponse) => void) | undefined,
) => void)
| null;
| ((
method: string,
params: unknown,
callback?: ((resp: JsonRpcResponse) => void) | undefined,
) => void)
| null;
setSendFn: (
sendFn: (
method: string,

View File

@ -18,20 +18,24 @@ export default function SettingsGeneralUpdateRoute() {
const location = useLocation();
const { updateSuccess } = location.state || {};
const { setModalView, otaState } = useUpdateStore();
const { setModalView, otaState, shouldReload, setShouldReload } = useUpdateStore();
const { send } = useJsonRpc();
const onClose = useCallback(async () => {
navigate(".."); // back to the devices.$id.settings page
// Add 1s delay between navigation and calling reload() to prevent reload from interrupting the navigation.
await sleep(1000);
window.location.reload(); // force a full reload to ensure the current device/cloud UI version is loaded
}, [navigate]);
if (shouldReload) {
setShouldReload(false);
await sleep(1000); // Add 1s delay between navigation and calling reload() to prevent reload from interrupting the navigation.
window.location.reload(); // force a full reload to ensure the current device/cloud UI version is loaded
}
}, [navigate, setShouldReload, shouldReload]);
const onConfirmUpdate = useCallback(() => {
setShouldReload(true);
send("tryUpdate", {});
setModalView("updating");
}, [send, setModalView]);
}, [send, setModalView, setShouldReload]);
useEffect(() => {
if (otaState.updating) {
@ -133,6 +137,7 @@ function LoadingState({
const { setModalView } = useUpdateStore();
const progressBarRef = useRef<HTMLDivElement>(null);
useEffect(() => {
abortControllerRef.current = new AbortController();
const signal = abortControllerRef.current.signal;