-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
window.ts
2298 lines (2179 loc) · 62.5 KB
/
window.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
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
/**
* Provides APIs to create windows, communicate with other windows and manipulate the current window.
*
* ## Window events
*
* Events can be listened to using {@link Window.listen}:
* ```typescript
* import { getCurrent } from "@tauri-apps/api/window";
* getCurrent().listen("my-window-event", ({ event, payload }) => { });
* ```
*
* @module
*/
import {
LogicalPosition,
LogicalSize,
PhysicalPosition,
PhysicalSize
} from './dpi'
import type { Event, EventName, EventCallback, UnlistenFn } from './event'
import {
TauriEvent,
// imported for documentation purposes
// eslint-disable-next-line
type EventTarget,
emit,
emitTo,
listen,
once
} from './event'
import { invoke } from './core'
import { WebviewWindow } from './webviewWindow'
import type { DragDropEvent, DragDropPayload } from './webview'
import { Image, transformImage } from './image'
/**
* Allows you to retrieve information about a given monitor.
*
* @since 1.0.0
*/
export interface Monitor {
/** Human-readable name of the monitor */
name: string | null
/** The monitor's resolution. */
size: PhysicalSize
/** the Top-left corner position of the monitor relative to the larger full screen area. */
position: PhysicalPosition
/** The scale factor that can be used to map physical pixels to logical pixels. */
scaleFactor: number
}
type Theme = 'light' | 'dark'
type TitleBarStyle = 'visible' | 'transparent' | 'overlay'
type ResizeDirection =
| 'East'
| 'North'
| 'NorthEast'
| 'NorthWest'
| 'South'
| 'SouthEast'
| 'SouthWest'
| 'West'
/**
* The payload for the `scaleChange` event.
*
* @since 1.0.2
*/
interface ScaleFactorChanged {
/** The new window scale factor. */
scaleFactor: number
/** The new window size */
size: PhysicalSize
}
/**
* Attention type to request on a window.
*
* @since 1.0.0
*/
enum UserAttentionType {
/**
* #### Platform-specific
* - **macOS:** Bounces the dock icon until the application is in focus.
* - **Windows:** Flashes both the window and the taskbar button until the application is in focus.
*/
Critical = 1,
/**
* #### Platform-specific
* - **macOS:** Bounces the dock icon once.
* - **Windows:** Flashes the taskbar button until the application is in focus.
*/
Informational
}
class CloseRequestedEvent {
/** Event name */
event: EventName
/** Event identifier used to unlisten */
id: number
private _preventDefault = false
constructor(event: Event<null>) {
this.event = event.event
this.id = event.id
}
preventDefault(): void {
this._preventDefault = true
}
isPreventDefault(): boolean {
return this._preventDefault
}
}
export type CursorIcon =
| 'default'
| 'crosshair'
| 'hand'
| 'arrow'
| 'move'
| 'text'
| 'wait'
| 'help'
| 'progress'
// something cannot be done
| 'notAllowed'
| 'contextMenu'
| 'cell'
| 'verticalText'
| 'alias'
| 'copy'
| 'noDrop'
// something can be grabbed
| 'grab'
/// something is grabbed
| 'grabbing'
| 'allScroll'
| 'zoomIn'
| 'zoomOut'
// edge is to be moved
| 'eResize'
| 'nResize'
| 'neResize'
| 'nwResize'
| 'sResize'
| 'seResize'
| 'swResize'
| 'wResize'
| 'ewResize'
| 'nsResize'
| 'neswResize'
| 'nwseResize'
| 'colResize'
| 'rowResize'
export enum ProgressBarStatus {
/**
* Hide progress bar.
*/
None = 'none',
/**
* Normal state.
*/
Normal = 'normal',
/**
* Indeterminate state. **Treated as Normal on Linux and macOS**
*/
Indeterminate = 'indeterminate',
/**
* Paused state. **Treated as Normal on Linux**
*/
Paused = 'paused',
/**
* Error state. **Treated as Normal on linux**
*/
Error = 'error'
}
export interface ProgressBarState {
/**
* The progress bar status.
*/
status?: ProgressBarStatus
/**
* The progress bar progress. This can be a value ranging from `0` to `100`
*/
progress?: number
}
/**
* Get an instance of `Window` for the current window.
*
* @since 1.0.0
*/
function getCurrent(): Window {
return new Window(window.__TAURI_INTERNALS__.metadata.currentWindow.label, {
// @ts-expect-error `skip` is not defined in the public API but it is handled by the constructor
skip: true
})
}
/**
* Gets a list of instances of `Window` for all available windows.
*
* @since 1.0.0
*/
function getAll(): Window[] {
return window.__TAURI_INTERNALS__.metadata.windows.map(
(w) =>
new Window(w.label, {
// @ts-expect-error `skip` is not defined in the public API but it is handled by the constructor
skip: true
})
)
}
/** @ignore */
// events that are emitted right here instead of by the created window
const localTauriEvents = ['tauri://created', 'tauri://error']
/** @ignore */
export type WindowLabel = string
/**
* Create new window or get a handle to an existing one.
*
* Windows are identified by a *label* a unique identifier that can be used to reference it later.
* It may only contain alphanumeric characters `a-zA-Z` plus the following special characters `-`, `/`, `:` and `_`.
*
* @example
* ```typescript
* import { Window } from "@tauri-apps/api/window"
*
* const appWindow = new Window('theUniqueLabel');
*
* appWindow.once('tauri://created', function () {
* // window successfully created
* });
* appWindow.once('tauri://error', function (e) {
* // an error happened creating the window
* });
*
* // emit an event to the backend
* await appWindow.emit("some-event", "data");
* // listen to an event from the backend
* const unlisten = await appWindow.listen("event-name", e => {});
* unlisten();
* ```
*
* @since 2.0.0
*/
class Window {
/** The window label. It is a unique identifier for the window, can be used to reference it later. */
label: WindowLabel
/** Local event listeners. */
// eslint-disable-next-line @typescript-eslint/no-explicit-any
listeners: Record<string, Array<EventCallback<any>>>
/**
* Creates a new Window.
* @example
* ```typescript
* import { Window } from '@tauri-apps/api/window';
* const appWindow = new Window('my-label');
* appWindow.once('tauri://created', function () {
* // window successfully created
* });
* appWindow.once('tauri://error', function (e) {
* // an error happened creating the window
* });
* ```
*
* @param label The unique window label. Must be alphanumeric: `a-zA-Z-/:_`.
* @returns The {@link Window} instance to communicate with the window.
*/
constructor(label: WindowLabel, options: WindowOptions = {}) {
this.label = label
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
this.listeners = Object.create(null)
// @ts-expect-error `skip` is not a public API so it is not defined in WindowOptions
if (!options?.skip) {
invoke('plugin:window|create', {
options: {
...options,
parent:
typeof options.parent === 'string'
? options.parent
: options.parent?.label,
label
}
})
.then(async () => this.emit('tauri://created'))
.catch(async (e: string) => this.emit('tauri://error', e))
}
}
/**
* Gets the Window associated with the given label.
* @example
* ```typescript
* import { Window } from '@tauri-apps/api/window';
* const mainWindow = Window.getByLabel('main');
* ```
*
* @param label The window label.
* @returns The Window instance to communicate with the window or null if the window doesn't exist.
*/
static getByLabel(label: string): Window | null {
return getAll().find((w) => w.label === label) ?? null
}
/**
* Get an instance of `Window` for the current window.
*/
static getCurrent(): Window {
return getCurrent()
}
/**
* Gets a list of instances of `Window` for all available windows.
*/
static getAll(): Window[] {
return getAll()
}
/**
* Gets the focused window.
* @example
* ```typescript
* import { Window } from '@tauri-apps/api/window';
* const focusedWindow = Window.getFocusedWindow();
* ```
*
* @returns The Window instance or `undefined` if there is not any focused window.
*/
static async getFocusedWindow(): Promise<Window | null> {
for (const w of getAll()) {
if (await w.isFocused()) {
return w
}
}
return null
}
/**
* Listen to an emitted event on this window.
*
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const unlisten = await getCurrent().listen<string>('state-changed', (event) => {
* console.log(`Got error: ${payload}`);
* });
*
* // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
* unlisten();
* ```
*
* @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`.
* @param handler Event handler.
* @returns A promise resolving to a function to unlisten to the event.
* Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
*/
async listen<T>(
event: EventName,
handler: EventCallback<T>
): Promise<UnlistenFn> {
if (this._handleTauriEvent(event, handler)) {
return Promise.resolve(() => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, security/detect-object-injection
const listeners = this.listeners[event]
listeners.splice(listeners.indexOf(handler), 1)
})
}
return listen(event, handler, {
target: { kind: 'Window', label: this.label }
})
}
/**
* Listen to an emitted event on this window only once.
*
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const unlisten = await getCurrent().once<null>('initialized', (event) => {
* console.log(`Window initialized!`);
* });
*
* // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
* unlisten();
* ```
*
* @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`.
* @param handler Event handler.
* @returns A promise resolving to a function to unlisten to the event.
* Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
*/
async once<T>(event: string, handler: EventCallback<T>): Promise<UnlistenFn> {
if (this._handleTauriEvent(event, handler)) {
return Promise.resolve(() => {
// eslint-disable-next-line security/detect-object-injection
const listeners = this.listeners[event]
listeners.splice(listeners.indexOf(handler), 1)
})
}
return once(event, handler, {
target: { kind: 'Window', label: this.label }
})
}
/**
* Emits an event to all {@link EventTarget|targets}.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().emit('window-loaded', { loggedIn: true, token: 'authToken' });
* ```
*
* @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`.
* @param payload Event payload.
*/
async emit(event: string, payload?: unknown): Promise<void> {
if (localTauriEvents.includes(event)) {
// eslint-disable-next-line
for (const handler of this.listeners[event] || []) {
handler({
event,
id: -1,
payload
})
}
return Promise.resolve()
}
return emit(event, payload)
}
/**
* Emits an event to all {@link EventTarget|targets} matching the given target.
*
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().emit('main', 'window-loaded', { loggedIn: true, token: 'authToken' });
* ```
* @param target Label of the target Window/Webview/WebviewWindow or raw {@link EventTarget} object.
* @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`.
* @param payload Event payload.
*/
async emitTo(
target: string | EventTarget,
event: string,
payload?: unknown
): Promise<void> {
if (localTauriEvents.includes(event)) {
// eslint-disable-next-line
for (const handler of this.listeners[event] || []) {
handler({
event,
id: -1,
payload
})
}
return Promise.resolve()
}
return emitTo(target, event, payload)
}
/** @ignore */
_handleTauriEvent<T>(event: string, handler: EventCallback<T>): boolean {
if (localTauriEvents.includes(event)) {
if (!(event in this.listeners)) {
// eslint-disable-next-line
this.listeners[event] = [handler]
} else {
// eslint-disable-next-line
this.listeners[event].push(handler)
}
return true
}
return false
}
// Getters
/**
* The scale factor that can be used to map physical pixels to logical pixels.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const factor = await getCurrent().scaleFactor();
* ```
*
* @returns The window's monitor scale factor.
*/
async scaleFactor(): Promise<number> {
return invoke('plugin:window|scale_factor', {
label: this.label
})
}
/**
* The position of the top-left hand corner of the window's client area relative to the top-left hand corner of the desktop.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const position = await getCurrent().innerPosition();
* ```
*
* @returns The window's inner position.
*/
async innerPosition(): Promise<PhysicalPosition> {
return invoke<{ x: number; y: number }>('plugin:window|inner_position', {
label: this.label
}).then(({ x, y }) => new PhysicalPosition(x, y))
}
/**
* The position of the top-left hand corner of the window relative to the top-left hand corner of the desktop.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const position = await getCurrent().outerPosition();
* ```
*
* @returns The window's outer position.
*/
async outerPosition(): Promise<PhysicalPosition> {
return invoke<{ x: number; y: number }>('plugin:window|outer_position', {
label: this.label
}).then(({ x, y }) => new PhysicalPosition(x, y))
}
/**
* The physical size of the window's client area.
* The client area is the content of the window, excluding the title bar and borders.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const size = await getCurrent().innerSize();
* ```
*
* @returns The window's inner size.
*/
async innerSize(): Promise<PhysicalSize> {
return invoke<{ width: number; height: number }>(
'plugin:window|inner_size',
{
label: this.label
}
).then(({ width, height }) => new PhysicalSize(width, height))
}
/**
* The physical size of the entire window.
* These dimensions include the title bar and borders. If you don't want that (and you usually don't), use inner_size instead.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const size = await getCurrent().outerSize();
* ```
*
* @returns The window's outer size.
*/
async outerSize(): Promise<PhysicalSize> {
return invoke<{ width: number; height: number }>(
'plugin:window|outer_size',
{
label: this.label
}
).then(({ width, height }) => new PhysicalSize(width, height))
}
/**
* Gets the window's current fullscreen state.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const fullscreen = await getCurrent().isFullscreen();
* ```
*
* @returns Whether the window is in fullscreen mode or not.
*/
async isFullscreen(): Promise<boolean> {
return invoke('plugin:window|is_fullscreen', {
label: this.label
})
}
/**
* Gets the window's current minimized state.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const minimized = await getCurrent().isMinimized();
* ```
*/
async isMinimized(): Promise<boolean> {
return invoke('plugin:window|is_minimized', {
label: this.label
})
}
/**
* Gets the window's current maximized state.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const maximized = await getCurrent().isMaximized();
* ```
*
* @returns Whether the window is maximized or not.
*/
async isMaximized(): Promise<boolean> {
return invoke('plugin:window|is_maximized', {
label: this.label
})
}
/**
* Gets the window's current focus state.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const focused = await getCurrent().isFocused();
* ```
*
* @returns Whether the window is focused or not.
*/
async isFocused(): Promise<boolean> {
return invoke('plugin:window|is_focused', {
label: this.label
})
}
/**
* Gets the window's current decorated state.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const decorated = await getCurrent().isDecorated();
* ```
*
* @returns Whether the window is decorated or not.
*/
async isDecorated(): Promise<boolean> {
return invoke('plugin:window|is_decorated', {
label: this.label
})
}
/**
* Gets the window's current resizable state.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const resizable = await getCurrent().isResizable();
* ```
*
* @returns Whether the window is resizable or not.
*/
async isResizable(): Promise<boolean> {
return invoke('plugin:window|is_resizable', {
label: this.label
})
}
/**
* Gets the window’s native maximize button state.
*
* #### Platform-specific
*
* - **Linux / iOS / Android:** Unsupported.
*
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const maximizable = await getCurrent().isMaximizable();
* ```
*
* @returns Whether the window's native maximize button is enabled or not.
*/
async isMaximizable(): Promise<boolean> {
return invoke('plugin:window|is_maximizable', {
label: this.label
})
}
/**
* Gets the window’s native minimize button state.
*
* #### Platform-specific
*
* - **Linux / iOS / Android:** Unsupported.
*
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const minimizable = await getCurrent().isMinimizable();
* ```
*
* @returns Whether the window's native minimize button is enabled or not.
*/
async isMinimizable(): Promise<boolean> {
return invoke('plugin:window|is_minimizable', {
label: this.label
})
}
/**
* Gets the window’s native close button state.
*
* #### Platform-specific
*
* - **iOS / Android:** Unsupported.
*
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const closable = await getCurrent().isClosable();
* ```
*
* @returns Whether the window's native close button is enabled or not.
*/
async isClosable(): Promise<boolean> {
return invoke('plugin:window|is_closable', {
label: this.label
})
}
/**
* Gets the window's current visible state.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const visible = await getCurrent().isVisible();
* ```
*
* @returns Whether the window is visible or not.
*/
async isVisible(): Promise<boolean> {
return invoke('plugin:window|is_visible', {
label: this.label
})
}
/**
* Gets the window's current title.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const title = await getCurrent().title();
* ```
*/
async title(): Promise<string> {
return invoke('plugin:window|title', {
label: this.label
})
}
/**
* Gets the window's current theme.
*
* #### Platform-specific
*
* - **macOS:** Theme was introduced on macOS 10.14. Returns `light` on macOS 10.13 and below.
*
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const theme = await getCurrent().theme();
* ```
*
* @returns The window theme.
*/
async theme(): Promise<Theme | null> {
return invoke('plugin:window|theme', {
label: this.label
})
}
// Setters
/**
* Centers the window.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().center();
* ```
*
* @returns A promise indicating the success or failure of the operation.
*/
async center(): Promise<void> {
return invoke('plugin:window|center', {
label: this.label
})
}
/**
* Requests user attention to the window, this has no effect if the application
* is already focused. How requesting for user attention manifests is platform dependent,
* see `UserAttentionType` for details.
*
* Providing `null` will unset the request for user attention. Unsetting the request for
* user attention might not be done automatically by the WM when the window receives input.
*
* #### Platform-specific
*
* - **macOS:** `null` has no effect.
* - **Linux:** Urgency levels have the same effect.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().requestUserAttention();
* ```
*
* @returns A promise indicating the success or failure of the operation.
*/
async requestUserAttention(
requestType: UserAttentionType | null
): Promise<void> {
let requestType_ = null
if (requestType) {
if (requestType === UserAttentionType.Critical) {
requestType_ = { type: 'Critical' }
} else {
requestType_ = { type: 'Informational' }
}
}
return invoke('plugin:window|request_user_attention', {
label: this.label,
value: requestType_
})
}
/**
* Updates the window resizable flag.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().setResizable(false);
* ```
*
* @returns A promise indicating the success or failure of the operation.
*/
async setResizable(resizable: boolean): Promise<void> {
return invoke('plugin:window|set_resizable', {
label: this.label,
value: resizable
})
}
/**
* Sets whether the window's native maximize button is enabled or not.
* If resizable is set to false, this setting is ignored.
*
* #### Platform-specific
*
* - **macOS:** Disables the "zoom" button in the window titlebar, which is also used to enter fullscreen mode.
* - **Linux / iOS / Android:** Unsupported.
*
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().setMaximizable(false);
* ```
*
* @returns A promise indicating the success or failure of the operation.
*/
async setMaximizable(maximizable: boolean): Promise<void> {
return invoke('plugin:window|set_maximizable', {
label: this.label,
value: maximizable
})
}
/**
* Sets whether the window's native minimize button is enabled or not.
*
* #### Platform-specific
*
* - **Linux / iOS / Android:** Unsupported.
*
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().setMinimizable(false);
* ```
*
* @returns A promise indicating the success or failure of the operation.
*/
async setMinimizable(minimizable: boolean): Promise<void> {
return invoke('plugin:window|set_minimizable', {
label: this.label,
value: minimizable
})
}
/**
* Sets whether the window's native close button is enabled or not.
*
* #### Platform-specific
*
* - **Linux:** GTK+ will do its best to convince the window manager not to show a close button. Depending on the system, this function may not have any effect when called on a window that is already visible
* - **iOS / Android:** Unsupported.
*
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().setClosable(false);
* ```
*
* @returns A promise indicating the success or failure of the operation.
*/
async setClosable(closable: boolean): Promise<void> {
return invoke('plugin:window|set_closable', {
label: this.label,
value: closable
})
}
/**
* Sets the window title.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().setTitle('Tauri');
* ```
*
* @param title The new title
* @returns A promise indicating the success or failure of the operation.
*/
async setTitle(title: string): Promise<void> {
return invoke('plugin:window|set_title', {
label: this.label,
value: title
})
}
/**
* Maximizes the window.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().maximize();
* ```
*
* @returns A promise indicating the success or failure of the operation.
*/
async maximize(): Promise<void> {
return invoke('plugin:window|maximize', {
label: this.label
})
}
/**
* Unmaximizes the window.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().unmaximize();
* ```
*
* @returns A promise indicating the success or failure of the operation.
*/
async unmaximize(): Promise<void> {
return invoke('plugin:window|unmaximize', {
label: this.label
})
}
/**
* Toggles the window maximized state.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().toggleMaximize();
* ```
*
* @returns A promise indicating the success or failure of the operation.
*/
async toggleMaximize(): Promise<void> {
return invoke('plugin:window|toggle_maximize', {
label: this.label
})
}
/**
* Minimizes the window.
* @example
* ```typescript