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

Switch to using applicationInformationToken from application feature

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
Janne Savolainen 2023-02-22 11:18:24 +02:00
parent bfb9295175
commit e2e5b08ae5
No known key found for this signature in database
GPG Key ID: 8C6CFB2FFFE8F68A
25 changed files with 101 additions and 112 deletions

4
package-lock.json generated
View File

@ -32465,6 +32465,7 @@
"node": ">=16 <17" "node": ">=16 <17"
}, },
"peerDependencies": { "peerDependencies": {
"@k8slens/application": "^6.4.0-beta.13",
"@types/byline": "^4.2.33", "@types/byline": "^4.2.33",
"@types/chart.js": "^2.9.36", "@types/chart.js": "^2.9.36",
"@types/color": "^3.0.3", "@types/color": "^3.0.3",
@ -34296,6 +34297,7 @@
"hasInstallScript": true, "hasInstallScript": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@k8slens/application": "^6.4.0-beta.13",
"@k8slens/core": "^6.4.0-beta.13", "@k8slens/core": "^6.4.0-beta.13",
"@k8slens/ensure-binaries": "^6.4.0-beta.13", "@k8slens/ensure-binaries": "^6.4.0-beta.13",
"@k8slens/generate-tray-icons": "^6.4.0-beta.13", "@k8slens/generate-tray-icons": "^6.4.0-beta.13",
@ -34542,7 +34544,7 @@
}, },
"packages/technical-features/application": { "packages/technical-features/application": {
"name": "@k8slens/application", "name": "@k8slens/application",
"version": "0.0.1", "version": "6.4.0-beta.13",
"license": "MIT", "license": "MIT",
"peerDependencies": { "peerDependencies": {
"@ogre-tools/fp": "^12.0.1", "@ogre-tools/fp": "^12.0.1",

View File

@ -330,6 +330,7 @@
"xterm-addon-fit": "^0.5.0" "xterm-addon-fit": "^0.5.0"
}, },
"peerDependencies": { "peerDependencies": {
"@k8slens/application": "^6.4.0-beta.13",
"@types/byline": "^4.2.33", "@types/byline": "^4.2.33",
"@types/chart.js": "^2.9.36", "@types/chart.js": "^2.9.36",
"@types/color": "^3.0.3", "@types/color": "^3.0.3",

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 { applicationInformationToken } from "@k8slens/application";
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { applicationInformationToken } from "../../../vars/application-information-token";
const welcomeRouteConfigInjectable = getInjectable({ const welcomeRouteConfigInjectable = getInjectable({
id: "welcome-route-config", id: "welcome-route-config",
instantiate: (di) => di.inject(applicationInformationToken).config.welcomeRoute, instantiate: (di) => di.inject(applicationInformationToken).welcomeRoute,
}); });
export default welcomeRouteConfigInjectable; export default welcomeRouteConfigInjectable;

View File

@ -4,6 +4,4 @@
*/ */
// @experimental // @experimental
export { applicationInformationToken } from "./vars/application-information-token";
export type { ApplicationInformation } from "./vars/application-information-token";
export { bundledExtensionInjectionToken } from "../extensions/extension-discovery/bundled-extension-token"; export { bundledExtensionInjectionToken } from "../extensions/extension-discovery/bundled-extension-token";

View File

@ -2,8 +2,8 @@
* 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 { applicationInformationToken } from "@k8slens/application";
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { applicationInformationToken } from "./application-information-token";
const applicationCopyrightInjectable = getInjectable({ const applicationCopyrightInjectable = getInjectable({
id: "application-copyright", id: "application-copyright",

View File

@ -2,8 +2,8 @@
* 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 { applicationInformationToken } from "@k8slens/application";
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { applicationInformationToken } from "./application-information-token";
const applicationDescriptionInjectable = getInjectable({ const applicationDescriptionInjectable = getInjectable({
id: "application-description", id: "application-description",

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 { getInjectable } from "@ogre-tools/injectable";
import { applicationInformationToken } from "@k8slens/application";
export const applicationInformationFakeInjectable = getInjectable({
id: "application-information-fake",
instantiate: () => ({
name: "some-product-name",
productName: "some-product-name",
version: "6.0.0",
updatingIsEnabled: false,
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",
}),
injectionToken: applicationInformationToken,
});

View File

@ -1,20 +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 packageJson from "../../../package.json";
import { applicationInformationToken } from "../../common/vars/application-information-token";
const applicationInformationInjectable = getInjectable({
id: "application-information",
injectionToken: applicationInformationToken,
instantiate: () => {
const { version, config, productName, build, copyright, description, name } = packageJson;
return { version, config, productName, build, copyright, description, name };
},
causesSideEffects: true,
});
export default applicationInformationInjectable;

View File

@ -1,15 +0,0 @@
/**
* 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 type packageJson from "../../../package.json";
export type ApplicationInformation = Pick<typeof packageJson, "version" | "config" | "productName" | "copyright" | "description" | "name"> & {
build: Partial<typeof packageJson["build"]> & { publish?: unknown[] };
};
export const applicationInformationToken = getInjectionToken<ApplicationInformation>({
id: "application-information-token",
});

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 { getGlobalOverride } from "../test-utils/get-global-override";
import applicationInformationInjectable from "./application-information-injectable";
export default getGlobalOverride(applicationInformationInjectable, () => ({
name: "some-product-name",
productName: "some-product-name",
version: "6.0.0",
build: {} as any,
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

@ -2,12 +2,12 @@
* 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 { applicationInformationToken } from "@k8slens/application";
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { applicationInformationToken } from "./application-information-token";
const bundledKubectlVersionInjectable = getInjectable({ const bundledKubectlVersionInjectable = getInjectable({
id: "bundled-kubectl-version", id: "bundled-kubectl-version",
instantiate: (di) => di.inject(applicationInformationToken).config.bundledKubectlVersion, instantiate: (di) => di.inject(applicationInformationToken).bundledKubectlVersion,
}); });
export default bundledKubectlVersionInjectable; export default bundledKubectlVersionInjectable;

View File

@ -2,12 +2,12 @@
* 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 { applicationInformationToken } from "@k8slens/application";
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { applicationInformationToken } from "./application-information-token";
const contentSecurityPolicyInjectable = getInjectable({ const contentSecurityPolicyInjectable = getInjectable({
id: "content-security-policy", id: "content-security-policy",
instantiate: (di) => di.inject(applicationInformationToken).config.contentSecurityPolicy, instantiate: (di) => di.inject(applicationInformationToken).contentSecurityPolicy,
}); });
export default contentSecurityPolicyInjectable; export default contentSecurityPolicyInjectable;

View File

@ -2,8 +2,8 @@
* 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 { applicationInformationToken } from "@k8slens/application";
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { applicationInformationToken } from "./application-information-token";
const productNameInjectable = getInjectable({ const productNameInjectable = getInjectable({
id: "product-name", id: "product-name",

View File

@ -2,12 +2,12 @@
* 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 { applicationInformationToken } from "@k8slens/application";
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { applicationInformationToken } from "./application-information-token";
const sentryDataSourceNameInjectable = getInjectable({ const sentryDataSourceNameInjectable = getInjectable({
id: "sentry-data-source-name", id: "sentry-data-source-name",
instantiate: (di) => di.inject(applicationInformationToken).config.sentryDsn, instantiate: (di) => di.inject(applicationInformationToken).sentryDsn,
}); });
export default sentryDataSourceNameInjectable; export default sentryDataSourceNameInjectable;

View File

@ -2,8 +2,8 @@
* 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 { applicationInformationToken } from "@k8slens/application";
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { applicationInformationToken } from "./application-information-token";
const storeMigrationVersionInjectable = getInjectable({ const storeMigrationVersionInjectable = getInjectable({
id: "store-migration-version", id: "store-migration-version",

View File

@ -2,12 +2,12 @@
* 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 { applicationInformationToken } from "@k8slens/application";
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { applicationInformationToken } from "../../../../../common/vars/application-information-token";
const publishIsConfiguredInjectable = getInjectable({ const publishIsConfiguredInjectable = getInjectable({
id: "publish-is-configured", id: "publish-is-configured",
instantiate: (di) => Boolean(di.inject(applicationInformationToken).build.publish?.length), instantiate: (di) => Boolean(di.inject(applicationInformationToken).updatingIsEnabled),
}); });
export default publishIsConfiguredInjectable; export default publishIsConfiguredInjectable;

View File

@ -6,12 +6,12 @@
// Fix embedded kubeconfig paths under snap config // Fix embedded kubeconfig paths under snap config
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { applicationInformationToken } from "../../../common/vars/application-information-token";
import { clusterStoreMigrationInjectionToken } from "../../../common/cluster-store/migration-token"; import { clusterStoreMigrationInjectionToken } from "../../../common/cluster-store/migration-token";
import loggerInjectable from "../../../common/logger.injectable"; import loggerInjectable from "../../../common/logger.injectable";
import isSnapPackageInjectable from "../../../common/vars/is-snap-package.injectable"; import isSnapPackageInjectable from "../../../common/vars/is-snap-package.injectable";
import type { ClusterModel } from "../../../common/cluster-types"; import type { ClusterModel } from "../../../common/cluster-types";
import pathExistsSyncInjectable from "../../../common/fs/path-exists-sync.injectable"; import pathExistsSyncInjectable from "../../../common/fs/path-exists-sync.injectable";
import { applicationInformationToken } from "@k8slens/application";
const clusterStoreSnapMigrationInjectable = getInjectable({ const clusterStoreSnapMigrationInjectable = getInjectable({
id: "cluster-store-snap-migration", id: "cluster-store-snap-migration",

View File

@ -3,15 +3,5 @@
* 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 { createContainer } from "@ogre-tools/injectable"; import { createContainer } from "@ogre-tools/injectable";
import { runInAction } from "mobx";
import applicationInformationInjectable from "../common/vars/application-information-injectable";
export const getDi = () => { export const getDi = () => createContainer("main");
const di = createContainer("main");
runInAction(() => {
di.register(applicationInformationInjectable);
});
return di;
};

View File

@ -29,9 +29,9 @@ import { registerMobX } from "@ogre-tools/injectable-extension-for-mobx";
import electronInjectable from "./utils/resolve-system-proxy/electron.injectable"; import electronInjectable from "./utils/resolve-system-proxy/electron.injectable";
import initializeClusterManagerInjectable from "./cluster/initialize-manager.injectable"; import initializeClusterManagerInjectable from "./cluster/initialize-manager.injectable";
import type { GlobalOverride } from "../common/test-utils/get-global-override"; import type { GlobalOverride } from "../common/test-utils/get-global-override";
import applicationInformationInjectable from "../common/vars/application-information-injectable";
import nodeEnvInjectionToken from "../common/vars/node-env-injection-token"; import nodeEnvInjectionToken from "../common/vars/node-env-injection-token";
import { getOverrideFsWithFakes } from "../test-utils/override-fs-with-fakes"; import { getOverrideFsWithFakes } from "../test-utils/override-fs-with-fakes";
import { applicationInformationFakeInjectable } from "../common/vars/application-information-fake-injectable";
export function getDiForUnitTesting(opts: { doGeneralOverrides?: boolean } = {}) { export function getDiForUnitTesting(opts: { doGeneralOverrides?: boolean } = {}) {
const { const {
@ -57,9 +57,10 @@ export function getDiForUnitTesting(opts: { doGeneralOverrides?: boolean } = {})
.filter(isInjectable) .filter(isInjectable)
) as Injectable<any, any, any>[]; ) as Injectable<any, any, any>[];
registerMobX(di);
runInAction(() => { runInAction(() => {
registerMobX(di); di.register(applicationInformationFakeInjectable);
di.register(applicationInformationInjectable);
chunk(100)(injectables).forEach(chunkInjectables => { chunk(100)(injectables).forEach(chunkInjectables => {
di.register(...chunkInjectables); di.register(...chunkInjectables);

View File

@ -13,9 +13,9 @@ import openLinkInBrowserInjectable from "../../../../common/utils/open-link-in-b
import getAbsolutePathInjectable from "../../../../common/path/get-absolute-path.injectable"; import getAbsolutePathInjectable from "../../../../common/path/get-absolute-path.injectable";
import lensResourcesDirInjectable from "../../../../common/vars/lens-resources-dir.injectable"; import lensResourcesDirInjectable from "../../../../common/vars/lens-resources-dir.injectable";
import isLinuxInjectable from "../../../../common/vars/is-linux.injectable"; import isLinuxInjectable from "../../../../common/vars/is-linux.injectable";
import { applicationInformationToken } from "../../../../common/vars/application-information-token";
import pathExistsSyncInjectable from "../../../../common/fs/path-exists-sync.injectable"; import pathExistsSyncInjectable from "../../../../common/fs/path-exists-sync.injectable";
import lensProxyCertificateInjectable from "../../../../common/certificate/lens-proxy-certificate.injectable"; import lensProxyCertificateInjectable from "../../../../common/certificate/lens-proxy-certificate.injectable";
import { applicationInformationToken } from "@k8slens/application";
export type ElectronWindowTitleBarStyle = "hiddenInset" | "hidden" | "default" | "customButtonsOnHover"; export type ElectronWindowTitleBarStyle = "hiddenInset" | "hidden" | "default" | "customButtonsOnHover";

View File

@ -7,8 +7,8 @@ import { docsUrl, slackUrl } from "../../../common/vars";
import type { WeblinkData } from "../../../common/weblinks-store/weblink-store"; import type { WeblinkData } from "../../../common/weblinks-store/weblink-store";
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { weblinkStoreMigrationInjectionToken } from "../../../common/weblinks-store/migration-token"; import { weblinkStoreMigrationInjectionToken } from "../../../common/weblinks-store/migration-token";
import { applicationInformationToken } from "../../../common/vars/application-information-token";
import { lensDocumentationWeblinkId, lensSlackWeblinkId } from "../links"; import { lensDocumentationWeblinkId, lensSlackWeblinkId } from "../links";
import { applicationInformationToken } from "@k8slens/application";
const currentVersionWeblinkStoreMigrationInjectable = getInjectable({ const currentVersionWeblinkStoreMigrationInjectable = getInjectable({
id: "current-version-weblink-store-migration", id: "current-version-weblink-store-migration",

View File

@ -4,15 +4,5 @@
*/ */
import { createContainer } from "@ogre-tools/injectable"; import { createContainer } from "@ogre-tools/injectable";
import { runInAction } from "mobx";
import applicationInformationInjectable from "../common/vars/application-information-injectable";
export const getDi = () => { export const getDi = () => createContainer("renderer");
const di = createContainer("renderer");
runInAction(() => {
di.register(applicationInformationInjectable);
});
return di;
};

View File

@ -18,8 +18,8 @@ import { registerMobX } from "@ogre-tools/injectable-extension-for-mobx";
import watchHistoryStateInjectable from "./remote-helpers/watch-history-state.injectable"; import watchHistoryStateInjectable from "./remote-helpers/watch-history-state.injectable";
import legacyOnChannelListenInjectable from "./ipc/legacy-channel-listen.injectable"; import legacyOnChannelListenInjectable from "./ipc/legacy-channel-listen.injectable";
import type { GlobalOverride } from "../common/test-utils/get-global-override"; import type { GlobalOverride } from "../common/test-utils/get-global-override";
import applicationInformationInjectable from "../common/vars/application-information-injectable";
import nodeEnvInjectionToken from "../common/vars/node-env-injection-token"; import nodeEnvInjectionToken from "../common/vars/node-env-injection-token";
import { applicationInformationFakeInjectable } from "../common/vars/application-information-fake-injectable";
export const getDiForUnitTesting = ( export const getDiForUnitTesting = (
opts: { doGeneralOverrides?: boolean } = {}, opts: { doGeneralOverrides?: boolean } = {},
@ -45,9 +45,10 @@ export const getDiForUnitTesting = (
.filter(isInjectable) .filter(isInjectable)
) as Injectable<any, any, any>[]; ) as Injectable<any, any, any>[];
registerMobX(di);
runInAction(() => { runInAction(() => {
registerMobX(di); di.register(applicationInformationFakeInjectable);
di.register(applicationInformationInjectable);
chunk(100)(injectables).forEach((chunkInjectables) => { chunk(100)(injectables).forEach((chunkInjectables) => {
di.register(...chunkInjectables); di.register(...chunkInjectables);

View File

@ -195,6 +195,7 @@
} }
}, },
"dependencies": { "dependencies": {
"@k8slens/application": "^6.4.0-beta.13",
"@k8slens/core": "^6.4.0-beta.13", "@k8slens/core": "^6.4.0-beta.13",
"@k8slens/ensure-binaries": "^6.4.0-beta.13", "@k8slens/ensure-binaries": "^6.4.0-beta.13",
"@k8slens/generate-tray-icons": "^6.4.0-beta.13", "@k8slens/generate-tray-icons": "^6.4.0-beta.13",

View File

@ -1,15 +1,49 @@
/**
* 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 { getInjectable } from "@ogre-tools/injectable";
import { applicationInformationToken, ApplicationInformation } from "@k8slens/core/common";
import packageJson from "../../package.json"; import packageJson from "../../package.json";
import { applicationInformationToken } from "@k8slens/application";
const applicationInformationInjectable = getInjectable({ const applicationInformationInjectable = getInjectable({
id: "application-information", id: "application-information",
injectionToken: applicationInformationToken, injectionToken: applicationInformationToken,
instantiate: () => {
const { version, config, productName, build, copyright, description, name } = packageJson;
return { version, config, productName, build, copyright, description, name } as ApplicationInformation; instantiate: () => {
const {
version,
config: {
bundledHelmVersion,
bundledKubectlVersion,
contentSecurityPolicy,
k8sProxyVersion,
sentryDsn,
welcomeRoute,
},
productName,
build,
copyright,
description,
name,
} = packageJson;
return {
version,
productName,
copyright,
description,
name,
k8sProxyVersion,
bundledKubectlVersion,
bundledHelmVersion,
sentryDsn,
contentSecurityPolicy,
welcomeRoute,
updatingIsEnabled: (build as any)?.publish?.length > 0,
};
}, },
causesSideEffects: true, causesSideEffects: true,
}); });