mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
using the update syncBox injectables directly for status bar notifications
Signed-off-by: Jim Ehrismann <jehrismann@mirantis.com>
This commit is contained in:
1 parent
7cbcc184a0
commit
041141fe39
8 files changed
+86
-128
No files matched your search
@@ -10,7 +10,8 @@ export type ApplicationUpdateStatusEventId =
|
||||
| "checking-for-updates"
|
||||
| "no-updates-available"
|
||||
| "download-for-update-started"
|
||||
| "download-for-update-failed";
|
||||
| "download-for-update-failed"
|
||||
| "download-for-update-succeeded";
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
||||
export type ApplicationUpdateStatusChannelMessage = { eventId: ApplicationUpdateStatusEventId; version?: string };
|
||||
|
||||
+7
-7
@@ -5,21 +5,21 @@
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import createSyncBoxInjectable from "../../utils/sync-box/create-sync-box.injectable";
|
||||
import type { UpdateChannel } from "../update-channels";
|
||||
import type { SyncBox } from "../../utils/sync-box/sync-box-injection-token";
|
||||
import { syncBoxInjectionToken } from "../../utils/sync-box/sync-box-injection-token";
|
||||
|
||||
export type DiscoveredUpdateVersion = SyncBox<{ version: string; updateChannel: UpdateChannel } | null>;
|
||||
|
||||
const discoveredUpdateVersionInjectable = getInjectable({
|
||||
id: "discovered-update-version",
|
||||
|
||||
instantiate: (di) => {
|
||||
const createSyncBox = di.inject(createSyncBoxInjectable);
|
||||
|
||||
return createSyncBox<
|
||||
| { version: string; updateChannel: UpdateChannel }
|
||||
| null
|
||||
>(
|
||||
"discovered-update-version",
|
||||
null,
|
||||
);
|
||||
return createSyncBox(
|
||||
"discovered-update-version",
|
||||
null,
|
||||
) as DiscoveredUpdateVersion;
|
||||
},
|
||||
|
||||
injectionToken: syncBoxInjectionToken,
|
||||
|
||||
+3
@@ -4,12 +4,15 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import createSyncBoxInjectable from "../../utils/sync-box/create-sync-box.injectable";
|
||||
import type { SyncBox } from "../../utils/sync-box/sync-box-injection-token";
|
||||
import { syncBoxInjectionToken } from "../../utils/sync-box/sync-box-injection-token";
|
||||
|
||||
export interface ProgressOfDownload {
|
||||
percentage: number;
|
||||
}
|
||||
|
||||
export type ProgressOfUpdateDownload = SyncBox<ProgressOfDownload>;
|
||||
|
||||
const progressOfUpdateDownloadInjectable = getInjectable({
|
||||
id: "progress-of-update-download-state",
|
||||
|
||||
|
||||
+3
@@ -4,8 +4,11 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import createSyncBoxInjectable from "../../utils/sync-box/create-sync-box.injectable";
|
||||
import type { SyncBox } from "../../utils/sync-box/sync-box-injection-token";
|
||||
import { syncBoxInjectionToken } from "../../utils/sync-box/sync-box-injection-token";
|
||||
|
||||
export type UpdateIsBeingDownloaded = SyncBox<boolean>;
|
||||
|
||||
const updateIsBeingDownloadedInjectable = getInjectable({
|
||||
id: "update-is-being-downloaded",
|
||||
|
||||
|
||||
+3
@@ -4,8 +4,11 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import createSyncBoxInjectable from "../../utils/sync-box/create-sync-box.injectable";
|
||||
import type { SyncBox } from "../../utils/sync-box/sync-box-injection-token";
|
||||
import { syncBoxInjectionToken } from "../../utils/sync-box/sync-box-injection-token";
|
||||
|
||||
export type UpdatesAreBeingDiscovered = SyncBox<boolean>;
|
||||
|
||||
const updatesAreBeingDiscoveredInjectable = getInjectable({
|
||||
id: "updates-are-being-discovered",
|
||||
|
||||
|
||||
@@ -1,67 +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 { makeObservable, observable } from "mobx";
|
||||
|
||||
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;
|
||||
@observable private _version: string | undefined = undefined;
|
||||
|
||||
constructor(state: AutoUpdateStateName = "idle") {
|
||||
makeObservable(this);
|
||||
|
||||
this._state = state;
|
||||
}
|
||||
|
||||
get name(): AutoUpdateStateName {
|
||||
return this._state;
|
||||
}
|
||||
|
||||
set name(state: AutoUpdateStateName) {
|
||||
this._state = state;
|
||||
|
||||
this.triggerIdle();
|
||||
}
|
||||
|
||||
get version(): string | undefined {
|
||||
return this._version;
|
||||
}
|
||||
|
||||
set version(version: string | undefined) {
|
||||
this._version = version;
|
||||
|
||||
this.triggerIdle();
|
||||
}
|
||||
|
||||
private triggerIdle(): void {
|
||||
clearTimeout(timerId);
|
||||
|
||||
switch (this.name) {
|
||||
case "checking":
|
||||
case "available":
|
||||
case "downloading":
|
||||
case "idle":
|
||||
break;
|
||||
|
||||
case "done":
|
||||
case "not-available":
|
||||
case "download-failed":
|
||||
case "download-succeeded":
|
||||
timerId = setTimeout(() => this.name = "idle", 5000);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const AutoUpdateStateInjectable = getInjectable({
|
||||
id: "auto-update-state",
|
||||
instantiate: () => new AutoUpdateState("idle"),
|
||||
});
|
||||
|
||||
export default AutoUpdateStateInjectable;
|
||||
Reference in new issue
Block a user