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

@@ -5,39 +5,46 @@
import { getInjectable } from "@ogre-tools/injectable";
import type { ApplicationUpdateStatusChannel, ApplicationUpdateStatusEventId } from "../../common/application-update/application-update-status-channel.injectable";
import applicationUpdateStatusChannelInjectable from "../../common/application-update/application-update-status-channel.injectable";
import showInfoNotificationInjectable from "../components/notifications/show-info-notification.injectable";
//import showInfoNotificationInjectable from "../components/notifications/show-info-notification.injectable";
import type { MessageChannelListener } from "../../common/utils/channel/message-channel-listener-injection-token";
import { messageChannelListenerInjectionToken } from "../../common/utils/channel/message-channel-listener-injection-token";
import AutoUpdateStateInjectable from "../../common/auto-update/auto-update-state.injectable";
const applicationUpdateStatusListenerInjectable = getInjectable({
id: "application-update-status-listener",
instantiate: (di): MessageChannelListener<ApplicationUpdateStatusChannel> => {
const channel = di.inject(applicationUpdateStatusChannelInjectable);
const showInfoNotification = di.inject(showInfoNotificationInjectable);
//const showInfoNotification = di.inject(showInfoNotificationInjectable);
const autoUpdateState = di.inject(AutoUpdateStateInjectable);
const eventHandlers: Record<ApplicationUpdateStatusEventId, { handle: (version?: string) => void }> = {
"checking-for-updates": {
handle: () => {
showInfoNotification("Checking for updates...");
//showInfoNotification("Checking for updates...");
autoUpdateState.name = "checking";
},
},
"no-updates-available": {
handle: () => {
showInfoNotification("No new updates available");
//showInfoNotification("No new updates available");
autoUpdateState.name = "not-available";
},
},
"download-for-update-started": {
handle: (version) => {
showInfoNotification(`Download for version ${version} started...`);
//showInfoNotification(`Download for version ${version} started...`);
autoUpdateState.name = "downloading";
autoUpdateState.version = version;
},
},
"download-for-update-failed": {
handle: () => {
showInfoNotification("Download of update failed");
//showInfoNotification("Download of update failed");
autoUpdateState.name = "download-failed";
},
},
};
@@ -8,25 +8,39 @@ import React from "react";
import AutoUpdateStateInjectable from "../../../common/auto-update/auto-update-state.injectable";
import type { AutoUpdateState } from "../../../common/auto-update/auto-update-state.injectable";
import { Spinner } from "../spinner";
import progressOfUpdateDownloadInjectable, { ProgressOfDownload } from "../../../common/application-update/progress-of-update-download/progress-of-update-download.injectable";
import type { SyncBox } from "../../../common/utils/sync-box/sync-box-injection-token";
interface Dependencies {
state: AutoUpdateState;
progressOfUpdateDownload: SyncBox<ProgressOfDownload>;
}
const checking = () => <><Spinner/><div>{"Checking for updates"}</div></>;
const checking = () => <><Spinner/><div>{"Checking for updates..."}</div></>;
const available = () => <div>{"Update is available"}</div>;
const notAvailable = () => <div>{"No new updates available"}</div>;
const downloading = (state: AutoUpdateState, percentDone: number) => {
const {version } = state;
const notAvailable = () => {
if ( percentDone === 0 ) {
return <><div>{`Download for version ${version} started `}</div><Spinner/></>;
}
return <div>{"Update is currently not available"}</div>;
if ( percentDone < 100 ) {
return <div>{`Download for version ${version} ${percentDone}%...`}</div>;
}
state.name = "download-succeeded";
return null;
};
const downloading = () => <div>{"Downloading update"}</div>;
const done = () => <div>{"Done checking for updates"}</div>;
const downloadFailed = (version: string | undefined) => <div>{`Download for version ${version} failed`}</div>;
const downloadSucceeded = (version: string | undefined) => <div>{`Download for version ${version} complete`}</div>;
const idle = () => <></>;
export const NonInjectedAutoUpdateComponent = observer(({ state }: Dependencies) => {
export const NonInjectedAutoUpdateComponent = observer(({ state, progressOfUpdateDownload }: Dependencies) => {
switch(state.name) {
case "checking":
@@ -39,13 +53,19 @@ export const NonInjectedAutoUpdateComponent = observer(({ state }: Dependencies)
return notAvailable();
case "downloading":
return downloading();
const roundedPercentage = Math.round(progressOfUpdateDownload.value.get().percentage);
return downloading(state, roundedPercentage);
case "done":
return done();
default:
case "idle":
case "download-failed":
return downloadFailed(state.version);
case "download-succeeded":
return downloadSucceeded(state.version);
case "idle":
return idle();
}
@@ -54,6 +74,7 @@ export const NonInjectedAutoUpdateComponent = observer(({ state }: Dependencies)
export const AutoUpdateComponent = withInjectables<Dependencies>(NonInjectedAutoUpdateComponent, {
getProps: (di, props) => ({
state: di.inject(AutoUpdateStateInjectable),
progressOfUpdateDownload: di.inject(progressOfUpdateDownloadInjectable),
...props,
}),
});
@@ -5,14 +5,12 @@
import { getInjectable } from "@ogre-tools/injectable";
import { registerIpcListeners } from "./register-listeners";
import listNamespacesForbiddenHandlerInjectable from "./list-namespaces-forbidden-handler.injectable";
import AutoUpdateStateInjectable from "../../common/auto-update/auto-update-state.injectable";
const registerIpcListenersInjectable = getInjectable({
id: "register-ipc-listeners",
instantiate: (di) => registerIpcListeners({
listNamespacesForbiddenHandler: di.inject(listNamespacesForbiddenHandlerInjectable),
updateState: di.inject(AutoUpdateStateInjectable),
}),
});