Prevent flashing of Reload button when upgrading.

This commit is contained in:
Robin Davies
2024-08-29 19:22:37 -04:00
parent 5b46b11f1f
commit efc1143d27
+39 -8
View File
@@ -54,6 +54,12 @@ export enum State {
InstallingUpdate, InstallingUpdate,
}; };
class UpdatedError extends Error {
constructor(message: string)
{
super(message);
}
};
export function wantsLoadingScreen(state: State) { export function wantsLoadingScreen(state: State) {
return state >= State.Reconnecting; return state >= State.Reconnecting;
} }
@@ -728,10 +734,7 @@ export class PiPedalModel //implements PiPedalModel
if (current.currentVersion.length !== 0 && current.currentVersion !== updateStatus.currentVersion) { if (current.currentVersion.length !== 0 && current.currentVersion !== updateStatus.currentVersion) {
// !! Server has been updated!!! // !! Server has been updated!!!
this.reloadPage(); this.reloadPage();
throw new Error("Reloading..."); throw new UpdatedError("Server has been updated");
}
if (updateStatus.getActiveRelease().updateAvailable) {
this.promptForUpdate.set(true);
} }
this.updatePromptForUpdate() this.updatePromptForUpdate()
} }
@@ -879,7 +882,12 @@ export class PiPedalModel //implements PiPedalModel
this.setState(State.Ready); this.setState(State.Ready);
}) })
.catch((what) => { .catch((what) => {
this.onError(what.toString()); if (what instanceof UpdatedError)
{
// do nothing. a page reload is imminent and unavoidable as soon as we return to the dispatcher.
} else {
this.onError(what.toString());
}
}) })
} }
makeSocketServerUrl(hostName: string, port: number): string { makeSocketServerUrl(hostName: string, port: number): string {
@@ -1070,8 +1078,20 @@ export class PiPedalModel //implements PiPedalModel
} }
onError(msg: string): void { onError(message: string| Error): void {
this.errorMessage.set(msg); let m = message;
if (message instanceof Error)
{
let e = message as Error;
if (e.message) {
m = e.message as string;
} else {
m = e.toString();
}
} else{
m = message.toString();
}
this.errorMessage.set(m);
this.state.set(State.Error); this.state.set(State.Error);
} }
@@ -1895,7 +1915,18 @@ export class PiPedalModel //implements PiPedalModel
} }
showAlert(message: string| Error): void { showAlert(message: string| Error): void {
let m = message.toString(); let m = message;
if (message instanceof Error)
{
let e = message as Error;
if (e.message) {
m = e.message as string;
} else {
m = e.toString();
}
} else{
m = message.toString();
}
this.alertMessage.set(m); this.alertMessage.set(m);
} }