-
-
Notifications
You must be signed in to change notification settings - Fork 62
/
type.d.ts
570 lines (423 loc) · 16.5 KB
/
type.d.ts
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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
declare module 'sketch-module-web-view' {
import { EventEmitter } from 'events'
export interface WebPreferences {
/**
* Whether to enable DevTools. If it is set to `false`, can not use
* `BrowserWindow.webContents.openDevTools()` to open DevTools.
* Default is `true`. */
devTools: boolean
/** Enables JavaScript support. Default is `true`. */
javascript?: boolean
/** Whether plugins should be enabled. Default is `false`. */
plugins?: boolean
/** Defaults to `0` */
minimumFontSize?: number
/**
* The default zoom factor of the page, `3.0` represents `300%`.
* Default is `1.0`.
*/
zoomFactor?: number
}
export interface BrowserWindowOptions {
/** Unique identifier of the window */
identifier?: string
/** Window's width in pixels. Default is `800`. */
width?: number
/** Window's height in pixels. Default is `600`. */
height?: number
/**
* (required if y is used) - Window's left offset from screen.
* Default is to center the window.
*/
x?: number
/**
* (required if x is used) - Window's top offset from screen.
* Default is to center the window.
*/
y?: number
/**
* Whether the window is removed from the screen when Sketch becomes
* inactive. Default is `true`.
*/
hidesOnDeactivate?: boolean
/**
* Whether to remember the position and the size of the window the next
* time. Defaults is `false`.
*/
remembersWindowFrame?: boolean
/**
* The `width` and `height` would be used as web page's size, which means
* the actual window's size will include window frame's size and be slightly
* larger. Default is `false`.
*/
useContentSize?: boolean
/** Show window in the center of the screen. */
center?: boolean
/** Window's minimum width. Default is `0`. */
minWidth?: number
/** Window's minimum height. Default is `0`. */
minHeight?: number
/** Window's maximum width. Default is no limit. */
maxWidth?: number
/** Window's maximum height. Default is no limit. */
maxHeight?: number
/** Whether window is resizable. Default is `true`. */
resizable?: boolean
/** Whether window is movable. Default is `true`. */
movable?: boolean
/** Whether window is minimizable. Default is `true`. */
minimizable?: boolean
/** Whether window is maximizable. Default is `true`. */
maximizable?: boolean
/** Whether window is closable. Default is `true`. */
closable?: boolean
/**
* Whether the window should always stay on top of other windows.
* Default is `false`.
*/
alwaysOnTop?: boolean
/**
* Whether the window should show in fullscreen. When explicitly set to
* `false` the fullscreen button will be hidden or disabled.
* Default is `false`.
*/
fullscreen?: boolean
/**
* Whether the window can be put into fullscreen mode. Also whether the
* maximize/zoom button should toggle full screen mode or maximize window.
* Default is `true`.
*/
fullscreenable?: boolean
/** Default window title. Default is your plugin name. */
title?: string
/** Whether window should be shown when created. Default is `true`. */
show?: boolean
/** Specify `false` to create a Frameless Window. Default is `true`. */
frame?: boolean
/** Specify parent Document. Default is `null`. */
parent?: any
/**
* Whether this is a modal window. This only works when the window is a
* child window. Default is `false`.
*/
modal?: boolean
/**
* Whether the web view accepts a single mouse-down event that
* simultaneously activates the window. Default is `false`.
*/
acceptsFirstMouse?: boolean
/** Whether to hide cursor when typing. Default is `false`. */
disableAutoHideCursor?: boolean
/**
* Window's background color as a hexadecimal value, like `#66CD00` or
* `#FFF` or `#80FFFFFF` (alpha is supported). Default is
* `NSColor.windowBackgroundColor()`.
*/
backgroundColor?: string
/** Whether window should have a shadow. Default is `true`. */
hasShadow?: boolean
/**
* Set the initial opacity of the window, between `0.0` (fully transparent)
* and `1.0` (fully opaque).
*/
opacity?: number
/** Makes the window transparent. Default is `false`. */
transparent?: boolean
/**
* The style of window title bar. Default is `default`. Possible values are:
* - `default` - Results in the standard gray opaque Mac title bar.
* - `hidden` - Results in a hidden title bar and a full size content
* window, yet the title bar still has the standard window controls
* ("traffic lights") in the top left.
* - `hiddenInset` - Results in a hidden title bar with an alternative look
* where the traffic light buttons are slightly more inset from the
* window edge.
*/
titleBarStyle?: 'default' | 'hidden' | 'hiddenInset'
/**
* Add a type of vibrancy effect to the window, only on macOS.
* Please note that using `frame: false` in combination with a `vibrancy`
* value requires that you use a non-default `titleBarStyle` as well.
*/
vibrancy?:
| 'appearance-based'
| 'light'
| 'dark'
| 'titlebar'
| 'selection'
| 'menu'
| 'popover'
| 'sidebar'
| 'medium-light'
| 'ultra-dark'
/** Settings of web page's features. */
webPreferences?: WebPreferences
}
export interface Rectangle {
/** The height of the rectangle (must be an integer). */
height: number
/** The width of the rectangle (must be an integer). */
width: number
/** The x coordinate of the origin of the rectangle (must be an integer). */
x: number
/** The y coordinate of the origin of the rectangle (must be an integer). */
y: number
}
export interface WebContents extends NodeJS.EventEmitter {
/**
* Load web page of given url
* @param url can be a remote address (e.g. `http://`) or a path to a local
* HTML file using the `file://` protocol.
*/
loadURL(url: string): Promise<void>
/** The URL of the current web page. */
getURL(): string
/** The title of the current web page. */
getTitle(): string
// todo
/** Whether the web page is destroyed. */
// isDestroyed(): boolean;
/** Whether web page is still loading resources. */
isLoading(): boolean
/** Whether web page is waiting for response */
isWaitingForResponse(): boolean
/** Stops any pending navigation. */
stop(): void
/** Reloads the current web page. */
reload(): void
/** Reload the current web page by ignoring local cache. */
reloadIgnoringCache(): void
/** Whether the browser can go back to previous web page. */
canGoBack(): boolean
/** Whether the browser can go forward to next web page. */
canGoForward(): boolean
/** Whether the browser can go to any index web package. */
canGoToOffset(offset: number): boolean
/** Makes the browser go back a web page. */
goBack(): void
/** Makes the browser go forward a web page. */
goForward(): void
/** Navigates browser to the specified absolute web page index. */
goToIndex(index: number): void
/** Navigates to the specified offset from the "current entry". */
goToOffset(offset: number): void
/** Return the user agent string of webview. */
getUserAgent(): string | undefined
/** Inject CSS code into a web page. */
insertCSS(css: string): void
/** Inject JS code into a web page. */
insertJS(source: string): void
/** Evaluates `code` in page. */
executeJavaScript<T>(
code: string,
callback?: (error: Error | null, result: T) => void
): Promise<T>
/** Changes the zoom factor to the specified factor. */
setZoomFactor(factor: number): void
/** Returns the current zoom factor. */
getZoomFactor(callback: (factor: number) => any): void
/** Changes the zoom level to the specified level. The original size is 0 and each increment above or below represents zooming 20% larger or smaller to default limits. */
setZoomLevel(level: number): void
/** Returns the current zoom level. */
getZoomLevel(callback: (level: number) => any): void
/** Executes the editing command `undo` in web page. */
undo(): void
/** Executes the editing command `redo` in web page. */
redo(): void
/** Executes the editing command `cut` in web page. */
cut(): void
/** Executes the editing command `copy` in web page. */
copy(): void
/** Executes the editing command `paste` in web page. */
paste(): void
/** Executes the editing command `pasteAndMatchStyle` in web page. */
pasteAndMatchStyle(): void
/** Executes the editing command `delete` in web page. */
delete(): void
/** Executes the editing command `replace` in web page. */
replace(): void
/** Send message to a web page. */
send(...args: any[]): void
}
export class BrowserWindow extends EventEmitter {
/** Create a browser window. */
constructor(options?: BrowserWindowOptions)
/** Return window with the given id */
static fromId(id: string): BrowserWindow
/**
* A `WebContents` object this window owns. All web page related events and
* operations will be done via it.
*/
webContents: WebContents
/** An integer representing the unique ID of the window. */
id: string
/**
* Force closing the window, the `unload` and `beforeunload` event won't be
* emitted for the web page, and `close` event will also not be emitted for
* this window, but it guarantees the `closed` event will be emitted.
*/
destroy(): void
/**
* Try to close the window. This has the same effect as a user manually
* clicking the close button of the window. The web page may cancel the
* close though.
*/
close(): void
/** Focuses on the window. */
focus(): void
/** Removes focus from the window. */
blur(): void
/** Whether the window is focused. */
isFocused(): boolean
/** Whether the window is destroyed. */
isDestroyed(): boolean
/** Shows and gives focus to the window. */
show(): void
/** Shows the window but doesn't focus on it. */
showInactive(): void
/** Hides the window. */
hide(): void
/** Whether the window is visible to the user. */
isVisible(): boolean
/** Whether current window is a modal window. */
isModal(): boolean
/**
* Maximizes the window. This will also show (but not focus) the window if
* it isn't being displayed already.
*/
maximize(): void
/** Unmaximizes the window. */
unmaximize(): void
/** Whether the window is maximized. */
isMaximized(): boolean
/**
* Minimizes the window.
* On some platforms the minimized window will be shown in the Dock.
*/
minimize(): void
/** Restores the window from minimized state to its previous state. */
restore(): void
/** Whether the window is minimized. */
isMinimized(): boolean
/** Sets whether the window should be in fullscreen mode. */
setFullScreen(shouldBeFullscreen: boolean): void
/** Whether the window is in fullscreen mode. */
isFullScreen(): boolean
/**
* Make a window maintain an aspect ratio.
* @param aspectRatio The aspect ratio to maintain for some portion of the
* content view.
* @param extraSize The extra size not to be included while maintaining the
* aspect ratio.
*/
setAspectRatio(
aspectRatio: number,
extraSize?: {
width: number
height: number
}
): void
/**
* Resizes and moves the window to the supplied bounds.
* @param bounds The supplied bounds. Any properties that are not supplied
* will default to their current values.
* @param animate Whether to show the animation when resizing
*/
setBounds(bounds: Partial<Rectangle>, animate: boolean): void
/** Get the bounds of the browser window */
getBounds(): Rectangle
/** Resizes and moves the window's client area to the supplied bounds. */
setContentBounds(bounds: Rectangle, animate: boolean): void
/** Get the bounds of the window's client area */
getContentBounds(): Rectangle
/** Disable or enable the window. */
setEnabled(enabled: boolean): void
/** Resizes the window to given `width` and `height`. */
setSize(width: number, height: number, animate: boolean): void
/** Contains the window's width and height. */
getSize(): [number, number]
/** Resizes the window's client area to given `width` and `height`. */
setContentSize(width: number, height: number, animate: boolean): void
/** Contains the window's client area's width and height. */
getContentSize(): [number, number]
/** Sets the minimum size of window to width and height. */
setMinimumSize(width: number, height: number): void
/** Contains the window's minimum width and height. */
getMinimumSize(): [number, number]
/** Sets the maximum size of window to `width` and `height`. */
setMaximumSize(width: number, height: number): void
/** Contains the window's maximum width and height. */
getMaximumSize(): [number, number]
/** Sets whether the window can be manually resized by user. */
setResizable(resizable: boolean): void
/** Whether the window can be manually resized by user. */
isResizable(): boolean
/** Sets whether the window can be moved by user. */
setMovable(movable: boolean): void
/** Sets whether the window can be manually minimized by user. */
setMinimizable(minimizable: boolean): void
/** Sets whether the window can be manually maximized by user. */
setMaximizable(maximizable: boolean): void
/** Whether the window can be manually maximized by user. */
isMaximizable(): boolean
/**
* Sets whether the maximize/zoom window button toggles fullscreen mode or
* maximizes the window.
*/
setFullScreenable(fullscreenable: boolean): void
/**
* Whether the maximize/zoom window button toggles fullscreen mode or
* maximizes the window.
*/
isFullScreenable(): boolean
/** Sets whether the window can be manually closed by user. */
setClosable(closable: boolean): void
/** Whether the window can be manually closed by user. */
isClosable(): boolean
/** Sets whether the window should show always on top of other windows. */
setAlwaysOnTop(flag: boolean, level?: string, relativeLevel?: number): void
/** Whether the window is always on top of other windows. */
isAlwaysOnTop(): boolean
/** Moves window to top(z-order) regardless of focus */
moveTop(): void
/** Moves window to the center of the screen. */
center(): void
/** Moves window to `x` and `y`. */
setPosition(x: number, y: number, animate: boolean): void
/** Contains the window's current position. */
getPosition(): [number, number]
/** Changes the title of native window to `title`. */
setTitle(title: string): void
/** The title of the native window. */
getTitle(): string
/** Starts or stops flashing the window to attract user's attention. */
flashFrame(flashing: boolean): void
/** The platform-specific handle of the window. */
getNativeWindowHandle(): Buffer
/** Load web page of given url */
loadURL(url: string): Promise<void>
/** Reload the page */
reload(): void
/** Sets whether the window should have a shadow. */
setHasShadow(hasShadow: boolean): void
/** Whether the window has a shadow. */
hasShadow(): boolean
/** Sets the opacity of the window. */
setOpacity(opacity: number): void
/** Return the opacity of the window */
getOpacity(): number
/** Sets whether the window should be visible on all workspaces. */
setVisibleOnAllWorkspaces(visible: boolean): void
/** Whether the window is visible on all workspaces. */
isVisibleOnAllWorkspaces(): boolean
/** Makes the window ignore all mouse events. */
setIgnoreMouseEvents(ignore: boolean): void
/** Prevents the window contents from being captured by other apps. */
setContentProtection(enabled: boolean): void
/** Controls whether to hide cursor when typing. */
setAutoHideCursor(autoHide: boolean): void
/** Adds a vibrancy effect to the browser window. */
setVibrancy(type: string | null): void
}
export default BrowserWindow
}