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

AppUpdateWarning class and injectable

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev 2022-05-24 15:17:05 +03:00
parent 1fd3487f3f
commit a28d79b5a8
2 changed files with 71 additions and 0 deletions

View File

@ -0,0 +1,22 @@
/**
* 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 { AppUpdateWarning } from "./app-update-warning";
const appUpdateWarningInjectable = getInjectable({
id: "app-update-warning",
instantiate: () => {
AppUpdateWarning.resetInstance();
return AppUpdateWarning.createInstance({
releaseDate: "Wed, 04 May 2022 02:35:00 +0300",
});
},
causesSideEffects: true,
});
export default appUpdateWarningInjectable;

View File

@ -0,0 +1,49 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { computed, makeObservable, observable } from "mobx";
import type { UpdateAvailableFromMain } from "../../common/ipc";
import { ipcRendererOn, UpdateAvailableChannel } from "../../common/ipc";
import { Singleton } from "../utils";
import moment from "moment";
interface Dependencies {
releaseDate: string;
}
export class AppUpdateWarning extends Singleton {
@observable updateReleaseDate = "";
constructor(private dependencies: Dependencies) {
super();
makeObservable(this);
ipcRendererOn(UpdateAvailableChannel, (event, ...[, updateInfo]: UpdateAvailableFromMain) => {
this.updateReleaseDate = updateInfo.releaseDate;
});
}
@computed
get warningLevel(): "high" | "medium" | "light" | "" {
const update = moment(this.updateReleaseDate);
const release = moment(this.dependencies.releaseDate);
const duration = moment.duration(update.diff(release));
const days = duration.asDays();
if (days >= 27) {
return "high";
}
if (days >= 25 && days < 27) {
return "medium";
}
if (days >= 20 && days < 25) {
return "light";
}
return "";
}
}