mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Introduce periodical check for updates
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
parent
eee8fb49e7
commit
ceca048b8d
@ -0,0 +1,11 @@
|
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`checking for updates automatically given updater is enabled and configuration exists, when started renders 1`] = `
|
||||||
|
<body>
|
||||||
|
<div>
|
||||||
|
<div
|
||||||
|
class="Notifications flex column align-flex-end"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
`;
|
||||||
@ -0,0 +1,117 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
import type { ApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
|
||||||
|
import { getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
|
||||||
|
import type { RenderResult } from "@testing-library/react";
|
||||||
|
import electronUpdaterIsActiveInjectable from "../../main/electron-app/features/electron-updater-is-active.injectable";
|
||||||
|
import publishIsConfiguredInjectable from "../../main/update-app/publish-is-configured.injectable";
|
||||||
|
import type { AsyncFnMock } from "@async-fn/jest";
|
||||||
|
import asyncFn from "@async-fn/jest";
|
||||||
|
import checkForUpdatesInjectable from "../../main/update-app/check-for-updates/check-for-updates.injectable";
|
||||||
|
import startCheckingForUpdatesInjectable
|
||||||
|
from "../../main/update-app/periodical-check-for-updates/start-checking-for-updates.injectable";
|
||||||
|
|
||||||
|
const ENOUGH_TIME = 1000 * 60 * 60 * 2;
|
||||||
|
|
||||||
|
describe("checking for updates automatically", () => {
|
||||||
|
let applicationBuilder: ApplicationBuilder;
|
||||||
|
let checkForUpdatesMock: AsyncFnMock<() => Promise<void>>;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
jest.useFakeTimers();
|
||||||
|
|
||||||
|
applicationBuilder = getApplicationBuilder();
|
||||||
|
|
||||||
|
applicationBuilder.beforeApplicationStart(({ mainDi }) => {
|
||||||
|
mainDi.unoverride(startCheckingForUpdatesInjectable);
|
||||||
|
|
||||||
|
checkForUpdatesMock = asyncFn();
|
||||||
|
|
||||||
|
mainDi.override(
|
||||||
|
checkForUpdatesInjectable,
|
||||||
|
() => checkForUpdatesMock,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("given updater is enabled and configuration exists, when started", () => {
|
||||||
|
let rendered: RenderResult;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
applicationBuilder.beforeApplicationStart(({ mainDi }) => {
|
||||||
|
mainDi.override(electronUpdaterIsActiveInjectable, () => true);
|
||||||
|
mainDi.override(publishIsConfiguredInjectable, () => true);
|
||||||
|
});
|
||||||
|
|
||||||
|
rendered = await applicationBuilder.render();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("renders", () => {
|
||||||
|
expect(rendered.baseElement).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("checks for updates", () => {
|
||||||
|
expect(checkForUpdatesMock).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("when just not enough time passes, does not check for updates again automatically yet", () => {
|
||||||
|
checkForUpdatesMock.mockClear();
|
||||||
|
|
||||||
|
jest.advanceTimersByTime(ENOUGH_TIME - 1);
|
||||||
|
|
||||||
|
expect(checkForUpdatesMock).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("when just enough time passes, checks for updates again automatically", () => {
|
||||||
|
checkForUpdatesMock.mockClear();
|
||||||
|
|
||||||
|
jest.advanceTimersByTime(ENOUGH_TIME);
|
||||||
|
|
||||||
|
expect(checkForUpdatesMock).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("given updater is enabled but no configuration exist, when started", () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
applicationBuilder.beforeApplicationStart(({ mainDi }) => {
|
||||||
|
mainDi.override(electronUpdaterIsActiveInjectable, () => true);
|
||||||
|
mainDi.override(publishIsConfiguredInjectable, () => false);
|
||||||
|
});
|
||||||
|
|
||||||
|
await applicationBuilder.render();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("does not check for updates", () => {
|
||||||
|
expect(checkForUpdatesMock).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("when enough time passes for checking updates again, still does not check for updates", () => {
|
||||||
|
jest.advanceTimersByTime(ENOUGH_TIME);
|
||||||
|
|
||||||
|
expect(checkForUpdatesMock).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("given updater is not enabled but and configuration exist, when started", () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
applicationBuilder.beforeApplicationStart(({ mainDi }) => {
|
||||||
|
mainDi.override(electronUpdaterIsActiveInjectable, () => false);
|
||||||
|
mainDi.override(publishIsConfiguredInjectable, () => true);
|
||||||
|
});
|
||||||
|
|
||||||
|
await applicationBuilder.render();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("does not check for updates", () => {
|
||||||
|
expect(checkForUpdatesMock).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("when enough time passes for checking updates again, still does not check for updates", () => {
|
||||||
|
jest.advanceTimersByTime(ENOUGH_TIME);
|
||||||
|
|
||||||
|
expect(checkForUpdatesMock).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -84,6 +84,8 @@ import setUpdateOnQuitInjectable from "./electron-app/features/set-update-on-qui
|
|||||||
import downloadPlatformUpdateInjectable from "./update-app/download-platform-update/download-platform-update.injectable";
|
import downloadPlatformUpdateInjectable from "./update-app/download-platform-update/download-platform-update.injectable";
|
||||||
import startCatalogSyncInjectable from "./catalog-sync-to-renderer/start-catalog-sync.injectable";
|
import startCatalogSyncInjectable from "./catalog-sync-to-renderer/start-catalog-sync.injectable";
|
||||||
import startKubeConfigSyncInjectable from "./start-main-application/runnables/kube-config-sync/start-kube-config-sync.injectable";
|
import startKubeConfigSyncInjectable from "./start-main-application/runnables/kube-config-sync/start-kube-config-sync.injectable";
|
||||||
|
import startCheckingForUpdatesInjectable
|
||||||
|
from "./update-app/periodical-check-for-updates/start-checking-for-updates.injectable";
|
||||||
|
|
||||||
export function getDiForUnitTesting(opts: GetDiForUnitTestingOptions = {}) {
|
export function getDiForUnitTesting(opts: GetDiForUnitTestingOptions = {}) {
|
||||||
const {
|
const {
|
||||||
@ -130,6 +132,8 @@ export function getDiForUnitTesting(opts: GetDiForUnitTestingOptions = {}) {
|
|||||||
|
|
||||||
di.override(applicationMenuInjectable, () => ({ start: () => {}, stop: () => {} }));
|
di.override(applicationMenuInjectable, () => ({ start: () => {}, stop: () => {} }));
|
||||||
|
|
||||||
|
di.override(startCheckingForUpdatesInjectable, () => ({ run: () => {} }));
|
||||||
|
|
||||||
// TODO: Remove usages of globally exported appEventBus to get rid of this
|
// TODO: Remove usages of globally exported appEventBus to get rid of this
|
||||||
di.override(appEventBusInjectable, () => new EventEmitter<[AppEvent]>());
|
di.override(appEventBusInjectable, () => new EventEmitter<[AppEvent]>());
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,33 @@
|
|||||||
|
/**
|
||||||
|
* 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 { getStartableStoppable } from "../../../common/utils/get-startable-stoppable";
|
||||||
|
import checkForUpdatesInjectable from "../check-for-updates/check-for-updates.injectable";
|
||||||
|
|
||||||
|
const periodicalCheckForUpdatesInjectable = getInjectable({
|
||||||
|
id: "periodical-check-for-updates",
|
||||||
|
|
||||||
|
instantiate: (di) => {
|
||||||
|
const checkForUpdates = di.inject(checkForUpdatesInjectable);
|
||||||
|
|
||||||
|
return getStartableStoppable("periodical-check-for-updates", () => {
|
||||||
|
const TWO_HOURS = 1000 * 60 * 60 * 2;
|
||||||
|
|
||||||
|
// Note: intentional orphan promise to make checking for updates happen in the background
|
||||||
|
checkForUpdates();
|
||||||
|
|
||||||
|
const intervalId = setInterval(() => {
|
||||||
|
// Note: intentional orphan promise to make checking for updates happen in the background
|
||||||
|
checkForUpdates();
|
||||||
|
}, TWO_HOURS);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
clearInterval(intervalId);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default periodicalCheckForUpdatesInjectable;
|
||||||
@ -0,0 +1,29 @@
|
|||||||
|
/**
|
||||||
|
* 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 periodicalCheckForUpdatesInjectable from "./periodical-check-for-updates.injectable";
|
||||||
|
import { afterRootFrameIsReadyInjectionToken } from "../../start-main-application/runnable-tokens/after-root-frame-is-ready-injection-token";
|
||||||
|
import updatingIsEnabledInjectable from "../updating-is-enabled.injectable";
|
||||||
|
|
||||||
|
const startCheckingForUpdatesInjectable = getInjectable({
|
||||||
|
id: "start-checking-for-updates",
|
||||||
|
|
||||||
|
instantiate: (di) => {
|
||||||
|
const periodicalCheckForUpdates = di.inject(periodicalCheckForUpdatesInjectable);
|
||||||
|
const updatingIsEnabled = di.inject(updatingIsEnabledInjectable);
|
||||||
|
|
||||||
|
return {
|
||||||
|
run: async () => {
|
||||||
|
if (updatingIsEnabled) {
|
||||||
|
await periodicalCheckForUpdates.start();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
injectionToken: afterRootFrameIsReadyInjectionToken,
|
||||||
|
});
|
||||||
|
|
||||||
|
export default startCheckingForUpdatesInjectable;
|
||||||
@ -0,0 +1,27 @@
|
|||||||
|
/**
|
||||||
|
* 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 { beforeQuitOfFrontEndInjectionToken } from "../../start-main-application/runnable-tokens/before-quit-of-front-end-injection-token";
|
||||||
|
import periodicalCheckForUpdatesInjectable from "./periodical-check-for-updates.injectable";
|
||||||
|
|
||||||
|
const stopCheckingForUpdatesInjectable = getInjectable({
|
||||||
|
id: "stop-checking-for-updates",
|
||||||
|
|
||||||
|
instantiate: (di) => {
|
||||||
|
const periodicalCheckForUpdates = di.inject(periodicalCheckForUpdatesInjectable);
|
||||||
|
|
||||||
|
return {
|
||||||
|
run: async () => {
|
||||||
|
if (periodicalCheckForUpdates.started) {
|
||||||
|
await periodicalCheckForUpdates.stop();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
injectionToken: beforeQuitOfFrontEndInjectionToken,
|
||||||
|
});
|
||||||
|
|
||||||
|
export default stopCheckingForUpdatesInjectable;
|
||||||
Loading…
Reference in New Issue
Block a user