1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Clean up versioning and packageJson uses (#6196)

This commit is contained in:
Sebastian Malton 2022-09-15 17:20:58 -04:00 committed by GitHub
parent cfe35ded90
commit 67ac1692b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
116 changed files with 1154 additions and 644 deletions

View File

@ -208,7 +208,8 @@
"lens" "lens"
], ],
"role": "Viewer" "role": "Viewer"
} },
"publish": []
}, },
"resolutions": { "resolutions": {
"@astronautlabs/jsonpath/underscore": "^1.12.1" "@astronautlabs/jsonpath/underscore": "^1.12.1"

View File

@ -18,13 +18,13 @@ import { createClusterInjectionToken } from "../cluster/create-cluster-injection
import directoryForUserDataInjectable from "../app-paths/directory-for-user-data/directory-for-user-data.injectable"; import directoryForUserDataInjectable from "../app-paths/directory-for-user-data/directory-for-user-data.injectable";
import { getDiForUnitTesting } from "../../main/getDiForUnitTesting"; import { getDiForUnitTesting } from "../../main/getDiForUnitTesting";
import getConfigurationFileModelInjectable from "../get-configuration-file-model/get-configuration-file-model.injectable"; import getConfigurationFileModelInjectable from "../get-configuration-file-model/get-configuration-file-model.injectable";
import appVersionInjectable from "../vars/app-version.injectable";
import assert from "assert"; import assert from "assert";
import directoryForTempInjectable from "../app-paths/directory-for-temp/directory-for-temp.injectable"; import directoryForTempInjectable from "../app-paths/directory-for-temp/directory-for-temp.injectable";
import kubectlBinaryNameInjectable from "../../main/kubectl/binary-name.injectable"; import kubectlBinaryNameInjectable from "../../main/kubectl/binary-name.injectable";
import kubectlDownloadingNormalizedArchInjectable from "../../main/kubectl/normalized-arch.injectable"; import kubectlDownloadingNormalizedArchInjectable from "../../main/kubectl/normalized-arch.injectable";
import normalizedPlatformInjectable from "../vars/normalized-platform.injectable"; import normalizedPlatformInjectable from "../vars/normalized-platform.injectable";
import fsInjectable from "../fs/fs.injectable"; import fsInjectable from "../fs/fs.injectable";
import storeMigrationVersionInjectable from "../vars/store-migration-version.injectable";
console = new Console(stdout, stderr); console = new Console(stdout, stderr);
@ -372,7 +372,7 @@ users:
mockFs(mockOpts); mockFs(mockOpts);
mainDi.override(appVersionInjectable, () => "3.6.0"); mainDi.override(storeMigrationVersionInjectable, () => "3.6.0");
createCluster = mainDi.inject(createClusterInjectionToken); createCluster = mainDi.inject(createClusterInjectionToken);

View File

@ -8,7 +8,6 @@ import mockFs from "mock-fs";
import type { CatalogEntity, CatalogEntityData, CatalogEntityKindData } from "../catalog"; import type { CatalogEntity, CatalogEntityData, CatalogEntityKindData } from "../catalog";
import { getDiForUnitTesting } from "../../main/getDiForUnitTesting"; import { getDiForUnitTesting } from "../../main/getDiForUnitTesting";
import getConfigurationFileModelInjectable from "../get-configuration-file-model/get-configuration-file-model.injectable"; import getConfigurationFileModelInjectable from "../get-configuration-file-model/get-configuration-file-model.injectable";
import appVersionInjectable from "../vars/app-version.injectable";
import type { DiContainer } from "@ogre-tools/injectable"; import type { DiContainer } from "@ogre-tools/injectable";
import hotbarStoreInjectable from "../hotbars/store.injectable"; import hotbarStoreInjectable from "../hotbars/store.injectable";
import type { HotbarStore } from "../hotbars/store"; import type { HotbarStore } from "../hotbars/store";
@ -19,6 +18,7 @@ import catalogCatalogEntityInjectable from "../catalog-entities/general-catalog-
import loggerInjectable from "../logger.injectable"; import loggerInjectable from "../logger.injectable";
import type { Logger } from "../logger"; import type { Logger } from "../logger";
import directoryForUserDataInjectable from "../app-paths/directory-for-user-data/directory-for-user-data.injectable"; import directoryForUserDataInjectable from "../app-paths/directory-for-user-data/directory-for-user-data.injectable";
import storeMigrationVersionInjectable from "../vars/store-migration-version.injectable";
function getMockCatalogEntity(data: Partial<CatalogEntityData> & CatalogEntityKindData): CatalogEntity { function getMockCatalogEntity(data: Partial<CatalogEntityData> & CatalogEntityKindData): CatalogEntity {
return { return {
@ -348,7 +348,7 @@ describe("HotbarStore", () => {
mockFs(configurationToBeMigrated); mockFs(configurationToBeMigrated);
di.override(appVersionInjectable, () => "5.0.0-beta.10"); di.override(storeMigrationVersionInjectable, () => "5.0.0-beta.10");
hotbarStore = di.inject(hotbarStoreInjectable); hotbarStore = di.inject(hotbarStoreInjectable);

View File

@ -23,8 +23,6 @@ jest.mock("electron", () => ({
import type { UserStore } from "../user-store"; import type { UserStore } from "../user-store";
import { Console } from "console"; import { Console } from "console";
import { SemVer } from "semver";
import electron from "electron";
import { stdout, stderr } from "process"; import { stdout, stderr } from "process";
import userStoreInjectable from "../user-store/user-store.injectable"; import userStoreInjectable from "../user-store/user-store.injectable";
import type { DiContainer } from "@ogre-tools/injectable"; import type { DiContainer } from "@ogre-tools/injectable";
@ -34,7 +32,7 @@ import { defaultThemeId } from "../vars";
import writeFileInjectable from "../fs/write-file.injectable"; import writeFileInjectable from "../fs/write-file.injectable";
import { getDiForUnitTesting } from "../../main/getDiForUnitTesting"; import { getDiForUnitTesting } from "../../main/getDiForUnitTesting";
import getConfigurationFileModelInjectable from "../get-configuration-file-model/get-configuration-file-model.injectable"; import getConfigurationFileModelInjectable from "../get-configuration-file-model/get-configuration-file-model.injectable";
import appVersionInjectable from "../vars/app-version.injectable"; import storeMigrationVersionInjectable from "../vars/store-migration-version.injectable";
console = new Console(stdout, stderr); console = new Console(stdout, stderr);
@ -86,13 +84,6 @@ describe("user store tests", () => {
userStore.resetTheme(); userStore.resetTheme();
expect(userStore.colorTheme).toBe(defaultThemeId); expect(userStore.colorTheme).toBe(defaultThemeId);
}); });
it("correctly calculates if the last seen version is an old release", () => {
expect(userStore.isNewVersion).toBe(true);
userStore.lastSeenAppVersion = (new SemVer(electron.app.getVersion())).inc("major").format();
expect(userStore.isNewVersion).toBe(false);
});
}); });
describe("migrations", () => { describe("migrations", () => {
@ -125,7 +116,7 @@ describe("user store tests", () => {
}, },
}); });
di.override(appVersionInjectable, () => "10.0.0"); di.override(storeMigrationVersionInjectable, () => "10.0.0");
userStore = di.inject(userStoreInjectable); userStore = di.inject(userStoreInjectable);
}); });

View File

@ -7,7 +7,6 @@ import { appPathsInjectionToken } from "./app-path-injection-token";
import getElectronAppPathInjectable from "../../main/app-paths/get-electron-app-path/get-electron-app-path.injectable"; import getElectronAppPathInjectable from "../../main/app-paths/get-electron-app-path/get-electron-app-path.injectable";
import type { PathName } from "./app-path-names"; import type { PathName } from "./app-path-names";
import setElectronAppPathInjectable from "../../main/app-paths/set-electron-app-path/set-electron-app-path.injectable"; import setElectronAppPathInjectable from "../../main/app-paths/set-electron-app-path/set-electron-app-path.injectable";
import appNameInjectable from "../../main/app-paths/app-name/app-name.injectable";
import directoryForIntegrationTestingInjectable from "../../main/app-paths/directory-for-integration-testing/directory-for-integration-testing.injectable"; import directoryForIntegrationTestingInjectable from "../../main/app-paths/directory-for-integration-testing/directory-for-integration-testing.injectable";
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";
@ -53,8 +52,6 @@ describe("app-paths", () => {
defaultAppPathsStub[key] = path; defaultAppPathsStub[key] = path;
}, },
); );
mainDi.override(appNameInjectable, () => "some-app-name");
}); });
}); });
@ -88,7 +85,7 @@ describe("app-paths", () => {
recent: "some-recent", recent: "some-recent",
temp: "some-temp", temp: "some-temp",
videos: "some-videos", videos: "some-videos",
userData: "some-app-data/some-app-name", userData: "some-app-data/some-product-name",
}); });
}); });
@ -111,7 +108,7 @@ describe("app-paths", () => {
recent: "some-recent", recent: "some-recent",
temp: "some-temp", temp: "some-temp",
videos: "some-videos", videos: "some-videos",
userData: "some-app-data/some-app-name", userData: "some-app-data/some-product-name",
}); });
}); });
}); });
@ -137,7 +134,7 @@ describe("app-paths", () => {
expect({ appData, userData }).toEqual({ expect({ appData, userData }).toEqual({
appData: "some-integration-testing-app-data", appData: "some-integration-testing-app-data",
userData: `some-integration-testing-app-data/some-app-name`, userData: `some-integration-testing-app-data/some-product-name`,
}); });
}); });
@ -146,7 +143,7 @@ describe("app-paths", () => {
expect({ appData, userData }).toEqual({ expect({ appData, userData }).toEqual({
appData: "some-integration-testing-app-data", appData: "some-integration-testing-app-data",
userData: "some-integration-testing-app-data/some-app-name", userData: "some-integration-testing-app-data/some-product-name",
}); });
}); });
}); });

View File

@ -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;

View File

@ -5,13 +5,13 @@
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import type { IComputedValue } from "mobx"; import type { IComputedValue } from "mobx";
import { action, computed, observable } from "mobx"; import { action, computed, observable } from "mobx";
import type { UpdateChannel, UpdateChannelId } from "../update-channels"; import type { UpdateChannel, ReleaseChannel } from "../update-channels";
import { updateChannels } from "../update-channels"; import { updateChannels } from "../update-channels";
import defaultUpdateChannelInjectable from "./default-update-channel.injectable"; import defaultUpdateChannelInjectable from "./default-update-channel.injectable";
export interface SelectedUpdateChannel { export interface SelectedUpdateChannel {
value: IComputedValue<UpdateChannel>; value: IComputedValue<UpdateChannel>;
setValue: (channelId?: UpdateChannelId) => void; setValue: (channelId?: ReleaseChannel) => void;
} }
const selectedUpdateChannelInjectable = getInjectable({ const selectedUpdateChannelInjectable = getInjectable({
@ -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);
}), }),

View File

