-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathindex.d.ts
More file actions
333 lines (289 loc) · 9.73 KB
/
Copy pathindex.d.ts
File metadata and controls
333 lines (289 loc) · 9.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
export * from './js-bindings';
export class SerializationError extends Error {
name: 'SerializationError';
}
export type JsonValue = null | boolean | number | string | JsonValue[] | { [key: string]: JsonValue };
export type ExposedTarget = Record<string, JsonValue | ((...args: any[]) => unknown | Promise<unknown>)>;
export type EventListener<TPayload> = (payload: TPayload) => void;
/** Shared EventEmitter surface with payloads inferred from an event map. */
export interface TypedEventEmitter<TEventMap extends object> {
on<K extends keyof TEventMap>(event: K, listener: EventListener<TEventMap[K]>): this;
on(event: string | symbol, listener: (...args: any[]) => void): this;
once<K extends keyof TEventMap>(event: K, listener: EventListener<TEventMap[K]>): this;
once(event: string | symbol, listener: (...args: any[]) => void): this;
off<K extends keyof TEventMap>(event: K, listener: EventListener<TEventMap[K]>): this;
off(event: string | symbol, listener: (...args: any[]) => void): this;
addListener<K extends keyof TEventMap>(event: K, listener: EventListener<TEventMap[K]>): this;
addListener(event: string | symbol, listener: (...args: any[]) => void): this;
removeListener<K extends keyof TEventMap>(event: K, listener: EventListener<TEventMap[K]>): this;
removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
removeAllListeners(event?: string | symbol): this;
listenerCount<K extends keyof TEventMap>(event: K, listener?: EventListener<TEventMap[K]>): number;
listenerCount(event: string | symbol, listener?: (...args: any[]) => void): number;
listeners<K extends keyof TEventMap>(event: K): Array<EventListener<TEventMap[K]>>;
listeners(event: string | symbol): Function[];
rawListeners<K extends keyof TEventMap>(event: K): Array<EventListener<TEventMap[K]>>;
rawListeners(event: string | symbol): Function[];
emit<K extends keyof TEventMap>(event: K, payload: TEventMap[K]): boolean;
emit(event: string | symbol, ...args: any[]): boolean;
eventNames(): Array<keyof TEventMap | string | symbol>;
}
export type NotificationPermission = 'granted';
export type NotificationDirection = 'auto' | 'ltr' | 'rtl';
export type NotificationEventName = 'click' | 'close' | 'error' | 'show';
export interface NotificationAction {
action: string;
title: string;
icon?: string;
}
export interface NotificationOptions {
body?: string;
icon?: string;
image?: string | Buffer;
badge?: string;
tag?: string;
data?: unknown;
dir?: NotificationDirection;
lang?: string;
renotify?: boolean;
requireInteraction?: boolean;
persistent?: boolean;
actions?: NotificationAction[];
silent?: boolean;
timestamp?: number;
vibrate?: number | number[];
}
export interface NotificationEvent {
type: NotificationEventName;
target: Notification;
action?: string;
error?: Error;
}
export type NotificationEventMap = {
[K in NotificationEventName]: NotificationEvent;
};
export interface Notification extends TypedEventEmitter<NotificationEventMap> {}
export class Notification {
constructor(title: string, options?: NotificationOptions);
static readonly permission: NotificationPermission;
static requestPermission(): Promise<NotificationPermission>;
readonly title: string;
readonly body: string;
readonly icon: string;
readonly image: string | Buffer;
readonly badge: string;
readonly tag: string;
readonly data: unknown;
readonly dir: NotificationDirection;
readonly lang: string;
readonly renotify: boolean;
readonly requireInteraction: boolean;
readonly persistent: boolean;
readonly actions: NotificationAction[];
readonly silent: boolean;
readonly timestamp: number;
readonly vibrate: number | number[];
onclick: ((event: NotificationEvent) => void) | null;
onclose: ((event: NotificationEvent) => void) | null;
onerror: ((event: NotificationEvent) => void) | null;
onshow: ((event: NotificationEvent) => void) | null;
close(): void;
}
export interface ApplicationEventMap {
'window-close-requested': import('./js-bindings').ApplicationEvent;
'application-close-requested': import('./js-bindings').ApplicationEvent;
'custom-menu-click': import('./js-bindings').ApplicationEvent;
ready: import('./js-bindings').ApplicationEvent;
}
export interface TrayEventMap {
click: import('./js-bindings').TrayEventPayload;
'double-click': import('./js-bindings').TrayEventPayload;
enter: import('./js-bindings').TrayEventPayload;
move: import('./js-bindings').TrayEventPayload;
leave: import('./js-bindings').TrayEventPayload;
}
export type ApplicationWhenReadyOptions =
| {
autoRun?: true;
interval?: number;
ref?: boolean;
}
| {
autoRun: false;
interval?: never;
ref?: never;
};
// ── Webview events ────────────────────────────────────────────────────────────
export interface WebviewPageLoadEvent {
event: number;
url?: string;
}
export interface WebviewTitleChangedEvent {
event: number;
title?: string;
}
export interface WebviewDownloadEvent {
event: number;
url?: string;
/** Only set for `download-completed` events. */
success?: boolean;
}
export interface WebviewDownloadStartedEvent extends WebviewDownloadEvent {}
export interface WebviewNavigationEvent {
event: number;
url?: string;
}
export interface WebviewNewWindowEvent {
event: number;
url?: string;
}
/** Maps Webview event names to their typed payloads. */
export interface WebviewEventMap {
'page-load-started': WebviewPageLoadEvent;
'page-load-finished': WebviewPageLoadEvent;
'title-changed': WebviewTitleChangedEvent;
'download-started': WebviewDownloadStartedEvent;
'download-completed': WebviewDownloadEvent;
/** Fired for every navigation attempt. */
navigation: WebviewNavigationEvent;
/**
* Fired when the page requests a new window.
* On Windows this event is observational because Wry dispatches it from a
* separate WebView2 thread.
*/
'new-window': WebviewNewWindowEvent;
}
export interface WindowMoveEvent {
event: number;
x: number;
y: number;
}
export interface WindowResizeEvent {
event: number;
width: number;
height: number;
}
export interface WindowMouseEvent {
event: number;
x: number;
y: number;
button?: number;
modifiers?: number;
}
export interface WindowScrollEvent {
event: number;
deltaX: number;
deltaY: number;
}
export interface WindowBaseEvent {
event: number;
}
export interface WindowKeyEvent {
event: number;
key?: string;
code?: string;
modifiers?: number;
isRepeat?: boolean;
}
export interface WindowFileEvent {
event: number;
files?: string[];
}
export interface WindowScaleEvent {
event: number;
scaleFactor: number;
}
export interface WindowThemeEvent {
event: number;
text: 'light' | 'dark';
}
export interface WindowImeEvent {
event: number;
text?: string;
phase: 'enabled' | 'preedit' | 'commit' | 'disabled';
}
export interface WindowTouchEvent {
event: number;
x: number;
y: number;
touchId: number;
phase: 'started' | 'moved' | 'ended' | 'cancelled';
}
export interface BrowserWindowEventMap {
move: WindowMoveEvent;
resize: WindowResizeEvent;
close: WindowBaseEvent;
focus: WindowBaseEvent;
blur: WindowBaseEvent;
'mouse-enter': WindowMouseEvent;
'mouse-leave': WindowBaseEvent;
'mouse-move': WindowMouseEvent;
'mouse-down': WindowMouseEvent;
'mouse-up': WindowMouseEvent;
scroll: WindowScrollEvent;
'key-down': WindowKeyEvent;
'key-up': WindowKeyEvent;
'file-drop': WindowFileEvent;
'file-hover': WindowFileEvent;
'file-hover-cancelled': WindowBaseEvent;
'scale-factor-changed': WindowScaleEvent;
'theme-changed': WindowThemeEvent;
ime: WindowImeEvent;
touch: WindowTouchEvent;
}
declare module './js-bindings' {
interface TrayIcon extends TypedEventEmitter<TrayEventMap> {
[Symbol.dispose](): void;
}
interface Application extends TypedEventEmitter<ApplicationEventMap> {
[Symbol.dispose](): void;
whenReady(options?: ApplicationWhenReadyOptions): Promise<void>;
}
interface WebviewOptions {
/**
* Shared `WebContext` for cookie/data isolation across webviews.
* Create one with `app.createWebContext({ dataDirectory })` and pass it here.
*/
webContext?: import('./js-bindings').WebContext | null;
/**
* Synchronous navigation guard. Called with the target URL before every
* navigation; return `true` to allow, `false` to cancel.
*
* A `navigation` event is **always** emitted regardless of this handler.
*/
navigationHandler?: (url: string) => boolean;
}
interface BrowserWindow extends TypedEventEmitter<BrowserWindowEventMap> {
[Symbol.dispose](): void;
/**
* Register a custom protocol handler.
*
* The handler receives a global `Request` object and should return a
* global `Response` (compatible with Hono, itty-router, and any other
* Fetch-API framework), or a legacy `CustomProtocolResponse` plain object.
*
* @example
* ```ts
* // With Hono:
* win.registerProtocol('app', (req) => honoApp.fetch(req));
*
* // With a plain Response:
* win.registerProtocol('app', async (req) => {
* const body = await readFile('./index.html');
* return new Response(body, { headers: { 'Content-Type': 'text/html' } });
* });
* ```
*/
registerProtocol(
name: string,
handler: (request: Request) => Response | CustomProtocolResponse | Promise<Response | CustomProtocolResponse>,
): void;
}
interface Webview extends TypedEventEmitter<WebviewEventMap> {
[Symbol.dispose](): void;
expose(name: string, target: ExposedTarget): void;
}
interface WebContext {
[Symbol.dispose](): void;
}
}