1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/src/renderer/components/update-button/update-warning-level.injectable.ts
2022-07-01 14:15:04 +03:00

46 lines
1.3 KiB
TypeScript

/**
* 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 { computed } from "mobx";
import updateDownloadedDateTimeInjectable from "../../../common/application-update/update-downloaded-date-time/update-downloaded-date-time.injectable";
import { reactiveNow } from "../../../common/utils/reactive-now/reactive-now";
const updateWarningLevelInjectable = getInjectable({
id: "update-warning-level",
instantiate: (di) => {
const updateDownloadedDateTime = di.inject(updateDownloadedDateTimeInjectable);
return computed(() => {
const downloadedAt = updateDownloadedDateTime.value.get();
if (!downloadedAt) {
return "";
}
const ONE_DAY = 1000 * 60 * 60 * 24;
const downloadedAtTimestamp = new Date(downloadedAt).getTime();
const currentDateTimeTimestamp = reactiveNow(ONE_DAY);
const elapsedTime = currentDateTimeTimestamp - downloadedAtTimestamp;
const elapsedDays = elapsedTime / ONE_DAY;
if (elapsedDays < 20) {
return "light";
}
if (elapsedDays >= 20 && elapsedDays < 25) {
return "medium";
}
return "high";
});
},
});
export default updateWarningLevelInjectable;