Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions ui/src/hooks/stores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => ({
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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,
Expand Down
17 changes: 11 additions & 6 deletions ui/src/routes/devices.$id.settings.general.update.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -133,6 +137,7 @@ function LoadingState({
const { setModalView } = useUpdateStore();

const progressBarRef = useRef<HTMLDivElement>(null);

useEffect(() => {
abortControllerRef.current = new AbortController();
const signal = abortControllerRef.current.signal;
Expand Down