Deglobalize ElectronBridge type.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2021-09-01 14:00:37 -07:00
parent 014e97b563
commit feb67e6c2d
4 changed files with 25 additions and 22 deletions

View File

@@ -15,6 +15,12 @@ import {clipboard} from "electron";
// dont leak anything from the users clipboard other than the token
// intended for us.
export interface ClipboardDecrypter {
version: number;
key: Uint8Array;
pasted: Promise<string>;
}
export class ClipboardDecrypterImpl implements ClipboardDecrypter {
version: number;
key: Uint8Array;

View File

@@ -1,6 +1,7 @@
import {remote} from "electron";
import {EventEmitter} from "events";
import type {ClipboardDecrypter} from "./clipboard-decrypter";
import {ClipboardDecrypterImpl} from "./clipboard-decrypter";
import type {NotificationData} from "./notification";
import {newNotification} from "./notification";
@@ -8,6 +9,21 @@ import {ipcRenderer} from "./typed-ipc-renderer";
type ListenerType = (...args: any[]) => void;
export interface ElectronBridge {
send_event: (eventName: string | symbol, ...args: unknown[]) => boolean;
on_event: (eventName: string, listener: ListenerType) => 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;
}
let notificationReplySupported = false;
// Indicates if the user is idle or not
let idle = false;
@@ -41,7 +57,7 @@ const electron_bridge: ElectronBridge = {
notificationReplySupported = value;
},
decrypt_clipboard: (version: number): ClipboardDecrypterImpl =>
decrypt_clipboard: (version: number): ClipboardDecrypter =>
new ClipboardDecrypterImpl(version),
};

View File

@@ -1,5 +1,7 @@
"use strict";
type ElectronBridge = import("./electron-bridge").ElectronBridge;
interface CompatElectronBridge extends ElectronBridge {
readonly idle_on_system: boolean;
readonly last_active_on_system: number;

21
typings.d.ts vendored
View File

@@ -2,24 +2,3 @@ declare namespace Electron {
// https://github.com/electron/typescript-definitions/issues/170
interface IncomingMessage extends NodeJS.ReadableStream {}
}
interface ClipboardDecrypter {
version: number;
key: Uint8Array;
pasted: Promise<string>;
}
interface ElectronBridge {
send_event: (eventName: string | symbol, ...args: unknown[]) => boolean;
on_event: (eventName: string, listener: (...args: any[]) => void) => void;
new_notification: (
title: string,
options: NotificationOptions,
dispatch: (type: string, eventInit: EventInit) => boolean,
) => import("./app/renderer/js/notification").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;
}