@ -4,7 +4,7 @@
*/ */
export type UpdateChannelId = "alpha" | "beta" | "latest"; export type ReleaseChannel = "alpha" | "beta" | "latest";
const latestChannel: UpdateChannel = { const latestChannel: UpdateChannel = {
id: "latest", id: "latest",
@ -31,7 +31,7 @@ export const updateChannels = {
}; };
export interface UpdateChannel { export interface UpdateChannel {
readonly id: UpdateChannelId; readonly id: ReleaseChannel;
readonly label: string; readonly label: string;
readonly moreStableUpdateChannel: UpdateChannel | null; readonly moreStableUpdateChannel: UpdateChannel | null;
} }

View File

@ -19,7 +19,7 @@ import { kebabCase } from "lodash";
import { getLegacyGlobalDiForExtensionApi } from "../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api"; import { getLegacyGlobalDiForExtensionApi } from "../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
import directoryForUserDataInjectable from "./app-paths/directory-for-user-data/directory-for-user-data.injectable"; import directoryForUserDataInjectable from "./app-paths/directory-for-user-data/directory-for-user-data.injectable";
import getConfigurationFileModelInjectable from "./get-configuration-file-model/get-configuration-file-model.injectable"; import getConfigurationFileModelInjectable from "./get-configuration-file-model/get-configuration-file-model.injectable";
import appVersionInjectable from "./vars/app-version.injectable"; import storeMigrationVersionInjectable from "./vars/store-migration-version.injectable";
export interface BaseStoreParams<T> extends ConfOptions<T> { export interface BaseStoreParams<T> extends ConfOptions<T> {
syncOptions?: { syncOptions?: {
@ -60,7 +60,7 @@ export abstract class BaseStore<T extends object> extends Singleton {
this.storeConfig = getConfigurationFileModel({ this.storeConfig = getConfigurationFileModel({
projectName: "lens", projectName: "lens",
projectVersion: di.inject(appVersionInjectable), projectVersion: di.inject(storeMigrationVersionInjectable),
cwd: this.cwd(), cwd: this.cwd(),
...this.params, ...this.params,
}); });

View File

@ -3,9 +3,10 @@
* 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 { getLegacyGlobalDiForExtensionApi } from "../../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
import type { CatalogEntityContextMenuContext, CatalogEntityMetadata, CatalogEntityStatus } from "../catalog"; import type { CatalogEntityContextMenuContext, CatalogEntityMetadata, CatalogEntityStatus } from "../catalog";
import { CatalogCategory, CatalogEntity, categoryVersion } from "../catalog/catalog-entity"; import { CatalogCategory, CatalogEntity, categoryVersion } from "../catalog/catalog-entity";
import { productName } from "../vars"; import productNameInjectable from "../vars/product-name.injectable";
import { WeblinkStore } from "../weblink-store"; import { WeblinkStore } from "../weblink-store";
export type WebLinkStatusPhase = "available" | "unavailable"; export type WebLinkStatusPhase = "available" | "unavailable";
@ -30,6 +31,9 @@ export class WebLink extends CatalogEntity<CatalogEntityMetadata, WebLinkStatus,
} }
onContextMenuOpen(context: CatalogEntityContextMenuContext) { onContextMenuOpen(context: CatalogEntityContextMenuContext) {
const di = getLegacyGlobalDiForExtensionApi();
const productName = di.inject(productNameInjectable);
if (this.metadata.source === "local") { if (this.metadata.source === "local") {
context.menuItems.push({ context.menuItems.push({
title: "Delete", title: "Delete",

View File

@ -0,0 +1,9 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getGlobalOverride } from "../test-utils/get-global-override";
import initializeSentryReportingWithInjectable from "./initialize-sentry-reporting.injectable";
export default getGlobalOverride(initializeSentryReportingWithInjectable, () => () => {});

View File

@ -0,0 +1,65 @@
/**
* 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 type { ElectronMainOptions } from "@sentry/electron/main";
import type { BrowserOptions } from "@sentry/electron/renderer";
import isProductionInjectable from "../vars/is-production.injectable";
import sentryDataSourceNameInjectable from "../vars/sentry-dsn-url.injectable";
import { Dedupe, Offline } from "@sentry/integrations";
import { inspect } from "util";
import userStoreInjectable from "../user-store/user-store.injectable";
export type InitializeSentryReportingWith = (initSentry: (opts: BrowserOptions | ElectronMainOptions) => void) => void;
const mapProcessName = (type: "browser" | "renderer" | "worker") => type === "browser" ? "main" : type;
const initializeSentryReportingWithInjectable = getInjectable({
id: "initialize-sentry-reporting-with",
instantiate: (di): InitializeSentryReportingWith => {
const sentryDataSourceName = di.inject(sentryDataSourceNameInjectable);
const isProduction = di.inject(isProductionInjectable);
if (!sentryDataSourceName) {
return () => {};
}
return (initSentry) => initSentry({
beforeSend: (event) => {
// TODO: remove loading from userStoreInjectable so that this can be moved out
const userStore = di.inject(userStoreInjectable);
if (userStore.allowErrorReporting) {
return event;
}
/**
* Directly write to stdout so that no other integrations capture this and create an infinite loop
*/
process.stdout.write(`🔒 [SENTRY-BEFORE-SEND-HOOK]: Sentry event is caught but not sent to server.`);
process.stdout.write("🔒 [SENTRY-BEFORE-SEND-HOOK]: === START OF SENTRY EVENT ===");
process.stdout.write(inspect(event, false, null, true));
process.stdout.write("🔒 [SENTRY-BEFORE-SEND-HOOK]: === END OF SENTRY EVENT ===");
// if return null, the event won't be sent
// ref https://github.com/getsentry/sentry-javascript/issues/2039
return null;
},
dsn: sentryDataSourceName,
integrations: [
new Dedupe(),
new Offline(),
],
initialScope: {
tags: {
"process": mapProcessName(process.type),
},
},
environment: isProduction ? "production" : "development",
});
},
causesSideEffects: true,
});
export default initializeSentryReportingWithInjectable;

View File

@ -1,8 +0,0 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getGlobalOverride } from "../../../test-utils/get-global-override";
import welcomeRouteConfig from "./welcome-route-config.injectable";
export default getGlobalOverride(welcomeRouteConfig, () => "/welcome");

View File

@ -3,16 +3,12 @@
* 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 packageJsonInjectable from "../../../vars/package-json.injectable"; import applicationInformationInjectable from "../../../vars/application-information.injectable";
const welcomeRouteConfigInjectable = getInjectable({ const welcomeRouteConfigInjectable = getInjectable({
id: "welcome-route-config", id: "welcome-route-config",
instantiate: (di) => { instantiate: (di) => di.inject(applicationInformationInjectable).config.welcomeRoute,
const packageJson = di.inject(packageJsonInjectable);
return packageJson.config.welcomeRoute;
},
}); });
export default welcomeRouteConfigInjectable; export default welcomeRouteConfigInjectable;

View File

@ -0,0 +1,77 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { AsyncFnMock } from "@async-fn/jest";
import asyncFn from "@async-fn/jest";
import type { DiContainer, Injectable } from "@ogre-tools/injectable";
import { runInAction } from "mobx";
import { getDiForUnitTesting } from "../../main/getDiForUnitTesting";
import type { InitializableState } from "./create";
import { createInitializableState } from "./create";
describe("InitializableState tests", () => {
let di: DiContainer;
beforeEach(() => {
di = getDiForUnitTesting({ doGeneralOverrides: true });
});
describe("when created", () => {
let stateInjectable: Injectable<InitializableState<number>, unknown, void>;
let initMock: AsyncFnMock<() => number>;
beforeEach(() => {
initMock = asyncFn();
stateInjectable = createInitializableState({
id: "my-state",
init: initMock,
});
runInAction(() => {
di.register(stateInjectable);
});
});
describe("when injected", () => {
let state: InitializableState<number>;
beforeEach(() => {
state = di.inject(stateInjectable);
});
it("when get is called, throw", () => {
expect(() => state.get()).toThrowError("InitializableState(my-state) has not been initialized yet");
});
describe("when init is called", () => {
beforeEach(() => {
state.init();
});
it("should call provided initialization function", () => {
expect(initMock).toBeCalled();
});
it("when get is called, throw", () => {
expect(() => state.get()).toThrowError("InitializableState(my-state) has not finished initializing");
});
describe("when initialization resolves", () => {
beforeEach(async () => {
await initMock.resolve(42);
});
it("when get is called, returns value", () => {
expect(state.get()).toBe(42);
});
it("when init is called again, throws", async () => {
await expect(() => state.init()).rejects.toThrow("Cannot initialize InitializableState(my-state) more than once");
});
});
});
});
});
});

View File

@ -0,0 +1,62 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { DiContainerForInjection, Injectable, InjectionToken } from "@ogre-tools/injectable";
import { getInjectable } from "@ogre-tools/injectable";
export interface CreateInitializableStateArgs<T> {
id: string;
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 } ;
export function createInitializableState<T>(args: CreateInitializableStateArgs<T>): Injectable<InitializableState<T>, unknown, void> {
const { id, init, injectionToken } = args;
return getInjectable({
id,
instantiate: (di) => {
let box: InitializableStateValue<T> = {
set: false,
};
let initCalled = false;
return {
init: async () => {
if (initCalled) {
throw new Error(`Cannot initialize InitializableState(${id}) more than once`);
}
initCalled = true;
box = {
set: true,
value: await init(di),
};
},
get: () => {
if (!initCalled) {
throw new Error(`InitializableState(${id}) has not been initialized yet`);
}
if (box.set === false) {
throw new Error(`InitializableState(${id}) has not finished initializing`);
}
return box.value;
},
};
},
injectionToken,
});
}

View File

@ -11,8 +11,9 @@ import logger from "../../main/logger";
import { app } from "electron"; import { app } from "electron";
import { ClusterStore } from "../cluster-store/cluster-store"; import { ClusterStore } from "../cluster-store/cluster-store";
import yaml from "js-yaml"; import yaml from "js-yaml";
import { productName } from "../vars";
import { requestKubectlApplyAll, requestKubectlDeleteAll } from "../../renderer/ipc"; import { requestKubectlApplyAll, requestKubectlDeleteAll } from "../../renderer/ipc";
import { getLegacyGlobalDiForExtensionApi } from "../../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
import productNameInjectable from "../vars/product-name.injectable";
export class ResourceStack { export class ResourceStack {
constructor(protected cluster: KubernetesCluster, protected name: string) {} constructor(protected cluster: KubernetesCluster, protected name: string) {}
@ -97,6 +98,8 @@ export class ResourceStack {
protected async renderTemplates(folderPath: string, templateContext: any): Promise<string[]> { protected async renderTemplates(folderPath: string, templateContext: any): Promise<string[]> {
const resources: string[] = []; const resources: string[] = [];
const di = getLegacyGlobalDiForExtensionApi();
const productName = di.inject(productNameInjectable);
logger.info(`[RESOURCE-STACK]: render templates from ${folderPath}`); logger.info(`[RESOURCE-STACK]: render templates from ${folderPath}`);
const files = await fse.readdir(folderPath); const files = await fse.readdir(folderPath);

View File

@ -1,67 +0,0 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { Dedupe, Offline } from "@sentry/integrations";
import { sentryDsn, isProduction } from "./vars";
import { UserStore } from "./user-store";
import { inspect } from "util";
import type { BrowserOptions } from "@sentry/electron/renderer";
import type { ElectronMainOptions } from "@sentry/electron/main";
/**
* "Translate" 'browser' to 'main' as Lens developer more familiar with the term 'main'
*/
function mapProcessName(processType: string) {
if (processType === "browser") {
return "main";
}
return processType;
}
/**
* Initialize Sentry for the current process so to send errors for debugging.
*/
export function initializeSentryReporting(init: (opts: BrowserOptions | ElectronMainOptions) => void) {
const processName = mapProcessName(process.type);
if (!sentryDsn) {
return; // do nothing if not configured to avoid uncaught error in dev mode
}
init({
beforeSend: (event) => {
// default to false, in case instance of UserStore is not created (yet)
const allowErrorReporting = UserStore.getInstance(false)?.allowErrorReporting ?? false;
if (allowErrorReporting) {
return event;
}
/**
* Directly write to stdout so that no other integrations capture this and create an infinite loop
*/
process.stdout.write(`🔒 [SENTRY-BEFORE-SEND-HOOK]: allowErrorReporting: ${allowErrorReporting}. Sentry event is caught but not sent to server.`);
process.stdout.write("🔒 [SENTRY-BEFORE-SEND-HOOK]: === START OF SENTRY EVENT ===");
process.stdout.write(inspect(event, false, null, true));
process.stdout.write("🔒 [SENTRY-BEFORE-SEND-HOOK]: === END OF SENTRY EVENT ===");
// if return null, the event won't be sent
// ref https://github.com/getsentry/sentry-javascript/issues/2039
return null;
},
dsn: sentryDsn,
integrations: [
new Dedupe(),
new Offline(),
],
initialScope: {
tags: {
"process": processName,
},
},
environment: isProduction ? "production" : "development",
});
}

View File

@ -4,19 +4,16 @@
*/ */
import { app } from "electron"; import { app } from "electron";
import semver from "semver";
import { action, computed, observable, reaction, makeObservable, isObservableArray, isObservableSet, isObservableMap } from "mobx"; import { action, computed, observable, reaction, makeObservable, isObservableArray, isObservableSet, isObservableMap } from "mobx";
import { BaseStore } from "../base-store"; import { BaseStore } from "../base-store";
import migrations from "../../migrations/user-store"; import migrations from "../../migrations/user-store";
import { getAppVersion } from "../utils/app-version";
import { kubeConfigDefaultPath } from "../kube-helpers"; import { kubeConfigDefaultPath } from "../kube-helpers";
import { appEventBus } from "../app-event-bus/event-bus";
import { getOrInsertSet, toggle, toJS, object } from "../../renderer/utils"; import { getOrInsertSet, toggle, toJS, object } from "../../renderer/utils";
import { DESCRIPTORS } from "./preferences-helpers"; import { DESCRIPTORS } from "./preferences-helpers";
import type { UserPreferencesModel, StoreType } from "./preferences-helpers"; import type { UserPreferencesModel, StoreType } from "./preferences-helpers";
import logger from "../../main/logger"; import logger from "../../main/logger";
import type { SelectedUpdateChannel } from "../application-update/selected-update-channel/selected-update-channel.injectable"; import type { SelectedUpdateChannel } from "../application-update/selected-update-channel/selected-update-channel.injectable";
import type { UpdateChannelId } from "../application-update/update-channels"; import type { ReleaseChannel } from "../application-update/update-channels";
export interface UserStoreModel { export interface UserStoreModel {
lastSeenAppVersion: string; lastSeenAppVersion: string;
@ -24,7 +21,7 @@ export interface UserStoreModel {
} }
interface Dependencies { interface Dependencies {
selectedUpdateChannel: SelectedUpdateChannel; readonly selectedUpdateChannel: SelectedUpdateChannel;
} }
export class UserStore extends BaseStore<UserStoreModel> /* implements UserStoreFlatModel (when strict null is enabled) */ { export class UserStore extends BaseStore<UserStoreModel> /* implements UserStoreFlatModel (when strict null is enabled) */ {
@ -98,10 +95,6 @@ export class UserStore extends BaseStore<UserStoreModel> /* implements UserStore
*/ */
@observable syncKubeconfigEntries!: StoreType<typeof DESCRIPTORS["syncKubeconfigEntries"]>; @observable syncKubeconfigEntries!: StoreType<typeof DESCRIPTORS["syncKubeconfigEntries"]>;
@computed get isNewVersion() {
return semver.gt(getAppVersion(), this.lastSeenAppVersion);
}
@computed get resolvedShell(): string | undefined { @computed get resolvedShell(): string | undefined {
return this.shell || process.env.SHELL || process.env.PTYSHELL; return this.shell || process.env.SHELL || process.env.PTYSHELL;
} }
@ -151,12 +144,6 @@ export class UserStore extends BaseStore<UserStoreModel> /* implements UserStore
this.colorTheme = DESCRIPTORS.colorTheme.fromStore(undefined); this.colorTheme = DESCRIPTORS.colorTheme.fromStore(undefined);
} }
@action
saveLastSeenAppVersion() {
appEventBus.emit({ name: "app", action: "whats-new-seen" });
this.lastSeenAppVersion = getAppVersion();
}
@action @action
protected fromStore({ lastSeenAppVersion, preferences }: Partial<UserStoreModel> = {}) { protected fromStore({ lastSeenAppVersion, preferences }: Partial<UserStoreModel> = {}) {
logger.debug("UserStore.fromStore()", { lastSeenAppVersion, preferences }); logger.debug("UserStore.fromStore()", { lastSeenAppVersion, preferences });
@ -180,7 +167,7 @@ export class UserStore extends BaseStore<UserStoreModel> /* implements UserStore
// TODO: Switch to action-based saving instead saving stores by reaction // TODO: Switch to action-based saving instead saving stores by reaction
if (preferences?.updateChannel) { if (preferences?.updateChannel) {
this.dependencies.selectedUpdateChannel.setValue(preferences?.updateChannel as UpdateChannelId); this.dependencies.selectedUpdateChannel.setValue(preferences?.updateChannel as ReleaseChannel);
} }
} }

View File

@ -4,15 +4,6 @@
*/ */
import requestPromise from "request-promise-native"; import requestPromise from "request-promise-native";
import packageInfo from "../../../package.json";
export function getAppVersion(): string {
return packageInfo.version;
}
export function getBundledKubectlVersion(): string {
return packageInfo.config.bundledKubectlVersion;
}
export async function getAppVersionFromProxyServer(proxyPort: number): Promise<string> { export async function getAppVersionFromProxyServer(proxyPort: number): Promise<string> {
const response = await requestPromise({ const response = await requestPromise({

View File

@ -5,7 +5,6 @@
// App's common configuration for any process (main, renderer, build pipeline, etc.) // App's common configuration for any process (main, renderer, build pipeline, etc.)
import path from "path"; import path from "path";
import packageInfo from "../../package.json";
import type { ThemeId } from "../renderer/themes/store"; import type { ThemeId } from "../renderer/themes/store";
import { lazyInitialized } from "./utils/lazy-initialized"; import { lazyInitialized } from "./utils/lazy-initialized";
@ -25,7 +24,6 @@ export const isWindows = process.platform === "win32";
export const isLinux = process.platform === "linux"; export const isLinux = process.platform === "linux";
export const isDebugging = ["true", "1", "yes", "y", "on"].includes((process.env.DEBUG ?? "").toLowerCase()); export const isDebugging = ["true", "1", "yes", "y", "on"].includes((process.env.DEBUG ?? "").toLowerCase());
export const isSnap = !!process.env.SNAP;
/** /**
* @deprecated Switch to using isTestEnvInjectable * @deprecated Switch to using isTestEnvInjectable
@ -42,13 +40,6 @@ export const isProduction = process.env.NODE_ENV === "production";
*/ */
export const isDevelopment = !isTestEnv && !isProduction; export const isDevelopment = !isTestEnv && !isProduction;
export const productName = packageInfo.productName;
/**
* @deprecated Switch to using appNameInjectable
*/
export const appName = `${packageInfo.productName}${isDevelopment ? "Dev" : ""}`;
export const publicPath = "/build/" as string; export const publicPath = "/build/" as string;
export const defaultThemeId: ThemeId = "lens-dark"; export const defaultThemeId: ThemeId = "lens-dark";
export const defaultFontSize = 12; export const defaultFontSize = 12;
@ -139,6 +130,3 @@ export const lensBlogWeblinkId = "lens-blog-link";
export const kubernetesDocumentationWeblinkId = "kubernetes-documentation-link"; export const kubernetesDocumentationWeblinkId = "kubernetes-documentation-link";
export const docsUrl = "https://docs.k8slens.dev/main" as string; export const docsUrl = "https://docs.k8slens.dev/main" as string;
export const sentryDsn = packageInfo.config?.sentryDsn ?? "";
export const contentSecurityPolicy = packageInfo.config?.contentSecurityPolicy ?? "";

View File

@ -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 isDevelopmentInjectable from "../../../common/vars/is-development.injectable"; import isDevelopmentInjectable from "./is-development.injectable";
import productNameInjectable from "./product-name.injectable"; import productNameInjectable from "./product-name.injectable";
const appNameInjectable = getInjectable({ const appNameInjectable = getInjectable({
@ -15,8 +15,6 @@ const appNameInjectable = getInjectable({
return `${productName}${isDevelopment ? "Dev" : ""}`; return `${productName}${isDevelopment ? "Dev" : ""}`;
}, },
causesSideEffects: true,
}); });
export default appNameInjectable; export default appNameInjectable;

View File

@ -1,14 +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 { SemVer } from "semver";
import appVersionInjectable from "./app-version.injectable";
const appSemanticVersionInjectable = getInjectable({
id: "app-semantic-version",
instantiate: (di) => new SemVer(di.inject(appVersionInjectable)),
});
export default appSemanticVersionInjectable;

View File

@ -1,13 +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 packageJsonInjectable from "./package-json.injectable";
const appVersionInjectable = getInjectable({
id: "app-version",
instantiate: (di) => di.inject(packageJsonInjectable).version,
});
export default appVersionInjectable;

View File

@ -0,0 +1,13 @@
/**
* 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 applicationInformationInjectable from "./application-information.injectable";
const applicationCopyrightInjectable = getInjectable({
id: "application-copyright",
instantiate: (di) => di.inject(applicationInformationInjectable).copyright,
});
export default applicationCopyrightInjectable;

View File

@ -0,0 +1,13 @@
/**
* 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 applicationInformationInjectable from "./application-information.injectable";
const applicationDescriptionInjectable = getInjectable({
id: "application-description",
instantiate: (di) => di.inject(applicationInformationInjectable).description,
});
export default applicationDescriptionInjectable;

View 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 { getGlobalOverride } from "../test-utils/get-global-override";
import applicationInformationInjectable from "./application-information.injectable";
export default getGlobalOverride(applicationInformationInjectable, () => ({
productName: "some-product-name",
version: "6.0.0",
build: {},
config: {
k8sProxyVersion: "0.2.1",
bundledKubectlVersion: "1.23.3",
bundledHelmVersion: "3.7.2",
sentryDsn: "",
contentSecurityPolicy: "script-src 'unsafe-eval' 'self'; frame-src http://*.localhost:*/; img-src * data:",
welcomeRoute: "/welcome",
},
copyright: "some-copyright-information",
description: "some-descriptive-text",
}));

View File

@ -0,0 +1,22 @@
/**
* 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 packageJson from "../../../package.json";
export type ApplicationInformation = Pick<typeof packageJson, "version" | "config" | "productName" | "copyright" | "description"> & {
build: Partial<typeof packageJson["build"]>;
};
const applicationInformationInjectable = getInjectable({
id: "application-information",
instantiate: (): ApplicationInformation => {
const { version, config, productName, build, copyright, description } = packageJson;
return { version, config, productName, build, copyright, description };
},
causesSideEffects: true,
});
export default applicationInformationInjectable;

View File

@ -0,0 +1,30 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectionToken } from "@ogre-tools/injectable";
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";
export const buildVersionInjectionToken = getInjectionToken<InitializableState<string>>({
id: "build-version-token",
});
export const buildVersionChannel: RequestChannel<void, string> = {
id: "build-version",
};
const buildSemanticVersionInjectable = createInitializableState({
id: "build-semantic-version",
init: (di) => {
const buildVersion = di.inject(buildVersionInjectionToken);
return new SemVer(buildVersion.get());
},
});
export default buildSemanticVersionInjectable;

View File

@ -0,0 +1,13 @@
/**
* 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 applicationInformationInjectable from "./application-information.injectable";
const bundledKubectlVersionInjectable = getInjectable({
id: "bundled-kubectl-version",
instantiate: (di) => di.inject(applicationInformationInjectable).config.bundledKubectlVersion,
});
export default bundledKubectlVersionInjectable;

View File

@ -0,0 +1,13 @@
/**
* 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 applicationInformationInjectable from "./application-information.injectable";
const contentSecurityPolicyInjectable = getInjectable({
id: "content-security-policy",
instantiate: (di) => di.inject(applicationInformationInjectable).config.contentSecurityPolicy,
});
export default contentSecurityPolicyInjectable;

View File

@ -0,0 +1,18 @@
/**
* 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 { SemVer } from "semver";
import applicationInformationInjectable from "./application-information.injectable";
const extensionApiVersionInjectable = getInjectable({
id: "extension-api-version",
instantiate: (di) => {
const { major, minor, patch } = new SemVer(di.inject(applicationInformationInjectable).version);
return `${major}.${minor}.${patch}`;
},
});
export default extensionApiVersionInjectable;

View File

@ -0,0 +1,9 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getGlobalOverride } from "../test-utils/get-global-override";
import isSnapPackageInjectable from "./is-snap-package.injectable";
export default getGlobalOverride(isSnapPackageInjectable, () => false);

View File

@ -3,12 +3,11 @@
* 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 packageJson from "../../../package.json";
const packageJsonInjectable = getInjectable({ const isSnapPackageInjectable = getInjectable({
id: "package-json", id: "is-snap",
instantiate: () => packageJson, instantiate: () => Boolean(process.env.SNAP),
causesSideEffects: true, causesSideEffects: true,
}); });
export default packageJsonInjectable; export default isSnapPackageInjectable;

View File

@ -3,12 +3,11 @@
* 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 packageInfo from "../../../../package.json"; import applicationInformationInjectable from "./application-information.injectable";
const productNameInjectable = getInjectable({ const productNameInjectable = getInjectable({
id: "product-name", id: "product-name",
instantiate: () => packageInfo.productName, instantiate: (di) => di.inject(applicationInformationInjectable).productName,
causesSideEffects: true,
}); });
export default productNameInjectable; export default productNameInjectable;

View File

@ -3,14 +3,14 @@
* 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 type { UpdateChannelId } from "../application-update/update-channels"; import type { ReleaseChannel } from "../application-update/update-channels";
import appSemanticVersionInjectable from "./app-semantic-version.injectable"; import buildSemanticVersionInjectable from "./build-semantic-version.injectable";
const releaseChannelInjectable = getInjectable({ const releaseChannelInjectable = getInjectable({
id: "release-channel", id: "release-channel",
instantiate: (di): UpdateChannelId => { instantiate: (di): ReleaseChannel => {
const appSemanticVersion = di.inject(appSemanticVersionInjectable); const buildSemanticVersion = di.inject(buildSemanticVersionInjectable);
const currentReleaseChannel = appSemanticVersion.prerelease[0]; const currentReleaseChannel = buildSemanticVersion.get().prerelease[0];
switch (currentReleaseChannel) { switch (currentReleaseChannel) {
case "latest": case "latest":

View File

@ -0,0 +1,13 @@
/**
* 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 applicationInformationInjectable from "./application-information.injectable";
const sentryDataSourceNameInjectable = getInjectable({
id: "sentry-data-source-name",
instantiate: (di) => di.inject(applicationInformationInjectable).config.sentryDsn,
});
export default sentryDataSourceNameInjectable;

View File

@ -0,0 +1,13 @@
/**
* 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 applicationInformationInjectable from "./application-information.injectable";
const storeMigrationVersionInjectable = getInjectable({
id: "store-migration-version",
instantiate: (di) => di.inject(applicationInformationInjectable).version,
});
export default storeMigrationVersionInjectable;

View File

@ -3,65 +3,53 @@
* 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 assert from "assert";
import semver from "semver";
import { isCompatibleExtension } from "../extension-discovery/is-compatible-extension/is-compatible-extension"; import { isCompatibleExtension } from "../extension-discovery/is-compatible-extension/is-compatible-extension";
import type { LensExtensionManifest } from "../lens-extension"; import type { LensExtensionManifest } from "../lens-extension";
describe("Extension/App versions compatibility checks", () => { describe("Extension/App versions compatibility checks", () => {
it("is compatible with exact version matching", () => { it("is compatible with exact version matching", () => {
expect(isCompatible({ extLensEngineVersion: "5.5.0", appVersion: "5.5.0" })).toBeTruthy(); expect(isCompatible({ extLensEngineVersion: "5.5.0", extensionApiVersion: "5.5.0" })).toBeTruthy();
}); });
it("is compatible with upper %PATCH versions of base app", () => { it("is compatible with upper %PATCH versions of base app", () => {
expect(isCompatible({ extLensEngineVersion: "5.5.0", appVersion: "5.5.5" })).toBeTruthy(); expect(isCompatible({ extLensEngineVersion: "5.5.0", extensionApiVersion: "5.5.5" })).toBeTruthy();
}); });
it("is compatible with higher %MINOR version of base app", () => { it("is compatible with higher %MINOR version of base app", () => {
expect(isCompatible({ extLensEngineVersion: "5.5.0", appVersion: "5.6.0" })).toBeTruthy(); expect(isCompatible({ extLensEngineVersion: "5.5.0", extensionApiVersion: "5.6.0" })).toBeTruthy();
}); });
it("is not compatible with higher %MAJOR version of base app", () => { it("is not compatible with higher %MAJOR version of base app", () => {
expect(isCompatible({ extLensEngineVersion: "5.6.0", appVersion: "6.0.0" })).toBeFalsy(); // extension for lens@5 not compatible with lens@6 expect(isCompatible({ extLensEngineVersion: "5.6.0", extensionApiVersion: "6.0.0" })).toBeFalsy(); // extension for lens@5 not compatible with lens@6
expect(isCompatible({ extLensEngineVersion: "6.0.0", appVersion: "5.6.0" })).toBeFalsy(); expect(isCompatible({ extLensEngineVersion: "6.0.0", extensionApiVersion: "5.6.0" })).toBeFalsy();
});
it("is compatible with lensEngine with prerelease", () => {
expect(isCompatible({
extLensEngineVersion: "^5.4.0-alpha.0",
appVersion: "5.5.0-alpha.0",
})).toBeTruthy();
}); });
it("supports short version format for manifest.engines.lens", () => { it("supports short version format for manifest.engines.lens", () => {
expect(isCompatible({ extLensEngineVersion: "5.5", appVersion: "5.5.1" })).toBeTruthy(); expect(isCompatible({ extLensEngineVersion: "5.5", extensionApiVersion: "5.5.1" })).toBeTruthy();
}); });
it("throws for incorrect or not supported version format", () => { it("throws for incorrect or not supported version format", () => {
expect(() => isCompatible({ expect(() => isCompatible({
extLensEngineVersion: ">=2.0", extLensEngineVersion: ">=2.0",
appVersion: "2.0", extensionApiVersion: "2.0",
})).toThrow(/Invalid format/i); })).toThrow(/Invalid format/i);
expect(() => isCompatible({ expect(() => isCompatible({
extLensEngineVersion: "~2.0", extLensEngineVersion: "~2.0",
appVersion: "2.0", extensionApiVersion: "2.0",
})).toThrow(/Invalid format/i); })).toThrow(/Invalid format/i);
expect(() => isCompatible({ expect(() => isCompatible({
extLensEngineVersion: "*", extLensEngineVersion: "*",
appVersion: "1.0", extensionApiVersion: "1.0",
})).toThrow(/Invalid format/i); })).toThrow(/Invalid format/i);
}); });
}); });
function isCompatible({ extLensEngineVersion = "^1.0", appVersion = "1.0" } = {}): boolean { function isCompatible({ extLensEngineVersion = "^1.0", extensionApiVersion = "1.0" } = {}): boolean {
const appSemVer = semver.coerce(appVersion);
const extensionManifestMock = getExtensionManifestMock(extLensEngineVersion); const extensionManifestMock = getExtensionManifestMock(extLensEngineVersion);
assert(appSemVer); return isCompatibleExtension({ extensionApiVersion })(extensionManifestMock);
return isCompatibleExtension({ appSemVer })(extensionManifestMock);
} }
function getExtensionManifestMock(lensEngine = "1.0"): LensExtensionManifest { function getExtensionManifestMock(lensEngine = "1.0"): LensExtensionManifest {

View File

@ -3,14 +3,65 @@
* 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 { getAppVersion } from "../../common/utils"; import appNameInjectable from "../../common/vars/app-name.injectable";
import isLinuxInjectable from "../../common/vars/is-linux.injectable";
import isMacInjectable from "../../common/vars/is-mac.injectable";
import isSnapPackageInjectable from "../../common/vars/is-snap-package.injectable";
import isWindowsInjectable from "../../common/vars/is-windows.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 getEnabledExtensionsInjectable from "./get-enabled-extensions/get-enabled-extensions.injectable"; import getEnabledExtensionsInjectable from "./get-enabled-extensions/get-enabled-extensions.injectable";
import * as Preferences from "./user-preferences"; import type { UserPreferenceExtensionItems } from "./user-preferences";
import { Preferences } from "./user-preferences";
import { slackUrl, issuesTrackerUrl } from "../../common/vars";
import { buildVersionInjectionToken } from "../../common/vars/build-semantic-version.injectable";
export const version = getAppVersion(); export interface AppExtensionItems {
export { isSnap, isWindows, isMac, isLinux, appName, slackUrl, issuesTrackerUrl } from "../../common/vars"; readonly Preferences: UserPreferenceExtensionItems;
readonly version: string;
readonly appName: string;
readonly slackUrl: string;
readonly issuesTrackerUrl: string;
readonly isSnap: boolean;
readonly isWindows: boolean;
readonly isMac: boolean;
readonly isLinux: boolean;
getEnabledExtensions: () => string[];
}
export const getEnabledExtensions = asLegacyGlobalFunctionForExtensionApi(getEnabledExtensionsInjectable); export const App: AppExtensionItems = {
Preferences,
getEnabledExtensions: asLegacyGlobalFunctionForExtensionApi(getEnabledExtensionsInjectable),
get version() {
const di = getLegacyGlobalDiForExtensionApi();
export { Preferences }; return di.inject(buildVersionInjectionToken).get();
},
get appName() {
const di = getLegacyGlobalDiForExtensionApi();
return di.inject(appNameInjectable);
},
get isSnap() {
const di = getLegacyGlobalDiForExtensionApi();
return di.inject(isSnapPackageInjectable);
},
get isWindows() {
const di = getLegacyGlobalDiForExtensionApi();
return di.inject(isWindowsInjectable);
},
get isMac() {
const di = getLegacyGlobalDiForExtensionApi();
return di.inject(isMacInjectable);
},
get isLinux() {
const di = getLegacyGlobalDiForExtensionApi();
return di.inject(isLinuxInjectable);
},
slackUrl,
issuesTrackerUrl,
};

View File

@ -4,10 +4,10 @@
*/ */
// APIs // APIs
import * as 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";

View File

@ -4,10 +4,13 @@
*/ */
import { UserStore } from "../../common/user-store"; import { UserStore } from "../../common/user-store";
export interface UserPreferenceExtensionItems {
/** /**
* Get the configured kubectl binaries path. * Get the configured kubectl binaries path.
*/ */
export function getKubectlPath(): string | undefined { getKubectlPath: () => string | undefined;
return UserStore.getInstance().kubectlBinariesPath;
} }
export const Preferences: UserPreferenceExtensionItems = {
getKubectlPath: () => UserStore.getInstance().kubectlBinariesPath,
};

View File

@ -4,14 +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/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 { 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, getAppVersion } 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;
openExternal: (url: string) => Promise<void>;
openBrowser: (url: string) => Promise<void>;
getAppVersion: () => string;
}
/** export const Util: UtilsExtensionItems = {
* @deprecated Use {@link openBrowser} instead Singleton,
*/ prevDefault,
export const openExternal = asLegacyGlobalFunctionForExtensionApi(openLinkInBrowserInjectable); stopPropagation,
export const openBrowser = asLegacyGlobalFunctionForExtensionApi(openLinkInBrowserInjectable); cssNames,
openExternal: asLegacyGlobalFunctionForExtensionApi(openLinkInBrowserInjectable),
openBrowser: asLegacyGlobalFunctionForExtensionApi(openLinkInBrowserInjectable),
getAppVersion: () => {
const di = getLegacyGlobalDiForExtensionApi();
return di.inject(buildVersionInjectable).get();
},
};

View File

@ -20,21 +20,20 @@ import watchInjectable from "../../common/fs/watch/watch.injectable";
const extensionDiscoveryInjectable = getInjectable({ const extensionDiscoveryInjectable = getInjectable({
id: "extension-discovery", id: "extension-discovery",
instantiate: (di) => instantiate: (di) => new ExtensionDiscovery({
new ExtensionDiscovery({ extensionLoader: di.inject(extensionLoaderInjectable),
extensionLoader: di.inject(extensionLoaderInjectable), extensionsStore: di.inject(extensionsStoreInjectable),
extensionsStore: di.inject(extensionsStoreInjectable), extensionInstallationStateStore: di.inject(extensionInstallationStateStoreInjectable),
extensionInstallationStateStore: di.inject(extensionInstallationStateStoreInjectable), isCompatibleExtension: di.inject(isCompatibleExtensionInjectable),
isCompatibleExtension: di.inject(isCompatibleExtensionInjectable), installExtension: di.inject(installExtensionInjectable),
installExtension: di.inject(installExtensionInjectable), installExtensions: di.inject(installExtensionsInjectable),
installExtensions: di.inject(installExtensionsInjectable), extensionPackageRootDirectory: di.inject(extensionPackageRootDirectoryInjectable),
extensionPackageRootDirectory: di.inject(extensionPackageRootDirectoryInjectable), staticFilesDirectory: di.inject(staticFilesDirectoryInjectable),
staticFilesDirectory: di.inject(staticFilesDirectoryInjectable), readJsonFile: di.inject(readJsonFileInjectable),
readJsonFile: di.inject(readJsonFileInjectable), pathExists: di.inject(pathExistsInjectable),
pathExists: di.inject(pathExistsInjectable), watch: di.inject(watchInjectable),
watch: di.inject(watchInjectable), logger: di.inject(loggerInjectable),
logger: di.inject(loggerInjectable), }),
}),
}); });
export default extensionDiscoveryInjectable; export default extensionDiscoveryInjectable;

View File

@ -15,10 +15,10 @@ import directoryForUserDataInjectable from "../../common/app-paths/directory-for
import mockFs from "mock-fs"; import mockFs from "mock-fs";
import { delay } from "../../renderer/utils"; import { delay } from "../../renderer/utils";
import { observable, when } from "mobx"; import { observable, when } from "mobx";
import appVersionInjectable from "../../common/vars/app-version.injectable";
import readJsonFileInjectable from "../../common/fs/read-json-file.injectable"; import readJsonFileInjectable from "../../common/fs/read-json-file.injectable";
import pathExistsInjectable from "../../common/fs/path-exists.injectable"; import pathExistsInjectable from "../../common/fs/path-exists.injectable";
import watchInjectable from "../../common/fs/watch/watch.injectable"; import watchInjectable from "../../common/fs/watch/watch.injectable";
import extensionApiVersionInjectable from "../../common/vars/extension-api-version.injectable";
console = new Console(process.stdout, process.stderr); // fix mockFS console = new Console(process.stdout, process.stderr); // fix mockFS
@ -33,7 +33,7 @@ describe("ExtensionDiscovery", () => {
di.override(directoryForUserDataInjectable, () => "some-directory-for-user-data"); di.override(directoryForUserDataInjectable, () => "some-directory-for-user-data");
di.override(installExtensionInjectable, () => () => Promise.resolve()); di.override(installExtensionInjectable, () => () => Promise.resolve());
di.override(appVersionInjectable, () => "5.0.0"); di.override(extensionApiVersionInjectable, () => "5.0.0");
readJsonFileMock = jest.fn(); readJsonFileMock = jest.fn();
di.override(readJsonFileInjectable, () => readJsonFileMock); di.override(readJsonFileInjectable, () => readJsonFileMock);

View File

@ -3,13 +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 { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import appSemanticVersionInjectable from "../../../common/vars/app-semantic-version.injectable"; import extensionApiVersionInjectable from "../../../common/vars/extension-api-version.injectable";
import { isCompatibleExtension } from "./is-compatible-extension"; import { isCompatibleExtension } from "./is-compatible-extension";
const isCompatibleExtensionInjectable = getInjectable({ const isCompatibleExtensionInjectable = getInjectable({
id: "is-compatible-extension", id: "is-compatible-extension",
instantiate: (di) => isCompatibleExtension({ instantiate: (di) => isCompatibleExtension({
appSemVer: di.inject(appSemanticVersionInjectable), extensionApiVersion: di.inject(extensionApiVersionInjectable),
}), }),
}); });

View File

@ -2,16 +2,15 @@
* 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 semver, { type SemVer } from "semver"; import semver from "semver";
import type { LensExtensionManifest } from "../../lens-extension"; import type { LensExtensionManifest } from "../../lens-extension";
interface Dependencies { interface Dependencies {
appSemVer: SemVer; extensionApiVersion: string;
} }
export const isCompatibleExtension = ({ appSemVer }: Dependencies): ((manifest: LensExtensionManifest) => boolean) => { export const isCompatibleExtension = ({ extensionApiVersion }: Dependencies): ((manifest: LensExtensionManifest) => boolean) => {
return (manifest: LensExtensionManifest): boolean => { return (manifest: LensExtensionManifest): boolean => {
const appVersion = appSemVer.raw.split("-")[0]; // drop prerelease version if any, e.g. "-alpha.0"
const manifestLensEngine = manifest.engines.lens; const manifestLensEngine = manifest.engines.lens;
const validVersion = manifestLensEngine.match(/^[\^0-9]\d*\.\d+\b/); // must start from ^ or number const validVersion = manifestLensEngine.match(/^[\^0-9]\d*\.\d+\b/); // must start from ^ or number
@ -30,7 +29,7 @@ export const isCompatibleExtension = ({ appSemVer }: Dependencies): ((manifest:
}) as semver.SemVer; }) as semver.SemVer;
const supportedVersionsByExtension = semver.validRange(`^${extMajor}.${extMinor}`) as string; const supportedVersionsByExtension = semver.validRange(`^${extMajor}.${extMinor}`) as string;
return semver.satisfies(appVersion, supportedVersionsByExtension, { return semver.satisfies(extensionApiVersion, supportedVersionsByExtension, {
loose: true, loose: true,
includePrerelease: false, includePrerelease: false,
}); });

View File

@ -76,7 +76,7 @@ exports[`extension special characters in page registrations renders 1`] = `
style="width: 320px;" style="width: 320px;"
> >
<h2> <h2>
Welcome to OpenLens! Welcome to some-product-name!
</h2> </h2>
<p> <p>
To get you started we have auto-detected your clusters in your To get you started we have auto-detected your clusters in your

View File

@ -76,7 +76,7 @@ exports[`navigate to extension page renders 1`] = `
style="width: 320px;" style="width: 320px;"
> >
<h2> <h2>
Welcome to OpenLens! Welcome to some-product-name!
</h2> </h2>
<p> <p>
To get you started we have auto-detected your clusters in your To get you started we have auto-detected your clusters in your

View File

@ -76,7 +76,7 @@ exports[`add-cluster - navigation using application menu renders 1`] = `
style="width: 320px;" style="width: 320px;"
> >
<h2> <h2>
Welcome to OpenLens! Welcome to some-product-name!
</h2> </h2>
<p> <p>
To get you started we have auto-detected your clusters in your To get you started we have auto-detected your clusters in your

View File

@ -95,7 +95,7 @@ exports[`force user to update when too long since update was downloaded when app
style="width: 320px;" style="width: 320px;"
> >
<h2> <h2>
Welcome to OpenLens! Welcome to some-product-name!
</h2> </h2>
<p> <p>
To get you started we have auto-detected your clusters in your To get you started we have auto-detected your clusters in your
@ -314,7 +314,7 @@ exports[`force user to update when too long since update was downloaded when app
style="width: 320px;" style="width: 320px;"
> >
<h2> <h2>
Welcome to OpenLens! Welcome to some-product-name!
</h2> </h2>
<p> <p>
To get you started we have auto-detected your clusters in your To get you started we have auto-detected your clusters in your
@ -580,7 +580,7 @@ exports[`force user to update when too long since update was downloaded when app
style="width: 320px;" style="width: 320px;"
> >
<h2> <h2>
Welcome to OpenLens! Welcome to some-product-name!
</h2> </h2>
<p> <p>
To get you started we have auto-detected your clusters in your To get you started we have auto-detected your clusters in your

View File

@ -95,7 +95,7 @@ exports[`encourage user to update when sufficient time passed since update was d
style="width: 320px;" style="width: 320px;"
> >
<h2> <h2>
Welcome to OpenLens! Welcome to some-product-name!
</h2> </h2>
<p> <p>
To get you started we have auto-detected your clusters in your To get you started we have auto-detected your clusters in your
@ -296,7 +296,7 @@ exports[`encourage user to update when sufficient time passed since update was d
style="width: 320px;" style="width: 320px;"
> >
<h2> <h2>
Welcome to OpenLens! Welcome to some-product-name!
</h2> </h2>
<p> <p>
To get you started we have auto-detected your clusters in your To get you started we have auto-detected your clusters in your

View File

@ -77,7 +77,7 @@ exports[`installing update using tray when started renders 1`] = `
style="width: 320px;" style="width: 320px;"
> >
<h2> <h2>
Welcome to OpenLens! Welcome to some-product-name!
</h2> </h2>
<p> <p>
To get you started we have auto-detected your clusters in your To get you started we have auto-detected your clusters in your
@ -278,7 +278,7 @@ exports[`installing update using tray when started when user checks for updates
style="width: 320px;" style="width: 320px;"
> >
<h2> <h2>
Welcome to OpenLens! Welcome to some-product-name!
</h2> </h2>
<p> <p>
To get you started we have auto-detected your clusters in your To get you started we have auto-detected your clusters in your
@ -479,7 +479,7 @@ exports[`installing update using tray when started when user checks for updates
style="width: 320px;" style="width: 320px;"
> >
<h2> <h2>
Welcome to OpenLens! Welcome to some-product-name!
</h2> </h2>
<p> <p>
To get you started we have auto-detected your clusters in your To get you started we have auto-detected your clusters in your
@ -698,7 +698,7 @@ exports[`installing update using tray when started when user checks for updates
style="width: 320px;" style="width: 320px;"
> >
<h2> <h2>
Welcome to OpenLens! Welcome to some-product-name!
</h2> </h2>
<p> <p>
To get you started we have auto-detected your clusters in your To get you started we have auto-detected your clusters in your
@ -917,7 +917,7 @@ exports[`installing update using tray when started when user checks for updates
style="width: 320px;" style="width: 320px;"
> >
<h2> <h2>
Welcome to OpenLens! Welcome to some-product-name!
</h2> </h2>
<p> <p>
To get you started we have auto-detected your clusters in your To get you started we have auto-detected your clusters in your
@ -1118,7 +1118,7 @@ exports[`installing update using tray when started when user checks for updates
style="width: 320px;" style="width: 320px;"
> >
<h2> <h2>
Welcome to OpenLens! Welcome to some-product-name!
</h2> </h2>
<p> <p>
To get you started we have auto-detected your clusters in your To get you started we have auto-detected your clusters in your

View File

@ -77,7 +77,7 @@ exports[`installing update when started renders 1`] = `
style="width: 320px;" style="width: 320px;"
> >
<h2> <h2>
Welcome to OpenLens! Welcome to some-product-name!
</h2> </h2>
<p> <p>
To get you started we have auto-detected your clusters in your To get you started we have auto-detected your clusters in your
@ -278,7 +278,7 @@ exports[`installing update when started when user checks for updates renders 1`]
style="width: 320px;" style="width: 320px;"
> >
<h2> <h2>
Welcome to OpenLens! Welcome to some-product-name!
</h2> </h2>
<p> <p>
To get you started we have auto-detected your clusters in your To get you started we have auto-detected your clusters in your
@ -479,7 +479,7 @@ exports[`installing update when started when user checks for updates when new up
style="width: 320px;" style="width: 320px;"
> >
<h2> <h2>
Welcome to OpenLens! Welcome to some-product-name!
</h2> </h2>
<p> <p>
To get you started we have auto-detected your clusters in your To get you started we have auto-detected your clusters in your
@ -698,7 +698,7 @@ exports[`installing update when started when user checks for updates when new up
style="width: 320px;" style="width: 320px;"
> >
<h2> <h2>
Welcome to OpenLens! Welcome to some-product-name!
</h2> </h2>
<p> <p>
To get you started we have auto-detected your clusters in your To get you started we have auto-detected your clusters in your
@ -917,7 +917,7 @@ exports[`installing update when started when user checks for updates when new up
style="width: 320px;" style="width: 320px;"
> >
<h2> <h2>
Welcome to OpenLens! Welcome to some-product-name!
</h2> </h2>
<p> <p>
To get you started we have auto-detected your clusters in your To get you started we have auto-detected your clusters in your
@ -1118,7 +1118,7 @@ exports[`installing update when started when user checks for updates when no new
style="width: 320px;" style="width: 320px;"
> >
<h2> <h2>
Welcome to OpenLens! Welcome to some-product-name!
</h2> </h2>
<p> <p>
To get you started we have auto-detected your clusters in your To get you started we have auto-detected your clusters in your

View File

@ -77,7 +77,7 @@ exports[`periodical checking of updates given updater is enabled and configurati
style="width: 320px;" style="width: 320px;"
> >
<h2> <h2>
Welcome to OpenLens! Welcome to some-product-name!
</h2> </h2>
<p> <p>
To get you started we have auto-detected your clusters in your To get you started we have auto-detected your clusters in your

View File

@ -77,7 +77,7 @@ exports[`selection of update stability when started renders 1`] = `
style="width: 320px;" style="width: 320px;"
> >
<h2> <h2>
Welcome to OpenLens! Welcome to some-product-name!
</h2> </h2>
<p> <p>
To get you started we have auto-detected your clusters in your To get you started we have auto-detected your clusters in your

View File

@ -16,10 +16,10 @@ import processCheckingForUpdatesInjectable from "../../main/application-update/c
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 quitAndInstallUpdateInjectable from "../../main/application-update/quit-and-install-update.injectable"; import quitAndInstallUpdateInjectable from "../../main/application-update/quit-and-install-update.injectable";
import appVersionInjectable from "../../common/vars/app-version.injectable";
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 getBuildVersionInjectable from "../../main/vars/build-version/get-build-version.injectable";
describe("analytics for installing update", () => { describe("analytics for installing update", () => {
let builder: ApplicationBuilder; let builder: ApplicationBuilder;
@ -36,7 +36,7 @@ describe("analytics for installing update", () => {
analyticsListenerMock = jest.fn(); analyticsListenerMock = jest.fn();
builder.beforeApplicationStart(mainDi => { builder.beforeApplicationStart(mainDi => {
mainDi.override(appVersionInjectable, () => "42.0.0"); mainDi.override(getBuildVersionInjectable, () => () => "42.0.0");
checkForPlatformUpdatesMock = asyncFn(); checkForPlatformUpdatesMock = asyncFn();

View File

@ -13,8 +13,8 @@ import checkForPlatformUpdatesInjectable from "../../main/application-update/che
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 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 appVersionInjectable from "../../common/vars/app-version.injectable";
import { updateChannels } from "../../common/application-update/update-channels"; import { updateChannels } from "../../common/application-update/update-channels";
import getBuildVersionInjectable from "../../main/vars/build-version/get-build-version.injectable";
describe("downgrading version update", () => { describe("downgrading version update", () => {
let applicationBuilder: ApplicationBuilder; let applicationBuilder: ApplicationBuilder;
@ -102,7 +102,7 @@ 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(appVersionInjectable, () => appVersion); mainDi.override(getBuildVersionInjectable, () => () => appVersion);
await applicationBuilder.render(); await applicationBuilder.render();

View File

@ -12,7 +12,7 @@ import type { CheckForPlatformUpdates } from "../../main/application-update/chec
import checkForPlatformUpdatesInjectable from "../../main/application-update/check-for-platform-updates/check-for-platform-updates.injectable"; import checkForPlatformUpdatesInjectable from "../../main/application-update/check-for-platform-updates/check-for-platform-updates.injectable";
import type { AsyncFnMock } from "@async-fn/jest"; import type { AsyncFnMock } from "@async-fn/jest";
import asyncFn from "@async-fn/jest"; import asyncFn from "@async-fn/jest";
import type { UpdateChannel, UpdateChannelId } from "../../common/application-update/update-channels"; import type { UpdateChannel, ReleaseChannel } from "../../common/application-update/update-channels";
import { updateChannels } from "../../common/application-update/update-channels"; import { updateChannels } from "../../common/application-update/update-channels";
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";
@ -21,8 +21,8 @@ import type { IComputedValue } from "mobx";
import setUpdateOnQuitInjectable from "../../main/electron-app/features/set-update-on-quit.injectable"; import setUpdateOnQuitInjectable from "../../main/electron-app/features/set-update-on-quit.injectable";
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 appVersionInjectable from "../../common/vars/app-version.injectable";
import type { DiContainer } from "@ogre-tools/injectable"; import type { DiContainer } from "@ogre-tools/injectable";
import getBuildVersionInjectable from "../../main/vars/build-version/get-build-version.injectable";
describe("selection of update stability", () => { describe("selection of update stability", () => {
let builder: ApplicationBuilder; let builder: ApplicationBuilder;
@ -89,7 +89,7 @@ describe("selection of update stability", () => {
describe('given update channel "alpha" is selected, when checking for updates', () => { describe('given update channel "alpha" is selected, when checking for updates', () => {
let selectedUpdateChannel: { let selectedUpdateChannel: {
value: IComputedValue<UpdateChannel>; value: IComputedValue<UpdateChannel>;
setValue: (channelId: UpdateChannelId) => void; setValue: (channelId: ReleaseChannel) => void;
}; };
beforeEach(() => { beforeEach(() => {
@ -180,7 +180,7 @@ describe("selection of update stability", () => {
describe('given update channel "beta" is selected', () => { describe('given update channel "beta" is selected', () => {
let selectedUpdateChannel: { let selectedUpdateChannel: {
value: IComputedValue<UpdateChannel>; value: IComputedValue<UpdateChannel>;
setValue: (channelId: UpdateChannelId) => void; setValue: (channelId: ReleaseChannel) => void;
}; };
beforeEach(() => { beforeEach(() => {
@ -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 () => { 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(); 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); const processCheckingForUpdates = mainDi.inject(processCheckingForUpdatesInjectable);
processCheckingForUpdates("irrelevant"); 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 () => { 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 UpdateChannelId);
});
await builder.render(); 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); const processCheckingForUpdates = mainDi.inject(processCheckingForUpdatesInjectable);
processCheckingForUpdates("irrelevant"); processCheckingForUpdates("irrelevant");
@ -268,7 +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 () => { 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(appVersionInjectable, () => "1.0.0"); mainDi.override(getBuildVersionInjectable, () => () => "1.0.0");
}); });
await builder.render(); await builder.render();
@ -285,7 +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 () => { 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(appVersionInjectable, () => "1.0.0-alpha"); mainDi.override(getBuildVersionInjectable, () => () => "1.0.0-alpha");
}); });
await builder.render(); await builder.render();
@ -299,7 +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 () => { 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(appVersionInjectable, () => "1.0.0-beta"); mainDi.override(getBuildVersionInjectable, () => () => "1.0.0-beta");
}); });
await builder.render(); await builder.render();
@ -312,18 +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 () => { 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(appVersionInjectable, () => "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(); 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); const processCheckingForUpdates = mainDi.inject(processCheckingForUpdatesInjectable);
processCheckingForUpdates("irrelevant"); processCheckingForUpdates("irrelevant");

View File

@ -158,7 +158,7 @@ exports[`Command Pallet: keyboard shortcut tests when on linux renders 1`] = `
style="width: 320px;" style="width: 320px;"
> >
<h2> <h2>
Welcome to OpenLens! Welcome to some-product-name!
</h2> </h2>
<p> <p>
To get you started we have auto-detected your clusters in your To get you started we have auto-detected your clusters in your
@ -440,7 +440,7 @@ exports[`Command Pallet: keyboard shortcut tests when on linux when pressing ESC
style="width: 320px;" style="width: 320px;"
> >
<h2> <h2>
Welcome to OpenLens! Welcome to some-product-name!
</h2> </h2>
<p> <p>
To get you started we have auto-detected your clusters in your To get you started we have auto-detected your clusters in your
@ -722,7 +722,7 @@ exports[`Command Pallet: keyboard shortcut tests when on linux when pressing SHI
style="width: 320px;" style="width: 320px;"
> >
<h2> <h2>
Welcome to OpenLens! Welcome to some-product-name!
</h2> </h2>
<p> <p>
To get you started we have auto-detected your clusters in your To get you started we have auto-detected your clusters in your
@ -1016,7 +1016,7 @@ exports[`Command Pallet: keyboard shortcut tests when on linux when pressing SHI
style="width: 320px;" style="width: 320px;"
> >
<h2> <h2>
Welcome to OpenLens! Welcome to some-product-name!
</h2> </h2>
<p> <p>
To get you started we have auto-detected your clusters in your To get you started we have auto-detected your clusters in your
@ -1217,7 +1217,7 @@ exports[`Command Pallet: keyboard shortcut tests when on macOS renders 1`] = `
style="width: 320px;" style="width: 320px;"
> >
<h2> <h2>
Welcome to OpenLens! Welcome to some-product-name!
</h2> </h2>
<p> <p>
To get you started we have auto-detected your clusters in your To get you started we have auto-detected your clusters in your
@ -1418,7 +1418,7 @@ exports[`Command Pallet: keyboard shortcut tests when on macOS when pressing ESC
style="width: 320px;" style="width: 320px;"
> >
<h2> <h2>
Welcome to OpenLens! Welcome to some-product-name!
</h2> </h2>
<p> <p>
To get you started we have auto-detected your clusters in your To get you started we have auto-detected your clusters in your
@ -1619,7 +1619,7 @@ exports[`Command Pallet: keyboard shortcut tests when on macOS when pressing SHI
style="width: 320px;" style="width: 320px;"
> >
<h2> <h2>
Welcome to OpenLens! Welcome to some-product-name!
</h2> </h2>
<p> <p>
To get you started we have auto-detected your clusters in your To get you started we have auto-detected your clusters in your
@ -1832,7 +1832,7 @@ exports[`Command Pallet: keyboard shortcut tests when on macOS when pressing SHI
style="width: 320px;" style="width: 320px;"
> >
<h2> <h2>
Welcome to OpenLens! Welcome to some-product-name!
</h2> </h2>
<p> <p>
To get you started we have auto-detected your clusters in your To get you started we have auto-detected your clusters in your

View File

@ -76,7 +76,7 @@ exports[`extensions - navigation using application menu renders 1`] = `
style="width: 320px;" style="width: 320px;"
> >
<h2> <h2>
Welcome to OpenLens! Welcome to some-product-name!
</h2> </h2>
<p> <p>
To get you started we have auto-detected your clusters in your To get you started we have auto-detected your clusters in your

View File

@ -76,7 +76,7 @@ exports[`preferences - navigation using application menu renders 1`] = `
style="width: 320px;" style="width: 320px;"
> >
<h2> <h2>
Welcome to OpenLens! Welcome to some-product-name!
</h2> </h2>
<p> <p>
To get you started we have auto-detected your clusters in your To get you started we have auto-detected your clusters in your

View File

@ -77,7 +77,7 @@ exports[`show-about-using-tray renders 1`] = `
style="width: 320px;" style="width: 320px;"
> >
<h2> <h2>
Welcome to OpenLens! Welcome to some-product-name!
</h2> </h2>
<p> <p>
To get you started we have auto-detected your clusters in your To get you started we have auto-detected your clusters in your

View File

@ -7,7 +7,7 @@ import React from "react";
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 navigateToTelemetryPreferencesInjectable from "../../common/front-end-routing/routes/preferences/telemetry/navigate-to-telemetry-preferences.injectable"; import navigateToTelemetryPreferencesInjectable from "../../common/front-end-routing/routes/preferences/telemetry/navigate-to-telemetry-preferences.injectable";
import sentryDnsUrlInjectable from "../../renderer/components/+preferences/sentry-dns-url.injectable"; import sentryDataSourceNameInjectable from "../../common/vars/sentry-dsn-url.injectable";
import type { FakeExtensionOptions } from "../../renderer/components/test-utils/get-extension-fake"; import type { FakeExtensionOptions } from "../../renderer/components/test-utils/get-extension-fake";
describe("preferences - navigation to telemetry preferences", () => { describe("preferences - navigation to telemetry preferences", () => {
@ -114,7 +114,7 @@ describe("preferences - navigation to telemetry preferences", () => {
beforeEach(async () => { beforeEach(async () => {
builder.beforeWindowStart((windowDi) => { builder.beforeWindowStart((windowDi) => {
windowDi.override(sentryDnsUrlInjectable, () => "some-sentry-dns-url"); windowDi.override(sentryDataSourceNameInjectable, () => "some-sentry-dns-url");
}); });
rendered = await builder.render(); rendered = await builder.render();
@ -144,7 +144,7 @@ describe("preferences - navigation to telemetry preferences", () => {
beforeEach(async () => { beforeEach(async () => {
builder.beforeWindowStart((windowDi) => { builder.beforeWindowStart((windowDi) => {
windowDi.override(sentryDnsUrlInjectable, () => null); windowDi.override(sentryDataSourceNameInjectable, () => null);
}); });
rendered = await builder.render(); rendered = await builder.render();

View File

@ -77,7 +77,7 @@ exports[`status-bar-items-originating-from-extensions when application starts wh
style="width: 320px;" style="width: 320px;"
> >
<h2> <h2>
Welcome to OpenLens! Welcome to some-product-name!
</h2> </h2>
<p> <p>
To get you started we have auto-detected your clusters in your To get you started we have auto-detected your clusters in your

View File

@ -76,7 +76,7 @@ exports[`welcome - navigation using application menu renders 1`] = `
style="width: 320px;" style="width: 320px;"
> >
<h2> <h2>
Welcome to OpenLens! Welcome to some-product-name!
</h2> </h2>
<p> <p>
To get you started we have auto-detected your clusters in your To get you started we have auto-detected your clusters in your
@ -915,7 +915,7 @@ exports[`welcome - navigation using application menu when navigated somewhere el
style="width: 320px;" style="width: 320px;"
> >
<h2> <h2>
Welcome to OpenLens! Welcome to some-product-name!
</h2> </h2>
<p> <p>
To get you started we have auto-detected your clusters in your To get you started we have auto-detected your clusters in your

View File

@ -6,7 +6,6 @@ import { getInjectable } from "@ogre-tools/injectable";
import type { AppPaths } from "../../common/app-paths/app-path-injection-token"; import type { AppPaths } from "../../common/app-paths/app-path-injection-token";
import getElectronAppPathInjectable from "./get-electron-app-path/get-electron-app-path.injectable"; import getElectronAppPathInjectable from "./get-electron-app-path/get-electron-app-path.injectable";
import setElectronAppPathInjectable from "./set-electron-app-path/set-electron-app-path.injectable"; import setElectronAppPathInjectable from "./set-electron-app-path/set-electron-app-path.injectable";
import appNameInjectable from "./app-name/app-name.injectable";
import directoryForIntegrationTestingInjectable from "./directory-for-integration-testing/directory-for-integration-testing.injectable"; import directoryForIntegrationTestingInjectable from "./directory-for-integration-testing/directory-for-integration-testing.injectable";
import appPathsStateInjectable from "../../common/app-paths/app-paths-state.injectable"; import appPathsStateInjectable from "../../common/app-paths/app-paths-state.injectable";
import { pathNames } from "../../common/app-paths/app-path-names"; import { pathNames } from "../../common/app-paths/app-path-names";
@ -14,6 +13,7 @@ import { fromPairs, map } from "lodash/fp";
import { pipeline } from "@ogre-tools/fp"; import { pipeline } from "@ogre-tools/fp";
import joinPathsInjectable from "../../common/path/join-paths.injectable"; import joinPathsInjectable from "../../common/path/join-paths.injectable";
import { beforeElectronIsReadyInjectionToken } from "../start-main-application/runnable-tokens/before-electron-is-ready-injection-token"; import { beforeElectronIsReadyInjectionToken } from "../start-main-application/runnable-tokens/before-electron-is-ready-injection-token";
import appNameInjectable from "../../common/vars/app-name.injectable";
const setupAppPathsInjectable = getInjectable({ const setupAppPathsInjectable = getInjectable({
id: "setup-app-paths", id: "setup-app-paths",

View File

@ -9,7 +9,7 @@ import asyncFn from "@async-fn/jest";
import type { AppUpdater, UpdateCheckResult } from "electron-updater"; import type { AppUpdater, UpdateCheckResult } from "electron-updater";
import type { CheckForPlatformUpdates } from "./check-for-platform-updates.injectable"; import type { CheckForPlatformUpdates } from "./check-for-platform-updates.injectable";
import checkForPlatformUpdatesInjectable from "./check-for-platform-updates.injectable"; import checkForPlatformUpdatesInjectable from "./check-for-platform-updates.injectable";
import type { UpdateChannel, UpdateChannelId } from "../../../common/application-update/update-channels"; import type { UpdateChannel, ReleaseChannel } from "../../../common/application-update/update-channels";
import { getPromiseStatus } from "../../../common/test-utils/get-promise-status"; import { getPromiseStatus } from "../../../common/test-utils/get-promise-status";
import loggerInjectable from "../../../common/logger.injectable"; import loggerInjectable from "../../../common/logger.injectable";
import type { Logger } from "../../../common/logger"; import type { Logger } from "../../../common/logger";
@ -47,7 +47,7 @@ describe("check-for-platform-updates", () => {
beforeEach(() => { beforeEach(() => {
const testUpdateChannel: UpdateChannel = { const testUpdateChannel: UpdateChannel = {
id: "some-update-channel" as UpdateChannelId, id: "some-update-channel" as ReleaseChannel,
label: "Some update channel", label: "Some update channel",
moreStableUpdateChannel: null, moreStableUpdateChannel: null,
}; };

View File

@ -6,14 +6,14 @@ 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 appVersionInjectable from "../../common/vars/app-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",
instantiate: (di) => { instantiate: (di) => {
const emitEvent = di.inject(emitEventInjectable); const emitEvent = di.inject(emitEventInjectable);
const appVersion = di.inject(appVersionInjectable); const buildVersion = di.inject(buildVersionInjectable);
return { return {
run: () => { run: () => {
@ -22,7 +22,7 @@ const emitCurrentVersionToAnalyticsInjectable = getInjectable({
action: "current-version", action: "current-version",
params: { params: {
version: appVersion, version: buildVersion.get(),
currentDateTime: getCurrentDateTime(), currentDateTime: getCurrentDateTime(),
}, },
}); });

View File

@ -3,18 +3,11 @@
* 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 packageJsonInjectable from "../../common/vars/package-json.injectable"; import applicationInformationInjectable from "../../common/vars/application-information.injectable";
import { has } from "lodash/fp";
// TOOO: Rename to something less technical
const publishIsConfiguredInjectable = getInjectable({ const publishIsConfiguredInjectable = getInjectable({
id: "publish-is-configured", id: "publish-is-configured",
instantiate: (di) => Boolean(di.inject(applicationInformationInjectable).build.publish?.length),
instantiate: (di) => {
const packageJson = di.inject(packageJsonInjectable);
return has("build.publish", packageJson);
},
}); });
export default publishIsConfiguredInjectable; export default publishIsConfiguredInjectable;

View 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 { requestChannelListenerInjectionToken } from "../../common/utils/channel/request-channel-listener-injection-token";
import { buildVersionChannel } from "../../common/vars/build-semantic-version.injectable";
import buildVersionInjectable from "../vars/build-version/build-version.injectable";
const setupBuildVersionRequestChannelInjectable = getInjectable({
id: "setup-build-version-request-channel",
instantiate: (di) => {
const buildVersion = di.inject(buildVersionInjectable);
return {
channel: buildVersionChannel,
handler: () => buildVersion.get(),
};
},
injectionToken: requestChannelListenerInjectionToken,
});
export default setupBuildVersionRequestChannelInjectable;

View File

@ -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));

View File

@ -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 appNameInjectable from "../../app-paths/app-name/app-name.injectable"; import appNameInjectable from "../../../common/vars/app-name.injectable";
import { beforeElectronIsReadyInjectionToken } from "../../start-main-application/runnable-tokens/before-electron-is-ready-injection-token"; import { beforeElectronIsReadyInjectionToken } from "../../start-main-application/runnable-tokens/before-electron-is-ready-injection-token";
import electronAppInjectable from "../electron-app.injectable"; import electronAppInjectable from "../electron-app.injectable";

View File

@ -7,7 +7,6 @@ import { kebabCase, noop, chunk } from "lodash/fp";
import type { DiContainer, Injectable } from "@ogre-tools/injectable"; import type { DiContainer, Injectable } from "@ogre-tools/injectable";
import { createContainer } from "@ogre-tools/injectable"; import { createContainer } from "@ogre-tools/injectable";
import { Environments, setLegacyGlobalDiForExtensionApi } from "../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api"; import { Environments, setLegacyGlobalDiForExtensionApi } from "../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
import appNameInjectable from "./app-paths/app-name/app-name.injectable";
import writeJsonFileInjectable from "../common/fs/write-json-file.injectable"; import writeJsonFileInjectable from "../common/fs/write-json-file.injectable";
import readJsonFileInjectable from "../common/fs/read-json-file.injectable"; import readJsonFileInjectable from "../common/fs/read-json-file.injectable";
import readFileInjectable from "../common/fs/read-file.injectable"; import readFileInjectable from "../common/fs/read-file.injectable";
@ -33,7 +32,6 @@ import lensResourcesDirInjectable from "../common/vars/lens-resources-dir.inject
import environmentVariablesInjectable from "../common/utils/environment-variables.injectable"; import environmentVariablesInjectable from "../common/utils/environment-variables.injectable";
import setupIpcMainHandlersInjectable from "./electron-app/runnables/setup-ipc-main-handlers/setup-ipc-main-handlers.injectable"; import setupIpcMainHandlersInjectable from "./electron-app/runnables/setup-ipc-main-handlers/setup-ipc-main-handlers.injectable";
import setupLensProxyInjectable from "./start-main-application/runnables/setup-lens-proxy.injectable"; import setupLensProxyInjectable from "./start-main-application/runnables/setup-lens-proxy.injectable";
import setupSentryInjectable from "./start-main-application/runnables/setup-sentry.injectable";
import setupShellInjectable from "./start-main-application/runnables/setup-shell.injectable"; import setupShellInjectable from "./start-main-application/runnables/setup-shell.injectable";
import setupSyncingOfWeblinksInjectable from "./start-main-application/runnables/setup-syncing-of-weblinks.injectable"; import setupSyncingOfWeblinksInjectable from "./start-main-application/runnables/setup-syncing-of-weblinks.injectable";
import stopServicesAndExitAppInjectable from "./stop-services-and-exit-app.injectable"; import stopServicesAndExitAppInjectable from "./stop-services-and-exit-app.injectable";
@ -63,7 +61,6 @@ import broadcastMessageInjectable from "../common/ipc/broadcast-message.injectab
import getElectronThemeInjectable from "./electron-app/features/get-electron-theme.injectable"; import getElectronThemeInjectable from "./electron-app/features/get-electron-theme.injectable";
import syncThemeFromOperatingSystemInjectable from "./electron-app/features/sync-theme-from-operating-system.injectable"; import syncThemeFromOperatingSystemInjectable from "./electron-app/features/sync-theme-from-operating-system.injectable";
import platformInjectable from "../common/vars/platform.injectable"; import platformInjectable from "../common/vars/platform.injectable";
import productNameInjectable from "./app-paths/app-name/product-name.injectable";
import electronQuitAndInstallUpdateInjectable from "./electron-app/features/electron-quit-and-install-update.injectable"; import electronQuitAndInstallUpdateInjectable from "./electron-app/features/electron-quit-and-install-update.injectable";
import electronUpdaterIsActiveInjectable from "./electron-app/features/electron-updater-is-active.injectable"; import electronUpdaterIsActiveInjectable from "./electron-app/features/electron-updater-is-active.injectable";
import publishIsConfiguredInjectable from "./application-update/publish-is-configured.injectable"; import publishIsConfiguredInjectable from "./application-update/publish-is-configured.injectable";
@ -73,7 +70,6 @@ import setUpdateOnQuitInjectable from "./electron-app/features/set-update-on-qui
import downloadPlatformUpdateInjectable from "./application-update/download-platform-update/download-platform-update.injectable"; import downloadPlatformUpdateInjectable from "./application-update/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 appVersionInjectable from "../common/vars/app-version.injectable";
import getRandomIdInjectable from "../common/utils/get-random-id.injectable"; import getRandomIdInjectable from "../common/utils/get-random-id.injectable";
import periodicalCheckForUpdatesInjectable from "./application-update/periodical-check-for-updates/periodical-check-for-updates.injectable"; import periodicalCheckForUpdatesInjectable from "./application-update/periodical-check-for-updates/periodical-check-for-updates.injectable";
import execFileInjectable from "../common/fs/exec-file.injectable"; import execFileInjectable from "../common/fs/exec-file.injectable";
@ -148,9 +144,6 @@ export function getDiForUnitTesting(opts: { doGeneralOverrides?: boolean } = {})
di.override(environmentVariablesInjectable, () => ({})); di.override(environmentVariablesInjectable, () => ({}));
di.override(commandLineArgumentsInjectable, () => []); di.override(commandLineArgumentsInjectable, () => []);
di.override(productNameInjectable, () => "some-product-name");
di.override(appVersionInjectable, () => "1.0.0");
di.override(clusterFramesInjectable, () => observable.map<string, ClusterFrameInfo>()); di.override(clusterFramesInjectable, () => observable.map<string, ClusterFrameInfo>());
di.override(stopServicesAndExitAppInjectable, () => () => {}); di.override(stopServicesAndExitAppInjectable, () => () => {});
@ -179,7 +172,6 @@ export function getDiForUnitTesting(opts: { doGeneralOverrides?: boolean } = {})
// 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]>());
di.override(appNameInjectable, () => "some-app-name");
di.override(broadcastMessageInjectable, () => (channel) => { di.override(broadcastMessageInjectable, () => (channel) => {
throw new Error(`Tried to broadcast message to channel "${channel}" over IPC without explicit override.`); throw new Error(`Tried to broadcast message to channel "${channel}" over IPC without explicit override.`);
}); });
@ -210,7 +202,6 @@ const overrideRunnablesHavingSideEffects = (di: DiContainer) => {
initializeExtensionsInjectable, initializeExtensionsInjectable,
setupIpcMainHandlersInjectable, setupIpcMainHandlersInjectable,
setupLensProxyInjectable, setupLensProxyInjectable,
setupSentryInjectable,
setupShellInjectable, setupShellInjectable,
setupSyncingOfWeblinksInjectable, setupSyncingOfWeblinksInjectable,
setupSystemCaInjectable, setupSystemCaInjectable,

View File

@ -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 { getBundledKubectlVersion } from "../../common/utils"; import bundledKubectlVersionInjectable from "../../common/vars/bundled-kubectl-version.injectable";
import createKubectlInjectable from "./create-kubectl.injectable"; import createKubectlInjectable from "./create-kubectl.injectable";
const bundledKubectlInjectable = getInjectable({ const bundledKubectlInjectable = getInjectable({
@ -11,8 +11,7 @@ const bundledKubectlInjectable = getInjectable({
instantiate: (di) => { instantiate: (di) => {
const createKubectl = di.inject(createKubectlInjectable); const createKubectl = di.inject(createKubectlInjectable);
const bundledKubectlVersion = di.inject(bundledKubectlVersionInjectable);
const bundledKubectlVersion = getBundledKubectlVersion();
return createKubectl(bundledKubectlVersion); return createKubectl(bundledKubectlVersion);
}, },

View File

@ -12,6 +12,8 @@ import normalizedPlatformInjectable from "../../common/vars/normalized-platform.
import kubectlBinaryNameInjectable from "./binary-name.injectable"; import kubectlBinaryNameInjectable from "./binary-name.injectable";
import bundledKubectlBinaryPathInjectable from "./bundled-binary-path.injectable"; import bundledKubectlBinaryPathInjectable from "./bundled-binary-path.injectable";
import baseBundledBinariesDirectoryInjectable from "../../common/vars/base-bundled-binaries-dir.injectable"; import baseBundledBinariesDirectoryInjectable from "../../common/vars/base-bundled-binaries-dir.injectable";
import bundledKubectlVersionInjectable from "../../common/vars/bundled-kubectl-version.injectable";
import kubectlVersionMapInjectable from "./version-map.injectable";
const createKubectlInjectable = getInjectable({ const createKubectlInjectable = getInjectable({
id: "create-kubectl", id: "create-kubectl",
@ -25,6 +27,8 @@ const createKubectlInjectable = getInjectable({
kubectlBinaryName: di.inject(kubectlBinaryNameInjectable), kubectlBinaryName: di.inject(kubectlBinaryNameInjectable),
bundledKubectlBinaryPath: di.inject(bundledKubectlBinaryPathInjectable), bundledKubectlBinaryPath: di.inject(bundledKubectlBinaryPathInjectable),
baseBundeledBinariesDirectory: di.inject(baseBundledBinariesDirectoryInjectable), baseBundeledBinariesDirectory: di.inject(baseBundledBinariesDirectoryInjectable),
bundledKubectlVersion: di.inject(bundledKubectlVersionInjectable),
kubectlVersionMap: di.inject(kubectlVersionMapInjectable),
}; };
return (clusterVersion: string) => new Kubectl(dependencies, clusterVersion); return (clusterVersion: string) => new Kubectl(dependencies, clusterVersion);

View File

@ -9,7 +9,6 @@ import { promiseExecFile } from "../../common/utils/promise-exec";
import logger from "../logger"; import logger from "../logger";
import { ensureDir, pathExists } from "fs-extra"; import { ensureDir, pathExists } from "fs-extra";
import * as lockFile from "proper-lockfile"; import * as lockFile from "proper-lockfile";
import { getBundledKubectlVersion } from "../../common/utils/app-version";
import { SemVer } from "semver"; import { SemVer } from "semver";
import { defaultPackageMirror, packageMirrors } from "../../common/user-store/preferences-helpers"; import { defaultPackageMirror, packageMirrors } from "../../common/user-store/preferences-helpers";
import got from "got/dist/source"; import got from "got/dist/source";
@ -17,26 +16,6 @@ import { promisify } from "util";
import stream from "stream"; import stream from "stream";
import { noop } from "lodash/fp"; import { noop } from "lodash/fp";
const bundledVersion = getBundledKubectlVersion();
const kubectlMap: Map<string, string> = new Map([
["1.7", "1.8.15"],
["1.8", "1.9.10"],
["1.9", "1.10.13"],
["1.10", "1.11.10"],
["1.11", "1.12.10"],
["1.12", "1.13.12"],
["1.13", "1.13.12"],
["1.14", "1.14.10"],
["1.15", "1.15.11"],
["1.16", "1.16.15"],
["1.17", "1.17.17"],
["1.18", "1.18.20"],
["1.19", "1.19.12"],
["1.20", "1.20.8"],
["1.21", "1.21.9"],
["1.22", "1.22.6"],
["1.23", bundledVersion],
]);
const initScriptVersionString = "# lens-initscript v3"; const initScriptVersionString = "# lens-initscript v3";
export interface KubectlDependencies { export interface KubectlDependencies {
@ -52,6 +31,8 @@ export interface KubectlDependencies {
readonly downloadKubectlBinaries: boolean; readonly downloadKubectlBinaries: boolean;
readonly downloadMirror: string; readonly downloadMirror: string;
}; };
readonly bundledKubectlVersion: string;
readonly kubectlVersionMap: Map<string, string>;
} }
export class Kubectl { export class Kubectl {
@ -60,7 +41,6 @@ export class Kubectl {
protected readonly path: string; protected readonly path: string;
protected readonly dirname: string; protected readonly dirname: string;
public static readonly bundledKubectlVersion = bundledVersion;
public static invalidBundle = false; public static invalidBundle = false;
constructor(protected readonly dependencies: KubectlDependencies, clusterVersion: string) { constructor(protected readonly dependencies: KubectlDependencies, clusterVersion: string) {
@ -69,10 +49,10 @@ export class Kubectl {
try { try {
version = new SemVer(clusterVersion); version = new SemVer(clusterVersion);
} catch { } catch {
version = new SemVer(Kubectl.bundledKubectlVersion); version = new SemVer(this.dependencies.bundledKubectlVersion);
} }
const fromMajorMinor = kubectlMap.get(`${version.major}.${version.minor}`); const fromMajorMinor = this.dependencies.kubectlVersionMap.get(`${version.major}.${version.minor}`);
/** /**
* minorVersion is the first two digits of kube server version if the version map includes that, * minorVersion is the first two digits of kube server version if the version map includes that,
@ -189,7 +169,7 @@ export class Kubectl {
} }
protected async checkBundled(): Promise<boolean> { protected async checkBundled(): Promise<boolean> {
if (this.kubectlVersion === Kubectl.bundledKubectlVersion) { if (this.kubectlVersion === this.dependencies.bundledKubectlVersion) {
try { try {
const exist = await pathExists(this.path); const exist = await pathExists(this.path);

View File

@ -0,0 +1,35 @@
/**
* 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 bundledKubectlVersionInjectable from "../../common/vars/bundled-kubectl-version.injectable";
const kubectlVersionMapInjectable = getInjectable({
id: "kubectl-version-map",
instantiate: (di) => {
const bundledKubectlVersion = di.inject(bundledKubectlVersionInjectable);
return new Map([
["1.7", "1.8.15"],
["1.8", "1.9.10"],
["1.9", "1.10.13"],
["1.10", "1.11.10"],
["1.11", "1.12.10"],
["1.12", "1.13.12"],
["1.13", "1.13.12"],
["1.14", "1.14.10"],
["1.15", "1.15.11"],
["1.16", "1.16.15"],
["1.17", "1.17.17"],
["1.18", "1.18.20"],
["1.19", "1.19.12"],
["1.20", "1.20.8"],
["1.21", "1.21.9"],
["1.22", "1.22.6"],
["1.23", bundledKubectlVersion],
]);
},
});
export default kubectlVersionMapInjectable;

View File

@ -10,26 +10,20 @@ import httpProxy from "http-proxy";
import clusterManagerInjectable from "../cluster-manager.injectable"; import clusterManagerInjectable from "../cluster-manager.injectable";
import shellApiRequestInjectable from "./proxy-functions/shell-api-request/shell-api-request.injectable"; import shellApiRequestInjectable from "./proxy-functions/shell-api-request/shell-api-request.injectable";
import lensProxyPortInjectable from "./lens-proxy-port.injectable"; import lensProxyPortInjectable from "./lens-proxy-port.injectable";
import contentSecurityPolicyInjectable from "../../common/vars/content-security-policy.injectable";
const lensProxyInjectable = getInjectable({ const lensProxyInjectable = getInjectable({
id: "lens-proxy", id: "lens-proxy",
instantiate: (di) => { instantiate: (di) => new LensProxy({
const clusterManager = di.inject(clusterManagerInjectable); router: di.inject(routerInjectable),
const router = di.inject(routerInjectable); proxy: httpProxy.createProxy(),
const shellApiRequest = di.inject(shellApiRequestInjectable); kubeApiUpgradeRequest,
const proxy = httpProxy.createProxy(); shellApiRequest: di.inject(shellApiRequestInjectable),
const lensProxyPort = di.inject(lensProxyPortInjectable); getClusterForRequest: di.inject(clusterManagerInjectable).getClusterForRequest,
lensProxyPort: di.inject(lensProxyPortInjectable),
return new LensProxy({ contentSecurityPolicy: di.inject(contentSecurityPolicyInjectable),
router, }),
proxy,
kubeApiUpgradeRequest,
shellApiRequest,
getClusterForRequest: clusterManager.getClusterForRequest,
lensProxyPort,
});
},
}); });
export default lensProxyInjectable; export default lensProxyInjectable;

View File

@ -7,7 +7,7 @@ import net from "net";
import type http from "http"; import type http from "http";
import spdy from "spdy"; import spdy from "spdy";
import type httpProxy from "http-proxy"; import type httpProxy from "http-proxy";
import { apiPrefix, apiKubePrefix, contentSecurityPolicy } from "../../common/vars"; import { apiPrefix, apiKubePrefix } from "../../common/vars";
import type { Router } from "../router/router"; import type { Router } from "../router/router";
import type { ClusterContextHandler } from "../context-handler/context-handler"; import type { ClusterContextHandler } from "../context-handler/context-handler";
import logger from "../logger"; import logger from "../logger";
@ -26,9 +26,10 @@ interface Dependencies {
getClusterForRequest: GetClusterForRequest; getClusterForRequest: GetClusterForRequest;
shellApiRequest: (args: ProxyApiRequestArgs) => void | Promise<void>; shellApiRequest: (args: ProxyApiRequestArgs) => void | Promise<void>;
kubeApiUpgradeRequest: (args: ProxyApiRequestArgs) => void | Promise<void>; kubeApiUpgradeRequest: (args: ProxyApiRequestArgs) => void | Promise<void>;
router: Router; readonly router: Router;
proxy: httpProxy; readonly proxy: httpProxy;
lensProxyPort: { set: (portNumber: number) => void }; readonly lensProxyPort: { set: (portNumber: number) => void };
readonly contentSecurityPolicy: string;
} }
const watchParam = "watch"; const watchParam = "watch";
@ -63,7 +64,7 @@ export class LensProxy {
protected closed = false; protected closed = false;
protected retryCounters = new Map<string, number>(); protected retryCounters = new Map<string, number>();
constructor(private dependencies: Dependencies) { constructor(private readonly dependencies: Dependencies) {
this.configureProxy(dependencies.proxy); this.configureProxy(dependencies.proxy);
this.proxyServer = spdy.createServer({ this.proxyServer = spdy.createServer({
@ -239,10 +240,7 @@ export class LensProxy {
} }
} }
if (contentSecurityPolicy) { res.setHeader("Content-Security-Policy", this.dependencies.contentSecurityPolicy);
res.setHeader("Content-Security-Policy", contentSecurityPolicy);
}
this.dependencies.router.route(cluster, req, res); this.dependencies.router.route(cluster, req, res);
} }
} }

View File

@ -3,12 +3,11 @@
* 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 { docsUrl, productName, supportUrl } from "../../common/vars"; import { docsUrl, supportUrl } from "../../common/vars";
import { broadcastMessage } from "../../common/ipc"; import { broadcastMessage } from "../../common/ipc";
import type { MenuItemConstructorOptions } from "electron"; import type { MenuItemConstructorOptions } from "electron";
import { webContents } from "electron"; import { webContents } from "electron";
import loggerInjectable from "../../common/logger.injectable"; import loggerInjectable from "../../common/logger.injectable";
import appNameInjectable from "../app-paths/app-name/app-name.injectable";
import electronMenuItemsInjectable from "./electron-menu-items.injectable"; import electronMenuItemsInjectable from "./electron-menu-items.injectable";
import updatingIsEnabledInjectable from "../application-update/updating-is-enabled.injectable"; import updatingIsEnabledInjectable from "../application-update/updating-is-enabled.injectable";
import navigateToPreferencesInjectable from "../../common/front-end-routing/routes/preferences/navigate-to-preferences.injectable"; import navigateToPreferencesInjectable from "../../common/front-end-routing/routes/preferences/navigate-to-preferences.injectable";
@ -24,6 +23,8 @@ import reloadCurrentApplicationWindowInjectable from "../start-main-application/
import showApplicationWindowInjectable from "../start-main-application/lens-window/show-application-window.injectable"; import showApplicationWindowInjectable from "../start-main-application/lens-window/show-application-window.injectable";
import processCheckingForUpdatesInjectable from "../application-update/check-for-updates/process-checking-for-updates.injectable"; import processCheckingForUpdatesInjectable from "../application-update/check-for-updates/process-checking-for-updates.injectable";
import openLinkInBrowserInjectable from "../../common/utils/open-link-in-browser.injectable"; import openLinkInBrowserInjectable from "../../common/utils/open-link-in-browser.injectable";
import appNameInjectable from "../../common/vars/app-name.injectable";
import productNameInjectable from "../../common/vars/product-name.injectable";
function ignoreIf(check: boolean, menuItems: MenuItemOpts[]) { function ignoreIf(check: boolean, menuItems: MenuItemOpts[]) {
return check ? [] : menuItems; return check ? [] : menuItems;
@ -39,6 +40,7 @@ const applicationMenuItemsInjectable = getInjectable({
instantiate: (di) => { instantiate: (di) => {
const logger = di.inject(loggerInjectable); const logger = di.inject(loggerInjectable);
const appName = di.inject(appNameInjectable); const appName = di.inject(appNameInjectable);
const productName = di.inject(productNameInjectable);
const isMac = di.inject(isMacInjectable); const isMac = di.inject(isMacInjectable);
const updatingIsEnabled = di.inject(updatingIsEnabledInjectable); const updatingIsEnabled = di.inject(updatingIsEnabledInjectable);
const electronMenuItems = di.inject(electronMenuItemsInjectable); const electronMenuItems = di.inject(electronMenuItemsInjectable);

View File

@ -1,13 +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 electronAppInjectable from "../electron-app/electron-app.injectable";
const buildVersionInjectable = getInjectable({
id: "build-version",
instantiate: (di) => di.inject(electronAppInjectable).getVersion(),
});
export default buildVersionInjectable;

View File

@ -3,36 +3,10 @@
* 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 { Menu } from "electron"; import { Menu } from "electron";
import { appName, isWindows, productName } from "../../common/vars";
import packageJson from "../../../package.json";
import type { MenuItemOpts } from "./application-menu-items.injectable"; import type { MenuItemOpts } from "./application-menu-items.injectable";
import type { ShowMessagePopup } from "../electron-app/features/show-message-popup.injectable";
export type MenuTopId = "mac" | "file" | "edit" | "view" | "help"; export type MenuTopId = "mac" | "file" | "edit" | "view" | "help";
interface Dependencies {
appVersion: string;
extensionApiVersion: string;
showMessagePopup: ShowMessagePopup;
}
export const showAbout = ({ showMessagePopup, extensionApiVersion, appVersion }: Dependencies) => async () => {
const appInfo = [
`${appName}: ${appVersion}`,
`Extension API: ${extensionApiVersion}`,
`Electron: ${process.versions.electron}`,
`Chrome: ${process.versions.chrome}`,
`Node: ${process.versions.node}`,
packageJson.copyright,
];
await showMessagePopup(
`${isWindows ? " ".repeat(2) : ""}${appName}`,
productName,
appInfo.join("\r\n"),
);
};
export function buildMenu(applicationMenuItems: MenuItemOpts[]) { export function buildMenu(applicationMenuItems: MenuItemOpts[]) {
Menu.setApplicationMenu( Menu.setApplicationMenu(
Menu.buildFromTemplate(applicationMenuItems), Menu.buildFromTemplate(applicationMenuItems),

View File

@ -3,20 +3,43 @@
* 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 { showAbout } from "./menu";
import showMessagePopupInjectable from "../electron-app/features/show-message-popup.injectable"; import showMessagePopupInjectable from "../electron-app/features/show-message-popup.injectable";
import appVersionInjectable from "../../common/vars/app-version.injectable"; import isWindowsInjectable from "../../common/vars/is-windows.injectable";
import buildVersionInjectable from "./build-version.injectable"; import appNameInjectable from "../../common/vars/app-name.injectable";
import productNameInjectable from "../../common/vars/product-name.injectable";
import buildVersionInjectable from "../vars/build-version/build-version.injectable";
import extensionApiVersionInjectable from "../../common/vars/extension-api-version.injectable";
import applicationCopyrightInjectable from "../../common/vars/application-copyright.injectable";
const showAboutInjectable = getInjectable({ const showAboutInjectable = getInjectable({
id: "show-about", id: "show-about",
instantiate: (di) => instantiate: (di) => {
showAbout({ const buildVersion = di.inject(buildVersionInjectable);
appVersion: di.inject(buildVersionInjectable), const extensionApiVersion = di.inject(extensionApiVersionInjectable);
extensionApiVersion: di.inject(appVersionInjectable), const showMessagePopup = di.inject(showMessagePopupInjectable);
showMessagePopup: di.inject(showMessagePopupInjectable), const isWindows = di.inject(isWindowsInjectable);
}), const appName = di.inject(appNameInjectable);
const productName = di.inject(productNameInjectable);
const applicationCopyright = di.inject(applicationCopyrightInjectable);
return () => {
const appInfo = [
`${appName}: ${buildVersion.get()}`,
`Extension API: ${extensionApiVersion}`,
`Electron: ${process.versions.electron}`,
`Chrome: ${process.versions.chrome}`,
`Node: ${process.versions.node}`,
applicationCopyright,
];
showMessagePopup(
`${isWindows ? " ".repeat(2) : ""}${appName}`,
productName,
appInfo.join("\r\n"),
);
};
},
}); });
export default showAboutInjectable; export default showAboutInjectable;

View File

@ -6,7 +6,7 @@ import type { SupportedFileExtension } from "../router/router-content-types";
import { contentTypes } from "../router/router-content-types"; import { contentTypes } from "../router/router-content-types";
import logger from "../logger"; import logger from "../logger";
import { getRouteInjectable } from "../router/router.injectable"; import { getRouteInjectable } from "../router/router.injectable";
import { appName, publicPath } from "../../common/vars"; import { publicPath } from "../../common/vars";
import path from "path"; import path from "path";
import isDevelopmentInjectable from "../../common/vars/is-development.injectable"; import isDevelopmentInjectable from "../../common/vars/is-development.injectable";
import httpProxy from "http-proxy"; import httpProxy from "http-proxy";
@ -19,66 +19,78 @@ import { webpackDevServerPort } from "../../../webpack/vars";
import type { LensApiRequest, RouteResponse } from "../router/route"; import type { LensApiRequest, RouteResponse } from "../router/route";
import { route } from "../router/route"; import { route } from "../router/route";
import staticFilesDirectoryInjectable from "../../common/vars/static-files-directory.injectable"; import staticFilesDirectoryInjectable from "../../common/vars/static-files-directory.injectable";
import appNameInjectable from "../../common/vars/app-name.injectable";
interface ProductionDependencies { interface ProductionDependencies {
readFileBuffer: (path: string) => Promise<Buffer>; readFileBuffer: (path: string) => Promise<Buffer>;
getAbsolutePath: GetAbsolutePath; getAbsolutePath: GetAbsolutePath;
joinPaths: JoinPaths; joinPaths: JoinPaths;
staticFilesDirectory: string; staticFilesDirectory: string;
appName: string;
} }
const handleStaticFileInProduction = const handleStaticFileInProduction = ({
({ readFileBuffer, getAbsolutePath, joinPaths, staticFilesDirectory }: ProductionDependencies) => readFileBuffer,
async ({ params }: LensApiRequest<"/{path*}">): Promise<RouteResponse<Buffer>> => { getAbsolutePath,
let filePath = params.path; joinPaths,
staticFilesDirectory,
appName,
}: ProductionDependencies) => (
async ({ params }: LensApiRequest<"/{path*}">): Promise<RouteResponse<Buffer>> => {
let filePath = params.path;
for (let retryCount = 0; retryCount < 5; retryCount += 1) { for (let retryCount = 0; retryCount < 5; retryCount += 1) {
const asset = joinPaths(staticFilesDirectory, filePath); const asset = joinPaths(staticFilesDirectory, filePath);
const normalizedFilePath = getAbsolutePath(asset); const normalizedFilePath = getAbsolutePath(asset);
if (!normalizedFilePath.startsWith(staticFilesDirectory)) {
return { statusCode: 404 };
}
try {
const fileExtension = path
.extname(asset)
.slice(1) as SupportedFileExtension;
const contentType = contentTypes[fileExtension] || contentTypes.txt;
return { response: await readFileBuffer(asset), contentType };
} catch (err) {
if (retryCount > 5) {
logger.error("handleStaticFile:", String(err));
if (!normalizedFilePath.startsWith(staticFilesDirectory)) {
return { statusCode: 404 }; return { statusCode: 404 };
} }
try { filePath = `${publicPath}/${appName}.html`;
const fileExtension = path
.extname(asset)
.slice(1) as SupportedFileExtension;
const contentType = contentTypes[fileExtension] || contentTypes.txt;
return { response: await readFileBuffer(asset), contentType };
} catch (err) {
if (retryCount > 5) {
logger.error("handleStaticFile:", String(err));
return { statusCode: 404 };
}
filePath = `${publicPath}/${appName}.html`;
}
} }
}
return { statusCode: 404 }; return { statusCode: 404 };
}; }
);
interface DevelopmentDependencies { interface DevelopmentDependencies {
proxy: httpProxy; proxy: httpProxy;
appName: string;
} }
const handleStaticFileInDevelopment = const handleStaticFileInDevelopment = ({
({ proxy }: DevelopmentDependencies) => proxy,
({ raw: { req, res }}: LensApiRequest<"/{path*}">): RouteResponse<Buffer> => { appName,
if (req.url === "/" || !req.url?.startsWith("/build/")) { }: DevelopmentDependencies) => (
req.url = `${publicPath}/${appName}.html`; ({ raw: { req, res }}: LensApiRequest<"/{path*}">): RouteResponse<Buffer> => {
} if (req.url === "/" || !req.url?.startsWith("/build/")) {
req.url = `${publicPath}/${appName}.html`;
}
proxy.web(req, res, { proxy.web(req, res, {
target: `http://127.0.0.1:${webpackDevServerPort}`, target: `http://127.0.0.1:${webpackDevServerPort}`,
}); });
return { proxy }; return { proxy };
}; }
);
const staticFileRouteInjectable = getRouteInjectable({ const staticFileRouteInjectable = getRouteInjectable({
id: "static-file-route", id: "static-file-route",
@ -89,6 +101,7 @@ const staticFileRouteInjectable = getRouteInjectable({
const getAbsolutePath = di.inject(getAbsolutePathInjectable); const getAbsolutePath = di.inject(getAbsolutePathInjectable);
const joinPaths = di.inject(joinPathsInjectable); const joinPaths = di.inject(joinPathsInjectable);
const staticFilesDirectory = di.inject(staticFilesDirectoryInjectable); const staticFilesDirectory = di.inject(staticFilesDirectoryInjectable);
const appName = di.inject(appNameInjectable);
return route({ return route({
method: "get", method: "get",
@ -97,12 +110,14 @@ const staticFileRouteInjectable = getRouteInjectable({
isDevelopment isDevelopment
? handleStaticFileInDevelopment({ ? handleStaticFileInDevelopment({
proxy: httpProxy.createProxy(), proxy: httpProxy.createProxy(),
appName,
}) })
: handleStaticFileInProduction({ : handleStaticFileInProduction({
readFileBuffer, readFileBuffer,
getAbsolutePath, getAbsolutePath,
joinPaths, joinPaths,
staticFilesDirectory, staticFilesDirectory,
appName,
}), }),
); );
}, },

View File

@ -3,20 +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 { getRouteInjectable } from "../../router/router.injectable"; import { getRouteInjectable } from "../../router/router.injectable";
import { getAppVersion } from "../../../common/utils";
import { route } from "../../router/route"; import { route } from "../../router/route";
import buildVersionInjectable from "../../vars/build-version/build-version.injectable";
const getVersionRouteInjectable = getRouteInjectable({ const getVersionRouteInjectable = getRouteInjectable({
id: "get-version-route", id: "get-version-route",
instantiate: () => route({ instantiate: (di) => {
method: "get", const buildVersion = di.inject(buildVersionInjectable);
path: `/version`,
})(() => ({ return route({
response: { method: "get",
version: getAppVersion(), path: `/version`,
}, })(() => ({
})), response: {
version: buildVersion.get(),
},
}));
},
}); });
export default getVersionRouteInjectable; export default getVersionRouteInjectable;

View File

@ -1,40 +0,0 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { shellEnv } from "./utils/shell-env";
import os from "os";
import { app } from "electron";
import logger from "./logger";
import { isSnap } from "../common/vars";
import { unionPATHs } from "../common/utils/union-env-path";
/**
* shellSync loads what would have been the environment if this application was
* run from the command line, into the process.env object. This is especially
* useful on macos where this always needs to be done.
*/
export async function shellSync() {
const env = await shellEnv(os.userInfo().shell);
if (!env.LANG) {
// the LANG env var expects an underscore instead of electron's dash
env.LANG = `${app.getLocale().replace("-", "_")}.UTF-8`;
} else if (!env.LANG.endsWith(".UTF-8")) {
env.LANG += ".UTF-8";
}
if (!isSnap) {
// Prefer the synced PATH over the initial one
process.env.PATH = unionPATHs(env.PATH ?? "", process.env.PATH ?? "");
}
// The spread operator allows joining of objects. The precedence is last to first.
process.env = {
...env,
...process.env,
};
logger.debug(`[SHELL-SYNC]: Synced shell env, and updating`, env, process.env);
}

View File

@ -6,11 +6,11 @@ import { getInjectable } from "@ogre-tools/injectable";
import createLensWindowInjectable from "./create-lens-window.injectable"; import createLensWindowInjectable from "./create-lens-window.injectable";
import lensProxyPortInjectable from "../../../lens-proxy/lens-proxy-port.injectable"; import lensProxyPortInjectable from "../../../lens-proxy/lens-proxy-port.injectable";
import isMacInjectable from "../../../../common/vars/is-mac.injectable"; import isMacInjectable from "../../../../common/vars/is-mac.injectable";
import appNameInjectable from "../../../app-paths/app-name/app-name.injectable";
import appEventBusInjectable from "../../../../common/app-event-bus/app-event-bus.injectable"; import appEventBusInjectable from "../../../../common/app-event-bus/app-event-bus.injectable";
import waitUntilBundledExtensionsAreLoadedInjectable from "./wait-until-bundled-extensions-are-loaded.injectable"; import waitUntilBundledExtensionsAreLoadedInjectable from "./wait-until-bundled-extensions-are-loaded.injectable";
import { applicationWindowInjectionToken } from "./application-window-injection-token"; import { applicationWindowInjectionToken } from "./application-window-injection-token";
import { runInAction } from "mobx"; import { runInAction } from "mobx";
import appNameInjectable from "../../../../common/vars/app-name.injectable";
const createApplicationWindowInjectable = getInjectable({ const createApplicationWindowInjectable = getInjectable({
id: "create-application-window", id: "create-application-window",

View File

@ -0,0 +1,9 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getGlobalOverride } from "../../../../common/test-utils/get-global-override";
import initializeSentryOnMainInjectable from "./initialize-on-main.injectable";
export default getGlobalOverride(initializeSentryOnMainInjectable, () => () => {});

View File

@ -0,0 +1,14 @@
/**
* 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 { init } from "@sentry/electron/main";
const initializeSentryOnMainInjectable = getInjectable({
id: "initialize-sentry-on-main",
instantiate: () => init,
causesSideEffects: true,
});
export default initializeSentryOnMainInjectable;

View 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 { beforeElectronIsReadyInjectionToken } from "../../runnable-tokens/before-electron-is-ready-injection-token";
import initializeSentryReportingWithInjectable from "../../../../common/error-reporting/initialize-sentry-reporting.injectable";
import initializeSentryOnMainInjectable from "./initialize-on-main.injectable";
const setupSentryInjectable = getInjectable({
id: "setup-sentry",
instantiate: (di) => {
const initializeSentryReportingWith = di.inject(initializeSentryReportingWithInjectable);
const initializeSentryOnMain = di.inject(initializeSentryOnMainInjectable);
return {
run: () => initializeSentryReportingWith(initializeSentryOnMain),
};
},
injectionToken: beforeElectronIsReadyInjectionToken,
});
export default setupSentryInjectable;

View File

@ -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 { getAppVersion, getAppVersionFromProxyServer } from "../../../common/utils"; import { getAppVersionFromProxyServer } from "../../../common/utils";
import exitAppInjectable from "../../electron-app/features/exit-app.injectable"; import exitAppInjectable from "../../electron-app/features/exit-app.injectable";
import lensProxyInjectable from "../../lens-proxy/lens-proxy.injectable"; import lensProxyInjectable from "../../lens-proxy/lens-proxy.injectable";
import loggerInjectable from "../../../common/logger.injectable"; import loggerInjectable from "../../../common/logger.injectable";
@ -11,6 +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/build-version.injectable";
const setupLensProxyInjectable = getInjectable({ const setupLensProxyInjectable = getInjectable({
id: "setup-lens-proxy", id: "setup-lens-proxy",
@ -22,6 +23,7 @@ const setupLensProxyInjectable = getInjectable({
const lensProxyPort = di.inject(lensProxyPortInjectable); const lensProxyPort = di.inject(lensProxyPortInjectable);
const isWindows = di.inject(isWindowsInjectable); const isWindows = di.inject(isWindowsInjectable);
const showErrorPopup = di.inject(showErrorPopupInjectable); const showErrorPopup = di.inject(showErrorPopupInjectable);
const buildVersion = di.inject(buildVersionInjectable);
return { return {
run: async () => { run: async () => {
@ -41,7 +43,7 @@ const setupLensProxyInjectable = getInjectable({
lensProxyPort.get(), lensProxyPort.get(),
); );
if (getAppVersion() !== 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();

View File

@ -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 { initializeSentryReporting } from "../../../common/sentry";
import { init } from "@sentry/electron/main";
import { beforeElectronIsReadyInjectionToken } from "../runnable-tokens/before-electron-is-ready-injection-token";
const setupSentryInjectable = getInjectable({
id: "setup-sentry",
instantiate: () => ({
run: () => {
initializeSentryReporting(init);
},
}),
causesSideEffects: true,
injectionToken: beforeElectronIsReadyInjectionToken,
});
export default setupSentryInjectable;

View File

@ -3,21 +3,47 @@
* 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 { shellSync } from "../../shell-sync";
import loggerInjectable from "../../../common/logger.injectable"; import loggerInjectable from "../../../common/logger.injectable";
import { onLoadOfApplicationInjectionToken } from "../runnable-tokens/on-load-of-application-injection-token"; import { onLoadOfApplicationInjectionToken } from "../runnable-tokens/on-load-of-application-injection-token";
import { shellEnv } from "../../utils/shell-env";
import os from "os";
import { unionPATHs } from "../../../common/utils/union-env-path";
import isSnapPackageInjectable from "../../../common/vars/is-snap-package.injectable";
import electronAppInjectable from "../../electron-app/electron-app.injectable";
const setupShellInjectable = getInjectable({ const setupShellInjectable = getInjectable({
id: "setup-shell", id: "setup-shell",
instantiate: (di) => { instantiate: (di) => {
const logger = di.inject(loggerInjectable); const logger = di.inject(loggerInjectable);
const isSnapPackage = di.inject(isSnapPackageInjectable);
const electronApp = di.inject(electronAppInjectable);
return { return {
run: async () => { run: async () => {
logger.info("🐚 Syncing shell environment"); logger.info("🐚 Syncing shell environment");
await shellSync(); const env = await shellEnv(os.userInfo().shell);
if (!env.LANG) {
// the LANG env var expects an underscore instead of electron's dash
env.LANG = `${electronApp.getLocale().replace("-", "_")}.UTF-8`;
} else if (!env.LANG.endsWith(".UTF-8")) {
env.LANG += ".UTF-8";
}
if (!isSnapPackage) {
// Prefer the synced PATH over the initial one
process.env.PATH = unionPATHs(env.PATH ?? "", process.env.PATH ?? "");
}
// The spread operator allows joining of objects. The precedence is last to first.
process.env = {
...env,
...process.env,
};
logger.debug(`[SHELL-SYNC]: Synced shell env, and updating`, env, process.env);
}, },
}; };
}, },

View File

@ -4,12 +4,12 @@
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { Menu, Tray } from "electron"; import { Menu, Tray } from "electron";
import packageJsonInjectable from "../../../common/vars/package-json.injectable";
import showApplicationWindowInjectable from "../../start-main-application/lens-window/show-application-window.injectable"; import showApplicationWindowInjectable from "../../start-main-application/lens-window/show-application-window.injectable";
import isWindowsInjectable from "../../../common/vars/is-windows.injectable"; import isWindowsInjectable from "../../../common/vars/is-windows.injectable";
import loggerInjectable from "../../../common/logger.injectable"; import loggerInjectable from "../../../common/logger.injectable";
import { convertToElectronMenuTemplate } from "../reactive-tray-menu-items/converters"; import { convertToElectronMenuTemplate } from "../reactive-tray-menu-items/converters";
import trayIconInjectable from "../menu-icon/tray-icon.injectable"; import trayIconInjectable from "../menu-icon/tray-icon.injectable";
import applicationDescriptionInjectable from "../../../common/vars/application-description.injectable";
const TRAY_LOG_PREFIX = "[TRAY]"; const TRAY_LOG_PREFIX = "[TRAY]";
@ -34,7 +34,7 @@ const electronTrayInjectable = getInjectable({
id: "electron-tray", id: "electron-tray",
instantiate: (di): ElectronTray => { instantiate: (di): ElectronTray => {
const packageJson = di.inject(packageJsonInjectable); const applicationDescription = di.inject(applicationDescriptionInjectable);
const showApplicationWindow = di.inject(showApplicationWindowInjectable); const showApplicationWindow = di.inject(showApplicationWindowInjectable);
const isWindows = di.inject(isWindowsInjectable); const isWindows = di.inject(isWindowsInjectable);
const logger = di.inject(loggerInjectable); const logger = di.inject(loggerInjectable);
@ -46,7 +46,7 @@ const electronTrayInjectable = getInjectable({
start: () => { start: () => {
tray = new Tray(trayIcon.get().iconPath); tray = new Tray(trayIcon.get().iconPath);
tray.setToolTip(packageJson.description); tray.setToolTip(applicationDescription);
tray.setIgnoreDoubleClickEvents(true); tray.setIgnoreDoubleClickEvents(true);
if (isWindows) { if (isWindows) {

View File

@ -3,7 +3,6 @@
* 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 productNameInjectable from "../../../app-paths/app-name/product-name.injectable";
import showApplicationWindowInjectable from "../../../start-main-application/lens-window/show-application-window.injectable"; import showApplicationWindowInjectable from "../../../start-main-application/lens-window/show-application-window.injectable";
import showAboutInjectable from "../../../menu/show-about.injectable"; import showAboutInjectable from "../../../menu/show-about.injectable";
import { trayMenuItemInjectionToken } from "../tray-menu-item-injection-token"; import { trayMenuItemInjectionToken } from "../tray-menu-item-injection-token";
@ -11,6 +10,7 @@ import { computed } from "mobx";
import withErrorLoggingInjectable from "../../../../common/utils/with-error-logging/with-error-logging.injectable"; import withErrorLoggingInjectable from "../../../../common/utils/with-error-logging/with-error-logging.injectable";
import { withErrorSuppression } from "../../../../common/utils/with-error-suppression/with-error-suppression"; import { withErrorSuppression } from "../../../../common/utils/with-error-suppression/with-error-suppression";
import { pipeline } from "@ogre-tools/fp"; import { pipeline } from "@ogre-tools/fp";
import productNameInjectable from "../../../../common/vars/product-name.injectable";
const aboutAppTrayItemInjectable = getInjectable({ const aboutAppTrayItemInjectable = getInjectable({
id: "about-app-tray-item", id: "about-app-tray-item",
@ -32,15 +32,10 @@ const aboutAppTrayItemInjectable = getInjectable({
click: pipeline( click: pipeline(
async () => { async () => {
await showApplicationWindow(); await showApplicationWindow();
showAbout();
await showAbout();
}, },
withErrorLoggingFor(() => "[TRAY]: Opening of show about failed."), withErrorLoggingFor(() => "[TRAY]: Opening of show about failed."),
withErrorSuppression,
// TODO: Find out how to improve typing so that instead of
// x => withErrorSuppression(x) there could only be withErrorSuppression
(x) => withErrorSuppression(x),
), ),
}; };
}, },

View File

@ -4,12 +4,12 @@
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { trayMenuItemInjectionToken } from "../tray-menu-item-injection-token"; import { trayMenuItemInjectionToken } from "../tray-menu-item-injection-token";
import productNameInjectable from "../../../app-paths/app-name/product-name.injectable";
import showApplicationWindowInjectable from "../../../start-main-application/lens-window/show-application-window.injectable"; import showApplicationWindowInjectable from "../../../start-main-application/lens-window/show-application-window.injectable";
import { computed } from "mobx"; import { computed } from "mobx";
import withErrorLoggingInjectable from "../../../../common/utils/with-error-logging/with-error-logging.injectable"; import withErrorLoggingInjectable from "../../../../common/utils/with-error-logging/with-error-logging.injectable";
import { withErrorSuppression } from "../../../../common/utils/with-error-suppression/with-error-suppression"; import { withErrorSuppression } from "../../../../common/utils/with-error-suppression/with-error-suppression";
import { pipeline } from "@ogre-tools/fp"; import { pipeline } from "@ogre-tools/fp";
import productNameInjectable from "../../../../common/vars/product-name.injectable";
const openAppTrayItemInjectable = getInjectable({ const openAppTrayItemInjectable = getInjectable({
id: "open-app-tray-item", id: "open-app-tray-item",
@ -28,15 +28,9 @@ const openAppTrayItemInjectable = getInjectable({
visible: computed(() => true), visible: computed(() => true),
click: pipeline( click: pipeline(
async () => { showApplicationWindow,
await showApplicationWindow();
},
withErrorLoggingFor(() => "[TRAY]: Opening of application window failed."), withErrorLoggingFor(() => "[TRAY]: Opening of application window failed."),
withErrorSuppression,
// TODO: Find out how to improve typing so that instead of
// x => withErrorSuppression(x) there could only be withErrorSuppression
(x) => withErrorSuppression(x),
), ),
}; };
}, },

View File

@ -0,0 +1,19 @@
/**
* 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 getBuildVersionInjectable from "./get-build-version.injectable";
const buildVersionInjectable = createInitializableState({
id: "build-version",
init: (di) => {
const getBuildVersion = di.inject(getBuildVersionInjectable);
return getBuildVersion();
},
injectionToken: buildVersionInjectionToken,
});
export default buildVersionInjectable;

View File

@ -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;

View 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;

Some files were not shown because too many files have changed in this diff Show More