1. API
  2. appMenu

API

Methods for manipulating native menus in ToDesktop.

Remarks

This package exposes a number of methods for manipulating native menus wthin ToDesktop windows.

On macOS, these menus are displayed at the top of the user's screen in the top bar. On Windows and Linux, these menus are displayed under the window title bar.

Functions

Function Description
add(parentMenu, label, handler, options) Adds an item to the Application's menu bar.
on(event, callback) Subscribes to a click event from the application menu
refresh() Triggers the application's menu bar UI to refresh. Useful after adding new menu items.

add()

Adds an item to the Application's menu bar.

Signature:

        import { appMenu } from "@todesktop/client-core"
appMenu.add(parentMenu: string, label: string, handler: () => void, options: MenuItemOptions): Promise<void>;

      
Parameters
Parameter Type Description
parentMenu string
label string
handler () => void
options MenuItemOptions

Returns:

Promise<void>

on()

Subscribes to a click event from the application menu

Signature:

        import { appMenu } from "@todesktop/client-core"
appMenu.on(event: string, callback: (event: string) => void): Promise<() => void>;

      
Parameters
Parameter Type Description
event string The name of the event to subscribe to.
callback (event: string) => void The function to be invoked when this event is triggered.

Returns:

Promise<() => void>

A callback for unsubscribing from the click event.

refresh()

Triggers the application's menu bar UI to refresh. Useful after adding new menu items.

Signature:

        import { appMenu } from "@todesktop/client-core"
appMenu.refresh(): Promise<void>;

      

Returns:

Promise<void>

Type Aliases

Configuration object for a native menu item.

Signature:

        export declare type MenuItemOptions = {
    accelerator: string;
};

      
Type Alias Description
MenuItemOptions Configuration object for a native menu item.