import type { Result } from "@cprussin/option-result"; import type { Dbus } from "./desktop/dbus"; import type { SystemError } from "./system"; export declare enum MenuEntryKind { Item = 0, Separator = 1 } export declare enum ToggleKind { Checkmark = 0, Radio = 1 } /** A check box or radio button beside an item. */ export type Toggle = { kind: ToggleKind; checked: boolean; }; /** One thing the menu can do, or a submenu. */ export type MenuItem = { /** What {@link WatchedMenu.click} names it by. */ id: number; /** Its text, with the mnemonic's underscore removed. */ label: string; /** Where in `label` the access key is, if its underscore marked one. */ mnemonic: number | undefined; enabled: boolean; /** A freedesktop icon name. */ icon: string | undefined; /** The application's own picture (`icon-data`), as a PNG `data:` URL. */ image: string | undefined; toggle: Toggle | undefined; /** Its entries, for an item that opens a submenu. */ submenu: readonly MenuEntry[] | undefined; }; type ItemEntry = MenuItem & { kind: MenuEntryKind.Item; }; type SeparatorEntry = { id: number; kind: MenuEntryKind.Separator; }; export declare const MenuEntry: { Item: (item: MenuItem) => ItemEntry; Separator: (id: number) => SeparatorEntry; }; /** An entry the application shows; hidden ones are left out. */ export type MenuEntry = ReturnType<(typeof MenuEntry)[keyof typeof MenuEntry]>; /** Where a menu answers: a tray item's `bus` and `menu`. */ export type MenuAddress = { bus: string; path: string; }; /** The calls this module makes. */ export type MenuDesktop = { readonly dbus: Pick; }; /** A menu being watched, and the requests it takes. */ export type WatchedMenu = { /** Activate an item. */ click: (id: number) => Promise>; /** * Tell the application the submenu under `id` (0 for the top) is about to * show. Reads the menu again if the application changed it. */ aboutToShow: (id: number) => Promise>; stop: () => void; }; /** * Calls `onMenu` with the menu at `address` now and after each change, until * stopped. * * An `Err` is a D-Bus failure, such as the application having quit or the * desktop being locked. The watch keeps listening after a failed read. */ export declare const watchMenu: (domicile: MenuDesktop, address: MenuAddress, onMenu: (menu: Result) => void) => WatchedMenu; export {};