From 57d61976434e531aae9881b19189762d900112c7 Mon Sep 17 00:00:00 2001
From: GitHub Action • IpcRegistrar.__@IpcPrefix@44748 IpcRegistrar.__@IpcPrefix@44753 • • [Disposers]: LensExtension.__@Disposers@30364 LensExtension.__@Disposers@30369 • appMenus: • protocolHandlers: LensExtension.protocolHandlers • trayMenus: • • IpcRegistrar.__@IpcPrefix@44748 IpcRegistrar.__@IpcPrefix@44753 • • [Disposers]: LensExtension.__@Disposers@30364 LensExtension.__@Disposers@30369 • appPreferences: This extension can register custom app menus that will be displayed on OS native menus. This extension can register custom app and tray menus that will be displayed on OS native menus. Example: The Main Extension API is the interface to Lens's main process.
Lens runs in both main and renderer processes.
The Main Extension API allows you to access, configure, and customize Lens data, add custom application menu items and protocol handlers, and run custom code in Lens's main process.
-It also provides convenient methods for navigating to built-in Lens pages and extension pages, as well as adding and removing sources of catalog entities. [IpcPrefix]#
Readonly [IpcPrefix]: stringInherited from#
-
extension#
Protected extension: LensExtensionAccessors#
@@ -1015,7 +1023,7 @@
[Disposers]#
ExtendableDisposerInherited from#
-
appMenus#
MenuRegistration[] = []ProtocolHandlerRegistration[] = []Inherited from#
+trayMenus#
+TrayMenuRegistration[] = []Accessors#
description#
get description(): string[IpcPrefix]#
Readonly [IpcPrefix]: stringInherited from#
-
extension#
Protected extension: LensExtension[Disposers]#
ExtendableDisposerInherited from#
-
appPreferences#
AppPreferenceRegistration[] = []App Menus#
-Menus#
+import { Main } from "@k8slens/extensions"
@@ -1022,6 +1022,29 @@ In order to see logs from this extension, you need to start Lens from the comman
}
}
]
+
+ trayMenus = [
+ {
+ label: "My links",
+ submenu: [
+ {
+ label: "Lens",
+ click() {
+ Main.Navigation.navigate("https://k8slens.dev");
+ }
+ },
+ {
+ type: "separator"
+ },
+ {
+ label: "Lens Github",
+ click() {
+ Main.Navigation.navigate("https://github.com/lensapp/lens");
+ }
+ }
+ ]
+ }
+ ]
}
Renderer Extension#
diff --git a/master/extensions/guides/main-extension/index.html b/master/extensions/guides/main-extension/index.html
index e42d9f3d16..227d5244a3 100644
--- a/master/extensions/guides/main-extension/index.html
+++ b/master/extensions/guides/main-extension/index.html
@@ -537,6 +537,13 @@
appMenus
+
+
+
Main.LensExtension Class#onActivate() and onDeactivate() Methods#To create a main extension simply extend the Main.LensExtension class:
For more details on accessing Lens state data, please see the Stores guide.
appMenus#The Main Extension API allows you to customize the UI application menu. -Note that this is the only UI feature that the Main Extension API allows you to customize. The following example demonstrates adding an item to the Help menu.
import { Main } from "@k8slens/extensions";
@@ -867,7 +880,7 @@ The following example demonstrates adding an item to the Help m
}
appMenus is an array of objects that satisfy the MenuRegistration interface.
-MenuRegistration extends React's MenuItemConstructorOptions interface.
+MenuRegistration extends Electron's MenuItemConstructorOptions interface.
The properties of the appMenus array objects are defined as follows:
parentId is the name of the menu where your new menu item will be listed.
@@ -894,6 +907,28 @@ Note that pages are associated with the R
When the menu item is clicked the navigate() method looks for and displays a global page with id "myGlobalPage".
This page would be defined in your extension's Renderer.LensExtension implementation (See Renderer.LensExtension).
trayMenus#trayMenus is an array of TrayMenuRegistration objects. Most importantly you can define a label and a click handler. Other properties are submenu, enabled, toolTip, id and type.
interface TrayMenuRegistration {
+ label?: string;
+ click?: (menuItem: TrayMenuRegistration) => void;
+ id?: string;
+ type?: "normal" | "separator" | "submenu"
+ toolTip?: string;
+ enabled?: boolean;
+ submenu?: TrayMenuRegistration[]
+}
+The following example demonstrates how tray menus can be added from extension:
+import { Main } from "@k8slens/extensions";
+
+export default class SampleTrayMenuMainExtension extends Main.LensExtension {
+ trayMenus = [{
+ label: "menu from the extension",
+ click: () => { console.log("tray menu clicked!") }
+ }]
+}
+addCatalogSource() and removeCatalogSource() Methods#The Main.LensExtension class also provides the addCatalogSource() and removeCatalogSource() methods, for managing custom catalog items (or entities).
See the Catalog documentation for full details about the catalog.