mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Complete local transition to InitializableState
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
54f4c51791
commit
c6d1e77237
@ -2,13 +2,13 @@
|
|||||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
* 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 { createInitializableState } from "../../initializable-state/create";
|
||||||
import releaseChannelInjectable from "../../vars/release-channel.injectable";
|
import releaseChannelInjectable from "../../vars/release-channel.injectable";
|
||||||
import { updateChannels } from "../update-channels";
|
import { updateChannels } from "../update-channels";
|
||||||
|
|
||||||
const defaultUpdateChannelInjectable = getInjectable({
|
const defaultUpdateChannelInjectable = createInitializableState({
|
||||||
id: "default-update-channel",
|
id: "default-update-channel",
|
||||||
instantiate: (di) => updateChannels[di.inject(releaseChannelInjectable)],
|
init: (di) => updateChannels[di.inject(releaseChannelInjectable)],
|
||||||
});
|
});
|
||||||
|
|
||||||
export default defaultUpdateChannelInjectable;
|
export default defaultUpdateChannelInjectable;
|
||||||
|
|||||||
@ -19,16 +19,16 @@ const selectedUpdateChannelInjectable = getInjectable({
|
|||||||
|
|
||||||
instantiate: (di): SelectedUpdateChannel => {
|
instantiate: (di): SelectedUpdateChannel => {
|
||||||
const defaultUpdateChannel = di.inject(defaultUpdateChannelInjectable);
|
const defaultUpdateChannel = di.inject(defaultUpdateChannelInjectable);
|
||||||
const state = observable.box(defaultUpdateChannel);
|
const state = observable.box<UpdateChannel>();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
value: computed(() => state.get()),
|
value: computed(() => state.get() ?? defaultUpdateChannel.get()),
|
||||||
|
|
||||||
setValue: action((channelId) => {
|
setValue: action((channelId) => {
|
||||||
const targetUpdateChannel =
|
const targetUpdateChannel =
|
||||||
channelId && updateChannels[channelId]
|
channelId && updateChannels[channelId]
|
||||||
? updateChannels[channelId]
|
? updateChannels[channelId]
|
||||||
: defaultUpdateChannel;
|
: defaultUpdateChannel.get();
|
||||||
|
|
||||||
state.set(targetUpdateChannel);
|
state.set(targetUpdateChannel);
|
||||||
}),
|
}),
|
||||||
|
|||||||
@ -3,18 +3,24 @@
|
|||||||
* 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 type { DiContainerForInjection } from "@ogre-tools/injectable";
|
import type { DiContainerForInjection, Injectable, InjectionToken } from "@ogre-tools/injectable";
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
|
|
||||||
export interface CreateInitializableStateArgs<T> {
|
export interface CreateInitializableStateArgs<T> {
|
||||||
id: string;
|
id: string;
|
||||||
init: (di: DiContainerForInjection) => Promise<T>;
|
init: (di: DiContainerForInjection) => Promise<T> | T;
|
||||||
|
injectionToken?: InjectionToken<InitializableState<T>, void>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface InitializableState<T> {
|
||||||
|
get: () => T;
|
||||||
|
init: () => Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
type InitializableStateValue<T> = { set: false } | { set: true; value: T };
|
type InitializableStateValue<T> = { set: false } | { set: true; value: T };
|
||||||
|
|
||||||
export function createInitializableState<T>(args: CreateInitializableStateArgs<T>) {
|
export function createInitializableState<T>(args: CreateInitializableStateArgs<T>): Injectable<InitializableState<T>, unknown, void> {
|
||||||
const { id, init } = args;
|
const { id, init, injectionToken } = args;
|
||||||
|
|
||||||
return getInjectable({
|
return getInjectable({
|
||||||
id,
|
id,
|
||||||
@ -49,5 +55,6 @@ export function createInitializableState<T>(args: CreateInitializableStateArgs<T
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
injectionToken,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,11 +3,13 @@
|
|||||||
* 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 { getInjectionToken, getInjectable } from "@ogre-tools/injectable";
|
import { getInjectionToken } from "@ogre-tools/injectable";
|
||||||
import { SemVer } from "semver";
|
import { SemVer } from "semver";
|
||||||
|
import type { InitializableState } from "../initializable-state/create";
|
||||||
|
import { createInitializableState } from "../initializable-state/create";
|
||||||
import type { RequestChannel } from "../utils/channel/request-channel-injection-token";
|
import type { RequestChannel } from "../utils/channel/request-channel-injection-token";
|
||||||
|
|
||||||
export const buildVersionInjectionToken = getInjectionToken<string>({
|
export const buildVersionInjectionToken = getInjectionToken<InitializableState<string>>({
|
||||||
id: "build-version-token",
|
id: "build-version-token",
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -15,9 +17,13 @@ export const buildVersionChannel: RequestChannel<void, string> = {
|
|||||||
id: "build-version",
|
id: "build-version",
|
||||||
};
|
};
|
||||||
|
|
||||||
const buildSemanticVersionInjectable = getInjectable({
|
const buildSemanticVersionInjectable = createInitializableState({
|
||||||
id: "build-semantic-version",
|
id: "build-semantic-version",
|
||||||
instantiate: (di) => new SemVer(di.inject(buildVersionInjectionToken)),
|
init: (di) => {
|
||||||
|
const buildVersion = di.inject(buildVersionInjectionToken);
|
||||||
|
|
||||||
|
return new SemVer(buildVersion.get());
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export default buildSemanticVersionInjectable;
|
export default buildSemanticVersionInjectable;
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
import { App } from "./app";
|
import { App } from "./app";
|
||||||
import * as EventBus from "./event-bus";
|
import * as EventBus from "./event-bus";
|
||||||
import * as Store from "./stores";
|
import * as Store from "./stores";
|
||||||
import * as Util from "./utils";
|
import { Util } from "./utils";
|
||||||
import * as Catalog from "./catalog";
|
import * as Catalog from "./catalog";
|
||||||
import * as Types from "./types";
|
import * as Types from "./types";
|
||||||
import * as Proxy from "./proxy";
|
import * as Proxy from "./proxy";
|
||||||
|
|||||||
@ -4,25 +4,34 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import openLinkInBrowserInjectable from "../../common/utils/open-link-in-browser.injectable";
|
import openLinkInBrowserInjectable from "../../common/utils/open-link-in-browser.injectable";
|
||||||
import buildVersionInjectable from "../../main/vars/build-version.injectable";
|
import buildVersionInjectable from "../../main/vars/build-version/build-version.injectable";
|
||||||
import { asLegacyGlobalFunctionForExtensionApi } from "../as-legacy-globals-for-extension-api/as-legacy-global-function-for-extension-api";
|
import { asLegacyGlobalFunctionForExtensionApi } from "../as-legacy-globals-for-extension-api/as-legacy-global-function-for-extension-api";
|
||||||
import { getLegacyGlobalDiForExtensionApi } from "../as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
import { getLegacyGlobalDiForExtensionApi } from "../as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||||
|
import { Singleton } from "../../common/utils";
|
||||||
|
import { prevDefault, stopPropagation } from "../../renderer/utils/prevDefault";
|
||||||
|
import type { IClassName } from "../../renderer/utils/cssNames";
|
||||||
|
import { cssNames } from "../../renderer/utils/cssNames";
|
||||||
|
|
||||||
export { Singleton } from "../../common/utils";
|
export interface UtilsExtensionItems {
|
||||||
export { prevDefault, stopPropagation } from "../../renderer/utils/prevDefault";
|
Singleton: Singleton;
|
||||||
export { cssNames } from "../../renderer/utils/cssNames";
|
prevDefault: <E extends React.SyntheticEvent | Event, R>(callback: (evt: E) => R) => (evt: E) => R;
|
||||||
|
stopPropagation: (evt: Event | React.SyntheticEvent) => void;
|
||||||
/**
|
cssNames: (...classNames: IClassName[]) => string;
|
||||||
* @deprecated Use {@link openBrowser} instead
|
openExternal: (url: string) => Promise<void>;
|
||||||
*/
|
openBrowser: (url: string) => Promise<void>;
|
||||||
export const openExternal = asLegacyGlobalFunctionForExtensionApi(openLinkInBrowserInjectable);
|
getAppVersion: () => string;
|
||||||
export const openBrowser = asLegacyGlobalFunctionForExtensionApi(openLinkInBrowserInjectable);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated use `Common.App.version` instead
|
|
||||||
*/
|
|
||||||
export function getAppVersion() {
|
|
||||||
const di = getLegacyGlobalDiForExtensionApi();
|
|
||||||
|
|
||||||
return di.inject(buildVersionInjectable);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const Util: UtilsExtensionItems = {
|
||||||
|
Singleton,
|
||||||
|
prevDefault,
|
||||||
|
stopPropagation,
|
||||||
|
cssNames,
|
||||||
|
openExternal: asLegacyGlobalFunctionForExtensionApi(openLinkInBrowserInjectable),
|
||||||
|
openBrowser: asLegacyGlobalFunctionForExtensionApi(openLinkInBrowserInjectable),
|
||||||
|
getAppVersion: () => {
|
||||||
|
const di = getLegacyGlobalDiForExtensionApi();
|
||||||
|
|
||||||
|
return di.inject(buildVersionInjectable).get();
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|||||||
@ -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 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 { advanceFakeTime, useFakeTime } from "../../common/test-utils/use-fake-time";
|
||||||
import emitEventInjectable from "../../common/app-event-bus/emit-event.injectable";
|
import emitEventInjectable from "../../common/app-event-bus/emit-event.injectable";
|
||||||
import buildVersionInjectable from "../../main/vars/build-version.injectable";
|
import buildVersionInjectable from "../../main/vars/build-version/build-version.injectable";
|
||||||
|
|
||||||
describe("analytics for installing update", () => {
|
describe("analytics for installing update", () => {
|
||||||
let builder: ApplicationBuilder;
|
let builder: ApplicationBuilder;
|
||||||
@ -36,7 +36,9 @@ describe("analytics for installing update", () => {
|
|||||||
analyticsListenerMock = jest.fn();
|
analyticsListenerMock = jest.fn();
|
||||||
|
|
||||||
builder.beforeApplicationStart(mainDi => {
|
builder.beforeApplicationStart(mainDi => {
|
||||||
mainDi.override(buildVersionInjectable, () => "42.0.0");
|
mainDi.override(buildVersionInjectable, () => ({
|
||||||
|
get: () => "42.0.0",
|
||||||
|
}));
|
||||||
|
|
||||||
checkForPlatformUpdatesMock = asyncFn();
|
checkForPlatformUpdatesMock = asyncFn();
|
||||||
|
|
||||||
|
|||||||
@ -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 selectedUpdateChannelInjectable from "../../common/application-update/selected-update-channel/selected-update-channel.injectable";
|
||||||
import type { DiContainer } from "@ogre-tools/injectable";
|
import type { DiContainer } from "@ogre-tools/injectable";
|
||||||
import { updateChannels } from "../../common/application-update/update-channels";
|
import { updateChannels } from "../../common/application-update/update-channels";
|
||||||
import buildVersionInjectable from "../../main/vars/build-version.injectable";
|
import buildVersionInjectable from "../../main/vars/build-version/build-version.injectable";
|
||||||
|
|
||||||
describe("downgrading version update", () => {
|
describe("downgrading version update", () => {
|
||||||
let applicationBuilder: ApplicationBuilder;
|
let applicationBuilder: ApplicationBuilder;
|
||||||
@ -102,7 +102,9 @@ describe("downgrading version update", () => {
|
|||||||
},
|
},
|
||||||
].forEach(({ appVersion, updateChannel, downgradeIsAllowed }) => {
|
].forEach(({ appVersion, updateChannel, downgradeIsAllowed }) => {
|
||||||
it(`given application version "${appVersion}" and update channel "${updateChannel.id}", when checking for updates, can${downgradeIsAllowed ? "": "not"} downgrade`, async () => {
|
it(`given application version "${appVersion}" and update channel "${updateChannel.id}", when checking for updates, can${downgradeIsAllowed ? "": "not"} downgrade`, async () => {
|
||||||
mainDi.override(buildVersionInjectable, () => appVersion);
|
mainDi.override(buildVersionInjectable, () => ({
|
||||||
|
get: () => appVersion,
|
||||||
|
}));
|
||||||
|
|
||||||
await applicationBuilder.render();
|
await applicationBuilder.render();
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@ import setUpdateOnQuitInjectable from "../../main/electron-app/features/set-upda
|
|||||||
import showInfoNotificationInjectable from "../../renderer/components/notifications/show-info-notification.injectable";
|
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 processCheckingForUpdatesInjectable from "../../main/application-update/check-for-updates/process-checking-for-updates.injectable";
|
||||||
import type { DiContainer } from "@ogre-tools/injectable";
|
import type { DiContainer } from "@ogre-tools/injectable";
|
||||||
import buildVersionInjectable from "../../main/vars/build-version.injectable";
|
import buildVersionInjectable from "../../main/vars/build-version/build-version.injectable";
|
||||||
|
|
||||||
describe("selection of update stability", () => {
|
describe("selection of update stability", () => {
|
||||||
let builder: ApplicationBuilder;
|
let builder: ApplicationBuilder;
|
||||||
@ -268,7 +268,9 @@ 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 () => {
|
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) => {
|
builder.beforeApplicationStart((mainDi) => {
|
||||||
mainDi.override(buildVersionInjectable, () => "1.0.0");
|
mainDi.override(buildVersionInjectable, () => ({
|
||||||
|
get: () => "1.0.0",
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
await builder.render();
|
await builder.render();
|
||||||
@ -285,7 +287,9 @@ 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 () => {
|
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) => {
|
builder.beforeApplicationStart((mainDi) => {
|
||||||
mainDi.override(buildVersionInjectable, () => "1.0.0-alpha");
|
mainDi.override(buildVersionInjectable, () => ({
|
||||||
|
get: () => "1.0.0-alpha",
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
await builder.render();
|
await builder.render();
|
||||||
@ -299,7 +303,9 @@ 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 () => {
|
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) => {
|
builder.beforeApplicationStart((mainDi) => {
|
||||||
mainDi.override(buildVersionInjectable, () => "1.0.0-beta");
|
mainDi.override(buildVersionInjectable, () => ({
|
||||||
|
get: () => "1.0.0-beta",
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
await builder.render();
|
await builder.render();
|
||||||
@ -313,7 +319,9 @@ 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 () => {
|
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) => {
|
builder.beforeApplicationStart((mainDi) => {
|
||||||
mainDi.override(buildVersionInjectable, () => "1.0.0-alpha");
|
mainDi.override(buildVersionInjectable, () => ({
|
||||||
|
get: () => "1.0.0-alpha",
|
||||||
|
}));
|
||||||
|
|
||||||
// TODO: Switch to more natural way of setting initial value
|
// TODO: Switch to more natural way of setting initial value
|
||||||
// TODO: UserStore is currently responsible for getting and setting initial value
|
// TODO: UserStore is currently responsible for getting and setting initial value
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import { getInjectable } from "@ogre-tools/injectable";
|
|||||||
import { afterApplicationIsLoadedInjectionToken } from "../start-main-application/runnable-tokens/after-application-is-loaded-injection-token";
|
import { afterApplicationIsLoadedInjectionToken } from "../start-main-application/runnable-tokens/after-application-is-loaded-injection-token";
|
||||||
import emitEventInjectable from "../../common/app-event-bus/emit-event.injectable";
|
import emitEventInjectable from "../../common/app-event-bus/emit-event.injectable";
|
||||||
import { getCurrentDateTime } from "../../common/utils/date/get-current-date-time";
|
import { getCurrentDateTime } from "../../common/utils/date/get-current-date-time";
|
||||||
import buildVersionInjectable from "../vars/build-version.injectable";
|
import buildVersionInjectable from "../vars/build-version/build-version.injectable";
|
||||||
|
|
||||||
const emitCurrentVersionToAnalyticsInjectable = getInjectable({
|
const emitCurrentVersionToAnalyticsInjectable = getInjectable({
|
||||||
id: "emit-current-version-to-analytics",
|
id: "emit-current-version-to-analytics",
|
||||||
@ -22,7 +22,7 @@ const emitCurrentVersionToAnalyticsInjectable = getInjectable({
|
|||||||
action: "current-version",
|
action: "current-version",
|
||||||
|
|
||||||
params: {
|
params: {
|
||||||
version: buildVersion,
|
version: buildVersion.get(),
|
||||||
currentDateTime: getCurrentDateTime(),
|
currentDateTime: getCurrentDateTime(),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@ -5,14 +5,16 @@
|
|||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import { requestChannelListenerInjectionToken } from "../../common/utils/channel/request-channel-listener-injection-token";
|
import { requestChannelListenerInjectionToken } from "../../common/utils/channel/request-channel-listener-injection-token";
|
||||||
import { buildVersionChannel } from "../../common/vars/build-semantic-version.injectable";
|
import { buildVersionChannel } from "../../common/vars/build-semantic-version.injectable";
|
||||||
import buildVersionInjectable from "../vars/build-version.injectable";
|
import buildVersionInjectable from "../vars/build-version/build-version.injectable";
|
||||||
|
|
||||||
const setupBuildVersionRequestChannelInjectable = getInjectable({
|
const setupBuildVersionRequestChannelInjectable = getInjectable({
|
||||||
id: "setup-build-version-request-channel",
|
id: "setup-build-version-request-channel",
|
||||||
instantiate: (di) => {
|
instantiate: (di) => {
|
||||||
|
const buildVersion = di.inject(buildVersionInjectable);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
channel: buildVersionChannel,
|
channel: buildVersionChannel,
|
||||||
handler: () => di.inject(buildVersionInjectable),
|
handler: () => buildVersion.get(),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
injectionToken: requestChannelListenerInjectionToken,
|
injectionToken: requestChannelListenerInjectionToken,
|
||||||
|
|||||||
@ -4,6 +4,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { getGlobalOverride } from "../../common/test-utils/get-global-override";
|
import { getGlobalOverride } from "../../common/test-utils/get-global-override";
|
||||||
import buildVersionInjectable from "./build-version.injectable";
|
import electronAppInjectable from "./electron-app.injectable";
|
||||||
|
|
||||||
export default getGlobalOverride(buildVersionInjectable, () => "6.0.0");
|
export default getGlobalOverride(electronAppInjectable, () => ({
|
||||||
|
getVersion: () => "6.0.0",
|
||||||
|
} as Electron.App));
|
||||||
@ -7,7 +7,7 @@ import showMessagePopupInjectable from "../electron-app/features/show-message-po
|
|||||||
import isWindowsInjectable from "../../common/vars/is-windows.injectable";
|
import isWindowsInjectable from "../../common/vars/is-windows.injectable";
|
||||||
import appNameInjectable from "../../common/vars/app-name.injectable";
|
import appNameInjectable from "../../common/vars/app-name.injectable";
|
||||||
import productNameInjectable from "../../common/vars/product-name.injectable";
|
import productNameInjectable from "../../common/vars/product-name.injectable";
|
||||||
import buildVersionInjectable from "../vars/build-version.injectable";
|
import buildVersionInjectable from "../vars/build-version/build-version.injectable";
|
||||||
import extensionApiVersionInjectable from "../../common/vars/extension-api-version.injectable";
|
import extensionApiVersionInjectable from "../../common/vars/extension-api-version.injectable";
|
||||||
import applicationCopyrightInjectable from "../../common/vars/application-copyright.injectable";
|
import applicationCopyrightInjectable from "../../common/vars/application-copyright.injectable";
|
||||||
|
|
||||||
@ -15,7 +15,7 @@ const showAboutInjectable = getInjectable({
|
|||||||
id: "show-about",
|
id: "show-about",
|
||||||
|
|
||||||
instantiate: (di) => {
|
instantiate: (di) => {
|
||||||
const appVersion = di.inject(buildVersionInjectable);
|
const buildVersion = di.inject(buildVersionInjectable);
|
||||||
const extensionApiVersion = di.inject(extensionApiVersionInjectable);
|
const extensionApiVersion = di.inject(extensionApiVersionInjectable);
|
||||||
const showMessagePopup = di.inject(showMessagePopupInjectable);
|
const showMessagePopup = di.inject(showMessagePopupInjectable);
|
||||||
const isWindows = di.inject(isWindowsInjectable);
|
const isWindows = di.inject(isWindowsInjectable);
|
||||||
@ -25,7 +25,7 @@ const showAboutInjectable = getInjectable({
|
|||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
const appInfo = [
|
const appInfo = [
|
||||||
`${appName}: ${appVersion}`,
|
`${appName}: ${buildVersion.get()}`,
|
||||||
`Extension API: ${extensionApiVersion}`,
|
`Extension API: ${extensionApiVersion}`,
|
||||||
`Electron: ${process.versions.electron}`,
|
`Electron: ${process.versions.electron}`,
|
||||||
`Chrome: ${process.versions.chrome}`,
|
`Chrome: ${process.versions.chrome}`,
|
||||||
|
|||||||
@ -4,19 +4,23 @@
|
|||||||
*/
|
*/
|
||||||
import { getRouteInjectable } from "../../router/router.injectable";
|
import { getRouteInjectable } from "../../router/router.injectable";
|
||||||
import { route } from "../../router/route";
|
import { route } from "../../router/route";
|
||||||
import buildVersionInjectable from "../../vars/build-version.injectable";
|
import buildVersionInjectable from "../../vars/build-version/build-version.injectable";
|
||||||
|
|
||||||
const getVersionRouteInjectable = getRouteInjectable({
|
const getVersionRouteInjectable = getRouteInjectable({
|
||||||
id: "get-version-route",
|
id: "get-version-route",
|
||||||
|
|
||||||
instantiate: (di) => route({
|
instantiate: (di) => {
|
||||||
method: "get",
|
const buildVersion = di.inject(buildVersionInjectable);
|
||||||
path: `/version`,
|
|
||||||
})(() => ({
|
return route({
|
||||||
response: {
|
method: "get",
|
||||||
version: di.inject(buildVersionInjectable),
|
path: `/version`,
|
||||||
},
|
})(() => ({
|
||||||
})),
|
response: {
|
||||||
|
version: buildVersion.get(),
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export default getVersionRouteInjectable;
|
export default getVersionRouteInjectable;
|
||||||
|
|||||||
@ -11,7 +11,7 @@ import lensProxyPortInjectable from "../../lens-proxy/lens-proxy-port.injectable
|
|||||||
import isWindowsInjectable from "../../../common/vars/is-windows.injectable";
|
import isWindowsInjectable from "../../../common/vars/is-windows.injectable";
|
||||||
import showErrorPopupInjectable from "../../electron-app/features/show-error-popup.injectable";
|
import showErrorPopupInjectable from "../../electron-app/features/show-error-popup.injectable";
|
||||||
import { beforeApplicationIsLoadingInjectionToken } from "../runnable-tokens/before-application-is-loading-injection-token";
|
import { beforeApplicationIsLoadingInjectionToken } from "../runnable-tokens/before-application-is-loading-injection-token";
|
||||||
import buildVersionInjectable from "../../vars/build-version.injectable";
|
import buildVersionInjectable from "../../vars/build-version/build-version.injectable";
|
||||||
|
|
||||||
const setupLensProxyInjectable = getInjectable({
|
const setupLensProxyInjectable = getInjectable({
|
||||||
id: "setup-lens-proxy",
|
id: "setup-lens-proxy",
|
||||||
@ -43,7 +43,7 @@ const setupLensProxyInjectable = getInjectable({
|
|||||||
lensProxyPort.get(),
|
lensProxyPort.get(),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (buildVersion !== versionFromProxy) {
|
if (buildVersion.get() !== versionFromProxy) {
|
||||||
logger.error("Proxy server responded with invalid response");
|
logger.error("Proxy server responded with invalid response");
|
||||||
|
|
||||||
return exitApp();
|
return exitApp();
|
||||||
|
|||||||
@ -1,15 +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 { buildVersionInjectionToken } from "../../common/vars/build-semantic-version.injectable";
|
|
||||||
import electronAppInjectable from "../electron-app/electron-app.injectable";
|
|
||||||
|
|
||||||
const buildVersionInjectable = getInjectable({
|
|
||||||
id: "build-version",
|
|
||||||
instantiate: (di) => di.inject(electronAppInjectable).getVersion(),
|
|
||||||
injectionToken: buildVersionInjectionToken,
|
|
||||||
});
|
|
||||||
|
|
||||||
export default buildVersionInjectable;
|
|
||||||
15
src/main/vars/build-version/build-version.injectable.ts
Normal file
15
src/main/vars/build-version/build-version.injectable.ts
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
import { createInitializableState } from "../../../common/initializable-state/create";
|
||||||
|
import { buildVersionInjectionToken } from "../../../common/vars/build-semantic-version.injectable";
|
||||||
|
import electronAppInjectable from "../../electron-app/electron-app.injectable";
|
||||||
|
|
||||||
|
const buildVersionInjectable = createInitializableState({
|
||||||
|
id: "build-version",
|
||||||
|
init: (di) => di.inject(electronAppInjectable).getVersion(),
|
||||||
|
injectionToken: buildVersionInjectionToken,
|
||||||
|
});
|
||||||
|
|
||||||
|
export default buildVersionInjectable;
|
||||||
21
src/main/vars/build-version/init.injectable.ts
Normal file
21
src/main/vars/build-version/init.injectable.ts
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
/**
|
||||||
|
* 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 { beforeApplicationIsLoadingInjectionToken } from "../../start-main-application/runnable-tokens/before-application-is-loading-injection-token";
|
||||||
|
import buildVersionInjectable from "./build-version.injectable";
|
||||||
|
|
||||||
|
const initializeBuildVersionAsyncSyncBoxInjectable = getInjectable({
|
||||||
|
id: "initialize-build-version-async-sync-box",
|
||||||
|
instantiate: (di) => {
|
||||||
|
const buildVersion = di.inject(buildVersionInjectable);
|
||||||
|
|
||||||
|
return {
|
||||||
|
run: () => buildVersion.init(),
|
||||||
|
};
|
||||||
|
},
|
||||||
|
injectionToken: beforeApplicationIsLoadingInjectionToken,
|
||||||
|
});
|
||||||
|
|
||||||
|
export default initializeBuildVersionAsyncSyncBoxInjectable;
|
||||||
23
src/main/vars/default-update-channel/init.injectable.ts
Normal file
23
src/main/vars/default-update-channel/init.injectable.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
/**
|
||||||
|
* 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 defaultUpdateChannelInjectable from "../../../common/application-update/selected-update-channel/default-update-channel.injectable";
|
||||||
|
import initSemanticBuildVersionInjectable from "../../../renderer/vars/semantic-build-version/init.injectable";
|
||||||
|
import { beforeApplicationIsLoadingInjectionToken } from "../../start-main-application/runnable-tokens/before-application-is-loading-injection-token";
|
||||||
|
|
||||||
|
const initDefaultUpdateChannelInjectableInjectable = getInjectable({
|
||||||
|
id: "init-default-update-channel-injectable",
|
||||||
|
instantiate: (di) => {
|
||||||
|
const defaultUpdateChannel = di.inject(defaultUpdateChannelInjectable);
|
||||||
|
|
||||||
|
return {
|
||||||
|
run: () => defaultUpdateChannel.init(),
|
||||||
|
runAfter: di.inject(initSemanticBuildVersionInjectable),
|
||||||
|
};
|
||||||
|
},
|
||||||
|
injectionToken: beforeApplicationIsLoadingInjectionToken,
|
||||||
|
});
|
||||||
|
|
||||||
|
export default initDefaultUpdateChannelInjectableInjectable;
|
||||||
23
src/main/vars/semantic-build-version/init.injectable.ts
Normal file
23
src/main/vars/semantic-build-version/init.injectable.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
/**
|
||||||
|
* 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 buildSemanticVersionInjectable from "../../../common/vars/build-semantic-version.injectable";
|
||||||
|
import { beforeApplicationIsLoadingInjectionToken } from "../../start-main-application/runnable-tokens/before-application-is-loading-injection-token";
|
||||||
|
import initializeBuildVersionInjectable from "../build-version/init.injectable";
|
||||||
|
|
||||||
|
const initSemanticBuildVersionInjectable = getInjectable({
|
||||||
|
id: "init-semantic-build-version",
|
||||||
|
instantiate: (di) => {
|
||||||
|
const buildSemanticVersion = di.inject(buildSemanticVersionInjectable);
|
||||||
|
|
||||||
|
return {
|
||||||
|
run: () => buildSemanticVersion.init(),
|
||||||
|
runAfter: di.inject(initializeBuildVersionInjectable),
|
||||||
|
};
|
||||||
|
},
|
||||||
|
injectionToken: beforeApplicationIsLoadingInjectionToken,
|
||||||
|
});
|
||||||
|
|
||||||
|
export default initSemanticBuildVersionInjectable;
|
||||||
@ -17,7 +17,7 @@ import type React from "react";
|
|||||||
// <Icon onClick={prevDefault(() => console.log('stay on the page and open dialog'))}/>
|
// <Icon onClick={prevDefault(() => console.log('stay on the page and open dialog'))}/>
|
||||||
// </a>
|
// </a>
|
||||||
|
|
||||||
export function prevDefault<E extends React.SyntheticEvent | Event>(callback: (evt: E) => any) {
|
export function prevDefault<E extends React.SyntheticEvent | Event, R>(callback: (evt: E) => R): (event: E) => R {
|
||||||
return function (evt: E) {
|
return function (evt: E) {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
evt.stopPropagation();
|
evt.stopPropagation();
|
||||||
|
|||||||
@ -2,16 +2,16 @@
|
|||||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
* 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 { createInitializableState } from "../../../common/initializable-state/create";
|
||||||
import { buildVersionInjectionToken } from "../../../common/vars/build-semantic-version.injectable";
|
import { requestFromChannelInjectionToken } from "../../../common/utils/channel/request-from-channel-injection-token";
|
||||||
import buildVersionAsyncSyncBoxInjectable from "./state.injectable";
|
import { buildVersionChannel, buildVersionInjectionToken } from "../../../common/vars/build-semantic-version.injectable";
|
||||||
|
|
||||||
const buildVersionInjectable = getInjectable({
|
const buildVersionInjectable = createInitializableState({
|
||||||
id: "build-version",
|
id: "build-version",
|
||||||
instantiate: (di) => {
|
init: (di) => {
|
||||||
const buildVersionAsyncSyncBox = di.inject(buildVersionAsyncSyncBoxInjectable);
|
const requestFromChannel = di.inject(requestFromChannelInjectionToken);
|
||||||
|
|
||||||
return buildVersionAsyncSyncBox.get();
|
return requestFromChannel(buildVersionChannel);
|
||||||
},
|
},
|
||||||
injectionToken: buildVersionInjectionToken,
|
injectionToken: buildVersionInjectionToken,
|
||||||
});
|
});
|
||||||
|
|||||||
@ -4,18 +4,18 @@
|
|||||||
*/
|
*/
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import { beforeFrameStartsInjectionToken } from "../../before-frame-starts/before-frame-starts-injection-token";
|
import { beforeFrameStartsInjectionToken } from "../../before-frame-starts/before-frame-starts-injection-token";
|
||||||
import buildVersionAsyncSyncBoxInjectable from "./state.injectable";
|
import buildVersionInjectable from "./build-version.injectable";
|
||||||
|
|
||||||
const initializeBuildVersionAsyncSyncBoxInjectable = getInjectable({
|
const initializeBuildVersionInjectable = getInjectable({
|
||||||
id: "initialize-build-version-async-sync-box",
|
id: "initialize-build-version",
|
||||||
instantiate: (di) => {
|
instantiate: (di) => {
|
||||||
const buildVersionAsyncSyncBox = di.inject(buildVersionAsyncSyncBoxInjectable);
|
const buildVersion = di.inject(buildVersionInjectable);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
run: () => buildVersionAsyncSyncBox.init(),
|
run: () => buildVersion.init(),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
injectionToken: beforeFrameStartsInjectionToken,
|
injectionToken: beforeFrameStartsInjectionToken,
|
||||||
});
|
});
|
||||||
|
|
||||||
export default initializeBuildVersionAsyncSyncBoxInjectable;
|
export default initializeBuildVersionInjectable;
|
||||||
|
|||||||
@ -1,19 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { createInitializableState } from "../../../common/initializable-state/create";
|
|
||||||
import { requestFromChannelInjectionToken } from "../../../common/utils/channel/request-from-channel-injection-token";
|
|
||||||
import { buildVersionChannel } from "../../../common/vars/build-semantic-version.injectable";
|
|
||||||
|
|
||||||
const buildVersionAsyncSyncBoxInjectable = createInitializableState({
|
|
||||||
id: "build-version",
|
|
||||||
init: (di) => {
|
|
||||||
const requestFromChannel = di.inject(requestFromChannelInjectionToken);
|
|
||||||
|
|
||||||
return requestFromChannel(buildVersionChannel);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
export default buildVersionAsyncSyncBoxInjectable;
|
|
||||||
23
src/renderer/vars/default-update-channel/init.injectable.ts
Normal file
23
src/renderer/vars/default-update-channel/init.injectable.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
/**
|
||||||
|
* 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 defaultUpdateChannelInjectable from "../../../common/application-update/selected-update-channel/default-update-channel.injectable";
|
||||||
|
import initSemanticBuildVersionInjectable from "../../../renderer/vars/semantic-build-version/init.injectable";
|
||||||
|
import { beforeFrameStartsInjectionToken } from "../../before-frame-starts/before-frame-starts-injection-token";
|
||||||
|
|
||||||
|
const initDefaultUpdateChannelInjectableInjectable = getInjectable({
|
||||||
|
id: "init-default-update-channel-injectable",
|
||||||
|
instantiate: (di) => {
|
||||||
|
const defaultUpdateChannel = di.inject(defaultUpdateChannelInjectable);
|
||||||
|
|
||||||
|
return {
|
||||||
|
run: () => defaultUpdateChannel.init(),
|
||||||
|
runAfter: di.inject(initSemanticBuildVersionInjectable),
|
||||||
|
};
|
||||||
|
},
|
||||||
|
injectionToken: beforeFrameStartsInjectionToken,
|
||||||
|
});
|
||||||
|
|
||||||
|
export default initDefaultUpdateChannelInjectableInjectable;
|
||||||
23
src/renderer/vars/semantic-build-version/init.injectable.ts
Normal file
23
src/renderer/vars/semantic-build-version/init.injectable.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
/**
|
||||||
|
* 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 buildSemanticVersionInjectable from "../../../common/vars/build-semantic-version.injectable";
|
||||||
|
import { beforeFrameStartsInjectionToken } from "../../before-frame-starts/before-frame-starts-injection-token";
|
||||||
|
import initializeBuildVersionInjectable from "../build-version/init.injectable";
|
||||||
|
|
||||||
|
const initSemanticBuildVersionInjectable = getInjectable({
|
||||||
|
id: "init-semantic-build-version",
|
||||||
|
instantiate: (di) => {
|
||||||
|
const buildSemanticVersion = di.inject(buildSemanticVersionInjectable);
|
||||||
|
|
||||||
|
return {
|
||||||
|
run: () => buildSemanticVersion.init(),
|
||||||
|
runAfter: di.inject(initializeBuildVersionInjectable),
|
||||||
|
};
|
||||||
|
},
|
||||||
|
injectionToken: beforeFrameStartsInjectionToken,
|
||||||
|
});
|
||||||
|
|
||||||
|
export default initSemanticBuildVersionInjectable;
|
||||||
Loading…
Reference in New Issue
Block a user