integrated with new and improved autoupdate code

Signed-off-by: Jim Ehrismann <jehrismann@mirantis.com>
This commit is contained in:
Jim Ehrismann committed 2022-06-29 11:51:22 -04:00
1 parent c2c231a585
commit 7cab54e6de
5 files changed
+64 -24

No files matched your search

@@ -3,10 +3,11 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import type { JsonObject } from "type-fest";
import createSyncBoxInjectable from "../../utils/sync-box/create-sync-box.injectable";
import { syncBoxInjectionToken } from "../../utils/sync-box/sync-box-injection-token";
export interface ProgressOfDownload {
export interface ProgressOfDownload extends JsonObject {
percentage: number;
}
@@ -5,16 +5,18 @@
import { getInjectable } from "@ogre-tools/injectable";
import { makeObservable, observable } from "mobx";
export type AutoUpdateStateName = "checking" | "available" | "not-available" | "done" | "downloading" | "idle";
export type AutoUpdateStateName = "checking" | "available" | "not-available" | "done" | "downloading" | "download-failed" | "download-succeeded" | "idle";
let timerId: NodeJS.Timeout;
export class AutoUpdateState {
@observable private _state: AutoUpdateStateName;
private timerId: NodeJS.Timeout;
@observable private _version: string | undefined = undefined;
constructor(state: AutoUpdateStateName = "idle") {
makeObservable(this);
this.name = state;
this._state = state;
}
get name() : AutoUpdateStateName {
@@ -27,9 +29,18 @@ export class AutoUpdateState {
this.triggerIdle();
}
get version() : string | undefined {
return this._version;
}
set version(version: string | undefined ) {
this._version = version;
this.triggerIdle();
}
private triggerIdle(): void {
clearTimeout(this.timerId);
this.timerId = null;
clearTimeout(timerId);
switch(this.name) {
case "checking":
@@ -40,7 +51,9 @@ export class AutoUpdateState {
case "done":
case "not-available":
this.timerId = setTimeout(() => this.name = "idle", 5000);
case "download-failed":
case "download-succeeded":
timerId = setTimeout(() => this.name = "idle", 5000);
break;
}
}