-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
832 lines (762 loc) · 24.1 KB
/
index.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
/**
* CONSTRAINED IDENTITY FUNCTIONS.
*
* Allow defining interfaces without loosing intellisense and error reporting,
* while keeping the interface identity intact.
*
* ```
* // TS just takes `foo` for `Foo`, ignoring what's inside `something`
* const foo: Foo = something;
*
* // TS examines `something` closely
* const foo = makeSomething(something);
*
* // You keep the identity, but you loose intellisense and errors while
* // defining `something`, because TS doesn't know what you're trying to define
* const foo = something;
* ```
*/
export declare function makeOptionsSchema<O extends OptionsData>(): <T extends OptionsSchema<O>>(val: T) => T;
export declare function makeAcceptsFlags<O extends OptionsData>(): <T extends AcceptsFlags<O>>(val: T) => T;
export declare function makeProcessorConfig<P extends AnyPayload>(): <T extends ProcessorConfig<P>>(val: T) => T;
export declare function makeDependencyConfig<T extends DependencyConfig = DependencyConfig>(val: T): T;
/**
* PLUGIN API.
*/
export type PluginModule = (plugin: Plugin) => void;
export interface Plugin {
registerProcessor<
Payload extends AnyPayload = AnyPayload,
Dependencies extends DependenciesData = DependenciesData
>(
name: string,
config: ProcessorConfig<Payload, Dependencies>
): void;
registerDependency(name: string, config: DependencyConfig): void;
}
export type Processor = (payload: any, utils?: ProcessorUtils) => Promise<void>;
export type PayloadData<
Options extends OptionsData | undefined = undefined,
Accepts extends AcceptsFlags<any> | undefined = undefined,
Extra = {}
> = {
readonly id: string;
options: Options;
input: undefined extends Accepts ? undefined : AcceptedItems<Exclude<Accepts, undefined>>;
inputs: undefined extends Accepts ? undefined : AcceptedItems<Exclude<Accepts, undefined>>[];
} & Extra;
export interface AnyPayload {
readonly id: string;
options: OptionsData | undefined;
input: undefined | Item;
inputs: undefined | Item[];
[key: string]: any;
}
export interface AcceptsFlags<O extends OptionsData | undefined = undefined> {
files?: boolean | string | FileFilter<O> | RegExp | (string | FileFilter<O> | RegExp)[];
directories?: boolean | string | DirectoryFilter<O> | RegExp | (string | DirectoryFilter<O> | RegExp)[];
blobs?: boolean | string | BlobFilter<O> | (string | BlobFilter<O>)[];
strings?: boolean | string | StringFilter<O> | RegExp | (string | StringFilter<O> | RegExp)[];
urls?: boolean | string | UrlFilter<O> | RegExp | (string | UrlFilter<O> | RegExp)[];
}
export type AcceptedItems<F extends {[key: string]: any}, K = keyof F> = K extends keyof F
? K extends 'files'
? ItemFile
: K extends 'directories'
? ItemDirectory
: K extends 'blobs'
? ItemBlob
: K extends 'urls'
? ItemUrl
: K extends 'strings'
? ItemString
: never
: never;
export type FileFilter<O extends OptionsData | undefined = OptionsData | undefined> = (
item: ItemFile,
options: O
) => boolean;
export type DirectoryFilter<O extends OptionsData | undefined = OptionsData | undefined> = (
item: ItemDirectory,
options: O
) => boolean;
export type BlobFilter<O extends OptionsData | undefined = OptionsData | undefined> = (
item: ItemBlob,
options: O
) => boolean;
export type StringFilter<O extends OptionsData | undefined = OptionsData | undefined> = (
item: ItemString,
options: O
) => boolean;
export type UrlFilter<O extends OptionsData | undefined = OptionsData | undefined> = (
item: ItemUrl,
options: O
) => boolean;
export interface ProcessorConfig<
Payload extends AnyPayload = AnyPayload,
Dependencies extends DependenciesData = DependenciesData
> {
main: string;
description?: string;
dependencies?: string[];
optionalDependencies?: string[];
accepts?: AcceptsFlags<Payload['options']>;
bulk?: boolean | ((items: Item[], options: Payload['options'], meta: {modifiers: string}) => boolean);
expandDirectory?: (item: ItemDirectory, options: Payload['options'], meta: {modifiers: string}) => boolean;
threadType?: string | string[] | ((payload: Payload) => string | string[]);
threadTypeDescription?: string;
options?: OptionsSchema<Payload['options']> | OptionsLaxSchema;
parallelize?: boolean | ((payload: Payload) => boolean);
keepAlive?: boolean;
dropFilter?: (items: Item[], options?: Payload['options']) => Item[] | Promise<Item[]>;
operationPreparator?: (
payload: Pick<Payload, 'id' | 'options' | 'input' | 'inputs'>,
utils: PreparatorUtils<Dependencies>
) => Payload | null | undefined | false | void | Promise<Payload | null | undefined | false | void>;
progressFormatter?: 'bytes' | ((progress: ProgressData) => string); // HTML
operationMetaFormatter?: (meta: any) => string; // HTML
profileMetaUpdater?: (profileMeta: any, operationMeta: any) => any;
profileMetaFormatter?: (meta: any) => string; // HTML
modifierDescriptions?: {[key: string]: string} | ((options: Payload['options']) => {[key: string]: string});
instructions?: string;
}
export interface DependencyData<T = unknown> {
version?: string;
payload?: T;
}
export interface DependencyConfig {
load(utils: LoadUtils): Promise<boolean | DependencyData>;
install?(utils: InstallUtils): Promise<void>;
instructions?: string;
}
/**
* OPTIONS.
*/
export type OptionsData = {[key: string]: unknown};
export type InputOptions = {[key: string]: string};
export interface OptionBase<V = any, O extends OptionsData | undefined = OptionsData | undefined> {
name: string;
title?: string | false;
hint?: string | ((value: V, options: O, path: (string | number)[]) => string | number | null | undefined);
description?: string | ((value: V, options: O, path: (string | number)[]) => string | number | null | undefined);
isDisabled?: boolean | ((value: V, options: O, path: (string | number)[]) => boolean);
isHidden?: boolean | ((value: V, options: O, path: (string | number)[]) => boolean);
isResettable?: boolean;
}
export interface OptionBoolean<O extends OptionsData | undefined = OptionsData | undefined>
extends OptionBase<boolean, O> {
type: 'boolean';
default?: boolean;
}
export type OptionNumber<O extends OptionsData | undefined = OptionsData | undefined> = OptionBase<number | null, O> & {
type: 'number';
kind?: 'integer' | 'float';
default?: number | null;
nullable?: boolean;
min?: number;
max?: number;
step?: number;
cols?: number;
softMin?: boolean;
softMax?: boolean;
steps?: number[];
};
export interface OptionString<O extends OptionsData | undefined = OptionsData | undefined>
extends OptionBase<string, O> {
type: 'string';
default?: string;
rows?: number;
cols?: number;
min?: number;
max?: number;
preselect?: boolean;
validator?: (value: string, options: O, path: (string | number)[]) => boolean;
asyncValidator?: (value: string, options: O, path: (string | number)[]) => Promise<boolean>;
asyncValidatorDebounce?: number;
validationDependencies?: string[];
}
export interface OptionColor<O extends OptionsData | undefined = OptionsData | undefined>
extends OptionBase<string, O> {
type: 'color';
default?: string;
formatSelection?: (newValue: string, oldValue: string) => string;
}
export interface OptionPath<O extends OptionsData | undefined = OptionsData | undefined> extends OptionBase<string, O> {
type: 'path';
default?: string;
kind?: 'file' | 'directory';
filters?: DialogFileFilter[];
formatSelection?: (newValue: string, oldValue: string) => string;
}
export interface OptionSelect<
OD extends OptionsData | undefined = OptionsData | undefined,
O extends (string | number)[] | {[x: string]: string} = (string | number)[] | {[x: string]: string},
Value = O extends (infer R)[] ? R : keyof O
> extends OptionBase<Value | null, OD> {
type: 'select';
default?: Value | Value[] | null;
options: O;
nullable?: boolean;
max?: number;
}
export interface OptionList<
O extends OptionsData | undefined = OptionsData | undefined,
S extends OptionString<O> | OptionColor<O> | OptionPath<O> | OptionNumber<O> | OptionSelect<O> =
| OptionString<O>
| OptionColor<O>
| OptionPath<O>
| OptionNumber<O>
| OptionSelect<O>
> extends OptionBase<S extends OptionNumber ? number : string, O> {
type: 'list';
default?: (S extends OptionNumber ? number : string)[];
schema: Omit<S, keyof OptionBase>;
}
export interface OptionNamespace<
O extends OptionsData | undefined = OptionsData | undefined,
S extends OptionsSchema<O> = OptionsSchema<O>
> extends OptionBase<OptionsData, O> {
type: 'namespace';
schema: S;
default?: OptionsData;
}
export interface OptionCollection<
O extends OptionsData | undefined = OptionsData | undefined,
S extends OptionsSchema<O> = OptionsSchema<O>
> extends OptionBase<OptionsData[], O> {
type: 'collection';
schema: S;
default?: OptionsData[];
itemTitle?: string;
}
export interface OptionDivider<O extends OptionsData | undefined = OptionsData | undefined>
extends Pick<OptionBase<undefined, O>, 'title' | 'description' | 'isHidden'> {
type: 'divider';
}
export interface OptionCategory<O extends OptionsData | undefined = OptionsData | undefined>
extends OptionBase<string, O> {
type: 'category';
default?: string;
options: string[] | InputOptions | ((options: O) => string[] | InputOptions);
}
export type OptionSerializable<O extends OptionsData | undefined = OptionsData | undefined> =
| OptionBoolean<O>
| OptionNumber<O>
| OptionString<O>
| OptionColor<O>
| OptionPath<O>
| OptionSelect<O>
| OptionList<O>
| OptionNamespace<O>
| OptionCollection<O>
| OptionCategory<O>;
export type OptionSimple<O extends OptionsData | undefined = OptionsData | undefined> =
| OptionBoolean<O>
| OptionNumber<O>
| OptionString<O>
| OptionColor<O>
| OptionPath<O>
| OptionSelect<O>
| OptionList<O>;
export type OptionDecorative<O extends OptionsData | undefined = OptionsData | undefined> = OptionDivider<O>;
export type OptionSchema<O extends OptionsData | undefined = OptionsData | undefined> =
| OptionSerializable<O>
| OptionDecorative<O>;
export type OptionsSchema<O extends OptionsData | undefined = OptionsData | undefined> = OptionSchema<O>[];
export type OptionsLaxSchema = {[x: string]: string | number | boolean | OptionsLaxSchema};
/**
* ITEMS.
*/
type Variant = 'success' | 'info' | 'warning' | 'danger';
/** A short text label displayed in item's card. */
export interface Flair {
title: string;
variant?: Variant;
description?: string;
}
/** An icon displayed in item's card. */
export interface Badge {
title: string;
icon: string;
variant?: Variant;
}
/** The only items processors deal with. */
export type Item = ItemFile | ItemDirectory | ItemBlob | ItemString | ItemUrl;
export interface ItemBase {
readonly id: string;
readonly created: number;
flair?: Flair;
badge?: Badge;
}
export interface ItemFile extends ItemBase {
kind: 'file';
/** Lowercase extension without the dot. */
type: string;
path: string;
exists: boolean;
size: number;
}
export interface ItemDirectory extends ItemBase {
kind: 'directory';
path: string;
exists: boolean;
}
export interface ItemBlob extends ItemBase {
kind: 'blob';
mime: string;
contents: Buffer;
}
export interface ItemString extends ItemBase {
kind: 'string';
type: string;
contents: string;
}
export interface ItemUrl extends ItemBase {
kind: 'url';
url: string;
}
export interface ItemError extends ItemBase {
kind: 'error';
message: string;
}
export interface ItemWarning extends ItemBase {
kind: 'warning';
message: string;
}
/**
* UTILS.
*/
interface CommonModals {
alert(data: ModalData): Promise<void>;
confirm(data: ModalData): Promise<ModalResult<boolean>>;
prompt(
data: ModalData,
stringOptions?: Omit<OptionString, 'title' | 'description' | 'type' | 'name'>
): Promise<ModalResult<string>>;
promptOptions<T extends OptionsData | undefined = undefined>(
data: ModalData,
schema: OptionsSchema<T>
): Promise<ModalResult<T>>;
showOpenDialog(options: OpenDialogOptions): Promise<OpenDialogReturnValue>;
showSaveDialog(options: SaveDialogOptions): Promise<SaveDialogReturnValue>;
openModalWindow<T = unknown>(options: string | OpenWindowOptions, payload?: unknown): Promise<ModalWindowResult<T>>;
}
export interface LoadUtils {
/** Dependency id (id: `drovp/ffmpeg:ffmpeg`, name: `ffmpeg`). */
id: string;
/** Dependency name (id: `drovp/ffmpeg:ffmpeg`, name: `ffmpeg`). */
name: string;
/** Path to store dependency data. */
dataPath: string;
/** Path to plugin's data directory. */
pluginDataPath: string;
}
export type InstallUtils = CommonModals & {
/** Dependency id (id: `drovp/ffmpeg:ffmpeg`, name: `ffmpeg`). */
id: string;
/** Dependency name (id: `drovp/ffmpeg:ffmpeg`, name: `ffmpeg`). */
name: string;
/** Path to store dependency data. */
dataPath: string;
/**
* Path to use for temporary files during installation.
* This directory will be deleted after installation completes.
*/
tmpPath: string;
/** Path to plugin's data directory. */
pluginDataPath: string;
/**
* Fetch & parse JSON from URL with built in timeout.
* Throws when response code is not 200.
*/
fetchJson: <T extends unknown = unknown>(url: string, init?: RequestInit & {timeout?: number}) => Promise<T>;
download: Download;
extract: Extract;
/** @deprecated Renamed to `prepareEmptyDirectory`. */
cleanup: PrepareEmptyDirectory;
prepareEmptyDirectory: PrepareEmptyDirectory;
progress: Progress;
stage: (name: string) => void;
log: (...args: any[]) => void;
};
export interface Progress {
(progress?: ProgressData | null): void;
(completed?: number | null, total?: number | null, indeterminate?: boolean): void;
data: ProgressData;
completed: number | undefined;
indeterminate: boolean | undefined;
total: number | undefined;
destroy: () => void;
toJSON: () => ProgressData;
}
export type ProgressData = {completed?: number; total?: number; indeterminate?: boolean};
export type DependenciesData = {[key: string]: unknown};
export type OutputMeta<T = {}> = T & {
flair?: Flair;
badge?: Badge;
};
export interface OutputEmitters {
file: (path: string, meta?: OutputMeta) => void;
directory: (path: string, meta?: OutputMeta) => void;
url: (url: string, meta?: OutputMeta) => void;
string: (contents: string, meta?: OutputMeta<{type?: string}>) => void;
error: (error: Error | string, meta?: OutputMeta) => void;
warning: (message: string, meta?: OutputMeta) => void;
}
export interface ProcessorUtils<Dependencies extends {[key: string]: any} = {[key: string]: any}> {
dependencies: Dependencies;
output: OutputEmitters;
progress: Progress;
title: (value: string | undefined | null) => void;
meta: (meta: unknown) => void;
log: (...args: any[]) => void;
stage: (name: string) => void;
appVersion: string;
/** Path to plugin's data directory. */
dataPath: string;
}
export interface PreparatorUtils<D extends DependenciesData = DependenciesData> extends CommonModals {
modifiers: string;
action: 'drop' | 'paste' | 'protocol';
title(value: string | undefined | null): void;
dependencies: D;
settings: AppSettings;
/** Path to node.js binary. */
nodePath: string;
/** Path to plugin's data directory. */
dataPath: string;
}
export interface AppSettings {
fontSize: number;
compact: boolean;
theme: 'os' | 'light' | 'dark';
developerMode: boolean;
editCommand: string;
}
export interface ModalData {
variant?: Variant;
title?: string;
message?: string;
details?: string;
}
export interface ModalResult<T = unknown> {
canceled: boolean;
payload: T;
modifiers: string;
}
export interface ModalWindowResult<T = unknown> {
canceled: boolean;
payload: T;
}
export interface OpenWindowOptions {
path: string;
title?: string;
/**
* Suggested width.
*/
width?: number;
/**
* Suggested height.
*/
height?: number;
minWidth?: number;
minHeight?: number;
}
interface PrepareEmptyDirectory {
(path: string): Promise<void>;
}
interface Download {
(url: string | URL, destination: string, options?: DownloadOptions): Promise<string>;
}
export interface DownloadOptions {
onProgress?: (progress: {completed: number; total?: number}) => void;
onLog?: (message: string) => void;
filename?: string;
timeout?: number;
signal?: AbortSignal;
}
interface Extract {
(archivePath: string, destinationPath: string, options: ExtractOptions & {listDetails: true}): Promise<
ExtractListDetailItem[]
>;
(archivePath: string, options: ExtractOptions & {listDetails: true}): Promise<ExtractListDetailItem[]>;
(archivePath: string, destinationPath: string, options?: ExtractOptions & {listDetails?: false}): Promise<string[]>;
(archivePath: string, options?: ExtractOptions & {listDetails?: false}): Promise<string[]>;
}
export interface ExtractOptions {
overwrite?: boolean;
listDetails?: boolean;
onLog?: (message: string) => void;
onProgress?: (progress: ProgressData) => void;
}
export interface ExtractListDetailItem {
/**
* File name.
*/
name: string;
/**
* Full path to a file.
*/
path: string;
size: number;
isDirectory: boolean;
isFile: boolean;
}
export interface FetchJsonError extends Error {
status: number;
}
/**
* TYPING UTILS.
*/
export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
/**
* Electron interfaces.
*/
export interface DialogFileFilter {
// Docs: https://electronjs.org/docs/api/structures/file-filter
extensions: string[];
name: string;
}
export interface OpenDialogOptions {
title?: string;
defaultPath?: string;
/**
* Custom label for the confirmation button, when left empty the default label will
* be used.
*/
buttonLabel?: string;
filters?: DialogFileFilter[];
/**
* Contains which features the dialog should use. The following values are
* supported:
*/
properties?: Array<
| 'openFile'
| 'openDirectory'
| 'multiSelections'
| 'showHiddenFiles'
| 'createDirectory'
| 'promptToCreate'
| 'noResolveAliases'
| 'treatPackageAsDirectory'
| 'dontAddToRecent'
>;
/**
* Message to display above input boxes.
*
* @platform darwin
*/
message?: string;
/**
* Create security scoped bookmarks when packaged for the Mac App Store.
*
* @platform darwin,mas
*/
securityScopedBookmarks?: boolean;
}
export interface OpenDialogReturnValue {
/**
* whether or not the dialog was canceled.
*/
canceled: boolean;
/**
* An array of file paths chosen by the user. If the dialog is cancelled this will
* be an empty array.
*/
filePaths: string[];
/**
* An array matching the `filePaths` array of base64 encoded strings which contains
* security scoped bookmark data. `securityScopedBookmarks` must be enabled for
* this to be populated. (For return values, see table here.)
*
* @platform darwin,mas
*/
bookmarks?: string[];
}
export interface SaveDialogOptions {
/**
* The dialog title. Cannot be displayed on some _Linux_ desktop environments.
*/
title?: string;
/**
* Absolute directory path, absolute file path, or file name to use by default.
*/
defaultPath?: string;
/**
* Custom label for the confirmation button, when left empty the default label will
* be used.
*/
buttonLabel?: string;
filters?: DialogFileFilter[];
/**
* Message to display above text fields.
*
* @platform darwin
*/
message?: string;
/**
* Custom label for the text displayed in front of the filename text field.
*
* @platform darwin
*/
nameFieldLabel?: string;
/**
* Show the tags input box, defaults to `true`.
*
* @platform darwin
*/
showsTagField?: boolean;
properties?: Array<
| 'showHiddenFiles'
| 'createDirectory'
| 'treatPackageAsDirectory'
| 'showOverwriteConfirmation'
| 'dontAddToRecent'
>;
/**
* Create a security scoped bookmark when packaged for the Mac App Store. If this
* option is enabled and the file doesn't already exist a blank file will be
* created at the chosen path.
*
* @platform darwin,mas
*/
securityScopedBookmarks?: boolean;
}
export interface SaveDialogReturnValue {
/**
* whether or not the dialog was canceled.
*/
canceled: boolean;
/**
* If the dialog is canceled, this will be `undefined`.
*/
filePath?: string;
/**
* Base64 encoded string which contains the security scoped bookmark data for the
* saved file. `securityScopedBookmarks` must be enabled for this to be present.
* (For return values, see table here.)
*
* @platform darwin,mas
*/
bookmark?: string;
}
export interface MenuItemConstructorOptions {
/**
* Will be called with `click()` when the menu item is clicked.
*/
click?: () => void;
// prettier-ignore
/**
* Can be `undo`, `redo`, `cut`, `copy`, `paste`, `pasteAndMatchStyle`, `delete`,
* `selectAll`, `reload`, `forceReload`, `toggleDevTools`, `resetZoom`, `zoomIn`,
* `zoomOut`, `toggleSpellChecker`, `togglefullscreen`, `window`, `minimize`,
* `close`, `help`, `about`, `services`, `hide`, `hideOthers`, `unhide`, `quit`,
* `startSpeaking`, `stopSpeaking`, `zoom`, `front`, `appMenu`, `fileMenu`,
* `editMenu`, `viewMenu`, `shareMenu`, `recentDocuments`, `toggleTabBar`,
* `selectNextTab`, `selectPreviousTab`, `mergeAllWindows`, `clearRecentDocuments`,
* `moveTabToNewWindow` or `windowMenu` - Define the action of the menu item, when
* specified the `click` property will be ignored. See roles.
*/
role?: 'undo' | 'redo' | 'cut' | 'copy' | 'paste' | 'pasteAndMatchStyle' | 'delete' | 'selectAll' | 'reload'
| 'forceReload' | 'toggleDevTools' | 'resetZoom' | 'zoomIn' | 'zoomOut' | 'toggleSpellChecker'
| 'togglefullscreen' | 'window' | 'minimize' | 'close' | 'help' | 'about' | 'services' | 'hide' | 'hideOthers'
| 'unhide' | 'quit' | 'startSpeaking' | 'stopSpeaking' | 'zoom' | 'front' | 'appMenu' | 'fileMenu' | 'editMenu'
| 'viewMenu' | 'shareMenu' | 'recentDocuments' | 'toggleTabBar' | 'selectNextTab' | 'selectPreviousTab'
| 'mergeAllWindows' | 'clearRecentDocuments' | 'moveTabToNewWindow' | 'windowMenu';
/**
* Can be `normal`, `separator`, `submenu`, `checkbox` or `radio`.
*/
type?: 'normal' | 'separator' | 'submenu' | 'checkbox' | 'radio';
label?: string;
sublabel?: string;
/**
* Hover text for this menu item.
*
* @platform darwin
*/
toolTip?: string;
accelerator?: string;
icon?: string;
/**
* If false, the menu item will be greyed out and unclickable.
*/
enabled?: boolean;
/**
* default is `true`, and when `false` will prevent the accelerator from triggering
* the item if the item is not visible`.
*
* @platform darwin
*/
acceleratorWorksWhenHidden?: boolean;
/**
* If false, the menu item will be entirely hidden.
*/
visible?: boolean;
/**
* Should only be specified for `checkbox` or `radio` type menu items.
*/
checked?: boolean;
/**
* If false, the accelerator won't be registered with the system, but it will still
* be displayed. Defaults to true.
*
* @platform linux,win32
*/
registerAccelerator?: boolean;
/**
* The item to share when the `role` is `shareMenu`.
*
* @platform darwin
*/
sharingItem?: SharingItem;
/**
* Should be specified for `submenu` type menu items. If `submenu` is specified,
* the `type: 'submenu'` can be omitted. If the value is not a `Menu` then it will
* be automatically converted to one using `Menu.buildFromTemplate`.
*/
submenu?: MenuItemConstructorOptions[];
/**
* Unique within a single menu. If defined then it can be used as a reference to
* this item by the position attribute.
*/
id?: string;
/**
* Inserts this item before the item with the specified label. If the referenced
* item doesn't exist the item will be inserted at the end of the menu. Also
* implies that the menu item in question should be placed in the same “group” as
* the item.
*/
before?: string[];
/**
* Inserts this item after the item with the specified label. If the referenced
* item doesn't exist the item will be inserted at the end of the menu.
*/
after?: string[];
/**
* Provides a means for a single context menu to declare the placement of their
* containing group before the containing group of the item with the specified
* label.
*/
beforeGroupContaining?: string[];
/**
* Provides a means for a single context menu to declare the placement of their
* containing group after the containing group of the item with the specified
* label.
*/
afterGroupContaining?: string[];
}
export interface SharingItem {
// Docs: https://electronjs.org/docs/api/structures/sharing-item
/**
* An array of files to share.
*/
filePaths?: string[];
/**
* An array of text to share.
*/
texts?: string[];
/**
* An array of URLs to share.
*/
urls?: string[];
}