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

View File

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