Replace status bar item application update with different tray icon based on status of the update (#5769)

* Remove the auto-update status bar item for not being needed anymore

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Make adding of new tray icons easier by complying to Open Closed Principle

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Start showing different tray icon when checking for updates

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Include placeholder icon for checking for updates

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Simplify code

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Add first keyframe for downloading spinner

Signed-off-by: Sebastian Malton <sebastian@malton.name>

Co-authored-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Janne SavolainenandSebastian Malton authored and GitHub committed 2022-07-05 15:44:03 -07:00
1 parent 26127fe906
commit 667053cdf5
52 files changed
+370 -1409

No files matched your search

@@ -1,107 +0,0 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { withInjectables } from "@ogre-tools/injectable-react";
import { observer } from "mobx-react";
import assert from "assert";
import React, { useState } from "react";
import { Spinner } from "../spinner";
import type { ProgressOfUpdateDownload } from "../../../common/application-update/progress-of-update-download/progress-of-update-download.injectable";
import progressOfUpdateDownloadInjectable from "../../../common/application-update/progress-of-update-download/progress-of-update-download.injectable";
import type { DiscoveredUpdateVersion } from "../../../common/application-update/discovered-update-version/discovered-update-version.injectable";
import discoveredUpdateVersionInjectable from "../../../common/application-update/discovered-update-version/discovered-update-version.injectable";
import type { UpdateIsBeingDownloaded } from "../../../common/application-update/update-is-being-downloaded/update-is-being-downloaded.injectable";
import updateIsBeingDownloadedInjectable from "../../../common/application-update/update-is-being-downloaded/update-is-being-downloaded.injectable";
import type { UpdatesAreBeingDiscovered } from "../../../common/application-update/updates-are-being-discovered/updates-are-being-discovered.injectable";
import updatesAreBeingDiscoveredInjectable from "../../../common/application-update/updates-are-being-discovered/updates-are-being-discovered.injectable";
import { reactiveNow } from "../../../common/utils/reactive-now/reactive-now";
interface Dependencies {
progressOfUpdateDownload: ProgressOfUpdateDownload;
discoveredVersionState: DiscoveredUpdateVersion;
downloadingUpdateState: UpdateIsBeingDownloaded;
checkingForUpdatesState: UpdatesAreBeingDiscovered;
}
interface EndNoteProps {
version?: string;
note: (version: string) => JSX.Element;
}
const EndNote = observer(({ version, note }: EndNoteProps) => {
const [start] = useState(Date.now());
if (start + 5000 <= reactiveNow()) {
return idle();
}
return note(version ?? "");
});
const checking = () => (
<>
<Spinner/>
<div data-testid="app-update-checking">Checking for updates...</div>
</>
);
const available = (version: string) => <div data-testid="app-update-available">{`${version ?? "Update"} is available`}</div>;
const notAvailable = () => <div data-testid="app-update-not-available">No new updates available</div>;
const downloading = (version: string) => {
return (
<>
<div data-testid="app-update-downloading">{`Downloading version ${version}...`}</div>
<Spinner/>
</>
);
};
const downloadFailed = (errMsg: string) => <div data-testid="app-update-download-failed">{errMsg}</div>;
const idle = () => <div data-testid="app-update-idle"></div>;
export const NonInjectedAutoUpdateComponent = observer(({
progressOfUpdateDownload,
discoveredVersionState,
downloadingUpdateState,
checkingForUpdatesState,
}: Dependencies) => {
const discoveredVersion = discoveredVersionState.value.get();
const { failed } = progressOfUpdateDownload.value.get();
if (downloadingUpdateState.value.get()) {
assert(discoveredVersion);
return downloading(discoveredVersion.version);
}
if (checkingForUpdatesState.value.get()) {
return checking();
}
if ( discoveredVersion) {
return <EndNote note={available} version={discoveredVersion.version} />;
}
if ( failed ) {
return <EndNote note={downloadFailed} version={failed} />;
}
return <EndNote note={notAvailable} />;
});
export const AutoUpdateComponent = withInjectables<Dependencies>(NonInjectedAutoUpdateComponent, {
getProps: (di, props) => ({
progressOfUpdateDownload: di.inject(progressOfUpdateDownloadInjectable),
discoveredVersionState: di.inject(discoveredUpdateVersionInjectable),
downloadingUpdateState: di.inject(updateIsBeingDownloadedInjectable),
checkingForUpdatesState: di.inject(updatesAreBeingDiscoveredInjectable),
...props,
}),
});
@@ -1,22 +0,0 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { computed } from "mobx";
import { AutoUpdateComponent } from "./auto-update-component";
import { statusBarItemInjectionToken } from "./status-bar-item-injection-token";
const autoUpdateStatusBarItemInjectable = getInjectable({
id: "auto-update-status-bar-item",
instantiate: () => ({
component: AutoUpdateComponent,
position: "left" as const,
visible: computed(() => true),
}),
injectionToken: statusBarItemInjectionToken,
});
export default autoUpdateStatusBarItemInjectable;