UNPKG

systray

Version:
68 lines (67 loc) 1.91 kB
/// <reference types="node" /> import * as child from 'child_process'; import * as EventEmitter from 'events'; import * as readline from 'readline'; export declare type MenuItem = { title: string; tooltip: string; checked: boolean; enabled: boolean; }; export declare type Menu = { icon: string; title: string; tooltip: string; items: MenuItem[]; }; export declare type ClickEvent = { type: 'clicked'; item: MenuItem; seq_id: number; }; export declare type ReadyEvent = { type: 'ready'; }; export declare type Event = ClickEvent | ReadyEvent; export declare type UpdateItemAction = { type: 'update-item'; item: MenuItem; seq_id: number; }; export declare type UpdateMenuAction = { type: 'update-menu'; menu: Menu; seq_id: number; }; export declare type UpdateMenuAndItemAction = { type: 'update-menu-and-item'; menu: Menu; item: MenuItem; seq_id: number; }; export declare type Action = UpdateItemAction | UpdateMenuAction | UpdateMenuAndItemAction; export declare type Conf = { menu: Menu; debug?: boolean; copyDir?: boolean | string; }; export default class SysTray extends EventEmitter { protected _conf: Conf; protected _process: child.ChildProcess; protected _rl: readline.ReadLine; protected _binPath: string; constructor(conf: Conf); onReady(listener: () => void): this; onClick(listener: (action: ClickEvent) => void): this; writeLine(line: string): this; sendAction(action: Action): this; /** * Kill the systray process * @param exitNode Exit current node process after systray process is killed, default is true */ kill(exitNode?: boolean): void; onExit(listener: (code: number | null, signal: string | null) => void): void; onError(listener: (err: Error) => void): void; readonly killed: boolean; readonly binPath: string; }