forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
github-electron.d.ts
1447 lines (1411 loc) · 40.3 KB
/
github-electron.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
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Type definitions for Electron 0.25.2 (shared between main and rederer processes)
// Project: http://electron.atom.io/
// Definitions by: jedmao <https://github.com/jedmao/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../node/node.d.ts" />
declare module GitHubElectron {
/**
* This class is used to represent an image.
*/
class NativeImage {
/**
* Creates an empty NativeImage instance.
*/
static createEmpty(): NativeImage;
/**
* Creates a new NativeImage instance from file located at path.
*/
static createFromPath(path: string): NativeImage;
/**
* Creates a new NativeImage instance from buffer.
* @param scaleFactor 1.0 by default.
*/
static createFromBuffer(buffer: Buffer, scaleFactor?: number): NativeImage;
/**
* Creates a new NativeImage instance from dataUrl
*/
static createFromDataUrl(dataUrl: string): NativeImage;
/**
* @returns Buffer Contains the image's PNG encoded data.
*/
toPng(): Buffer;
/**
* @returns Buffer Contains the image's JPEG encoded data.
*/
toJpeg(quality: number): Buffer;
/**
* @returns string The data URL of the image.
*/
toDataUrl(): string;
/**
* @returns boolean Whether the image is empty.
*/
isEmpty(): boolean;
/**
* @returns {} The size of the image.
*/
getSize(): any;
/**
* Marks the image as template image.
*/
setTemplateImage(option: boolean): void;
}
module Clipboard {
/**
* @returns The contents of the clipboard as a NativeImage.
*/
function readImage(type?: string): NativeImage;
/**
* Writes the image into the clipboard.
*/
function writeImage(image: NativeImage, type?: string): void;
}
class Screen implements NodeJS.EventEmitter {
addListener(event: string, listener: Function): Screen;
on(event: string, listener: Function): Screen;
once(event: string, listener: Function): Screen;
removeListener(event: string, listener: Function): Screen;
removeAllListeners(event?: string): Screen;
setMaxListeners(n: number): void;
listeners(event: string): Function[];
emit(event: string, ...args: any[]): boolean;
/**
* @returns The current absolute position of the mouse pointer.
*/
getCursorScreenPoint(): any;
/**
* @returns The primary display.
*/
getPrimaryDisplay(): any;
/**
* @returns An array of displays that are currently available.
*/
getAllDisplays(): any[];
/**
* @returns The display nearest the specified point.
*/
getDisplayNearestPoint(point: {
x: number;
y: number;
}): any;
/**
* @returns The display that most closely intersects the provided bounds.
*/
getDisplayMatching(rect: Rectangle): any;
}
/**
* The BrowserWindow class gives you ability to create a browser window.
* You can also create a window without chrome by using Frameless Window API.
*/
class BrowserWindow implements NodeJS.EventEmitter {
addListener(event: string, listener: Function): WebContents;
on(event: string, listener: Function): WebContents;
once(event: string, listener: Function): WebContents;
removeListener(event: string, listener: Function): WebContents;
removeAllListeners(event?: string): WebContents;
setMaxListeners(n: number): void;
listeners(event: string): Function[];
emit(event: string, ...args: any[]): boolean;
constructor(options?: BrowserWindowOptions);
/**
* @returns All opened browser windows.
*/
static getAllWindows(): BrowserWindow[];
/**
* @returns The window that is focused in this application.
*/
static getFocusedWindow(): BrowserWindow;
/**
* Find a window according to the webContents it owns.
*/
static fromWebContents(webContents: WebContents): BrowserWindow;
/**
* Find a window according to its ID.
*/
static fromId(id: number): BrowserWindow;
/**
* Adds devtools extension located at path. The extension will be remembered
* so you only need to call this API once, this API is not for programming use.
* @returns The extension's name.
*/
static addDevToolsExtension(path: string): string;
/**
* Remove a devtools extension.
* @param name The name of the devtools extension to remove.
*/
static removeDevToolsExtension(name: string): void;
/**
* The WebContents object this window owns, all web page related events and
* operations would be done via it.
* Note: Users should never store this object because it may become null when
* the renderer process (web page) has crashed.
*/
webContents: WebContents;
/**
* Get the WebContents of devtools of this window.
* Note: Users should never store this object because it may become null when
* the devtools has been closed.
*/
devToolsWebContents: WebContents;
/**
* Get the unique ID of this window.
*/
id: number;
/**
* Force closing the window, the unload and beforeunload event won't be emitted
* for the web page, and close event would also not be emitted for this window,
* but it would guarantee the closed event to be emitted.
* You should only use this method when the renderer process (web page) has crashed.
*/
destroy(): void;
/**
* Try to close the window, this has the same effect with user manually clicking
* the close button of the window. The web page may cancel the close though,
* see the close event.
*/
close(): void;
/**
* Focus on the window.
*/
focus(): void;
/**
* @returns Whether the window is focused.
*/
isFocused(): 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;
/**
* @returns Whether the window is visible to the user.
*/
isVisible(): boolean;
/**
* Maximizes the window.
*/
maximize(): void;
/**
* Unmaximizes the window.
*/
unmaximize(): void;
/**
* @returns 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;
/**
* @returns Whether the window is minimized.
*/
isMinimized(): boolean;
/**
* Sets whether the window should be in fullscreen mode.
*/
setFullScreen(flag: boolean): void;
/**
* @returns Whether the window is in fullscreen mode.
*/
isFullScreen(): boolean;
/**
* Resizes and moves the window to width, height, x, y.
*/
setBounds(options: Rectangle): void;
/**
* @returns The window's width, height, x and y values.
*/
getBounds(): Rectangle;
/**
* Resizes the window to width and height.
*/
setSize(width: number, height: number): void;
/**
* @returns The window's width and height.
*/
getSize(): number[];
/**
* Resizes the window's client area (e.g. the web page) to width and height.
*/
setContentSize(width: number, height: number): void;
/**
* @returns The window's client area's width and height.
*/
getContentSize(): number[];
/**
* Sets the minimum size of window to width and height.
*/
setMinimumSize(width: number, height: number): void;
/**
* @returns The window's minimum width and height.
*/
getMinimumSize(): number[];
/**
* Sets the maximum size of window to width and height.
*/
setMaximumSize(width: number, height: number): void;
/**
* @returns The window's maximum width and height.
*/
getMaximumSize(): number[];
/**
* Sets whether the window can be manually resized by user.
*/
setResizable(resizable: boolean): void;
/**
* @returns Whether the window can be manually resized by user.
*/
isResizable(): boolean;
/**
* Sets whether the window should show always on top of other windows. After
* setting this, the window is still a normal window, not a toolbox window
* which can not be focused on.
*/
setAlwaysOnTop(flag: boolean): void;
/**
* @returns Whether the window is always on top of other windows.
*/
isAlwaysOnTop(): boolean;
/**
* Moves window to the center of the screen.
*/
center(): void;
/**
* Moves window to x and y.
*/
setPosition(x: number, y: number): void;
/**
* @returns The window's current position.
*/
getPosition(): number[];
/**
* Changes the title of native window to title.
*/
setTitle(title: string): void;
/**
* Note: The title of web page can be different from the title of the native window.
* @returns The title of the native window.
*/
getTitle(): string;
/**
* Starts or stops flashing the window to attract user's attention.
*/
flashFrame(flag: boolean): void;
/**
* Makes the window do not show in Taskbar.
*/
setSkipTaskbar(skip: boolean): void;
/**
* Enters or leaves the kiosk mode.
*/
setKiosk(flag: boolean): void;
/**
* @returns Whether the window is in kiosk mode.
*/
isKiosk(): boolean;
/**
* Sets the pathname of the file the window represents, and the icon of the
* file will show in window's title bar.
* Note: This API is available only on OS X.
*/
setRepresentedFilename(filename: string): void;
/**
* Note: This API is available only on OS X.
* @returns The pathname of the file the window represents.
*/
getRepresentedFilename(): string;
/**
* Specifies whether the window’s document has been edited, and the icon in
* title bar will become grey when set to true.
* Note: This API is available only on OS X.
*/
setDocumentEdited(edited: boolean): void;
/**
* Note: This API is available only on OS X.
* @returns Whether the window's document has been edited.
*/
isDocumentEdited(): boolean;
/**
* Opens the developer tools.
*/
openDevTools(options?: {
/**
* Opens devtools in a new window.
*/
detach?: boolean;
}): void;
/**
* Closes the developer tools.
*/
closeDevTools(): void;
/**
* Returns whether the developer tools are opened.
*/
isDevToolsOpened(): boolean;
/**
* Toggle the developer tools.
*/
toggleDevTools(): void;
reloadIgnoringCache(): void;
/**
* Starts inspecting element at position (x, y).
*/
inspectElement(x: number, y: number): void;
focusOnWebView(): void;
blurWebView(): void;
/**
* Captures the snapshot of page within rect, upon completion the callback
* will be called. Omitting the rect would capture the whole visible page.
* Note: Be sure to read documents on remote buffer in remote if you are going
* to use this API in renderer process.
* @param callback Supplies the image that stores data of the snapshot.
*/
capturePage(rect: Rectangle, callback: (image: NativeImage) => void): void;
capturePage(callback: (image: NativeImage) => void): void;
/**
* Same with webContents.print([options])
*/
print(options?: {
silent?: boolean;
printBackground?: boolean;
}): void;
/**
* Same with webContents.printToPDF([options])
*/
printToPDF(options: {
marginsType?: number;
pageSize?: string;
printBackground?: boolean;
printSelectionOnly?: boolean;
landscape?: boolean;
}, callback: (error: Error, data: Buffer) => void): void;
/**
* Same with webContents.loadUrl(url).
*/
loadUrl(url: string, options?: {
httpReferrer?: string;
userAgent?: string;
}): void;
/**
* Same with webContents.reload.
*/
reload(): void;
/**
* Sets the menu as the window top menu.
* Note: This API is not available on OS X.
*/
setMenu(menu: Menu): void;
/**
* Sets the progress value in the progress bar.
* On Linux platform, only supports Unity desktop environment, you need to
* specify the *.desktop file name to desktopName field in package.json.
* By default, it will assume app.getName().desktop.
* @param progress Valid range is [0, 1.0]. If < 0, the progress bar is removed.
* If greater than 0, it becomes indeterminate.
*/
setProgressBar(progress: number): void;
/**
* Sets a 16px overlay onto the current Taskbar icon, usually used to convey
* some sort of application status or to passively notify the user.
* Note: This API is only available on Windows 7 or above.
* @param overlay The icon to display on the bottom right corner of the Taskbar
* icon. If this parameter is null, the overlay is cleared
* @param description Provided to Accessibility screen readers.
*/
setOverlayIcon(overlay: NativeImage, description: string): void;
/**
* Shows pop-up dictionary that searches the selected word on the page.
* Note: This API is available only on OS X.
*/
showDefinitionForSelection(): void;
/**
* Sets whether the window menu bar should hide itself automatically. Once set
* the menu bar will only show when users press the single Alt key.
* If the menu bar is already visible, calling setAutoHideMenuBar(true) won't
* hide it immediately.
*/
setAutoHideMenuBar(hide: boolean): void;
/**
* @returns Whether menu bar automatically hides itself.
*/
isMenuBarAutoHide(): boolean;
/**
* Sets whether the menu bar should be visible. If the menu bar is auto-hide,
* users can still bring up the menu bar by pressing the single Alt key.
*/
setMenuBarVisibility(visibile: boolean): void;
/**
* @returns Whether the menu bar is visible.
*/
isMenuBarVisible(): boolean;
/**
* Sets whether the window should be visible on all workspaces.
* Note: This API does nothing on Windows.
*/
setVisibleOnAllWorkspaces(visible: boolean): void;
/**
* Note: This API always returns false on Windows.
* @returns Whether the window is visible on all workspaces.
*/
isVisibleOnAllWorkspaces(): boolean;
}
// Includes all options BrowserWindow can take as of this writing
// http://electron.atom.io/docs/v0.29.0/api/browser-window/
interface BrowserWindowOptions extends Rectangle {
show?: boolean;
'use-content-size'?: boolean;
center?: boolean;
'min-width'?: number;
'min-height'?: number;
'max-width'?: number;
'max-height'?: number;
resizable?: boolean;
'always-on-top'?: boolean;
fullscreen?: boolean;
'skip-taskbar'?: boolean;
'zoom-factor'?: number;
kiosk?: boolean;
title?: string;
icon?: NativeImage|string;
frame?: boolean;
'node-integration'?: boolean;
'accept-first-mouse'?: boolean;
'disable-auto-hide-cursor'?: boolean;
'auto-hide-menu-bar'?: boolean;
'enable-larger-than-screen'?: boolean;
'dark-theme'?: boolean;
preload?: string;
transparent?: boolean;
type?: string;
'standard-window'?: boolean;
'web-preferences'?: any; // Object
javascript?: boolean;
'web-security'?: boolean;
images?: boolean;
java?: boolean;
'text-areas-are-resizable'?: boolean;
webgl?: boolean;
webaudio?: boolean;
plugins?: boolean;
'extra-plugin-dirs'?: string[];
'experimental-features'?: boolean;
'experimental-canvas-features'?: boolean;
'subpixel-font-scaling'?: boolean;
'overlay-scrollbars'?: boolean;
'overlay-fullscreen-video'?: boolean;
'shared-worker'?: boolean;
'direct-write'?: boolean;
'page-visibility'?: boolean;
'title-bar-style'?: string;
}
interface Rectangle {
x?: number;
y?: number;
width?: number;
height?: number;
}
/**
* A WebContents is responsible for rendering and controlling a web page.
*/
class WebContents implements NodeJS.EventEmitter {
addListener(event: string, listener: Function): WebContents;
on(event: string, listener: Function): WebContents;
once(event: string, listener: Function): WebContents;
removeListener(event: string, listener: Function): WebContents;
removeAllListeners(event?: string): WebContents;
setMaxListeners(n: number): void;
listeners(event: string): Function[];
emit(event: string, ...args: any[]): boolean;
/**
* Loads the url in the window.
* @param url Must contain the protocol prefix (e.g., the http:// or file://).
*/
loadUrl(url: string, options?: {
httpReferrer?: string;
userAgent?: string;
}): void;
/**
* @returns The URL of current web page.
*/
getUrl(): string;
/**
* @returns The title of web page.
*/
getTitle(): string;
/**
* @returns The favicon of the web page.
*/
getFavicon(): NativeImage;
/**
* @returns Whether web page is still loading resources.
*/
isLoading(): boolean;
/**
* @returns Whether web page is waiting for a first-response for the main
* resource of the page.
*/
isWaitingForResponse(): boolean;
/**
* Stops any pending navigation.
*/
stop(): void;
/**
* Reloads current page.
*/
reload(): void;
/**
* Reloads current page and ignores cache.
*/
reloadIgnoringCache(): void;
/**
* @returns Whether the web page can go back.
*/
canGoBack(): boolean;
/**
* @returns Whether the web page can go forward.
*/
canGoForward(): boolean;
/**
* @returns Whether the web page can go to offset.
*/
canGoToOffset(offset: number): boolean;
/**
* Makes the web page go back.
*/
goBack(): void;
/**
* Makes the web page go forward.
*/
goForward(): void;
/**
* Navigates to the specified absolute index.
*/
goToIndex(index: number): void;
/**
* Navigates to the specified offset from the "current entry".
*/
goToOffset(offset: number): void;
/**
* @returns Whether the renderer process has crashed.
*/
isCrashed(): boolean;
/**
* Overrides the user agent for this page.
*/
setUserAgent(userAgent: string): void;
/**
* Injects CSS into this page.
*/
insertCSS(css: string): void;
/**
* Evaluates code in page.
* @param code Code to evaluate.
*/
executeJavaScript(code: string): void;
/**
* Executes Edit -> Undo command in page.
*/
undo(): void;
/**
* Executes Edit -> Redo command in page.
*/
redo(): void;
/**
* Executes Edit -> Cut command in page.
*/
cut(): void;
/**
* Executes Edit -> Copy command in page.
*/
copy(): void;
/**
* Executes Edit -> Paste command in page.
*/
paste(): void;
/**
* Executes Edit -> Delete command in page.
*/
delete(): void;
/**
* Executes Edit -> Select All command in page.
*/
selectAll(): void;
/**
* Executes Edit -> Unselect command in page.
*/
unselect(): void;
/**
* Executes Edit -> Replace command in page.
*/
replace(text: string): void;
/**
* Executes Edit -> Replace Misspelling command in page.
*/
replaceMisspelling(text: string): void;
/**
* Checks if any serviceworker is registered.
*/
hasServiceWorker(callback: (hasServiceWorker: boolean) => void): void;
/**
* Unregisters any serviceworker if present.
*/
unregisterServiceWorker(callback:
/**
* @param isFulfilled Whether the JS promise is fulfilled.
*/
(isFulfilled: boolean) => void): void;
/**
*
* Prints window's web page. When silent is set to false, Electron will pick up system's default printer and default settings for printing.
* Calling window.print() in web page is equivalent to call WebContents.print({silent: false, printBackground: false}).
* Note:
* On Windows, the print API relies on pdf.dll. If your application doesn't need print feature, you can safely remove pdf.dll in saving binary size.
*/
print(options?: {
/**
* Don't ask user for print settings, defaults to false
*/
silent?: boolean;
/**
* Also prints the background color and image of the web page, defaults to false.
*/
printBackground: boolean;
}): void;
/**
* Prints windows' web page as PDF with Chromium's preview printing custom settings.
*/
printToPDF(options: {
/**
* Specify the type of margins to use. Default is 0.
* 0 - default
* 1 - none
* 2 - minimum
*/
marginsType?: number;
/**
* String - Specify page size of the generated PDF. Default is A4.
* A4
* A3
* Legal
* Letter
* Tabloid
*/
pageSize?: string;
/**
* Whether to print CSS backgrounds. Default is false.
*/
printBackground?: boolean;
/**
* Whether to print selection only. Default is false.
*/
printSelectionOnly?: boolean;
/**
* true for landscape, false for portrait. Default is false.
*/
landscape?: boolean;
},
/**
* Callback function on completed converting to PDF.
* error Error
* data Buffer - PDF file content
*/
callback: (error: Error, data: Buffer) => void): void;
/**
* Send args.. to the web page via channel in asynchronous message, the web page
* can handle it by listening to the channel event of ipc module.
* Note:
* 1. The IPC message handler in web pages do not have a event parameter,
* which is different from the handlers on the main process.
* 2. There is no way to send synchronous messages from the main process
* to a renderer process, because it would be very easy to cause dead locks.
*/
send(channel: string, ...args: any[]): void;
}
/**
* The Menu class is used to create native menus that can be used as application
* menus and context menus. Each menu consists of multiple menu items, and each
* menu item can have a submenu.
*/
class Menu {
/**
* Creates a new menu.
*/
constructor();
/**
* Sets menu as the application menu on OS X. On Windows and Linux, the menu
* will be set as each window's top menu.
*/
static setApplicationMenu(menu: Menu): void;
/**
* Sends the action to the first responder of application, this is used for
* emulating default Cocoa menu behaviors, usually you would just use the
* selector property of MenuItem.
*
* Note: This method is OS X only.
*/
static sendActionToFirstResponder(action: string): void;
/**
* @param template Generally, just an array of options for constructing MenuItem.
* You can also attach other fields to element of the template, and they will
* become properties of the constructed menu items.
*/
static buildFromTemplate(template: MenuItemOptions[]): Menu;
/**
* Popups this menu as a context menu in the browserWindow. You can optionally
* provide a (x,y) coordinate to place the menu at, otherwise it will be placed
* at the current mouse cursor position.
* @param x Horizontal coordinate where the menu will be placed.
* @param y Vertical coordinate where the menu will be placed.
*/
popup(browserWindow: BrowserWindow, x?: number, y?: number): void;
/**
* Appends the menuItem to the menu.
*/
append(menuItem: MenuItem): void;
/**
* Inserts the menuItem to the pos position of the menu.
*/
insert(position: number, menuItem: MenuItem): void;
items: MenuItem[];
}
class MenuItem {
constructor(options?: MenuItemOptions);
options: MenuItemOptions;
}
interface MenuItemOptions {
/**
* Callback when the menu item is clicked.
*/
click?: Function;
/**
* Call the selector of first responder when clicked (OS X only).
*/
selector?: string;
/**
* Can be normal, separator, submenu, checkbox or radio.
*/
type?: string;
label?: string;
sublabel?: string;
/**
* An accelerator is string that represents a keyboard shortcut, it can contain
* multiple modifiers and key codes, combined by the + character.
*
* Examples:
* Command+A
* Ctrl+Shift+Z
*
* Platform notice: On Linux and Windows, the Command key would not have any effect,
* you can use CommandOrControl which represents Command on OS X and Control on
* Linux and Windows to define some accelerators.
*
* Available modifiers:
* Command (or Cmd for short)
* Control (or Ctrl for short)
* CommandOrControl (or CmdOrCtrl for short)
* Alt
* Shift
*
* Available key codes:
* 0 to 9
* A to Z
* F1 to F24
* Punctuations like ~, !, @, #, $, etc.
* Plus
* Space
* Backspace
* Delete
* Insert
* Return (or Enter as alias)
* Up, Down, Left and Right
* Home and End
* PageUp and PageDown
* Escape (or Esc for short)
* VolumeUp, VolumeDown and VolumeMute
* MediaNextTrack, MediaPreviousTrack, MediaStop and MediaPlayPause
*/
accelerator?: string;
/**
* In Electron for the APIs that take images, you can pass either file paths
* or NativeImage instances. When passing null, an empty image will be used.
*/
icon?: NativeImage|string;
enabled?: boolean;
visible?: boolean;
checked?: boolean;
/**
* Should be specified for submenu type menu item, when it's specified the
* type: 'submenu' can be omitted for the menu item
*/
submenu?: MenuItemOptions[];
/**
* Unique within a single menu. If defined then it can be used as a reference
* to this item by the position attribute.
*/
id?: string;
/**
* This field allows fine-grained definition of the specific location within
* a given menu.
*/
position?: string;
}
class BrowserWindowProxy {
/**
* Removes focus from the child window.
*/
blur(): void;
/**
* Forcefully closes the child window without calling its unload event.
*/
close(): void;
/**
* Set to true after the child window gets closed.
*/
closed: boolean;
/**
* Evaluates the code in the child window.
*/
eval(code: string): void;
/**
* Focuses the child window (brings the window to front).
*/
focus(): void;
/**
* Sends a message to the child window with the specified origin or * for no origin preference.
* In addition to these methods, the child window implements window.opener object with no
* properties and a single method.
*/
postMessage(message: string, targetOrigin: string): void;
}
class App implements NodeJS.EventEmitter {
addListener(event: string, listener: Function): App;
on(event: string, listener: Function): App;
once(event: string, listener: Function): App;
removeListener(event: string, listener: Function): App;
removeAllListeners(event?: string): App;
setMaxListeners(n: number): void;
listeners(event: string): Function[];
emit(event: string, ...args: any[]): boolean;
/**
* Try to close all windows. The before-quit event will first be emitted.
* If all windows are successfully closed, the will-quit event will be emitted
* and by default the application would be terminated.
*
* This method guarantees all beforeunload and unload handlers are correctly
* executed. It is possible that a window cancels the quitting by returning
* false in beforeunload handler.
*/
quit(): void;
/**
* Quit the application directly, it will not try to close all windows so
* cleanup code will not run.
*/
terminate(): void;
/**
* Returns the current application directory.
*/
getAppPath(): string;
/**
* @param name One of: home, appData, userData, cache, userCache, temp, userDesktop, exe, module
* @returns The path to a special directory or file associated with name.
* On failure an Error would throw.
*/
getPath(name: string): string;
/**
* Overrides the path to a special directory or file associated with name.
* If the path specifies a directory that does not exist, the directory will
* be created by this method. On failure an Error would throw.
*
* You can only override paths of names defined in app.getPath.
*
* By default web pages' cookies and caches will be stored under userData
* directory, if you want to change this location, you have to override the
* userData path before the ready event of app module gets emitted.
*/
setPath(name: string, path: string): void;
/**
* @returns The version of loaded application, if no version is found in
* application's package.json, the version of current bundle or executable.
*/
getVersion(): string;
/**
*
* @returns The current application's name, the name in package.json would be used.
* Usually the name field of package.json is a short lowercased name, according to
* the spec of npm modules. So usually you should also specify a productName field,
* which is your application's full capitalized name, and it will be preferred over
* name by Electron.
*/
getName(): string;
/**
* Resolves the proxy information for url, the callback would be called with
* callback(proxy) when the request is done.
*/
resolveProxy(url: string, callback: Function): void;
/**
* Adds path to recent documents list.
*
* This list is managed by the system, on Windows you can visit the list from
* task bar, and on Mac you can visit it from dock menu.
*/
addRecentDocument(path: string): void;
/**
* Clears the recent documents list.
*/
clearRecentDocuments(): void;
/**
* Adds tasks to the Tasks category of JumpList on Windows.
*
* Note: This API is only available on Windows.
*/
setUserTasks(tasks: Task[]): void;
dock: BrowserWindow;
commandLine: CommandLine;
/**
* This method makes your application a Single Instance Application instead of allowing
* multiple instances of your app to run, this will ensure that only a single instance
* of your app is running, and other instances signal this instance and exit.
*/
makeSingleInstance(callback: (args: string[], workingDirectory: string) => boolean): boolean;
}
interface CommandLine {
/**
* Append a switch [with optional value] to Chromium's command line.