Switch to getting menu items by observing change in extensions instead local state

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com>
This commit is contained in:
Janne SavolainenandMikko Aspiala committed 2021-12-08 13:10:50 +02:00
1 parent 7965649521
commit 67c24cac9a
11 files changed
+371 -43

No files matched your search

+2 -21
View File
@@ -32,7 +32,6 @@ 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 { LensMainExtension } from "./lens-main-extension";
import type { LensRendererExtension } from "./lens-renderer-extension";
import * as registries from "./registries";
@@ -47,7 +46,7 @@ const logModule = "[EXTENSIONS-LOADER]";
*/
export class ExtensionLoader extends Singleton {
protected extensions = observable.map<LensExtensionId, InstalledExtension>();
protected instances = observable.map<LensExtensionId, LensExtension>();
instances = observable.map<LensExtensionId, LensExtension>();
/**
* This is the set of extensions that don't come with either
@@ -248,25 +247,7 @@ export class ExtensionLoader extends Singleton {
}
loadOnMain() {
registries.MenuRegistry.createInstance();
logger.debug(`${logModule}: load on main`);
this.autoInitExtensions(async (extension: LensMainExtension) => {
// Each .add returns a function to remove the item
const removeItems = [
registries.MenuRegistry.getInstance().add(extension.appMenus),
];
this.events.on("remove", (removedExtension: LensRendererExtension) => {
if (removedExtension.id === extension.id) {
removeItems.forEach(remove => {
remove();
});
}
});
return removeItems;
});
this.autoInitExtensions(() => Promise.resolve([]));
}
loadOnClusterManagerRenderer() {
+42
View File
@@ -0,0 +1,42 @@
/**
* 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 { Injectable, lifecycleEnum } from "@ogre-tools/injectable";
import { computed, IComputedValue } from "mobx";
import { ExtensionLoader } from "./extension-loader";
import type { LensExtension } from "./lens-extension";
const extensionsInjectable: Injectable<
IComputedValue<LensExtension[]>,
{ extensionLoader: ExtensionLoader }
> = {
getDependencies: () => ({
extensionLoader: ExtensionLoader.createInstance(),
}),
lifecycle: lifecycleEnum.singleton,
instantiate: ({ extensionLoader }) =>
computed(() =>
[...extensionLoader.instances.values()],
),
};
export default extensionsInjectable;
+1 -1
View File
@@ -24,7 +24,7 @@ import { WindowManager } from "../main/window-manager";
import { catalogEntityRegistry } from "../main/catalog";
import type { CatalogEntity } from "../common/catalog";
import type { IObservableArray } from "mobx";
import type { MenuRegistration } from "./registries";
import type { MenuRegistration } from "../main/menu/menu-registration";
export class LensMainExtension extends LensExtension {
appMenus: MenuRegistration[] = [];