mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
auto-update notifications on the status bar
Signed-off-by: Jim Ehrismann <jehrismann@mirantis.com>
This commit is contained in:
parent
aedcc472f8
commit
c2c231a585
54
src/common/auto-update/auto-update-state.injectable.ts
Normal file
54
src/common/auto-update/auto-update-state.injectable.ts
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
/**
|
||||||
|
* 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" | "idle";
|
||||||
|
|
||||||
|
export class AutoUpdateState {
|
||||||
|
@observable private _state: AutoUpdateStateName;
|
||||||
|
private timerId: NodeJS.Timeout;
|
||||||
|
|
||||||
|
constructor(state: AutoUpdateStateName = "idle") {
|
||||||
|
makeObservable(this);
|
||||||
|
|
||||||
|
this.name = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
get name() : AutoUpdateStateName {
|
||||||
|
return this._state;
|
||||||
|
}
|
||||||
|
|
||||||
|
set name(state: AutoUpdateStateName) {
|
||||||
|
this._state = state;
|
||||||
|
|
||||||
|
this.triggerIdle();
|
||||||
|
}
|
||||||
|
|
||||||
|
private triggerIdle(): void {
|
||||||
|
clearTimeout(this.timerId);
|
||||||
|
this.timerId = null;
|
||||||
|
|
||||||
|
switch(this.name) {
|
||||||
|
case "checking":
|
||||||
|
case "available":
|
||||||
|
case "downloading":
|
||||||
|
case "idle":
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "done":
|
||||||
|
case "not-available":
|
||||||
|
this.timerId = setTimeout(() => this.name = "idle", 5000);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const AutoUpdateStateInjectable = getInjectable({
|
||||||
|
id: "auto-update-state",
|
||||||
|
instantiate: () => new AutoUpdateState("idle"),
|
||||||
|
});
|
||||||
|
|
||||||
|
export default AutoUpdateStateInjectable;
|
||||||
@ -0,0 +1,59 @@
|
|||||||
|
/**
|
||||||
|
* 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 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";
|
||||||
|
|
||||||
|
interface Dependencies {
|
||||||
|
state: AutoUpdateState;
|
||||||
|
}
|
||||||
|
|
||||||
|
const checking = () => <><Spinner/><div>{"Checking for updates"}</div></>;
|
||||||
|
const available = () => <div>{"Update is available"}</div>;
|
||||||
|
|
||||||
|
const notAvailable = () => {
|
||||||
|
|
||||||
|
return <div>{"Update is currently not available"}</div>;
|
||||||
|
};
|
||||||
|
|
||||||
|
const downloading = () => <div>{"Downloading update"}</div>;
|
||||||
|
const done = () => <div>{"Done checking for updates"}</div>;
|
||||||
|
|
||||||
|
const idle = () => <></>;
|
||||||
|
|
||||||
|
export const NonInjectedAutoUpdateComponent = observer(({ state }: Dependencies) => {
|
||||||
|
|
||||||
|
switch(state.name) {
|
||||||
|
case "checking":
|
||||||
|
return checking();
|
||||||
|
|
||||||
|
case "available":
|
||||||
|
return available();
|
||||||
|
|
||||||
|
case "not-available":
|
||||||
|
return notAvailable();
|
||||||
|
|
||||||
|
case "downloading":
|
||||||
|
return downloading();
|
||||||
|
|
||||||
|
case "done":
|
||||||
|
return done();
|
||||||
|
|
||||||
|
default:
|
||||||
|
case "idle":
|
||||||
|
return idle();
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
export const AutoUpdateComponent = withInjectables<Dependencies>(NonInjectedAutoUpdateComponent, {
|
||||||
|
getProps: (di, props) => ({
|
||||||
|
state: di.inject(AutoUpdateStateInjectable),
|
||||||
|
...props,
|
||||||
|
}),
|
||||||
|
});
|
||||||
@ -11,6 +11,7 @@ import { withInjectables } from "@ogre-tools/injectable-react";
|
|||||||
import type { RegisteredStatusBarItems } from "./registered-status-bar-items.injectable";
|
import type { RegisteredStatusBarItems } from "./registered-status-bar-items.injectable";
|
||||||
import registeredStatusBarItemsInjectable from "./registered-status-bar-items.injectable";
|
import registeredStatusBarItemsInjectable from "./registered-status-bar-items.injectable";
|
||||||
import type { IComputedValue } from "mobx";
|
import type { IComputedValue } from "mobx";
|
||||||
|
import { AutoUpdateComponent } from "./auto-update-status-bar-item";
|
||||||
|
|
||||||
export interface StatusBarProps {}
|
export interface StatusBarProps {}
|
||||||
|
|
||||||
@ -19,7 +20,9 @@ interface Dependencies {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const NonInjectedStatusBar = observer(({ items }: Dependencies & StatusBarProps) => {
|
const NonInjectedStatusBar = observer(({ items }: Dependencies & StatusBarProps) => {
|
||||||
const { left, right } = items.get();
|
const { left: leftItems, right } = items.get();
|
||||||
|
|
||||||
|
const left = [AutoUpdateComponent, ...leftItems];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.StatusBar}>
|
<div className={styles.StatusBar}>
|
||||||
|
|||||||
@ -5,12 +5,14 @@
|
|||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import { registerIpcListeners } from "./register-listeners";
|
import { registerIpcListeners } from "./register-listeners";
|
||||||
import listNamespacesForbiddenHandlerInjectable from "./list-namespaces-forbidden-handler.injectable";
|
import listNamespacesForbiddenHandlerInjectable from "./list-namespaces-forbidden-handler.injectable";
|
||||||
|
import AutoUpdateStateInjectable from "../../common/auto-update/auto-update-state.injectable";
|
||||||
|
|
||||||
const registerIpcListenersInjectable = getInjectable({
|
const registerIpcListenersInjectable = getInjectable({
|
||||||
id: "register-ipc-listeners",
|
id: "register-ipc-listeners",
|
||||||
|
|
||||||
instantiate: (di) => registerIpcListeners({
|
instantiate: (di) => registerIpcListeners({
|
||||||
listNamespacesForbiddenHandler: di.inject(listNamespacesForbiddenHandlerInjectable),
|
listNamespacesForbiddenHandler: di.inject(listNamespacesForbiddenHandlerInjectable),
|
||||||
|
updateState: di.inject(AutoUpdateStateInjectable),
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user