From 82e4250592e5468dd725c8932e2a72913238fa98 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Wed, 11 Oct 2023 17:17:19 -0700 Subject: [PATCH] electron_bridge: Declare Zulip Desktop binding types. Signed-off-by: Anders Kaseorg --- tools/test-js-with-node | 1 + web/src/electron_bridge.d.ts | 45 ++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 web/src/electron_bridge.d.ts diff --git a/tools/test-js-with-node b/tools/test-js-with-node index 15393b7b97..456f5b4ca7 100755 --- a/tools/test-js-with-node +++ b/tools/test-js-with-node @@ -98,6 +98,7 @@ EXEMPT_FILES = make_set( "web/src/drafts_overlay_ui.js", "web/src/dropdown_widget.js", "web/src/echo.js", + "web/src/electron_bridge.d.ts", "web/src/emoji_picker.js", "web/src/emojisets.ts", "web/src/favicon.ts", diff --git a/web/src/electron_bridge.d.ts b/web/src/electron_bridge.d.ts new file mode 100644 index 0000000000..1bdd4a89e6 --- /dev/null +++ b/web/src/electron_bridge.d.ts @@ -0,0 +1,45 @@ +export type NotificationData = { + title: string; + dir: NotificationDirection; + lang: string; + body: string; + tag: string; + icon: string; + data: unknown; + close(): void; +}; + +export type ClipboardDecrypter = { + version: number; + key: Uint8Array; + pasted: Promise; +}; + +export type ElectronBridge = { + send_event(eventName: string | symbol, ...args: unknown[]): boolean; + on_event( + eventName: "logout" | "show-keyboard-shortcuts" | "show-notification-settings", + listener: () => void, + ): void; + on_event( + eventName: "send_notification_reply_message", + listener: (message_id: unknown, reply: unknown) => void, + ): void; + new_notification?( + title: string, + options: NotificationOptions, + dispatch: (type: string, eventInit: EventInit) => boolean, + ): NotificationData; + get_idle_on_system?(): boolean; + get_last_active_on_system?(): number; + get_send_notification_reply_message_supported?(): boolean; + set_send_notification_reply_message_supported?(value: boolean): void; + decrypt_clipboard?(version: number): ClipboardDecrypter; +}; + +declare global { + // eslint-disable-next-line @typescript-eslint/consistent-type-definitions + interface Window { + electron_bridge?: ElectronBridge; + } +}