mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Make ExtensionLoader injectable to avoid confusion when instance should be created
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
parent
34a47f5f44
commit
b4a1c2af9f
@ -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<ExtensionLoader> = {
|
||||||
|
getDependencies: () => ({}),
|
||||||
|
instantiate: () => new ExtensionLoader(),
|
||||||
|
lifecycle: lifecycleEnum.singleton,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default extensionLoaderInjectable;
|
||||||
@ -24,16 +24,16 @@ import { EventEmitter } from "events";
|
|||||||
import { isEqual } from "lodash";
|
import { isEqual } from "lodash";
|
||||||
import { action, computed, makeObservable, observable, observe, reaction, when } from "mobx";
|
import { action, computed, makeObservable, observable, observe, reaction, when } from "mobx";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { AppPaths } from "../common/app-paths";
|
import { AppPaths } from "../../common/app-paths";
|
||||||
import { ClusterStore } from "../common/cluster-store";
|
import { ClusterStore } from "../../common/cluster-store";
|
||||||
import { broadcastMessage, ipcMainOn, ipcRendererOn, requestMain, ipcMainHandle } from "../common/ipc";
|
import { broadcastMessage, ipcMainOn, ipcRendererOn, requestMain, ipcMainHandle } from "../../common/ipc";
|
||||||
import { Disposer, getHostedClusterId, Singleton, toJS } from "../common/utils";
|
import { Disposer, getHostedClusterId, toJS } from "../../common/utils";
|
||||||
import logger from "../main/logger";
|
import logger from "../../main/logger";
|
||||||
import type { InstalledExtension } from "./extension-discovery";
|
import type { InstalledExtension } from "../extension-discovery";
|
||||||
import { ExtensionsStore } from "./extensions-store";
|
import { ExtensionsStore } from "../extensions-store";
|
||||||
import type { LensExtension, LensExtensionConstructor, LensExtensionId } from "./lens-extension";
|
import type { LensExtension, LensExtensionConstructor, LensExtensionId } from "../lens-extension";
|
||||||
import type { LensRendererExtension } from "./lens-renderer-extension";
|
import type { LensRendererExtension } from "../lens-renderer-extension";
|
||||||
import * as registries from "./registries";
|
import * as registries from "../registries";
|
||||||
|
|
||||||
export function extensionPackagesRoot() {
|
export function extensionPackagesRoot() {
|
||||||
return path.join(AppPaths.get("userData"));
|
return path.join(AppPaths.get("userData"));
|
||||||
@ -44,7 +44,7 @@ const logModule = "[EXTENSIONS-LOADER]";
|
|||||||
/**
|
/**
|
||||||
* Loads installed extensions to the Lens application
|
* Loads installed extensions to the Lens application
|
||||||
*/
|
*/
|
||||||
export class ExtensionLoader extends Singleton {
|
export class ExtensionLoader {
|
||||||
protected extensions = observable.map<LensExtensionId, InstalledExtension>();
|
protected extensions = observable.map<LensExtensionId, InstalledExtension>();
|
||||||
protected instances = observable.map<LensExtensionId, LensExtension>();
|
protected instances = observable.map<LensExtensionId, LensExtension>();
|
||||||
|
|
||||||
@ -76,7 +76,6 @@ export class ExtensionLoader extends Singleton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
|
||||||
makeObservable(this);
|
makeObservable(this);
|
||||||
observe(this.instances, change => {
|
observe(this.instances, change => {
|
||||||
switch (change.type) {
|
switch (change.type) {
|
||||||
29
src/extensions/extension-loader/index.ts
Normal file
29
src/extensions/extension-loader/index.ts
Normal file
@ -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);
|
||||||
@ -20,12 +20,13 @@
|
|||||||
*/
|
*/
|
||||||
import { Injectable, lifecycleEnum } from "@ogre-tools/injectable";
|
import { Injectable, lifecycleEnum } from "@ogre-tools/injectable";
|
||||||
import { computed, IComputedValue } from "mobx";
|
import { computed, IComputedValue } from "mobx";
|
||||||
import { ExtensionLoader } from "./extension-loader";
|
|
||||||
import type { LensExtension } from "./lens-extension";
|
import type { LensExtension } from "./lens-extension";
|
||||||
|
import { ExtensionLoader } from "./extension-loader";
|
||||||
|
import type { ExtensionLoader as ExtensionLoaderType } from "./extension-loader/extension-loader";
|
||||||
|
|
||||||
const extensionsInjectable: Injectable<
|
const extensionsInjectable: Injectable<
|
||||||
IComputedValue<LensExtension[]>,
|
IComputedValue<LensExtension[]>,
|
||||||
{ extensionLoader: ExtensionLoader }
|
{ extensionLoader: ExtensionLoaderType }
|
||||||
> = {
|
> = {
|
||||||
getDependencies: () => ({
|
getDependencies: () => ({
|
||||||
extensionLoader: ExtensionLoader.getInstance(),
|
extensionLoader: ExtensionLoader.getInstance(),
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user