diff --git a/src/extensions/extension-loader/extension-loader.injectable.ts b/src/extensions/extension-loader/extension-loader.injectable.ts new file mode 100644 index 0000000000..70922daf94 --- /dev/null +++ b/src/extensions/extension-loader/extension-loader.injectable.ts @@ -0,0 +1,31 @@ +/** + * Copyright (c) 2021 OpenLens Authors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +import type { Injectable } from "@ogre-tools/injectable"; +import { lifecycleEnum } from "@ogre-tools/injectable"; +import { ExtensionLoader } from "./extension-loader"; + +const extensionLoaderInjectable: Injectable = { + getDependencies: () => ({}), + instantiate: () => new ExtensionLoader(), + lifecycle: lifecycleEnum.singleton, +}; + +export default extensionLoaderInjectable; diff --git a/src/extensions/extension-loader.ts b/src/extensions/extension-loader/extension-loader.ts similarity index 95% rename from src/extensions/extension-loader.ts rename to src/extensions/extension-loader/extension-loader.ts index f5b4806de1..43d3eece63 100644 --- a/src/extensions/extension-loader.ts +++ b/src/extensions/extension-loader/extension-loader.ts @@ -24,16 +24,16 @@ import { EventEmitter } from "events"; import { isEqual } from "lodash"; import { action, computed, makeObservable, observable, observe, reaction, when } from "mobx"; import path from "path"; -import { AppPaths } from "../common/app-paths"; -import { ClusterStore } from "../common/cluster-store"; -import { broadcastMessage, ipcMainOn, ipcRendererOn, requestMain, ipcMainHandle } from "../common/ipc"; -import { Disposer, getHostedClusterId, Singleton, toJS } from "../common/utils"; -import logger from "../main/logger"; -import type { InstalledExtension } from "./extension-discovery"; -import { ExtensionsStore } from "./extensions-store"; -import type { LensExtension, LensExtensionConstructor, LensExtensionId } from "./lens-extension"; -import type { LensRendererExtension } from "./lens-renderer-extension"; -import * as registries from "./registries"; +import { AppPaths } from "../../common/app-paths"; +import { ClusterStore } from "../../common/cluster-store"; +import { broadcastMessage, ipcMainOn, ipcRendererOn, requestMain, ipcMainHandle } from "../../common/ipc"; +import { Disposer, getHostedClusterId, toJS } from "../../common/utils"; +import logger from "../../main/logger"; +import type { InstalledExtension } from "../extension-discovery"; +import { ExtensionsStore } from "../extensions-store"; +import type { LensExtension, LensExtensionConstructor, LensExtensionId } from "../lens-extension"; +import type { LensRendererExtension } from "../lens-renderer-extension"; +import * as registries from "../registries"; export function extensionPackagesRoot() { return path.join(AppPaths.get("userData")); @@ -44,7 +44,7 @@ const logModule = "[EXTENSIONS-LOADER]"; /** * Loads installed extensions to the Lens application */ -export class ExtensionLoader extends Singleton { +export class ExtensionLoader { protected extensions = observable.map(); protected instances = observable.map(); @@ -76,7 +76,6 @@ export class ExtensionLoader extends Singleton { } constructor() { - super(); makeObservable(this); observe(this.instances, change => { switch (change.type) { diff --git a/src/extensions/extension-loader/index.ts b/src/extensions/extension-loader/index.ts new file mode 100644 index 0000000000..283fb3b5ee --- /dev/null +++ b/src/extensions/extension-loader/index.ts @@ -0,0 +1,29 @@ +/** + * Copyright (c) 2021 OpenLens Authors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +import { getLegacySingleton } from "../../common/di-kludge/get-legacy-singleton/get-legacy-singleton"; +import extensionLoaderInjectable from "./extension-loader.injectable"; + +export * from "./extension-loader"; + +/** + * @deprecated Switch to using di.inject(extensionLoaderInjectable) + */ +export const ExtensionLoader = getLegacySingleton(extensionLoaderInjectable); diff --git a/src/extensions/extensions.injectable.ts b/src/extensions/extensions.injectable.ts index 08a2a253d4..9bd1bfae66 100644 --- a/src/extensions/extensions.injectable.ts +++ b/src/extensions/extensions.injectable.ts @@ -20,12 +20,13 @@ */ import { Injectable, lifecycleEnum } from "@ogre-tools/injectable"; import { computed, IComputedValue } from "mobx"; -import { ExtensionLoader } from "./extension-loader"; import type { LensExtension } from "./lens-extension"; +import { ExtensionLoader } from "./extension-loader"; +import type { ExtensionLoader as ExtensionLoaderType } from "./extension-loader/extension-loader"; const extensionsInjectable: Injectable< IComputedValue, - { extensionLoader: ExtensionLoader } + { extensionLoader: ExtensionLoaderType } > = { getDependencies: () => ({ extensionLoader: ExtensionLoader.getInstance(),