1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Add setter for downloadedUpdateDate

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev 2022-05-25 14:41:14 +03:00
parent d7824f4a89
commit b5c5e4f8f7
2 changed files with 20 additions and 7 deletions

View File

@ -4,12 +4,14 @@
*/
import { computed, makeObservable, observable } from "mobx";
import type { UpdateAvailableFromMain } from "../../common/ipc";
import { ipcRendererOn, UpdateAvailableChannel } from "../../common/ipc";
import { UpdateAvailableChannel } from "../../common/ipc";
import { Singleton } from "../utils";
import moment from "moment";
import type { IpcRenderer } from "electron";
interface Dependencies {
releaseDate: string;
readonly releaseDate: string;
readonly ipcRenderer: IpcRenderer;
}
export class AppUpdateWarning extends Singleton {
@ -19,15 +21,26 @@ export class AppUpdateWarning extends Singleton {
super();
makeObservable(this);
ipcRendererOn(UpdateAvailableChannel, (event, ...[, updateInfo]: UpdateAvailableFromMain) => {
this.updateReleaseDate = updateInfo.releaseDate;
dependencies.ipcRenderer.on(UpdateAvailableChannel, (event, ...[, updateInfo]: UpdateAvailableFromMain) => {
this.downloadedUpdateDate = updateInfo?.releaseDate;
});
}
set downloadedUpdateDate(date: string) {
this.updateReleaseDate = date;
}
@computed
get warningLevel(): "high" | "medium" | "light" | "" {
const update = moment(this.updateReleaseDate);
const release = moment(this.dependencies.releaseDate);
const { updateReleaseDate, dependencies } = this;
const { releaseDate } = dependencies;
if (!updateReleaseDate || !releaseDate) {
return "";
}
const update = moment(updateReleaseDate);
const release = moment(releaseDate);
const duration = moment.duration(update.diff(release));
const days = duration.asDays();

View File

@ -12,7 +12,7 @@ import { cssNames } from "../../utils";
import type { IconProps } from "../icon";
import { Icon } from "../icon";
import { withInjectables } from "@ogre-tools/injectable-react";
import appUpdateWarningInjectable from "../../app-freshness/app-update-warning.injectable";
import appUpdateWarningInjectable from "../../app-update-warning/app-update-warning.injectable";
interface UpdateButtonProps extends HTMLAttributes<HTMLButtonElement> {
update: () => void;