mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Define a type for tray menu registration
Signed-off-by: Juho Heikka <juho.heikka@gmail.com>
This commit is contained in:
parent
d407b27f7f
commit
bb4790e3d8
@ -97,7 +97,7 @@ This page would be defined in your extension's `Renderer.LensExtension` implemen
|
||||
|
||||
### `trayMenus`
|
||||
|
||||
`trayMenus` is an array of Electron's [`MenuItemConstructorOptions`](https://www.electronjs.org/docs/v14-x-y/api/menu-item). Most importantly you can define a `label` and a `click` handler.
|
||||
`trayMenus` is a subset of Electron's [`MenuItemConstructorOptions`](https://www.electronjs.org/docs/v14-x-y/api/menu-item). Most importantly you can define a `label` and a `click` handler. Other properties are `submenu`, `enabled`, `visible`, `toolTip`, `id` and `type`.
|
||||
|
||||
The following example demonstrates how tray menus can be added from extension:
|
||||
|
||||
|
||||
@ -25,11 +25,10 @@ import { catalogEntityRegistry } from "../main/catalog";
|
||||
import type { CatalogEntity } from "../common/catalog";
|
||||
import type { IObservableArray } from "mobx";
|
||||
import type { MenuRegistration } from "../main/menu/menu-registration";
|
||||
import type { MenuItemConstructorOptions } from "electron";
|
||||
|
||||
import type { TrayMenuRegistration } from "../main/tray/tray-menu-registration";
|
||||
export class LensMainExtension extends LensExtension {
|
||||
appMenus: MenuRegistration[] = [];
|
||||
trayMenus: MenuItemConstructorOptions[] = [];
|
||||
trayMenus: TrayMenuRegistration[] = [];
|
||||
|
||||
async navigate(pageId?: string, params?: Record<string, any>, frameId?: number) {
|
||||
return WindowManager.getInstance().navigateExtension(this.id, pageId, params, frameId);
|
||||
|
||||
@ -23,13 +23,13 @@ import { LensMainExtension } from "../../extensions/lens-main-extension";
|
||||
import trayItemsInjectable from "./tray-menu-items.injectable";
|
||||
import type { IComputedValue } from "mobx";
|
||||
import { computed, ObservableMap, runInAction } from "mobx";
|
||||
import type { MenuItemConstructorOptions } from "electron";
|
||||
import { getDiForUnitTesting } from "../getDiForUnitTesting";
|
||||
import mainExtensionsInjectable from "../../extensions/main-extensions.injectable";
|
||||
import type { TrayMenuRegistration } from "./tray-menu-registration";
|
||||
|
||||
describe("tray-menu-items", () => {
|
||||
let di: ConfigurableDependencyInjectionContainer;
|
||||
let trayMenuItems: IComputedValue<MenuItemConstructorOptions[]>;
|
||||
let trayMenuItems: IComputedValue<TrayMenuRegistration[]>;
|
||||
let extensionsStub: ObservableMap<string, LensMainExtension>;
|
||||
|
||||
beforeEach(() => {
|
||||
@ -115,7 +115,7 @@ describe("tray-menu-items", () => {
|
||||
class SomeTestExtension extends LensMainExtension {
|
||||
constructor({ id, trayMenus }: {
|
||||
id: string;
|
||||
trayMenus: MenuItemConstructorOptions[];
|
||||
trayMenus: TrayMenuRegistration[];
|
||||
}) {
|
||||
super({
|
||||
id,
|
||||
|
||||
26
src/main/tray/tray-menu-registration.d.ts
vendored
Normal file
26
src/main/tray/tray-menu-registration.d.ts
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
/**
|
||||
* 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 { MenuItemConstructorOptions } from "electron";
|
||||
|
||||
export type TrayMenuRegistration = Pick<MenuItemConstructorOptions,
|
||||
"label" | "type" | "submenu" | "click" |
|
||||
"toolTip" | "visible" | "enabled" | "id">;
|
||||
@ -31,7 +31,7 @@ import { isDevelopment, isWindows, productName } from "../../common/vars";
|
||||
import { exitApp } from "../exit-app";
|
||||
import { preferencesURL } from "../../common/routes";
|
||||
import { toJS } from "../../common/utils";
|
||||
import type { MenuItemConstructorOptions } from "electron/main";
|
||||
import type { TrayMenuRegistration } from "./tray-menu-registration";
|
||||
|
||||
const TRAY_LOG_PREFIX = "[TRAY]";
|
||||
|
||||
@ -48,7 +48,7 @@ export function getTrayIcon(): string {
|
||||
|
||||
export function initTray(
|
||||
windowManager: WindowManager,
|
||||
trayMenuItems: IComputedValue<MenuItemConstructorOptions[]>,
|
||||
trayMenuItems: IComputedValue<TrayMenuRegistration[]>,
|
||||
) {
|
||||
const icon = getTrayIcon();
|
||||
|
||||
@ -85,7 +85,7 @@ export function initTray(
|
||||
|
||||
function createTrayMenu(
|
||||
windowManager: WindowManager,
|
||||
extensionTrayItems: MenuItemConstructorOptions[],
|
||||
extensionTrayItems: TrayMenuRegistration[],
|
||||
): Menu {
|
||||
let template: Electron.MenuItemConstructorOptions[] = [
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user