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:
parent
1fd3487f3f
commit
a28d79b5a8
22
src/renderer/app-freshness/app-update-warning.injectable.ts
Normal file
22
src/renderer/app-freshness/app-update-warning.injectable.ts
Normal 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;
|
||||||
49
src/renderer/app-freshness/app-update-warning.ts
Normal file
49
src/renderer/app-freshness/app-update-warning.ts
Normal 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 "";
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user