mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Make update warning level completely reactive and responsibility of a renderer
Co-authored-by: Alex Andreev <alex.andreev.email@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
parent
5a8ffdf191
commit
2c39b9019f
@ -11,7 +11,6 @@ import checkForPlatformUpdatesInjectable from "../../main/application-update/che
|
|||||||
import type { DownloadPlatformUpdate } from "../../main/application-update/download-platform-update/download-platform-update.injectable";
|
import type { DownloadPlatformUpdate } from "../../main/application-update/download-platform-update/download-platform-update.injectable";
|
||||||
import downloadPlatformUpdateInjectable from "../../main/application-update/download-platform-update/download-platform-update.injectable";
|
import downloadPlatformUpdateInjectable from "../../main/application-update/download-platform-update/download-platform-update.injectable";
|
||||||
import publishIsConfiguredInjectable from "../../main/application-update/publish-is-configured.injectable";
|
import publishIsConfiguredInjectable from "../../main/application-update/publish-is-configured.injectable";
|
||||||
import periodicalCheckForUpdateWarningInjectable from "../../main/application-update/update-warning-level/periodical-check-for-update-warning.injectable";
|
|
||||||
import electronUpdaterIsActiveInjectable from "../../main/electron-app/features/electron-updater-is-active.injectable";
|
import electronUpdaterIsActiveInjectable from "../../main/electron-app/features/electron-updater-is-active.injectable";
|
||||||
import closeWindowInjectable from "../../renderer/components/layout/top-bar/close-window.injectable";
|
import closeWindowInjectable from "../../renderer/components/layout/top-bar/close-window.injectable";
|
||||||
import goBackInjectable from "../../renderer/components/layout/top-bar/go-back.injectable";
|
import goBackInjectable from "../../renderer/components/layout/top-bar/go-back.injectable";
|
||||||
@ -22,6 +21,7 @@ import toggleMaximizeWindowInjectable from "../../renderer/components/layout/top
|
|||||||
import type { ApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
|
import type { ApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
|
||||||
import { getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
|
import { getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
|
||||||
import restartAndInstallUpdateInjectable from "../../renderer/components/update-button/restart-and-install-update.injectable";
|
import restartAndInstallUpdateInjectable from "../../renderer/components/update-button/restart-and-install-update.injectable";
|
||||||
|
import processCheckingForUpdatesInjectable from "../../main/application-update/check-for-updates/process-checking-for-updates.injectable";
|
||||||
|
|
||||||
function daysToMilliseconds(days: number) {
|
function daysToMilliseconds(days: number) {
|
||||||
return Math.round(days * 24 * 60 * 60 * 1000);
|
return Math.round(days * 24 * 60 * 60 * 1000);
|
||||||
@ -53,9 +53,6 @@ describe("encourage user to update when sufficient time passed since update was
|
|||||||
mainDi.override(electronUpdaterIsActiveInjectable, () => true);
|
mainDi.override(electronUpdaterIsActiveInjectable, () => true);
|
||||||
mainDi.override(publishIsConfiguredInjectable, () => true);
|
mainDi.override(publishIsConfiguredInjectable, () => true);
|
||||||
|
|
||||||
mainDi.unoverride(periodicalCheckForUpdateWarningInjectable);
|
|
||||||
mainDi.permitSideEffects(periodicalCheckForUpdateWarningInjectable);
|
|
||||||
|
|
||||||
rendererDi.override(restartAndInstallUpdateInjectable, () => restartAndInstallUpdate = jest.fn());
|
rendererDi.override(restartAndInstallUpdateInjectable, () => restartAndInstallUpdate = jest.fn());
|
||||||
|
|
||||||
// TODO: Remove below lines when TopBar are free from side-effects
|
// TODO: Remove below lines when TopBar are free from side-effects
|
||||||
@ -96,8 +93,9 @@ describe("encourage user to update when sufficient time passed since update was
|
|||||||
let processCheckingForUpdatesPromise: Promise<void>;
|
let processCheckingForUpdatesPromise: Promise<void>;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
// TODO: initiate update check process automatically, not from tray
|
const processCheckingForUpdates = applicationBuilder.dis.mainDi.inject(processCheckingForUpdatesInjectable);
|
||||||
processCheckingForUpdatesPromise = applicationBuilder.tray.click("check-for-updates");
|
|
||||||
|
processCheckingForUpdatesPromise = processCheckingForUpdates("irrelevant");
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when update downloaded", () => {
|
describe("when update downloaded", () => {
|
||||||
|
|||||||
@ -0,0 +1,24 @@
|
|||||||
|
/**
|
||||||
|
* 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 createSyncBoxInjectable from "../../utils/sync-box/create-sync-box.injectable";
|
||||||
|
import { syncBoxInjectionToken } from "../../utils/sync-box/sync-box-injection-token";
|
||||||
|
|
||||||
|
const updateDownloadedDateTimeInjectable = getInjectable({
|
||||||
|
id: "update-downloaded-date-time",
|
||||||
|
|
||||||
|
instantiate: (di) => {
|
||||||
|
const createSyncBox = di.inject(createSyncBoxInjectable);
|
||||||
|
|
||||||
|
return createSyncBox<string | null>(
|
||||||
|
"update-downloaded-date-time",
|
||||||
|
null,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
injectionToken: syncBoxInjectionToken,
|
||||||
|
});
|
||||||
|
|
||||||
|
export default updateDownloadedDateTimeInjectable;
|
||||||
@ -9,6 +9,8 @@ import discoveredUpdateVersionInjectable from "../../../common/application-updat
|
|||||||
import { action, runInAction } from "mobx";
|
import { action, runInAction } from "mobx";
|
||||||
import type { ProgressOfDownload } from "../../../common/application-update/progress-of-update-download/progress-of-update-download.injectable";
|
import type { ProgressOfDownload } from "../../../common/application-update/progress-of-update-download/progress-of-update-download.injectable";
|
||||||
import progressOfUpdateDownloadInjectable from "../../../common/application-update/progress-of-update-download/progress-of-update-download.injectable";
|
import progressOfUpdateDownloadInjectable from "../../../common/application-update/progress-of-update-download/progress-of-update-download.injectable";
|
||||||
|
import { getCurrentDateTime } from "../../../common/utils/date/get-current-date-time";
|
||||||
|
import updateDownloadedDateTimeInjectable from "../../../common/application-update/update-downloaded-date-time/update-downloaded-date-time.injectable";
|
||||||
|
|
||||||
const downloadUpdateInjectable = getInjectable({
|
const downloadUpdateInjectable = getInjectable({
|
||||||
id: "download-update",
|
id: "download-update",
|
||||||
@ -18,6 +20,7 @@ const downloadUpdateInjectable = getInjectable({
|
|||||||
const downloadingUpdateState = di.inject(updateIsBeingDownloadedInjectable);
|
const downloadingUpdateState = di.inject(updateIsBeingDownloadedInjectable);
|
||||||
const discoveredVersionState = di.inject(discoveredUpdateVersionInjectable);
|
const discoveredVersionState = di.inject(discoveredUpdateVersionInjectable);
|
||||||
const progressOfUpdateDownload = di.inject(progressOfUpdateDownloadInjectable);
|
const progressOfUpdateDownload = di.inject(progressOfUpdateDownloadInjectable);
|
||||||
|
const updateDownloadedDate = di.inject(updateDownloadedDateTimeInjectable);
|
||||||
|
|
||||||
const updateDownloadProgress = action((progressOfDownload: ProgressOfDownload) => {
|
const updateDownloadProgress = action((progressOfDownload: ProgressOfDownload) => {
|
||||||
progressOfUpdateDownload.set(progressOfDownload);
|
progressOfUpdateDownload.set(progressOfDownload);
|
||||||
@ -38,6 +41,10 @@ const downloadUpdateInjectable = getInjectable({
|
|||||||
discoveredVersionState.set(null);
|
discoveredVersionState.set(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const currentDateTime = getCurrentDateTime();
|
||||||
|
|
||||||
|
updateDownloadedDate.set(currentDateTime);
|
||||||
|
|
||||||
downloadingUpdateState.set(false);
|
downloadingUpdateState.set(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import restartAndInstallUpdateChannel from "../../../common/application-update/update-warning-level/restart-and-install-update-channel.injectable";
|
import restartAndInstallUpdateChannel from "../../../common/application-update/restart-and-install-update-channel/restart-and-install-update-channel.injectable";
|
||||||
import { messageChannelListenerInjectionToken } from "../../../common/utils/channel/message-channel-listener-injection-token";
|
import { messageChannelListenerInjectionToken } from "../../../common/utils/channel/message-channel-listener-injection-token";
|
||||||
import quitAndInstallUpdateInjectable from "../quit-and-install-update.injectable";
|
import quitAndInstallUpdateInjectable from "../quit-and-install-update.injectable";
|
||||||
|
|
||||||
@ -1,24 +0,0 @@
|
|||||||
/**
|
|
||||||
* 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 createSyncBoxInjectable from "../../../common/utils/sync-box/create-sync-box.injectable";
|
|
||||||
import { syncBoxInjectionToken } from "../../../common/utils/sync-box/sync-box-injection-token";
|
|
||||||
|
|
||||||
const updateDownloadedDateInjectable = getInjectable({
|
|
||||||
id: "update-downloaded-date",
|
|
||||||
|
|
||||||
instantiate: (di) => {
|
|
||||||
const createSyncBox = di.inject(createSyncBoxInjectable);
|
|
||||||
|
|
||||||
return createSyncBox<Date | null>(
|
|
||||||
"update-downloaded-date",
|
|
||||||
null,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
|
|
||||||
injectionToken: syncBoxInjectionToken,
|
|
||||||
});
|
|
||||||
|
|
||||||
export default updateDownloadedDateInjectable;
|
|
||||||
@ -3,7 +3,7 @@
|
|||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import restartAndInstallUpdateChannel from "../../../common/application-update/update-warning-level/restart-and-install-update-channel.injectable";
|
import restartAndInstallUpdateChannel from "../../../common/application-update/restart-and-install-update-channel/restart-and-install-update-channel.injectable";
|
||||||
import messageToChannelInjectable from "../../utils/channel/message-to-channel.injectable";
|
import messageToChannelInjectable from "../../utils/channel/message-to-channel.injectable";
|
||||||
|
|
||||||
const restartAndInstallUpdateInjectable = getInjectable({
|
const restartAndInstallUpdateInjectable = getInjectable({
|
||||||
|
|||||||
@ -13,13 +13,11 @@ 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 { observer } from "mobx-react";
|
import { observer } from "mobx-react";
|
||||||
import updateWarningLevelInjectable from "../../../common/application-update/update-warning-level/update-warning-level.injectable";
|
|
||||||
import type { IComputedValue } from "mobx";
|
import type { IComputedValue } from "mobx";
|
||||||
import { computed } from "mobx";
|
|
||||||
import restartAndInstallUpdateInjectable from "./restart-and-install-update.injectable";
|
import restartAndInstallUpdateInjectable from "./restart-and-install-update.injectable";
|
||||||
|
import updateWarningLevelInjectable from "./update-warning-level.injectable";
|
||||||
|
|
||||||
interface UpdateButtonProps extends HTMLAttributes<HTMLButtonElement> {
|
interface UpdateButtonProps extends HTMLAttributes<HTMLButtonElement> {}
|
||||||
}
|
|
||||||
|
|
||||||
interface Dependencies {
|
interface Dependencies {
|
||||||
warningLevel: IComputedValue<"light" | "medium" | "high" | "">;
|
warningLevel: IComputedValue<"light" | "medium" | "high" | "">;
|
||||||
@ -72,14 +70,13 @@ export const NonInjectedUpdateButton = observer(({ warningLevel, update, id }: U
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
export const UpdateButton = withInjectables<Dependencies, UpdateButtonProps>(NonInjectedUpdateButton, {
|
export const UpdateButton = withInjectables<Dependencies, UpdateButtonProps>(
|
||||||
getProps: (di, props) => {
|
NonInjectedUpdateButton,
|
||||||
const warnignLevel = di.inject(updateWarningLevelInjectable);
|
{
|
||||||
|
getProps: (di, props) => ({
|
||||||
return {
|
|
||||||
...props,
|
...props,
|
||||||
warningLevel: computed(() => warnignLevel.value.get()),
|
warningLevel: di.inject(updateWarningLevelInjectable),
|
||||||
update: di.inject(restartAndInstallUpdateInjectable),
|
update: di.inject(restartAndInstallUpdateInjectable),
|
||||||
};
|
}),
|
||||||
},
|
},
|
||||||
});
|
);
|
||||||
|
|||||||
@ -0,0 +1,45 @@
|
|||||||
|
/**
|
||||||
|
* 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 { now as reactiveDateNow } from "mobx-utils";
|
||||||
|
import updateDownloadedDateTimeInjectable from "../../../common/application-update/update-downloaded-date-time/update-downloaded-date-time.injectable";
|
||||||
|
|
||||||
|
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 = reactiveDateNow(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;
|
||||||
Loading…
Reference in New Issue
Block a user