diff --git a/src/features/application-update/analytics-for-installing-update.test.ts b/src/features/application-update/analytics-for-installing-update.test.ts index 9a4f993796..625022b040 100644 --- a/src/features/application-update/analytics-for-installing-update.test.ts +++ b/src/features/application-update/analytics-for-installing-update.test.ts @@ -19,7 +19,7 @@ import quitAndInstallUpdateInjectable from "../../main/application-update/quit-a import periodicalCheckForUpdatesInjectable from "../../main/application-update/periodical-check-for-updates/periodical-check-for-updates.injectable"; import { advanceFakeTime, useFakeTime } from "../../common/test-utils/use-fake-time"; import emitEventInjectable from "../../common/app-event-bus/emit-event.injectable"; -import buildVersionInjectable from "../../main/vars/build-version/build-version.injectable"; +import getBuildVersionInjectable from "../../main/vars/build-version/get-build-version.injectable"; describe("analytics for installing update", () => { let builder: ApplicationBuilder; @@ -36,9 +36,7 @@ describe("analytics for installing update", () => { analyticsListenerMock = jest.fn(); builder.beforeApplicationStart(mainDi => { - mainDi.override(buildVersionInjectable, () => ({ - get: () => "42.0.0", - })); + mainDi.override(getBuildVersionInjectable, () => () => "42.0.0"); checkForPlatformUpdatesMock = asyncFn(); diff --git a/src/features/application-update/downgrading-version-update.test.ts b/src/features/application-update/downgrading-version-update.test.ts index dc3cb6be1f..8f56ebd15c 100644 --- a/src/features/application-update/downgrading-version-update.test.ts +++ b/src/features/application-update/downgrading-version-update.test.ts @@ -14,7 +14,7 @@ import processCheckingForUpdatesInjectable from "../../main/application-update/c import selectedUpdateChannelInjectable from "../../common/application-update/selected-update-channel/selected-update-channel.injectable"; import type { DiContainer } from "@ogre-tools/injectable"; import { updateChannels } from "../../common/application-update/update-channels"; -import buildVersionInjectable from "../../main/vars/build-version/build-version.injectable"; +import getBuildVersionInjectable from "../../main/vars/build-version/get-build-version.injectable"; describe("downgrading version update", () => { let applicationBuilder: ApplicationBuilder; @@ -102,9 +102,7 @@ describe("downgrading version update", () => { }, ].forEach(({ appVersion, updateChannel, downgradeIsAllowed }) => { it(`given application version "${appVersion}" and update channel "${updateChannel.id}", when checking for updates, can${downgradeIsAllowed ? "": "not"} downgrade`, async () => { - mainDi.override(buildVersionInjectable, () => ({ - get: () => appVersion, - })); + mainDi.override(getBuildVersionInjectable, () => () => appVersion); await applicationBuilder.render(); diff --git a/src/features/application-update/selection-of-update-stability.test.ts b/src/features/application-update/selection-of-update-stability.test.ts index a24cf9f675..d948573dcd 100644 --- a/src/features/application-update/selection-of-update-stability.test.ts +++ b/src/features/application-update/selection-of-update-stability.test.ts @@ -22,7 +22,7 @@ import setUpdateOnQuitInjectable from "../../main/electron-app/features/set-upda import showInfoNotificationInjectable from "../../renderer/components/notifications/show-info-notification.injectable"; import processCheckingForUpdatesInjectable from "../../main/application-update/check-for-updates/process-checking-for-updates.injectable"; import type { DiContainer } from "@ogre-tools/injectable"; -import buildVersionInjectable from "../../main/vars/build-version/build-version.injectable"; +import getBuildVersionInjectable from "../../main/vars/build-version/get-build-version.injectable"; describe("selection of update stability", () => { let builder: ApplicationBuilder; @@ -231,16 +231,12 @@ describe("selection of update stability", () => { }); it("given valid update channel selection is stored, when checking for updates, checks for updates from the update channel", async () => { - builder.beforeApplicationStart((mainDi) => { - // TODO: Switch to more natural way of setting initial value - // TODO: UserStore is currently responsible for getting and setting initial value - const selectedUpdateChannel = mainDi.inject(selectedUpdateChannelInjectable); - - selectedUpdateChannel.setValue(updateChannels.beta.id); - }); - await builder.render(); + // TODO: Switch to more natural way of setting initial value + // TODO: UserStore is currently responsible for getting and setting initial value + mainDi.inject(selectedUpdateChannelInjectable).setValue(updateChannels.beta.id); + const processCheckingForUpdates = mainDi.inject(processCheckingForUpdatesInjectable); processCheckingForUpdates("irrelevant"); @@ -249,16 +245,12 @@ describe("selection of update stability", () => { }); it("given invalid update channel selection is stored, when checking for updates, checks for updates from the update channel", async () => { - builder.beforeApplicationStart((mainDi) => { - // TODO: Switch to more natural way of setting initial value - // TODO: UserStore is currently responsible for getting and setting initial value - const selectedUpdateChannel = mainDi.inject(selectedUpdateChannelInjectable); - - selectedUpdateChannel.setValue("something-invalid" as ReleaseChannel); - }); - await builder.render(); + // TODO: Switch to more natural way of setting initial value + // TODO: UserStore is currently responsible for getting and setting initial value + mainDi.inject(selectedUpdateChannelInjectable).setValue("something-invalid" as ReleaseChannel); + const processCheckingForUpdates = mainDi.inject(processCheckingForUpdatesInjectable); processCheckingForUpdates("irrelevant"); @@ -268,9 +260,7 @@ describe("selection of update stability", () => { it('given no update channel selection is stored and currently using stable release, when user checks for updates, checks for updates from "latest" update channel by default', async () => { builder.beforeApplicationStart((mainDi) => { - mainDi.override(buildVersionInjectable, () => ({ - get: () => "1.0.0", - })); + mainDi.override(getBuildVersionInjectable, () => () => "1.0.0"); }); await builder.render(); @@ -287,9 +277,7 @@ describe("selection of update stability", () => { it('given no update channel selection is stored and currently using alpha release, when checking for updates, checks for updates from "alpha" channel', async () => { builder.beforeApplicationStart((mainDi) => { - mainDi.override(buildVersionInjectable, () => ({ - get: () => "1.0.0-alpha", - })); + mainDi.override(getBuildVersionInjectable, () => () => "1.0.0-alpha"); }); await builder.render(); @@ -303,9 +291,7 @@ describe("selection of update stability", () => { it('given no update channel selection is stored and currently using beta release, when checking for updates, checks for updates from "beta" channel', async () => { builder.beforeApplicationStart((mainDi) => { - mainDi.override(buildVersionInjectable, () => ({ - get: () => "1.0.0-beta", - })); + mainDi.override(getBuildVersionInjectable, () => () => "1.0.0-beta"); }); await builder.render(); @@ -318,20 +304,12 @@ describe("selection of update stability", () => { }); it("given update channel selection is stored and currently using prerelease, when checking for updates, checks for updates from stored channel", async () => { - builder.beforeApplicationStart((mainDi) => { - mainDi.override(buildVersionInjectable, () => ({ - get: () => "1.0.0-alpha", - })); - - // TODO: Switch to more natural way of setting initial value - // TODO: UserStore is currently responsible for getting and setting initial value - const selectedUpdateChannel = mainDi.inject(selectedUpdateChannelInjectable); - - selectedUpdateChannel.setValue(updateChannels.beta.id); - }); - await builder.render(); + // TODO: Switch to more natural way of setting initial value + // TODO: UserStore is currently responsible for getting and setting initial value + mainDi.inject(selectedUpdateChannelInjectable).setValue(updateChannels.beta.id); + const processCheckingForUpdates = mainDi.inject(processCheckingForUpdatesInjectable); processCheckingForUpdates("irrelevant"); diff --git a/src/main/vars/build-version/build-version.injectable.ts b/src/main/vars/build-version/build-version.injectable.ts index edee04cd10..5e560282b9 100644 --- a/src/main/vars/build-version/build-version.injectable.ts +++ b/src/main/vars/build-version/build-version.injectable.ts @@ -4,11 +4,15 @@ */ import { createInitializableState } from "../../../common/initializable-state/create"; import { buildVersionInjectionToken } from "../../../common/vars/build-semantic-version.injectable"; -import electronAppInjectable from "../../electron-app/electron-app.injectable"; +import getBuildVersionInjectable from "./get-build-version.injectable"; const buildVersionInjectable = createInitializableState({ id: "build-version", - init: (di) => di.inject(electronAppInjectable).getVersion(), + init: (di) => { + const getBuildVersion = di.inject(getBuildVersionInjectable); + + return getBuildVersion(); + }, injectionToken: buildVersionInjectionToken, }); diff --git a/src/main/vars/build-version/get-build-version.injectable.ts b/src/main/vars/build-version/get-build-version.injectable.ts new file mode 100644 index 0000000000..ddbef55262 --- /dev/null +++ b/src/main/vars/build-version/get-build-version.injectable.ts @@ -0,0 +1,17 @@ +/** + * 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 electronAppInjectable from "../../electron-app/electron-app.injectable"; + +const getBuildVersionInjectable = getInjectable({ + id: "get-build-version", + instantiate: (di) => { + const electronApp = di.inject(electronAppInjectable); + + return () => electronApp.getVersion(); + }, +}); + +export default getBuildVersionInjectable;