@tauri-apps/plugin-window-state 2.0.0-alpha.2 → 2.0.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-js/index.min.js +1929 -8
- package/package.json +2 -2
package/dist-js/index.min.js
CHANGED
|
@@ -1,12 +1,1933 @@
|
|
|
1
|
-
|
|
1
|
+
/******************************************************************************
|
|
2
|
+
Copyright (c) Microsoft Corporation.
|
|
3
|
+
|
|
4
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
5
|
+
purpose with or without fee is hereby granted.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
8
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
9
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
10
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
11
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
12
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
13
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
14
|
+
***************************************************************************** */
|
|
15
|
+
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
19
|
+
var e = new Error(message);
|
|
20
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
21
|
+
};
|
|
2
22
|
|
|
3
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Invoke your custom commands.
|
|
25
|
+
*
|
|
26
|
+
* This package is also accessible with `window.__TAURI__.tauri` when [`build.withGlobalTauri`](https://tauri.app/v1/api/config/#buildconfig.withglobaltauri) in `tauri.conf.json` is set to `true`.
|
|
27
|
+
* @module
|
|
28
|
+
*/
|
|
29
|
+
/**
|
|
30
|
+
* Transforms a callback function to a string identifier that can be passed to the backend.
|
|
31
|
+
* The backend uses the identifier to `eval()` the callback.
|
|
32
|
+
*
|
|
33
|
+
* @return A unique identifier associated with the callback function.
|
|
34
|
+
*
|
|
35
|
+
* @since 1.0.0
|
|
36
|
+
*/
|
|
37
|
+
function transformCallback(callback, once = false) {
|
|
38
|
+
return window.__TAURI_INTERNALS__.transformCallback(callback, once);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Sends a message to the backend.
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* import { invoke } from '@tauri-apps/api/primitives';
|
|
45
|
+
* await invoke('login', { user: 'tauri', password: 'poiwe3h4r5ip3yrhtew9ty' });
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* @param cmd The command name.
|
|
49
|
+
* @param args The optional arguments to pass to the command.
|
|
50
|
+
* @param options The request options.
|
|
51
|
+
* @return A promise resolving or rejecting to the backend response.
|
|
52
|
+
*
|
|
53
|
+
* @since 1.0.0
|
|
54
|
+
*/
|
|
55
|
+
async function invoke(cmd, args = {}, options) {
|
|
56
|
+
return window.__TAURI_INTERNALS__.invoke(cmd, args, options);
|
|
57
|
+
}
|
|
4
58
|
|
|
5
|
-
|
|
59
|
+
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
|
60
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
61
|
+
// SPDX-License-Identifier: MIT
|
|
62
|
+
/**
|
|
63
|
+
* A size represented in logical pixels.
|
|
64
|
+
*
|
|
65
|
+
* @since 2.0.0
|
|
66
|
+
*/
|
|
67
|
+
class LogicalSize {
|
|
68
|
+
constructor(width, height) {
|
|
69
|
+
this.type = 'Logical';
|
|
70
|
+
this.width = width;
|
|
71
|
+
this.height = height;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* A size represented in physical pixels.
|
|
76
|
+
*
|
|
77
|
+
* @since 2.0.0
|
|
78
|
+
*/
|
|
79
|
+
class PhysicalSize {
|
|
80
|
+
constructor(width, height) {
|
|
81
|
+
this.type = 'Physical';
|
|
82
|
+
this.width = width;
|
|
83
|
+
this.height = height;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Converts the physical size to a logical one.
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* import { getCurrent } from '@tauri-apps/api/window';
|
|
90
|
+
* const appWindow = getCurrent();
|
|
91
|
+
* const factor = await appWindow.scaleFactor();
|
|
92
|
+
* const size = await appWindow.innerSize();
|
|
93
|
+
* const logical = size.toLogical(factor);
|
|
94
|
+
* ```
|
|
95
|
+
* */
|
|
96
|
+
toLogical(scaleFactor) {
|
|
97
|
+
return new LogicalSize(this.width / scaleFactor, this.height / scaleFactor);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* A position represented in logical pixels.
|
|
102
|
+
*
|
|
103
|
+
* @since 2.0.0
|
|
104
|
+
*/
|
|
105
|
+
class LogicalPosition {
|
|
106
|
+
constructor(x, y) {
|
|
107
|
+
this.type = 'Logical';
|
|
108
|
+
this.x = x;
|
|
109
|
+
this.y = y;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* A position represented in physical pixels.
|
|
114
|
+
*
|
|
115
|
+
* @since 2.0.0
|
|
116
|
+
*/
|
|
117
|
+
class PhysicalPosition {
|
|
118
|
+
constructor(x, y) {
|
|
119
|
+
this.type = 'Physical';
|
|
120
|
+
this.x = x;
|
|
121
|
+
this.y = y;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Converts the physical position to a logical one.
|
|
125
|
+
* @example
|
|
126
|
+
* ```typescript
|
|
127
|
+
* import { getCurrent } from '@tauri-apps/api/window';
|
|
128
|
+
* const appWindow = getCurrent();
|
|
129
|
+
* const factor = await appWindow.scaleFactor();
|
|
130
|
+
* const position = await appWindow.innerPosition();
|
|
131
|
+
* const logical = position.toLogical(factor);
|
|
132
|
+
* ```
|
|
133
|
+
* */
|
|
134
|
+
toLogical(scaleFactor) {
|
|
135
|
+
return new LogicalPosition(this.x / scaleFactor, this.y / scaleFactor);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
6
138
|
|
|
7
|
-
|
|
139
|
+
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
|
140
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
141
|
+
// SPDX-License-Identifier: MIT
|
|
142
|
+
/**
|
|
143
|
+
* The event system allows you to emit events to the backend and listen to events from it.
|
|
144
|
+
*
|
|
145
|
+
* This package is also accessible with `window.__TAURI__.event` when [`build.withGlobalTauri`](https://tauri.app/v1/api/config/#buildconfig.withglobaltauri) in `tauri.conf.json` is set to `true`.
|
|
146
|
+
* @module
|
|
147
|
+
*/
|
|
148
|
+
/**
|
|
149
|
+
* @since 1.1.0
|
|
150
|
+
*/
|
|
151
|
+
var TauriEvent;
|
|
152
|
+
(function (TauriEvent) {
|
|
153
|
+
TauriEvent["WINDOW_RESIZED"] = "tauri://resize";
|
|
154
|
+
TauriEvent["WINDOW_MOVED"] = "tauri://move";
|
|
155
|
+
TauriEvent["WINDOW_CLOSE_REQUESTED"] = "tauri://close-requested";
|
|
156
|
+
TauriEvent["WINDOW_CREATED"] = "tauri://window-created";
|
|
157
|
+
TauriEvent["WINDOW_DESTROYED"] = "tauri://destroyed";
|
|
158
|
+
TauriEvent["WINDOW_FOCUS"] = "tauri://focus";
|
|
159
|
+
TauriEvent["WINDOW_BLUR"] = "tauri://blur";
|
|
160
|
+
TauriEvent["WINDOW_SCALE_FACTOR_CHANGED"] = "tauri://scale-change";
|
|
161
|
+
TauriEvent["WINDOW_THEME_CHANGED"] = "tauri://theme-changed";
|
|
162
|
+
TauriEvent["WINDOW_FILE_DROP"] = "tauri://file-drop";
|
|
163
|
+
TauriEvent["WINDOW_FILE_DROP_HOVER"] = "tauri://file-drop-hover";
|
|
164
|
+
TauriEvent["WINDOW_FILE_DROP_CANCELLED"] = "tauri://file-drop-cancelled";
|
|
165
|
+
TauriEvent["MENU"] = "tauri://menu";
|
|
166
|
+
})(TauriEvent || (TauriEvent = {}));
|
|
167
|
+
/**
|
|
168
|
+
* Unregister the event listener associated with the given name and id.
|
|
169
|
+
*
|
|
170
|
+
* @ignore
|
|
171
|
+
* @param event The event name
|
|
172
|
+
* @param eventId Event identifier
|
|
173
|
+
* @returns
|
|
174
|
+
*/
|
|
175
|
+
async function _unlisten(event, eventId) {
|
|
176
|
+
await invoke('plugin:event|unlisten', {
|
|
177
|
+
event,
|
|
178
|
+
eventId
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Listen to an event. The event can be either global or window-specific.
|
|
183
|
+
* See {@link Event.windowLabel} to check the event source.
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* ```typescript
|
|
187
|
+
* import { listen } from '@tauri-apps/api/event';
|
|
188
|
+
* const unlisten = await listen<string>('error', (event) => {
|
|
189
|
+
* console.log(`Got error in window ${event.windowLabel}, payload: ${event.payload}`);
|
|
190
|
+
* });
|
|
191
|
+
*
|
|
192
|
+
* // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
|
|
193
|
+
* unlisten();
|
|
194
|
+
* ```
|
|
195
|
+
*
|
|
196
|
+
* @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`.
|
|
197
|
+
* @param handler Event handler callback.
|
|
198
|
+
* @returns A promise resolving to a function to unlisten to the event.
|
|
199
|
+
* Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
|
|
200
|
+
*
|
|
201
|
+
* @since 1.0.0
|
|
202
|
+
*/
|
|
203
|
+
async function listen(event, handler, options) {
|
|
204
|
+
return invoke('plugin:event|listen', {
|
|
205
|
+
event,
|
|
206
|
+
windowLabel: options?.target,
|
|
207
|
+
handler: transformCallback(handler)
|
|
208
|
+
}).then((eventId) => {
|
|
209
|
+
return async () => _unlisten(event, eventId);
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Listen to an one-off event. See {@link listen} for more information.
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* ```typescript
|
|
217
|
+
* import { once } from '@tauri-apps/api/event';
|
|
218
|
+
* interface LoadedPayload {
|
|
219
|
+
* loggedIn: boolean,
|
|
220
|
+
* token: string
|
|
221
|
+
* }
|
|
222
|
+
* const unlisten = await once<LoadedPayload>('loaded', (event) => {
|
|
223
|
+
* console.log(`App is loaded, loggedIn: ${event.payload.loggedIn}, token: ${event.payload.token}`);
|
|
224
|
+
* });
|
|
225
|
+
*
|
|
226
|
+
* // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
|
|
227
|
+
* unlisten();
|
|
228
|
+
* ```
|
|
229
|
+
*
|
|
230
|
+
* @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`.
|
|
231
|
+
* @returns A promise resolving to a function to unlisten to the event.
|
|
232
|
+
* Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
|
|
233
|
+
*
|
|
234
|
+
* @since 1.0.0
|
|
235
|
+
*/
|
|
236
|
+
async function once(event, handler, options) {
|
|
237
|
+
return listen(event, (eventData) => {
|
|
238
|
+
handler(eventData);
|
|
239
|
+
_unlisten(event, eventData.id).catch(() => { });
|
|
240
|
+
}, options);
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Emits an event to the backend and all Tauri windows.
|
|
244
|
+
* @example
|
|
245
|
+
* ```typescript
|
|
246
|
+
* import { emit } from '@tauri-apps/api/event';
|
|
247
|
+
* await emit('frontend-loaded', { loggedIn: true, token: 'authToken' });
|
|
248
|
+
* ```
|
|
249
|
+
*
|
|
250
|
+
* @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`.
|
|
251
|
+
*
|
|
252
|
+
* @since 1.0.0
|
|
253
|
+
*/
|
|
254
|
+
async function emit(event, payload, options) {
|
|
255
|
+
await invoke('plugin:event|emit', {
|
|
256
|
+
event,
|
|
257
|
+
windowLabel: options?.target,
|
|
258
|
+
payload
|
|
259
|
+
});
|
|
260
|
+
}
|
|
8
261
|
|
|
9
|
-
var T={};g(T,{CloseRequestedEvent:()=>d,Effect:()=>S,EffectState:()=>C,LogicalPosition:()=>h$1,LogicalSize:()=>r,PhysicalPosition:()=>i,PhysicalSize:()=>u,ProgressBarStatus:()=>_,UserAttentionType:()=>v,Window:()=>c,availableMonitors:()=>x,currentMonitor:()=>D,getAll:()=>b,getCurrent:()=>z,primaryMonitor:()=>L});var v=(n=>(n[n.Critical=1]="Critical",n[n.Informational=2]="Informational",n))(v||{}),d=class{constructor(e){this._preventDefault=!1;this.event=e.event,this.windowLabel=e.windowLabel,this.id=e.id;}preventDefault(){this._preventDefault=!0;}isPreventDefault(){return this._preventDefault}},_=(o=>(o.None="none",o.Normal="normal",o.Indeterminate="indeterminate",o.Paused="paused",o.Error="error",o))(_||{});function z(){return new c(window.__TAURI_INTERNALS__.metadata.currentWindow.label,{skip:!0})}function b(){return window.__TAURI_INTERNALS__.metadata.windows.map(a=>new c(a.label,{skip:!0}))}var P=["tauri://created","tauri://error"],c=class a{constructor(e,n={}){this.label=e,this.listeners=Object.create(null),n?.skip||u$1("plugin:window|create",{options:{...n,label:e}}).then(async()=>this.emit("tauri://created")).catch(async t=>this.emit("tauri://error",t));}static getByLabel(e){return b().some(n=>n.label===e)?new a(e,{skip:!0}):null}static getCurrent(){return z()}static getAll(){return b()}static async getFocusedWindow(){for(let e of b())if(await e.isFocused())return e;return null}async listen(e,n){return this._handleTauriEvent(e,n)?Promise.resolve(()=>{let t=this.listeners[e];t.splice(t.indexOf(n),1);}):c$1(e,n,{target:this.label})}async once(e,n){return this._handleTauriEvent(e,n)?Promise.resolve(()=>{let t=this.listeners[e];t.splice(t.indexOf(n),1);}):W$1(e,n,{target:this.label})}async emit(e,n){if(P.includes(e)){for(let t of this.listeners[e]||[])t({event:e,id:-1,windowLabel:this.label,payload:n});return Promise.resolve()}return D$1(e,n,{target:this.label})}_handleTauriEvent(e,n){return P.includes(e)?(e in this.listeners?this.listeners[e].push(n):this.listeners[e]=[n],!0):!1}async scaleFactor(){return u$1("plugin:window|scale_factor",{label:this.label})}async innerPosition(){return u$1("plugin:window|inner_position",{label:this.label}).then(({x:e,y:n})=>new i(e,n))}async outerPosition(){return u$1("plugin:window|outer_position",{label:this.label}).then(({x:e,y:n})=>new i(e,n))}async innerSize(){return u$1("plugin:window|inner_size",{label:this.label}).then(({width:e,height:n})=>new u(e,n))}async outerSize(){return u$1("plugin:window|outer_size",{label:this.label}).then(({width:e,height:n})=>new u(e,n))}async isFullscreen(){return u$1("plugin:window|is_fullscreen",{label:this.label})}async isMinimized(){return u$1("plugin:window|is_minimized",{label:this.label})}async isMaximized(){return u$1("plugin:window|is_maximized",{label:this.label})}async isFocused(){return u$1("plugin:window|is_focused",{label:this.label})}async isDecorated(){return u$1("plugin:window|is_decorated",{label:this.label})}async isResizable(){return u$1("plugin:window|is_resizable",{label:this.label})}async isMaximizable(){return u$1("plugin:window|is_maximizable",{label:this.label})}async isMinimizable(){return u$1("plugin:window|is_minimizable",{label:this.label})}async isClosable(){return u$1("plugin:window|is_closable",{label:this.label})}async isVisible(){return u$1("plugin:window|is_visible",{label:this.label})}async title(){return u$1("plugin:window|title",{label:this.label})}async theme(){return u$1("plugin:window|theme",{label:this.label})}async center(){return u$1("plugin:window|center",{label:this.label})}async requestUserAttention(e){let n=null;return e&&(e===1?n={type:"Critical"}:n={type:"Informational"}),u$1("plugin:window|request_user_attention",{label:this.label,value:n})}async setResizable(e){return u$1("plugin:window|set_resizable",{label:this.label,value:e})}async setMaximizable(e){return u$1("plugin:window|set_maximizable",{label:this.label,value:e})}async setMinimizable(e){return u$1("plugin:window|set_minimizable",{label:this.label,value:e})}async setClosable(e){return u$1("plugin:window|set_closable",{label:this.label,value:e})}async setTitle(e){return u$1("plugin:window|set_title",{label:this.label,value:e})}async maximize(){return u$1("plugin:window|maximize",{label:this.label})}async unmaximize(){return u$1("plugin:window|unmaximize",{label:this.label})}async toggleMaximize(){return u$1("plugin:window|toggle_maximize",{label:this.label})}async minimize(){return u$1("plugin:window|minimize",{label:this.label})}async unminimize(){return u$1("plugin:window|unminimize",{label:this.label})}async show(){return u$1("plugin:window|show",{label:this.label})}async hide(){return u$1("plugin:window|hide",{label:this.label})}async close(){return u$1("plugin:window|close",{label:this.label})}async setDecorations(e){return u$1("plugin:window|set_decorations",{label:this.label,value:e})}async setShadow(e){return u$1("plugin:window|set_shadow",{label:this.label,value:e})}async setEffects(e){return u$1("plugin:window|set_effects",{label:this.label,value:e})}async clearEffects(){return u$1("plugin:window|set_effects",{label:this.label,value:null})}async setAlwaysOnTop(e){return u$1("plugin:window|set_always_on_top",{label:this.label,value:e})}async setAlwaysOnBottom(e){return u$1("plugin:window|set_always_on_bottom",{label:this.label,value:e})}async setContentProtected(e){return u$1("plugin:window|set_content_protected",{label:this.label,value:e})}async setSize(e){if(!e||e.type!=="Logical"&&e.type!=="Physical")throw new Error("the `size` argument must be either a LogicalSize or a PhysicalSize instance");return u$1("plugin:window|set_size",{label:this.label,value:{type:e.type,data:{width:e.width,height:e.height}}})}async setMinSize(e){if(e&&e.type!=="Logical"&&e.type!=="Physical")throw new Error("the `size` argument must be either a LogicalSize or a PhysicalSize instance");return u$1("plugin:window|set_min_size",{label:this.label,value:e?{type:e.type,data:{width:e.width,height:e.height}}:null})}async setMaxSize(e){if(e&&e.type!=="Logical"&&e.type!=="Physical")throw new Error("the `size` argument must be either a LogicalSize or a PhysicalSize instance");return u$1("plugin:window|set_max_size",{label:this.label,value:e?{type:e.type,data:{width:e.width,height:e.height}}:null})}async setPosition(e){if(!e||e.type!=="Logical"&&e.type!=="Physical")throw new Error("the `position` argument must be either a LogicalPosition or a PhysicalPosition instance");return u$1("plugin:window|set_position",{label:this.label,value:{type:e.type,data:{x:e.x,y:e.y}}})}async setFullscreen(e){return u$1("plugin:window|set_fullscreen",{label:this.label,value:e})}async setFocus(){return u$1("plugin:window|set_focus",{label:this.label})}async setIcon(e){return u$1("plugin:window|set_icon",{label:this.label,value:typeof e=="string"?e:Array.from(e)})}async setSkipTaskbar(e){return u$1("plugin:window|set_skip_taskbar",{label:this.label,value:e})}async setCursorGrab(e){return u$1("plugin:window|set_cursor_grab",{label:this.label,value:e})}async setCursorVisible(e){return u$1("plugin:window|set_cursor_visible",{label:this.label,value:e})}async setCursorIcon(e){return u$1("plugin:window|set_cursor_icon",{label:this.label,value:e})}async setCursorPosition(e){if(!e||e.type!=="Logical"&&e.type!=="Physical")throw new Error("the `position` argument must be either a LogicalPosition or a PhysicalPosition instance");return u$1("plugin:window|set_cursor_position",{label:this.label,value:{type:e.type,data:{x:e.x,y:e.y}}})}async setIgnoreCursorEvents(e){return u$1("plugin:window|set_ignore_cursor_events",{label:this.label,value:e})}async startDragging(){return u$1("plugin:window|start_dragging",{label:this.label})}async setProgressBar(e){return u$1("plugin:window|set_progress_bar",{label:this.label,value:e})}async onResized(e){return this.listen("tauri://resize",n=>{n.payload=W(n.payload),e(n);})}async onMoved(e){return this.listen("tauri://move",n=>{n.payload=F(n.payload),e(n);})}async onCloseRequested(e){return this.listen("tauri://close-requested",n=>{let t=new d(n);Promise.resolve(e(t)).then(()=>{if(!t.isPreventDefault())return this.close()});})}async onFocusChanged(e){let n=await this.listen("tauri://focus",s=>{e({...s,payload:!0});}),t=await this.listen("tauri://blur",s=>{e({...s,payload:!1});});return ()=>{n(),t();}}async onScaleChanged(e){return this.listen("tauri://scale-change",e)}async onMenuClicked(e){return this.listen("tauri://menu",e)}async onFileDropEvent(e){let n=await this.listen("tauri://file-drop",o=>{e({...o,payload:{type:"drop",paths:o.payload}});}),t=await this.listen("tauri://file-drop-hover",o=>{e({...o,payload:{type:"hover",paths:o.payload}});}),s=await this.listen("tauri://file-drop-cancelled",o=>{e({...o,payload:{type:"cancel"}});});return ()=>{n(),t(),s();}}async onThemeChanged(e){return this.listen("tauri://theme-changed",e)}},S=(l=>(l.AppearanceBased="appearanceBased",l.Light="light",l.Dark="dark",l.MediumLight="mediumLight",l.UltraDark="ultraDark",l.Titlebar="titlebar",l.Selection="selection",l.Menu="menu",l.Popover="popover",l.Sidebar="sidebar",l.HeaderView="headerView",l.Sheet="sheet",l.WindowBackground="windowBackground",l.HudWindow="hudWindow",l.FullScreenUI="fullScreenUI",l.Tooltip="tooltip",l.ContentBackground="contentBackground",l.UnderWindowBackground="underWindowBackground",l.UnderPageBackground="underPageBackground",l.Mica="mica",l.Blur="blur",l.Acrylic="acrylic",l.Tabbed="tabbed",l.TabbedDark="tabbedDark",l.TabbedLight="tabbedLight",l))(S||{}),C=(t=>(t.FollowsWindowActiveState="followsWindowActiveState",t.Active="active",t.Inactive="inactive",t))(C||{});function h(a){return a===null?null:{name:a.name,scaleFactor:a.scaleFactor,position:F(a.position),size:W(a.size)}}function F(a){return new i(a.x,a.y)}function W(a){return new u(a.width,a.height)}async function D(){return u$1("plugin:window|current_monitor").then(h)}async function L(){return u$1("plugin:window|primary_monitor").then(h)}async function x(){return u$1("plugin:window|available_monitors").then(a=>a.map(h))}
|
|
262
|
+
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
|
263
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
264
|
+
// SPDX-License-Identifier: MIT
|
|
265
|
+
/**
|
|
266
|
+
* Provides APIs to create windows, communicate with other windows and manipulate the current window.
|
|
267
|
+
*
|
|
268
|
+
* ## Window events
|
|
269
|
+
*
|
|
270
|
+
* Events can be listened to using {@link Window.listen}:
|
|
271
|
+
* ```typescript
|
|
272
|
+
* import { getCurrent } from "@tauri-apps/api/window";
|
|
273
|
+
* getCurrent().listen("my-window-event", ({ event, payload }) => { });
|
|
274
|
+
* ```
|
|
275
|
+
*
|
|
276
|
+
* @module
|
|
277
|
+
*/
|
|
278
|
+
/**
|
|
279
|
+
* Attention type to request on a window.
|
|
280
|
+
*
|
|
281
|
+
* @since 1.0.0
|
|
282
|
+
*/
|
|
283
|
+
var UserAttentionType;
|
|
284
|
+
(function (UserAttentionType) {
|
|
285
|
+
/**
|
|
286
|
+
* #### Platform-specific
|
|
287
|
+
* - **macOS:** Bounces the dock icon until the application is in focus.
|
|
288
|
+
* - **Windows:** Flashes both the window and the taskbar button until the application is in focus.
|
|
289
|
+
*/
|
|
290
|
+
UserAttentionType[UserAttentionType["Critical"] = 1] = "Critical";
|
|
291
|
+
/**
|
|
292
|
+
* #### Platform-specific
|
|
293
|
+
* - **macOS:** Bounces the dock icon once.
|
|
294
|
+
* - **Windows:** Flashes the taskbar button until the application is in focus.
|
|
295
|
+
*/
|
|
296
|
+
UserAttentionType[UserAttentionType["Informational"] = 2] = "Informational";
|
|
297
|
+
})(UserAttentionType || (UserAttentionType = {}));
|
|
298
|
+
class CloseRequestedEvent {
|
|
299
|
+
constructor(event) {
|
|
300
|
+
this._preventDefault = false;
|
|
301
|
+
this.event = event.event;
|
|
302
|
+
this.windowLabel = event.windowLabel;
|
|
303
|
+
this.id = event.id;
|
|
304
|
+
}
|
|
305
|
+
preventDefault() {
|
|
306
|
+
this._preventDefault = true;
|
|
307
|
+
}
|
|
308
|
+
isPreventDefault() {
|
|
309
|
+
return this._preventDefault;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
var ProgressBarStatus;
|
|
313
|
+
(function (ProgressBarStatus) {
|
|
314
|
+
/**
|
|
315
|
+
* Hide progress bar.
|
|
316
|
+
*/
|
|
317
|
+
ProgressBarStatus["None"] = "none";
|
|
318
|
+
/**
|
|
319
|
+
* Normal state.
|
|
320
|
+
*/
|
|
321
|
+
ProgressBarStatus["Normal"] = "normal";
|
|
322
|
+
/**
|
|
323
|
+
* Indeterminate state. **Treated as Normal on Linux and macOS**
|
|
324
|
+
*/
|
|
325
|
+
ProgressBarStatus["Indeterminate"] = "indeterminate";
|
|
326
|
+
/**
|
|
327
|
+
* Paused state. **Treated as Normal on Linux**
|
|
328
|
+
*/
|
|
329
|
+
ProgressBarStatus["Paused"] = "paused";
|
|
330
|
+
/**
|
|
331
|
+
* Error state. **Treated as Normal on linux**
|
|
332
|
+
*/
|
|
333
|
+
ProgressBarStatus["Error"] = "error";
|
|
334
|
+
})(ProgressBarStatus || (ProgressBarStatus = {}));
|
|
335
|
+
/**
|
|
336
|
+
* Get an instance of `Window` for the current window.
|
|
337
|
+
*
|
|
338
|
+
* @since 1.0.0
|
|
339
|
+
*/
|
|
340
|
+
function getCurrent() {
|
|
341
|
+
return new Window(window.__TAURI_INTERNALS__.metadata.currentWindow.label, {
|
|
342
|
+
// @ts-expect-error `skip` is not defined in the public API but it is handled by the constructor
|
|
343
|
+
skip: true
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Gets a list of instances of `Window` for all available windows.
|
|
348
|
+
*
|
|
349
|
+
* @since 1.0.0
|
|
350
|
+
*/
|
|
351
|
+
function getAll() {
|
|
352
|
+
return window.__TAURI_INTERNALS__.metadata.windows.map((w) => new Window(w.label, {
|
|
353
|
+
// @ts-expect-error `skip` is not defined in the public API but it is handled by the constructor
|
|
354
|
+
skip: true
|
|
355
|
+
}));
|
|
356
|
+
}
|
|
357
|
+
/** @ignore */
|
|
358
|
+
// events that are emitted right here instead of by the created webview
|
|
359
|
+
const localTauriEvents = ['tauri://created', 'tauri://error'];
|
|
360
|
+
/**
|
|
361
|
+
* Create new webview window or get a handle to an existing one.
|
|
362
|
+
*
|
|
363
|
+
* Windows are identified by a *label* a unique identifier that can be used to reference it later.
|
|
364
|
+
* It may only contain alphanumeric characters `a-zA-Z` plus the following special characters `-`, `/`, `:` and `_`.
|
|
365
|
+
*
|
|
366
|
+
* @example
|
|
367
|
+
* ```typescript
|
|
368
|
+
* // loading embedded asset:
|
|
369
|
+
* const appWindow = new Window('theUniqueLabel', {
|
|
370
|
+
* url: 'path/to/page.html'
|
|
371
|
+
* });
|
|
372
|
+
* // alternatively, load a remote URL:
|
|
373
|
+
* const appWindow = new Window('theUniqueLabel', {
|
|
374
|
+
* url: 'https://github.com/tauri-apps/tauri'
|
|
375
|
+
* });
|
|
376
|
+
*
|
|
377
|
+
* appWindow.once('tauri://created', function () {
|
|
378
|
+
* // window successfully created
|
|
379
|
+
* });
|
|
380
|
+
* appWindow.once('tauri://error', function (e) {
|
|
381
|
+
* // an error happened creating the window
|
|
382
|
+
* });
|
|
383
|
+
*
|
|
384
|
+
* // emit an event to the backend
|
|
385
|
+
* await appWindow.emit("some event", "data");
|
|
386
|
+
* // listen to an event from the backend
|
|
387
|
+
* const unlisten = await appWindow.listen("event name", e => {});
|
|
388
|
+
* unlisten();
|
|
389
|
+
* ```
|
|
390
|
+
*
|
|
391
|
+
* @since 2.0.0
|
|
392
|
+
*/
|
|
393
|
+
class Window {
|
|
394
|
+
/**
|
|
395
|
+
* Creates a new Window.
|
|
396
|
+
* @example
|
|
397
|
+
* ```typescript
|
|
398
|
+
* import { Window } from '@tauri-apps/api/window';
|
|
399
|
+
* const appWindow = new Window('my-label', {
|
|
400
|
+
* url: 'https://github.com/tauri-apps/tauri'
|
|
401
|
+
* });
|
|
402
|
+
* appWindow.once('tauri://created', function () {
|
|
403
|
+
* // window successfully created
|
|
404
|
+
* });
|
|
405
|
+
* appWindow.once('tauri://error', function (e) {
|
|
406
|
+
* // an error happened creating the window
|
|
407
|
+
* });
|
|
408
|
+
* ```
|
|
409
|
+
*
|
|
410
|
+
* @param label The unique webview window label. Must be alphanumeric: `a-zA-Z-/:_`.
|
|
411
|
+
* @returns The {@link Window} instance to communicate with the webview.
|
|
412
|
+
*/
|
|
413
|
+
constructor(label, options = {}) {
|
|
414
|
+
this.label = label;
|
|
415
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
416
|
+
this.listeners = Object.create(null);
|
|
417
|
+
// @ts-expect-error `skip` is not a public API so it is not defined in WindowOptions
|
|
418
|
+
if (!options?.skip) {
|
|
419
|
+
invoke('plugin:window|create', {
|
|
420
|
+
options: {
|
|
421
|
+
...options,
|
|
422
|
+
label
|
|
423
|
+
}
|
|
424
|
+
})
|
|
425
|
+
.then(async () => this.emit('tauri://created'))
|
|
426
|
+
.catch(async (e) => this.emit('tauri://error', e));
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* Gets the Window for the webview associated with the given label.
|
|
431
|
+
* @example
|
|
432
|
+
* ```typescript
|
|
433
|
+
* import { Window } from '@tauri-apps/api/window';
|
|
434
|
+
* const mainWindow = Window.getByLabel('main');
|
|
435
|
+
* ```
|
|
436
|
+
*
|
|
437
|
+
* @param label The webview window label.
|
|
438
|
+
* @returns The Window instance to communicate with the webview or null if the webview doesn't exist.
|
|
439
|
+
*/
|
|
440
|
+
static getByLabel(label) {
|
|
441
|
+
if (getAll().some((w) => w.label === label)) {
|
|
442
|
+
// @ts-expect-error `skip` is not defined in the public API but it is handled by the constructor
|
|
443
|
+
return new Window(label, { skip: true });
|
|
444
|
+
}
|
|
445
|
+
return null;
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* Get an instance of `Window` for the current window.
|
|
449
|
+
*/
|
|
450
|
+
static getCurrent() {
|
|
451
|
+
return getCurrent();
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Gets a list of instances of `Window` for all available windows.
|
|
455
|
+
*/
|
|
456
|
+
static getAll() {
|
|
457
|
+
return getAll();
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* Gets the focused window.
|
|
461
|
+
* @example
|
|
462
|
+
* ```typescript
|
|
463
|
+
* import { Window } from '@tauri-apps/api/window';
|
|
464
|
+
* const focusedWindow = Window.getFocusedWindow();
|
|
465
|
+
* ```
|
|
466
|
+
*
|
|
467
|
+
* @returns The Window instance to communicate with the webview or `undefined` if there is not any focused window.
|
|
468
|
+
*/
|
|
469
|
+
static async getFocusedWindow() {
|
|
470
|
+
for (const w of getAll()) {
|
|
471
|
+
if (await w.isFocused()) {
|
|
472
|
+
return w;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
return null;
|
|
476
|
+
}
|
|
477
|
+
/**
|
|
478
|
+
* Listen to an event emitted by the backend that is tied to the webview window.
|
|
479
|
+
*
|
|
480
|
+
* @example
|
|
481
|
+
* ```typescript
|
|
482
|
+
* import { getCurrent } from '@tauri-apps/api/window';
|
|
483
|
+
* const unlisten = await getCurrent().listen<string>('state-changed', (event) => {
|
|
484
|
+
* console.log(`Got error: ${payload}`);
|
|
485
|
+
* });
|
|
486
|
+
*
|
|
487
|
+
* // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
|
|
488
|
+
* unlisten();
|
|
489
|
+
* ```
|
|
490
|
+
*
|
|
491
|
+
* @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`.
|
|
492
|
+
* @param handler Event handler.
|
|
493
|
+
* @returns A promise resolving to a function to unlisten to the event.
|
|
494
|
+
* Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
|
|
495
|
+
*/
|
|
496
|
+
async listen(event, handler) {
|
|
497
|
+
if (this._handleTauriEvent(event, handler)) {
|
|
498
|
+
return Promise.resolve(() => {
|
|
499
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, security/detect-object-injection
|
|
500
|
+
const listeners = this.listeners[event];
|
|
501
|
+
listeners.splice(listeners.indexOf(handler), 1);
|
|
502
|
+
});
|
|
503
|
+
}
|
|
504
|
+
return listen(event, handler, { target: this.label });
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* Listen to an one-off event emitted by the backend that is tied to the webview window.
|
|
508
|
+
*
|
|
509
|
+
* @example
|
|
510
|
+
* ```typescript
|
|
511
|
+
* import { getCurrent } from '@tauri-apps/api/window';
|
|
512
|
+
* const unlisten = await getCurrent().once<null>('initialized', (event) => {
|
|
513
|
+
* console.log(`Window initialized!`);
|
|
514
|
+
* });
|
|
515
|
+
*
|
|
516
|
+
* // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
|
|
517
|
+
* unlisten();
|
|
518
|
+
* ```
|
|
519
|
+
*
|
|
520
|
+
* @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`.
|
|
521
|
+
* @param handler Event handler.
|
|
522
|
+
* @returns A promise resolving to a function to unlisten to the event.
|
|
523
|
+
* Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
|
|
524
|
+
*/
|
|
525
|
+
async once(event, handler) {
|
|
526
|
+
if (this._handleTauriEvent(event, handler)) {
|
|
527
|
+
return Promise.resolve(() => {
|
|
528
|
+
// eslint-disable-next-line security/detect-object-injection
|
|
529
|
+
const listeners = this.listeners[event];
|
|
530
|
+
listeners.splice(listeners.indexOf(handler), 1);
|
|
531
|
+
});
|
|
532
|
+
}
|
|
533
|
+
return once(event, handler, { target: this.label });
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
536
|
+
* Emits an event to the backend, tied to the webview window.
|
|
537
|
+
* @example
|
|
538
|
+
* ```typescript
|
|
539
|
+
* import { getCurrent } from '@tauri-apps/api/window';
|
|
540
|
+
* await getCurrent().emit('window-loaded', { loggedIn: true, token: 'authToken' });
|
|
541
|
+
* ```
|
|
542
|
+
*
|
|
543
|
+
* @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`.
|
|
544
|
+
* @param payload Event payload.
|
|
545
|
+
*/
|
|
546
|
+
async emit(event, payload) {
|
|
547
|
+
if (localTauriEvents.includes(event)) {
|
|
548
|
+
// eslint-disable-next-line
|
|
549
|
+
for (const handler of this.listeners[event] || []) {
|
|
550
|
+
handler({ event, id: -1, windowLabel: this.label, payload });
|
|
551
|
+
}
|
|
552
|
+
return Promise.resolve();
|
|
553
|
+
}
|
|
554
|
+
return emit(event, payload, { target: this.label });
|
|
555
|
+
}
|
|
556
|
+
/** @ignore */
|
|
557
|
+
_handleTauriEvent(event, handler) {
|
|
558
|
+
if (localTauriEvents.includes(event)) {
|
|
559
|
+
if (!(event in this.listeners)) {
|
|
560
|
+
// eslint-disable-next-line
|
|
561
|
+
this.listeners[event] = [handler];
|
|
562
|
+
}
|
|
563
|
+
else {
|
|
564
|
+
// eslint-disable-next-line
|
|
565
|
+
this.listeners[event].push(handler);
|
|
566
|
+
}
|
|
567
|
+
return true;
|
|
568
|
+
}
|
|
569
|
+
return false;
|
|
570
|
+
}
|
|
571
|
+
// Getters
|
|
572
|
+
/**
|
|
573
|
+
* The scale factor that can be used to map physical pixels to logical pixels.
|
|
574
|
+
* @example
|
|
575
|
+
* ```typescript
|
|
576
|
+
* import { getCurrent } from '@tauri-apps/api/window';
|
|
577
|
+
* const factor = await getCurrent().scaleFactor();
|
|
578
|
+
* ```
|
|
579
|
+
*
|
|
580
|
+
* @returns The window's monitor scale factor.
|
|
581
|
+
*/
|
|
582
|
+
async scaleFactor() {
|
|
583
|
+
return invoke('plugin:window|scale_factor', {
|
|
584
|
+
label: this.label
|
|
585
|
+
});
|
|
586
|
+
}
|
|
587
|
+
/**
|
|
588
|
+
* The position of the top-left hand corner of the window's client area relative to the top-left hand corner of the desktop.
|
|
589
|
+
* @example
|
|
590
|
+
* ```typescript
|
|
591
|
+
* import { getCurrent } from '@tauri-apps/api/window';
|
|
592
|
+
* const position = await getCurrent().innerPosition();
|
|
593
|
+
* ```
|
|
594
|
+
*
|
|
595
|
+
* @returns The window's inner position.
|
|
596
|
+
*/
|
|
597
|
+
async innerPosition() {
|
|
598
|
+
return invoke('plugin:window|inner_position', {
|
|
599
|
+
label: this.label
|
|
600
|
+
}).then(({ x, y }) => new PhysicalPosition(x, y));
|
|
601
|
+
}
|
|
602
|
+
/**
|
|
603
|
+
* The position of the top-left hand corner of the window relative to the top-left hand corner of the desktop.
|
|
604
|
+
* @example
|
|
605
|
+
* ```typescript
|
|
606
|
+
* import { getCurrent } from '@tauri-apps/api/window';
|
|
607
|
+
* const position = await getCurrent().outerPosition();
|
|
608
|
+
* ```
|
|
609
|
+
*
|
|
610
|
+
* @returns The window's outer position.
|
|
611
|
+
*/
|
|
612
|
+
async outerPosition() {
|
|
613
|
+
return invoke('plugin:window|outer_position', {
|
|
614
|
+
label: this.label
|
|
615
|
+
}).then(({ x, y }) => new PhysicalPosition(x, y));
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
618
|
+
* The physical size of the window's client area.
|
|
619
|
+
* The client area is the content of the window, excluding the title bar and borders.
|
|
620
|
+
* @example
|
|
621
|
+
* ```typescript
|
|
622
|
+
* import { getCurrent } from '@tauri-apps/api/window';
|
|
623
|
+
* const size = await getCurrent().innerSize();
|
|
624
|
+
* ```
|
|
625
|
+
*
|
|
626
|
+
* @returns The window's inner size.
|
|
627
|
+
*/
|
|
628
|
+
async innerSize() {
|
|
629
|
+
return invoke('plugin:window|inner_size', {
|
|
630
|
+
label: this.label
|
|
631
|
+
}).then(({ width, height }) => new PhysicalSize(width, height));
|
|
632
|
+
}
|
|
633
|
+
/**
|
|
634
|
+
* The physical size of the entire window.
|
|
635
|
+
* These dimensions include the title bar and borders. If you don't want that (and you usually don't), use inner_size instead.
|
|
636
|
+
* @example
|
|
637
|
+
* ```typescript
|
|
638
|
+
* import { getCurrent } from '@tauri-apps/api/window';
|
|
639
|
+
* const size = await getCurrent().outerSize();
|
|
640
|
+
* ```
|
|
641
|
+
*
|
|
642
|
+
* @returns The window's outer size.
|
|
643
|
+
*/
|
|
644
|
+
async outerSize() {
|
|
645
|
+
return invoke('plugin:window|outer_size', {
|
|
646
|
+
label: this.label
|
|
647
|
+
}).then(({ width, height }) => new PhysicalSize(width, height));
|
|
648
|
+
}
|
|
649
|
+
/**
|
|
650
|
+
* Gets the window's current fullscreen state.
|
|
651
|
+
* @example
|
|
652
|
+
* ```typescript
|
|
653
|
+
* import { getCurrent } from '@tauri-apps/api/window';
|
|
654
|
+
* const fullscreen = await getCurrent().isFullscreen();
|
|
655
|
+
* ```
|
|
656
|
+
*
|
|
657
|
+
* @returns Whether the window is in fullscreen mode or not.
|
|
658
|
+
*/
|
|
659
|
+
async isFullscreen() {
|
|
660
|
+
return invoke('plugin:window|is_fullscreen', {
|
|
661
|
+
label: this.label
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
/**
|
|
665
|
+
* Gets the window's current minimized state.
|
|
666
|
+
* @example
|
|
667
|
+
* ```typescript
|
|
668
|
+
* import { getCurrent } from '@tauri-apps/api/window';
|
|
669
|
+
* const minimized = await getCurrent().isMinimized();
|
|
670
|
+
* ```
|
|
671
|
+
*/
|
|
672
|
+
async isMinimized() {
|
|
673
|
+
return invoke('plugin:window|is_minimized', {
|
|
674
|
+
label: this.label
|
|
675
|
+
});
|
|
676
|
+
}
|
|
677
|
+
/**
|
|
678
|
+
* Gets the window's current maximized state.
|
|
679
|
+
* @example
|
|
680
|
+
* ```typescript
|
|
681
|
+
* import { getCurrent } from '@tauri-apps/api/window';
|
|
682
|
+
* const maximized = await getCurrent().isMaximized();
|
|
683
|
+
* ```
|
|
684
|
+
*
|
|
685
|
+
* @returns Whether the window is maximized or not.
|
|
686
|
+
*/
|
|
687
|
+
async isMaximized() {
|
|
688
|
+
return invoke('plugin:window|is_maximized', {
|
|
689
|
+
label: this.label
|
|
690
|
+
});
|
|
691
|
+
}
|
|
692
|
+
/**
|
|
693
|
+
* Gets the window's current focus state.
|
|
694
|
+
* @example
|
|
695
|
+
* ```typescript
|
|
696
|
+
* import { getCurrent } from '@tauri-apps/api/window';
|
|
697
|
+
* const focused = await getCurrent().isFocused();
|
|
698
|
+
* ```
|
|
699
|
+
*
|
|
700
|
+
* @returns Whether the window is focused or not.
|
|
701
|
+
*/
|
|
702
|
+
async isFocused() {
|
|
703
|
+
return invoke('plugin:window|is_focused', {
|
|
704
|
+
label: this.label
|
|
705
|
+
});
|
|
706
|
+
}
|
|
707
|
+
/**
|
|
708
|
+
* Gets the window's current decorated state.
|
|
709
|
+
* @example
|
|
710
|
+
* ```typescript
|
|
711
|
+
* import { getCurrent } from '@tauri-apps/api/window';
|
|
712
|
+
* const decorated = await getCurrent().isDecorated();
|
|
713
|
+
* ```
|
|
714
|
+
*
|
|
715
|
+
* @returns Whether the window is decorated or not.
|
|
716
|
+
*/
|
|
717
|
+
async isDecorated() {
|
|
718
|
+
return invoke('plugin:window|is_decorated', {
|
|
719
|
+
label: this.label
|
|
720
|
+
});
|
|
721
|
+
}
|
|
722
|
+
/**
|
|
723
|
+
* Gets the window's current resizable state.
|
|
724
|
+
* @example
|
|
725
|
+
* ```typescript
|
|
726
|
+
* import { getCurrent } from '@tauri-apps/api/window';
|
|
727
|
+
* const resizable = await getCurrent().isResizable();
|
|
728
|
+
* ```
|
|
729
|
+
*
|
|
730
|
+
* @returns Whether the window is resizable or not.
|
|
731
|
+
*/
|
|
732
|
+
async isResizable() {
|
|
733
|
+
return invoke('plugin:window|is_resizable', {
|
|
734
|
+
label: this.label
|
|
735
|
+
});
|
|
736
|
+
}
|
|
737
|
+
/**
|
|
738
|
+
* Gets the window’s native maximize button state.
|
|
739
|
+
*
|
|
740
|
+
* #### Platform-specific
|
|
741
|
+
*
|
|
742
|
+
* - **Linux / iOS / Android:** Unsupported.
|
|
743
|
+
*
|
|
744
|
+
* @example
|
|
745
|
+
* ```typescript
|
|
746
|
+
* import { getCurrent } from '@tauri-apps/api/window';
|
|
747
|
+
* const maximizable = await getCurrent().isMaximizable();
|
|
748
|
+
* ```
|
|
749
|
+
*
|
|
750
|
+
* @returns Whether the window's native maximize button is enabled or not.
|
|
751
|
+
*/
|
|
752
|
+
async isMaximizable() {
|
|
753
|
+
return invoke('plugin:window|is_maximizable', {
|
|
754
|
+
label: this.label
|
|
755
|
+
});
|
|
756
|
+
}
|
|
757
|
+
/**
|
|
758
|
+
* Gets the window’s native minimize button state.
|
|
759
|
+
*
|
|
760
|
+
* #### Platform-specific
|
|
761
|
+
*
|
|
762
|
+
* - **Linux / iOS / Android:** Unsupported.
|
|
763
|
+
*
|
|
764
|
+
* @example
|
|
765
|
+
* ```typescript
|
|
766
|
+
* import { getCurrent } from '@tauri-apps/api/window';
|
|
767
|
+
* const minimizable = await getCurrent().isMinimizable();
|
|
768
|
+
* ```
|
|
769
|
+
*
|
|
770
|
+
* @returns Whether the window's native minimize button is enabled or not.
|
|
771
|
+
*/
|
|
772
|
+
async isMinimizable() {
|
|
773
|
+
return invoke('plugin:window|is_minimizable', {
|
|
774
|
+
label: this.label
|
|
775
|
+
});
|
|
776
|
+
}
|
|
777
|
+
/**
|
|
778
|
+
* Gets the window’s native close button state.
|
|
779
|
+
*
|
|
780
|
+
* #### Platform-specific
|
|
781
|
+
*
|
|
782
|
+
* - **iOS / Android:** Unsupported.
|
|
783
|
+
*
|
|
784
|
+
* @example
|
|
785
|
+
* ```typescript
|
|
786
|
+
* import { getCurrent } from '@tauri-apps/api/window';
|
|
787
|
+
* const closable = await getCurrent().isClosable();
|
|
788
|
+
* ```
|
|
789
|
+
*
|
|
790
|
+
* @returns Whether the window's native close button is enabled or not.
|
|
791
|
+
*/
|
|
792
|
+
async isClosable() {
|
|
793
|
+
return invoke('plugin:window|is_closable', {
|
|
794
|
+
label: this.label
|
|
795
|
+
});
|
|
796
|
+
}
|
|
797
|
+
/**
|
|
798
|
+
* Gets the window's current visible state.
|
|
799
|
+
* @example
|
|
800
|
+
* ```typescript
|
|
801
|
+
* import { getCurrent } from '@tauri-apps/api/window';
|
|
802
|
+
* const visible = await getCurrent().isVisible();
|
|
803
|
+
* ```
|
|
804
|
+
*
|
|
805
|
+
* @returns Whether the window is visible or not.
|
|
806
|
+
*/
|
|
807
|
+
async isVisible() {
|
|
808
|
+
return invoke('plugin:window|is_visible', {
|
|
809
|
+
label: this.label
|
|
810
|
+
});
|
|
811
|
+
}
|
|
812
|
+
/**
|
|
813
|
+
* Gets the window's current title.
|
|
814
|
+
* @example
|
|
815
|
+
* ```typescript
|
|
816
|
+
* import { getCurrent } from '@tauri-apps/api/window';
|
|
817
|
+
* const title = await getCurrent().title();
|
|
818
|
+
* ```
|
|
819
|
+
*/
|
|
820
|
+
async title() {
|
|
821
|
+
return invoke('plugin:window|title', {
|
|
822
|
+
label: this.label
|
|
823
|
+
});
|
|
824
|
+
}
|
|
825
|
+
/**
|
|
826
|
+
* Gets the window's current theme.
|
|
827
|
+
*
|
|
828
|
+
* #### Platform-specific
|
|
829
|
+
*
|
|
830
|
+
* - **macOS:** Theme was introduced on macOS 10.14. Returns `light` on macOS 10.13 and below.
|
|
831
|
+
*
|
|
832
|
+
* @example
|
|
833
|
+
* ```typescript
|
|
834
|
+
* import { getCurrent } from '@tauri-apps/api/window';
|
|
835
|
+
* const theme = await getCurrent().theme();
|
|
836
|
+
* ```
|
|
837
|
+
*
|
|
838
|
+
* @returns The window theme.
|
|
839
|
+
*/
|
|
840
|
+
async theme() {
|
|
841
|
+
return invoke('plugin:window|theme', {
|
|
842
|
+
label: this.label
|
|
843
|
+
});
|
|
844
|
+
}
|
|
845
|
+
// Setters
|
|
846
|
+
/**
|
|
847
|
+
* Centers the window.
|
|
848
|
+
* @example
|
|
849
|
+
* ```typescript
|
|
850
|
+
* import { getCurrent } from '@tauri-apps/api/window';
|
|
851
|
+
* await getCurrent().center();
|
|
852
|
+
* ```
|
|
853
|
+
*
|
|
854
|
+
* @returns A promise indicating the success or failure of the operation.
|
|
855
|
+
*/
|
|
856
|
+
async center() {
|
|
857
|
+
return invoke('plugin:window|center', {
|
|
858
|
+
label: this.label
|
|
859
|
+
});
|
|
860
|
+
}
|
|
861
|
+
/**
|
|
862
|
+
* Requests user attention to the window, this has no effect if the application
|
|
863
|
+
* is already focused. How requesting for user attention manifests is platform dependent,
|
|
864
|
+
* see `UserAttentionType` for details.
|
|
865
|
+
*
|
|
866
|
+
* Providing `null` will unset the request for user attention. Unsetting the request for
|
|
867
|
+
* user attention might not be done automatically by the WM when the window receives input.
|
|
868
|
+
*
|
|
869
|
+
* #### Platform-specific
|
|
870
|
+
*
|
|
871
|
+
* - **macOS:** `null` has no effect.
|
|
872
|
+
* - **Linux:** Urgency levels have the same effect.
|
|
873
|
+
* @example
|
|
874
|
+
* ```typescript
|
|
875
|
+
* import { getCurrent } from '@tauri-apps/api/window';
|
|
876
|
+
* await getCurrent().requestUserAttention();
|
|
877
|
+
* ```
|
|
878
|
+
*
|
|
879
|
+
* @returns A promise indicating the success or failure of the operation.
|
|
880
|
+
*/
|
|
881
|
+
async requestUserAttention(requestType) {
|
|
882
|
+
let requestType_ = null;
|
|
883
|
+
if (requestType) {
|
|
884
|
+
if (requestType === UserAttentionType.Critical) {
|
|
885
|
+
requestType_ = { type: 'Critical' };
|
|
886
|
+
}
|
|
887
|
+
else {
|
|
888
|
+
requestType_ = { type: 'Informational' };
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
return invoke('plugin:window|request_user_attention', {
|
|
892
|
+
label: this.label,
|
|
893
|
+
value: requestType_
|
|
894
|
+
});
|
|
895
|
+
}
|
|
896
|
+
/**
|
|
897
|
+
* Updates the window resizable flag.
|
|
898
|
+
* @example
|
|
899
|
+
* ```typescript
|
|
900
|
+
* import { getCurrent } from '@tauri-apps/api/window';
|
|
901
|
+
* await getCurrent().setResizable(false);
|
|
902
|
+
* ```
|
|
903
|
+
*
|
|
904
|
+
* @returns A promise indicating the success or failure of the operation.
|
|
905
|
+
*/
|
|
906
|
+
async setResizable(resizable) {
|
|
907
|
+
return invoke('plugin:window|set_resizable', {
|
|
908
|
+
label: this.label,
|
|
909
|
+
value: resizable
|
|
910
|
+
});
|
|
911
|
+
}
|
|
912
|
+
/**
|
|
913
|
+
* Sets whether the window's native maximize button is enabled or not.
|
|
914
|
+
* If resizable is set to false, this setting is ignored.
|
|
915
|
+
*
|
|
916
|
+
* #### Platform-specific
|
|
917
|
+
*
|
|
918
|
+
* - **macOS:** Disables the "zoom" button in the window titlebar, which is also used to enter fullscreen mode.
|
|
919
|
+
* - **Linux / iOS / Android:** Unsupported.
|
|
920
|
+
*
|
|
921
|
+
* @example
|
|
922
|
+
* ```typescript
|
|
923
|
+
* import { getCurrent } from '@tauri-apps/api/window';
|
|
924
|
+
* await getCurrent().setMaximizable(false);
|
|
925
|
+
* ```
|
|
926
|
+
*
|
|
927
|
+
* @returns A promise indicating the success or failure of the operation.
|
|
928
|
+
*/
|
|
929
|
+
async setMaximizable(maximizable) {
|
|
930
|
+
return invoke('plugin:window|set_maximizable', {
|
|
931
|
+
label: this.label,
|
|
932
|
+
value: maximizable
|
|
933
|
+
});
|
|
934
|
+
}
|
|
935
|
+
/**
|
|
936
|
+
* Sets whether the window's native minimize button is enabled or not.
|
|
937
|
+
*
|
|
938
|
+
* #### Platform-specific
|
|
939
|
+
*
|
|
940
|
+
* - **Linux / iOS / Android:** Unsupported.
|
|
941
|
+
*
|
|
942
|
+
* @example
|
|
943
|
+
* ```typescript
|
|
944
|
+
* import { getCurrent } from '@tauri-apps/api/window';
|
|
945
|
+
* await getCurrent().setMinimizable(false);
|
|
946
|
+
* ```
|
|
947
|
+
*
|
|
948
|
+
* @returns A promise indicating the success or failure of the operation.
|
|
949
|
+
*/
|
|
950
|
+
async setMinimizable(minimizable) {
|
|
951
|
+
return invoke('plugin:window|set_minimizable', {
|
|
952
|
+
label: this.label,
|
|
953
|
+
value: minimizable
|
|
954
|
+
});
|
|
955
|
+
}
|
|
956
|
+
/**
|
|
957
|
+
* Sets whether the window's native close button is enabled or not.
|
|
958
|
+
*
|
|
959
|
+
* #### Platform-specific
|
|
960
|
+
*
|
|
961
|
+
* - **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
|
|
962
|
+
* - **iOS / Android:** Unsupported.
|
|
963
|
+
*
|
|
964
|
+
* @example
|
|
965
|
+
* ```typescript
|
|
966
|
+
* import { getCurrent } from '@tauri-apps/api/window';
|
|
967
|
+
* await getCurrent().setClosable(false);
|
|
968
|
+
* ```
|
|
969
|
+
*
|
|
970
|
+
* @returns A promise indicating the success or failure of the operation.
|
|
971
|
+
*/
|
|
972
|
+
async setClosable(closable) {
|
|
973
|
+
return invoke('plugin:window|set_closable', {
|
|
974
|
+
label: this.label,
|
|
975
|
+
value: closable
|
|
976
|
+
});
|
|
977
|
+
}
|
|
978
|
+
/**
|
|
979
|
+
* Sets the window title.
|
|
980
|
+
* @example
|
|
981
|
+
* ```typescript
|
|
982
|
+
* import { getCurrent } from '@tauri-apps/api/window';
|
|
983
|
+
* await getCurrent().setTitle('Tauri');
|
|
984
|
+
* ```
|
|
985
|
+
*
|
|
986
|
+
* @param title The new title
|
|
987
|
+
* @returns A promise indicating the success or failure of the operation.
|
|
988
|
+
*/
|
|
989
|
+
async setTitle(title) {
|
|
990
|
+
return invoke('plugin:window|set_title', {
|
|
991
|
+
label: this.label,
|
|
992
|
+
value: title
|
|
993
|
+
});
|
|
994
|
+
}
|
|
995
|
+
/**
|
|
996
|
+
* Maximizes the window.
|
|
997
|
+
* @example
|
|
998
|
+
* ```typescript
|
|
999
|
+
* import { getCurrent } from '@tauri-apps/api/window';
|
|
1000
|
+
* await getCurrent().maximize();
|
|
1001
|
+
* ```
|
|
1002
|
+
*
|
|
1003
|
+
* @returns A promise indicating the success or failure of the operation.
|
|
1004
|
+
*/
|
|
1005
|
+
async maximize() {
|
|
1006
|
+
return invoke('plugin:window|maximize', {
|
|
1007
|
+
label: this.label
|
|
1008
|
+
});
|
|
1009
|
+
}
|
|
1010
|
+
/**
|
|
1011
|
+
* Unmaximizes the window.
|
|
1012
|
+
* @example
|
|
1013
|
+
* ```typescript
|
|
1014
|
+
* import { getCurrent } from '@tauri-apps/api/window';
|
|
1015
|
+
* await getCurrent().unmaximize();
|
|
1016
|
+
* ```
|
|
1017
|
+
*
|
|
1018
|
+
* @returns A promise indicating the success or failure of the operation.
|
|
1019
|
+
*/
|
|
1020
|
+
async unmaximize() {
|
|
1021
|
+
return invoke('plugin:window|unmaximize', {
|
|
1022
|
+
label: this.label
|
|
1023
|
+
});
|
|
1024
|
+
}
|
|
1025
|
+
/**
|
|
1026
|
+
* Toggles the window maximized state.
|
|
1027
|
+
* @example
|
|
1028
|
+
* ```typescript
|
|
1029
|
+
* import { getCurrent } from '@tauri-apps/api/window';
|
|
1030
|
+
* await getCurrent().toggleMaximize();
|
|
1031
|
+
* ```
|
|
1032
|
+
*
|
|
1033
|
+
* @returns A promise indicating the success or failure of the operation.
|
|
1034
|
+
*/
|
|
1035
|
+
async toggleMaximize() {
|
|
1036
|
+
return invoke('plugin:window|toggle_maximize', {
|
|
1037
|
+
label: this.label
|
|
1038
|
+
});
|
|
1039
|
+
}
|
|
1040
|
+
/**
|
|
1041
|
+
* Minimizes the window.
|
|
1042
|
+
* @example
|
|
1043
|
+
* ```typescript
|
|
1044
|
+
* import { getCurrent } from '@tauri-apps/api/window';
|
|
1045
|
+
* await getCurrent().minimize();
|
|
1046
|
+
* ```
|
|
1047
|
+
*
|
|
1048
|
+
* @returns A promise indicating the success or failure of the operation.
|
|
1049
|
+
*/
|
|
1050
|
+
async minimize() {
|
|
1051
|
+
return invoke('plugin:window|minimize', {
|
|
1052
|
+
label: this.label
|
|
1053
|
+
});
|
|
1054
|
+
}
|
|
1055
|
+
/**
|
|
1056
|
+
* Unminimizes the window.
|
|
1057
|
+
* @example
|
|
1058
|
+
* ```typescript
|
|
1059
|
+
* import { getCurrent } from '@tauri-apps/api/window';
|
|
1060
|
+
* await getCurrent().unminimize();
|
|
1061
|
+
* ```
|
|
1062
|
+
*
|
|
1063
|
+
* @returns A promise indicating the success or failure of the operation.
|
|
1064
|
+
*/
|
|
1065
|
+
async unminimize() {
|
|
1066
|
+
return invoke('plugin:window|unminimize', {
|
|
1067
|
+
label: this.label
|
|
1068
|
+
});
|
|
1069
|
+
}
|
|
1070
|
+
/**
|
|
1071
|
+
* Sets the window visibility to true.
|
|
1072
|
+
* @example
|
|
1073
|
+
* ```typescript
|
|
1074
|
+
* import { getCurrent } from '@tauri-apps/api/window';
|
|
1075
|
+
* await getCurrent().show();
|
|
1076
|
+
* ```
|
|
1077
|
+
*
|
|
1078
|
+
* @returns A promise indicating the success or failure of the operation.
|
|
1079
|
+
*/
|
|
1080
|
+
async show() {
|
|
1081
|
+
return invoke('plugin:window|show', {
|
|
1082
|
+
label: this.label
|
|
1083
|
+
});
|
|
1084
|
+
}
|
|
1085
|
+
/**
|
|
1086
|
+
* Sets the window visibility to false.
|
|
1087
|
+
* @example
|
|
1088
|
+
* ```typescript
|
|
1089
|
+
* import { getCurrent } from '@tauri-apps/api/window';
|
|
1090
|
+
* await getCurrent().hide();
|
|
1091
|
+
* ```
|
|
1092
|
+
*
|
|
1093
|
+
* @returns A promise indicating the success or failure of the operation.
|
|
1094
|
+
*/
|
|
1095
|
+
async hide() {
|
|
1096
|
+
return invoke('plugin:window|hide', {
|
|
1097
|
+
label: this.label
|
|
1098
|
+
});
|
|
1099
|
+
}
|
|
1100
|
+
/**
|
|
1101
|
+
* Closes the window.
|
|
1102
|
+
* @example
|
|
1103
|
+
* ```typescript
|
|
1104
|
+
* import { getCurrent } from '@tauri-apps/api/window';
|
|
1105
|
+
* await getCurrent().close();
|
|
1106
|
+
* ```
|
|
1107
|
+
*
|
|
1108
|
+
* @returns A promise indicating the success or failure of the operation.
|
|
1109
|
+
*/
|
|
1110
|
+
async close() {
|
|
1111
|
+
return invoke('plugin:window|close', {
|
|
1112
|
+
label: this.label
|
|
1113
|
+
});
|
|
1114
|
+
}
|
|
1115
|
+
/**
|
|
1116
|
+
* Whether the window should have borders and bars.
|
|
1117
|
+
* @example
|
|
1118
|
+
* ```typescript
|
|
1119
|
+
* import { getCurrent } from '@tauri-apps/api/window';
|
|
1120
|
+
* await getCurrent().setDecorations(false);
|
|
1121
|
+
* ```
|
|
1122
|
+
*
|
|
1123
|
+
* @param decorations Whether the window should have borders and bars.
|
|
1124
|
+
* @returns A promise indicating the success or failure of the operation.
|
|
1125
|
+
*/
|
|
1126
|
+
async setDecorations(decorations) {
|
|
1127
|
+
return invoke('plugin:window|set_decorations', {
|
|
1128
|
+
label: this.label,
|
|
1129
|
+
value: decorations
|
|
1130
|
+
});
|
|
1131
|
+
}
|
|
1132
|
+
/**
|
|
1133
|
+
* Whether or not the window should have shadow.
|
|
1134
|
+
*
|
|
1135
|
+
* #### Platform-specific
|
|
1136
|
+
*
|
|
1137
|
+
* - **Windows:**
|
|
1138
|
+
* - `false` has no effect on decorated window, shadows are always ON.
|
|
1139
|
+
* - `true` will make ndecorated window have a 1px white border,
|
|
1140
|
+
* and on Windows 11, it will have a rounded corners.
|
|
1141
|
+
* - **Linux:** Unsupported.
|
|
1142
|
+
*
|
|
1143
|
+
* @example
|
|
1144
|
+
* ```typescript
|
|
1145
|
+
* import { getCurrent } from '@tauri-apps/api/window';
|
|
1146
|
+
* await getCurrent().setShadow(false);
|
|
1147
|
+
* ```
|
|
1148
|
+
*
|
|
1149
|
+
* @returns A promise indicating the success or failure of the operation.
|
|
1150
|
+
*/
|
|
1151
|
+
async setShadow(enable) {
|
|
1152
|
+
return invoke('plugin:window|set_shadow', {
|
|
1153
|
+
label: this.label,
|
|
1154
|
+
value: enable
|
|
1155
|
+
});
|
|
1156
|
+
}
|
|
1157
|
+
/**
|
|
1158
|
+
* Set window effects.
|
|
1159
|
+
*/
|
|
1160
|
+
async setEffects(effects) {
|
|
1161
|
+
return invoke('plugin:window|set_effects', {
|
|
1162
|
+
label: this.label,
|
|
1163
|
+
value: effects
|
|
1164
|
+
});
|
|
1165
|
+
}
|
|
1166
|
+
/**
|
|
1167
|
+
* Clear any applied effects if possible.
|
|
1168
|
+
*/
|
|
1169
|
+
async clearEffects() {
|
|
1170
|
+
return invoke('plugin:window|set_effects', {
|
|
1171
|
+
label: this.label,
|
|
1172
|
+
value: null
|
|
1173
|
+
});
|
|
1174
|
+
}
|
|
1175
|
+
/**
|
|
1176
|
+
* Whether the window should always be on top of other windows.
|
|
1177
|
+
* @example
|
|
1178
|
+
* ```typescript
|
|
1179
|
+
* import { getCurrent } from '@tauri-apps/api/window';
|
|
1180
|
+
* await getCurrent().setAlwaysOnTop(true);
|
|
1181
|
+
* ```
|
|
1182
|
+
*
|
|
1183
|
+
* @param alwaysOnTop Whether the window should always be on top of other windows or not.
|
|
1184
|
+
* @returns A promise indicating the success or failure of the operation.
|
|
1185
|
+
*/
|
|
1186
|
+
async setAlwaysOnTop(alwaysOnTop) {
|
|
1187
|
+
return invoke('plugin:window|set_always_on_top', {
|
|
1188
|
+
label: this.label,
|
|
1189
|
+
value: alwaysOnTop
|
|
1190
|
+
});
|
|
1191
|
+
}
|
|
1192
|
+
/**
|
|
1193
|
+
* Whether the window should always be below other windows.
|
|
1194
|
+
* @example
|
|
1195
|
+
* ```typescript
|
|
1196
|
+
* import { getCurrent } from '@tauri-apps/api/window';
|
|
1197
|
+
* await getCurrent().setAlwaysOnBottom(true);
|
|
1198
|
+
* ```
|
|
1199
|
+
*
|
|
1200
|
+
* @param alwaysOnBottom Whether the window should always be below other windows or not.
|
|
1201
|
+
* @returns A promise indicating the success or failure of the operation.
|
|
1202
|
+
*/
|
|
1203
|
+
async setAlwaysOnBottom(alwaysOnBottom) {
|
|
1204
|
+
return invoke('plugin:window|set_always_on_bottom', {
|
|
1205
|
+
label: this.label,
|
|
1206
|
+
value: alwaysOnBottom
|
|
1207
|
+
});
|
|
1208
|
+
}
|
|
1209
|
+
/**
|
|
1210
|
+
* Prevents the window contents from being captured by other apps.
|
|
1211
|
+
* @example
|
|
1212
|
+
* ```typescript
|
|
1213
|
+
* import { getCurrent } from '@tauri-apps/api/window';
|
|
1214
|
+
* await getCurrent().setContentProtected(true);
|
|
1215
|
+
* ```
|
|
1216
|
+
*
|
|
1217
|
+
* @returns A promise indicating the success or failure of the operation.
|
|
1218
|
+
*/
|
|
1219
|
+
async setContentProtected(protected_) {
|
|
1220
|
+
return invoke('plugin:window|set_content_protected', {
|
|
1221
|
+
label: this.label,
|
|
1222
|
+
value: protected_
|
|
1223
|
+
});
|
|
1224
|
+
}
|
|
1225
|
+
/**
|
|
1226
|
+
* Resizes the window with a new inner size.
|
|
1227
|
+
* @example
|
|
1228
|
+
* ```typescript
|
|
1229
|
+
* import { getCurrent, LogicalSize } from '@tauri-apps/api/window';
|
|
1230
|
+
* await getCurrent().setSize(new LogicalSize(600, 500));
|
|
1231
|
+
* ```
|
|
1232
|
+
*
|
|
1233
|
+
* @param size The logical or physical inner size.
|
|
1234
|
+
* @returns A promise indicating the success or failure of the operation.
|
|
1235
|
+
*/
|
|
1236
|
+
async setSize(size) {
|
|
1237
|
+
if (!size || (size.type !== 'Logical' && size.type !== 'Physical')) {
|
|
1238
|
+
throw new Error('the `size` argument must be either a LogicalSize or a PhysicalSize instance');
|
|
1239
|
+
}
|
|
1240
|
+
return invoke('plugin:window|set_size', {
|
|
1241
|
+
label: this.label,
|
|
1242
|
+
value: {
|
|
1243
|
+
type: size.type,
|
|
1244
|
+
data: {
|
|
1245
|
+
width: size.width,
|
|
1246
|
+
height: size.height
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
});
|
|
1250
|
+
}
|
|
1251
|
+
/**
|
|
1252
|
+
* Sets the window minimum inner size. If the `size` argument is not provided, the constraint is unset.
|
|
1253
|
+
* @example
|
|
1254
|
+
* ```typescript
|
|
1255
|
+
* import { getCurrent, PhysicalSize } from '@tauri-apps/api/window';
|
|
1256
|
+
* await getCurrent().setMinSize(new PhysicalSize(600, 500));
|
|
1257
|
+
* ```
|
|
1258
|
+
*
|
|
1259
|
+
* @param size The logical or physical inner size, or `null` to unset the constraint.
|
|
1260
|
+
* @returns A promise indicating the success or failure of the operation.
|
|
1261
|
+
*/
|
|
1262
|
+
async setMinSize(size) {
|
|
1263
|
+
if (size && size.type !== 'Logical' && size.type !== 'Physical') {
|
|
1264
|
+
throw new Error('the `size` argument must be either a LogicalSize or a PhysicalSize instance');
|
|
1265
|
+
}
|
|
1266
|
+
return invoke('plugin:window|set_min_size', {
|
|
1267
|
+
label: this.label,
|
|
1268
|
+
value: size
|
|
1269
|
+
? {
|
|
1270
|
+
type: size.type,
|
|
1271
|
+
data: {
|
|
1272
|
+
width: size.width,
|
|
1273
|
+
height: size.height
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1276
|
+
: null
|
|
1277
|
+
});
|
|
1278
|
+
}
|
|
1279
|
+
/**
|
|
1280
|
+
* Sets the window maximum inner size. If the `size` argument is undefined, the constraint is unset.
|
|
1281
|
+
* @example
|
|
1282
|
+
* ```typescript
|
|
1283
|
+
* import { getCurrent, LogicalSize } from '@tauri-apps/api/window';
|
|
1284
|
+
* await getCurrent().setMaxSize(new LogicalSize(600, 500));
|
|
1285
|
+
* ```
|
|
1286
|
+
*
|
|
1287
|
+
* @param size The logical or physical inner size, or `null` to unset the constraint.
|
|
1288
|
+
* @returns A promise indicating the success or failure of the operation.
|
|
1289
|
+
*/
|
|
1290
|
+
async setMaxSize(size) {
|
|
1291
|
+
if (size && size.type !== 'Logical' && size.type !== 'Physical') {
|
|
1292
|
+
throw new Error('the `size` argument must be either a LogicalSize or a PhysicalSize instance');
|
|
1293
|
+
}
|
|
1294
|
+
return invoke('plugin:window|set_max_size', {
|
|
1295
|
+
label: this.label,
|
|
1296
|
+
value: size
|
|
1297
|
+
? {
|
|
1298
|
+
type: size.type,
|
|
1299
|
+
data: {
|
|
1300
|
+
width: size.width,
|
|
1301
|
+
height: size.height
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1304
|
+
: null
|
|
1305
|
+
});
|
|
1306
|
+
}
|
|
1307
|
+
/**
|
|
1308
|
+
* Sets the window outer position.
|
|
1309
|
+
* @example
|
|
1310
|
+
* ```typescript
|
|
1311
|
+
* import { getCurrent, LogicalPosition } from '@tauri-apps/api/window';
|
|
1312
|
+
* await getCurrent().setPosition(new LogicalPosition(600, 500));
|
|
1313
|
+
* ```
|
|
1314
|
+
*
|
|
1315
|
+
* @param position The new position, in logical or physical pixels.
|
|
1316
|
+
* @returns A promise indicating the success or failure of the operation.
|
|
1317
|
+
*/
|
|
1318
|
+
async setPosition(position) {
|
|
1319
|
+
if (!position ||
|
|
1320
|
+
(position.type !== 'Logical' && position.type !== 'Physical')) {
|
|
1321
|
+
throw new Error('the `position` argument must be either a LogicalPosition or a PhysicalPosition instance');
|
|
1322
|
+
}
|
|
1323
|
+
return invoke('plugin:window|set_position', {
|
|
1324
|
+
label: this.label,
|
|
1325
|
+
value: {
|
|
1326
|
+
type: position.type,
|
|
1327
|
+
data: {
|
|
1328
|
+
x: position.x,
|
|
1329
|
+
y: position.y
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
});
|
|
1333
|
+
}
|
|
1334
|
+
/**
|
|
1335
|
+
* Sets the window fullscreen state.
|
|
1336
|
+
* @example
|
|
1337
|
+
* ```typescript
|
|
1338
|
+
* import { getCurrent } from '@tauri-apps/api/window';
|
|
1339
|
+
* await getCurrent().setFullscreen(true);
|
|
1340
|
+
* ```
|
|
1341
|
+
*
|
|
1342
|
+
* @param fullscreen Whether the window should go to fullscreen or not.
|
|
1343
|
+
* @returns A promise indicating the success or failure of the operation.
|
|
1344
|
+
*/
|
|
1345
|
+
async setFullscreen(fullscreen) {
|
|
1346
|
+
return invoke('plugin:window|set_fullscreen', {
|
|
1347
|
+
label: this.label,
|
|
1348
|
+
value: fullscreen
|
|
1349
|
+
});
|
|
1350
|
+
}
|
|
1351
|
+
/**
|
|
1352
|
+
* Bring the window to front and focus.
|
|
1353
|
+
* @example
|
|
1354
|
+
* ```typescript
|
|
1355
|
+
* import { getCurrent } from '@tauri-apps/api/window';
|
|
1356
|
+
* await getCurrent().setFocus();
|
|
1357
|
+
* ```
|
|
1358
|
+
*
|
|
1359
|
+
* @returns A promise indicating the success or failure of the operation.
|
|
1360
|
+
*/
|
|
1361
|
+
async setFocus() {
|
|
1362
|
+
return invoke('plugin:window|set_focus', {
|
|
1363
|
+
label: this.label
|
|
1364
|
+
});
|
|
1365
|
+
}
|
|
1366
|
+
/**
|
|
1367
|
+
* Sets the window icon.
|
|
1368
|
+
* @example
|
|
1369
|
+
* ```typescript
|
|
1370
|
+
* import { getCurrent } from '@tauri-apps/api/window';
|
|
1371
|
+
* await getCurrent().setIcon('/tauri/awesome.png');
|
|
1372
|
+
* ```
|
|
1373
|
+
*
|
|
1374
|
+
* Note that you need the `icon-ico` or `icon-png` Cargo features to use this API.
|
|
1375
|
+
* To enable it, change your Cargo.toml file:
|
|
1376
|
+
* ```toml
|
|
1377
|
+
* [dependencies]
|
|
1378
|
+
* tauri = { version = "...", features = ["...", "icon-png"] }
|
|
1379
|
+
* ```
|
|
1380
|
+
*
|
|
1381
|
+
* @param icon Icon bytes or path to the icon file.
|
|
1382
|
+
* @returns A promise indicating the success or failure of the operation.
|
|
1383
|
+
*/
|
|
1384
|
+
async setIcon(icon) {
|
|
1385
|
+
return invoke('plugin:window|set_icon', {
|
|
1386
|
+
label: this.label,
|
|
1387
|
+
value: typeof icon === 'string' ? icon : Array.from(icon)
|
|
1388
|
+
});
|
|
1389
|
+
}
|
|
1390
|
+
/**
|
|
1391
|
+
* Whether the window icon should be hidden from the taskbar or not.
|
|
1392
|
+
*
|
|
1393
|
+
* #### Platform-specific
|
|
1394
|
+
*
|
|
1395
|
+
* - **macOS:** Unsupported.
|
|
1396
|
+
* @example
|
|
1397
|
+
* ```typescript
|
|
1398
|
+
* import { getCurrent } from '@tauri-apps/api/window';
|
|
1399
|
+
* await getCurrent().setSkipTaskbar(true);
|
|
1400
|
+
* ```
|
|
1401
|
+
*
|
|
1402
|
+
* @param skip true to hide window icon, false to show it.
|
|
1403
|
+
* @returns A promise indicating the success or failure of the operation.
|
|
1404
|
+
*/
|
|
1405
|
+
async setSkipTaskbar(skip) {
|
|
1406
|
+
return invoke('plugin:window|set_skip_taskbar', {
|
|
1407
|
+
label: this.label,
|
|
1408
|
+
value: skip
|
|
1409
|
+
});
|
|
1410
|
+
}
|
|
1411
|
+
/**
|
|
1412
|
+
* Grabs the cursor, preventing it from leaving the window.
|
|
1413
|
+
*
|
|
1414
|
+
* There's no guarantee that the cursor will be hidden. You should
|
|
1415
|
+
* hide it by yourself if you want so.
|
|
1416
|
+
*
|
|
1417
|
+
* #### Platform-specific
|
|
1418
|
+
*
|
|
1419
|
+
* - **Linux:** Unsupported.
|
|
1420
|
+
* - **macOS:** This locks the cursor in a fixed location, which looks visually awkward.
|
|
1421
|
+
* @example
|
|
1422
|
+
* ```typescript
|
|
1423
|
+
* import { getCurrent } from '@tauri-apps/api/window';
|
|
1424
|
+
* await getCurrent().setCursorGrab(true);
|
|
1425
|
+
* ```
|
|
1426
|
+
*
|
|
1427
|
+
* @param grab `true` to grab the cursor icon, `false` to release it.
|
|
1428
|
+
* @returns A promise indicating the success or failure of the operation.
|
|
1429
|
+
*/
|
|
1430
|
+
async setCursorGrab(grab) {
|
|
1431
|
+
return invoke('plugin:window|set_cursor_grab', {
|
|
1432
|
+
label: this.label,
|
|
1433
|
+
value: grab
|
|
1434
|
+
});
|
|
1435
|
+
}
|
|
1436
|
+
/**
|
|
1437
|
+
* Modifies the cursor's visibility.
|
|
1438
|
+
*
|
|
1439
|
+
* #### Platform-specific
|
|
1440
|
+
*
|
|
1441
|
+
* - **Windows:** The cursor is only hidden within the confines of the window.
|
|
1442
|
+
* - **macOS:** The cursor is hidden as long as the window has input focus, even if the cursor is
|
|
1443
|
+
* outside of the window.
|
|
1444
|
+
* @example
|
|
1445
|
+
* ```typescript
|
|
1446
|
+
* import { getCurrent } from '@tauri-apps/api/window';
|
|
1447
|
+
* await getCurrent().setCursorVisible(false);
|
|
1448
|
+
* ```
|
|
1449
|
+
*
|
|
1450
|
+
* @param visible If `false`, this will hide the cursor. If `true`, this will show the cursor.
|
|
1451
|
+
* @returns A promise indicating the success or failure of the operation.
|
|
1452
|
+
*/
|
|
1453
|
+
async setCursorVisible(visible) {
|
|
1454
|
+
return invoke('plugin:window|set_cursor_visible', {
|
|
1455
|
+
label: this.label,
|
|
1456
|
+
value: visible
|
|
1457
|
+
});
|
|
1458
|
+
}
|
|
1459
|
+
/**
|
|
1460
|
+
* Modifies the cursor icon of the window.
|
|
1461
|
+
* @example
|
|
1462
|
+
* ```typescript
|
|
1463
|
+
* import { getCurrent } from '@tauri-apps/api/window';
|
|
1464
|
+
* await getCurrent().setCursorIcon('help');
|
|
1465
|
+
* ```
|
|
1466
|
+
*
|
|
1467
|
+
* @param icon The new cursor icon.
|
|
1468
|
+
* @returns A promise indicating the success or failure of the operation.
|
|
1469
|
+
*/
|
|
1470
|
+
async setCursorIcon(icon) {
|
|
1471
|
+
return invoke('plugin:window|set_cursor_icon', {
|
|
1472
|
+
label: this.label,
|
|
1473
|
+
value: icon
|
|
1474
|
+
});
|
|
1475
|
+
}
|
|
1476
|
+
/**
|
|
1477
|
+
* Changes the position of the cursor in window coordinates.
|
|
1478
|
+
* @example
|
|
1479
|
+
* ```typescript
|
|
1480
|
+
* import { getCurrent, LogicalPosition } from '@tauri-apps/api/window';
|
|
1481
|
+
* await getCurrent().setCursorPosition(new LogicalPosition(600, 300));
|
|
1482
|
+
* ```
|
|
1483
|
+
*
|
|
1484
|
+
* @param position The new cursor position.
|
|
1485
|
+
* @returns A promise indicating the success or failure of the operation.
|
|
1486
|
+
*/
|
|
1487
|
+
async setCursorPosition(position) {
|
|
1488
|
+
if (!position ||
|
|
1489
|
+
(position.type !== 'Logical' && position.type !== 'Physical')) {
|
|
1490
|
+
throw new Error('the `position` argument must be either a LogicalPosition or a PhysicalPosition instance');
|
|
1491
|
+
}
|
|
1492
|
+
return invoke('plugin:window|set_cursor_position', {
|
|
1493
|
+
label: this.label,
|
|
1494
|
+
value: {
|
|
1495
|
+
type: position.type,
|
|
1496
|
+
data: {
|
|
1497
|
+
x: position.x,
|
|
1498
|
+
y: position.y
|
|
1499
|
+
}
|
|
1500
|
+
}
|
|
1501
|
+
});
|
|
1502
|
+
}
|
|
1503
|
+
/**
|
|
1504
|
+
* Changes the cursor events behavior.
|
|
1505
|
+
*
|
|
1506
|
+
* @example
|
|
1507
|
+
* ```typescript
|
|
1508
|
+
* import { getCurrent } from '@tauri-apps/api/window';
|
|
1509
|
+
* await getCurrent().setIgnoreCursorEvents(true);
|
|
1510
|
+
* ```
|
|
1511
|
+
*
|
|
1512
|
+
* @param ignore `true` to ignore the cursor events; `false` to process them as usual.
|
|
1513
|
+
* @returns A promise indicating the success or failure of the operation.
|
|
1514
|
+
*/
|
|
1515
|
+
async setIgnoreCursorEvents(ignore) {
|
|
1516
|
+
return invoke('plugin:window|set_ignore_cursor_events', {
|
|
1517
|
+
label: this.label,
|
|
1518
|
+
value: ignore
|
|
1519
|
+
});
|
|
1520
|
+
}
|
|
1521
|
+
/**
|
|
1522
|
+
* Starts dragging the window.
|
|
1523
|
+
* @example
|
|
1524
|
+
* ```typescript
|
|
1525
|
+
* import { getCurrent } from '@tauri-apps/api/window';
|
|
1526
|
+
* await getCurrent().startDragging();
|
|
1527
|
+
* ```
|
|
1528
|
+
*
|
|
1529
|
+
* @return A promise indicating the success or failure of the operation.
|
|
1530
|
+
*/
|
|
1531
|
+
async startDragging() {
|
|
1532
|
+
return invoke('plugin:window|start_dragging', {
|
|
1533
|
+
label: this.label
|
|
1534
|
+
});
|
|
1535
|
+
}
|
|
1536
|
+
/**
|
|
1537
|
+
* Sets the taskbar progress state.
|
|
1538
|
+
*
|
|
1539
|
+
* #### Platform-specific
|
|
1540
|
+
*
|
|
1541
|
+
* - **Linux / macOS**: Progress bar is app-wide and not specific to this window.
|
|
1542
|
+
* - **Linux**: Only supported desktop environments with `libunity` (e.g. GNOME).
|
|
1543
|
+
*
|
|
1544
|
+
* @example
|
|
1545
|
+
* ```typescript
|
|
1546
|
+
* import { getCurrent, ProgressBarStatus } from '@tauri-apps/api/window';
|
|
1547
|
+
* await getCurrent().setProgressBar({
|
|
1548
|
+
* status: ProgressBarStatus.Normal,
|
|
1549
|
+
* progress: 50,
|
|
1550
|
+
* });
|
|
1551
|
+
* ```
|
|
1552
|
+
*
|
|
1553
|
+
* @return A promise indicating the success or failure of the operation.
|
|
1554
|
+
*/
|
|
1555
|
+
async setProgressBar(state) {
|
|
1556
|
+
return invoke('plugin:window|set_progress_bar', {
|
|
1557
|
+
label: this.label,
|
|
1558
|
+
value: state
|
|
1559
|
+
});
|
|
1560
|
+
}
|
|
1561
|
+
// Listeners
|
|
1562
|
+
/**
|
|
1563
|
+
* Listen to window resize.
|
|
1564
|
+
*
|
|
1565
|
+
* @example
|
|
1566
|
+
* ```typescript
|
|
1567
|
+
* import { getCurrent } from "@tauri-apps/api/window";
|
|
1568
|
+
* const unlisten = await getCurrent().onResized(({ payload: size }) => {
|
|
1569
|
+
* console.log('Window resized', size);
|
|
1570
|
+
* });
|
|
1571
|
+
*
|
|
1572
|
+
* // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
|
|
1573
|
+
* unlisten();
|
|
1574
|
+
* ```
|
|
1575
|
+
*
|
|
1576
|
+
* @returns A promise resolving to a function to unlisten to the event.
|
|
1577
|
+
* Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
|
|
1578
|
+
*/
|
|
1579
|
+
async onResized(handler) {
|
|
1580
|
+
return this.listen(TauriEvent.WINDOW_RESIZED, (e) => {
|
|
1581
|
+
e.payload = mapPhysicalSize(e.payload);
|
|
1582
|
+
handler(e);
|
|
1583
|
+
});
|
|
1584
|
+
}
|
|
1585
|
+
/**
|
|
1586
|
+
* Listen to window move.
|
|
1587
|
+
*
|
|
1588
|
+
* @example
|
|
1589
|
+
* ```typescript
|
|
1590
|
+
* import { getCurrent } from "@tauri-apps/api/window";
|
|
1591
|
+
* const unlisten = await getCurrent().onMoved(({ payload: position }) => {
|
|
1592
|
+
* console.log('Window moved', position);
|
|
1593
|
+
* });
|
|
1594
|
+
*
|
|
1595
|
+
* // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
|
|
1596
|
+
* unlisten();
|
|
1597
|
+
* ```
|
|
1598
|
+
*
|
|
1599
|
+
* @returns A promise resolving to a function to unlisten to the event.
|
|
1600
|
+
* Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
|
|
1601
|
+
*/
|
|
1602
|
+
async onMoved(handler) {
|
|
1603
|
+
return this.listen(TauriEvent.WINDOW_MOVED, (e) => {
|
|
1604
|
+
e.payload = mapPhysicalPosition(e.payload);
|
|
1605
|
+
handler(e);
|
|
1606
|
+
});
|
|
1607
|
+
}
|
|
1608
|
+
/**
|
|
1609
|
+
* Listen to window close requested. Emitted when the user requests to closes the window.
|
|
1610
|
+
*
|
|
1611
|
+
* @example
|
|
1612
|
+
* ```typescript
|
|
1613
|
+
* import { getCurrent } from "@tauri-apps/api/window";
|
|
1614
|
+
* import { confirm } from '@tauri-apps/api/dialog';
|
|
1615
|
+
* const unlisten = await getCurrent().onCloseRequested(async (event) => {
|
|
1616
|
+
* const confirmed = await confirm('Are you sure?');
|
|
1617
|
+
* if (!confirmed) {
|
|
1618
|
+
* // user did not confirm closing the window; let's prevent it
|
|
1619
|
+
* event.preventDefault();
|
|
1620
|
+
* }
|
|
1621
|
+
* });
|
|
1622
|
+
*
|
|
1623
|
+
* // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
|
|
1624
|
+
* unlisten();
|
|
1625
|
+
* ```
|
|
1626
|
+
*
|
|
1627
|
+
* @returns A promise resolving to a function to unlisten to the event.
|
|
1628
|
+
* Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
|
|
1629
|
+
*/
|
|
1630
|
+
/* eslint-disable @typescript-eslint/promise-function-async */
|
|
1631
|
+
async onCloseRequested(handler) {
|
|
1632
|
+
return this.listen(TauriEvent.WINDOW_CLOSE_REQUESTED, (event) => {
|
|
1633
|
+
const evt = new CloseRequestedEvent(event);
|
|
1634
|
+
void Promise.resolve(handler(evt)).then(() => {
|
|
1635
|
+
if (!evt.isPreventDefault()) {
|
|
1636
|
+
return this.close();
|
|
1637
|
+
}
|
|
1638
|
+
});
|
|
1639
|
+
});
|
|
1640
|
+
}
|
|
1641
|
+
/* eslint-enable */
|
|
1642
|
+
/**
|
|
1643
|
+
* Listen to window focus change.
|
|
1644
|
+
*
|
|
1645
|
+
* @example
|
|
1646
|
+
* ```typescript
|
|
1647
|
+
* import { getCurrent } from "@tauri-apps/api/window";
|
|
1648
|
+
* const unlisten = await getCurrent().onFocusChanged(({ payload: focused }) => {
|
|
1649
|
+
* console.log('Focus changed, window is focused? ' + focused);
|
|
1650
|
+
* });
|
|
1651
|
+
*
|
|
1652
|
+
* // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
|
|
1653
|
+
* unlisten();
|
|
1654
|
+
* ```
|
|
1655
|
+
*
|
|
1656
|
+
* @returns A promise resolving to a function to unlisten to the event.
|
|
1657
|
+
* Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
|
|
1658
|
+
*/
|
|
1659
|
+
async onFocusChanged(handler) {
|
|
1660
|
+
const unlistenFocus = await this.listen(TauriEvent.WINDOW_FOCUS, (event) => {
|
|
1661
|
+
handler({ ...event, payload: true });
|
|
1662
|
+
});
|
|
1663
|
+
const unlistenBlur = await this.listen(TauriEvent.WINDOW_BLUR, (event) => {
|
|
1664
|
+
handler({ ...event, payload: false });
|
|
1665
|
+
});
|
|
1666
|
+
return () => {
|
|
1667
|
+
unlistenFocus();
|
|
1668
|
+
unlistenBlur();
|
|
1669
|
+
};
|
|
1670
|
+
}
|
|
1671
|
+
/**
|
|
1672
|
+
* Listen to window scale change. Emitted when the window's scale factor has changed.
|
|
1673
|
+
* The following user actions can cause DPI changes:
|
|
1674
|
+
* - Changing the display's resolution.
|
|
1675
|
+
* - Changing the display's scale factor (e.g. in Control Panel on Windows).
|
|
1676
|
+
* - Moving the window to a display with a different scale factor.
|
|
1677
|
+
*
|
|
1678
|
+
* @example
|
|
1679
|
+
* ```typescript
|
|
1680
|
+
* import { getCurrent } from "@tauri-apps/api/window";
|
|
1681
|
+
* const unlisten = await getCurrent().onScaleChanged(({ payload }) => {
|
|
1682
|
+
* console.log('Scale changed', payload.scaleFactor, payload.size);
|
|
1683
|
+
* });
|
|
1684
|
+
*
|
|
1685
|
+
* // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
|
|
1686
|
+
* unlisten();
|
|
1687
|
+
* ```
|
|
1688
|
+
*
|
|
1689
|
+
* @returns A promise resolving to a function to unlisten to the event.
|
|
1690
|
+
* Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
|
|
1691
|
+
*/
|
|
1692
|
+
async onScaleChanged(handler) {
|
|
1693
|
+
return this.listen(TauriEvent.WINDOW_SCALE_FACTOR_CHANGED, handler);
|
|
1694
|
+
}
|
|
1695
|
+
/**
|
|
1696
|
+
* Listen to the window menu item click. The payload is the item id.
|
|
1697
|
+
*
|
|
1698
|
+
* @example
|
|
1699
|
+
* ```typescript
|
|
1700
|
+
* import { getCurrent } from "@tauri-apps/api/window";
|
|
1701
|
+
* const unlisten = await getCurrent().onMenuClicked(({ payload: menuId }) => {
|
|
1702
|
+
* console.log('Menu clicked: ' + menuId);
|
|
1703
|
+
* });
|
|
1704
|
+
*
|
|
1705
|
+
* // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
|
|
1706
|
+
* unlisten();
|
|
1707
|
+
* ```
|
|
1708
|
+
*
|
|
1709
|
+
* @returns A promise resolving to a function to unlisten to the event.
|
|
1710
|
+
* Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
|
|
1711
|
+
*/
|
|
1712
|
+
async onMenuClicked(handler) {
|
|
1713
|
+
return this.listen(TauriEvent.MENU, handler);
|
|
1714
|
+
}
|
|
1715
|
+
/**
|
|
1716
|
+
* Listen to a file drop event.
|
|
1717
|
+
* The listener is triggered when the user hovers the selected files on the window,
|
|
1718
|
+
* drops the files or cancels the operation.
|
|
1719
|
+
*
|
|
1720
|
+
* @example
|
|
1721
|
+
* ```typescript
|
|
1722
|
+
* import { getCurrent } from "@tauri-apps/api/window";
|
|
1723
|
+
* const unlisten = await getCurrent().onFileDropEvent((event) => {
|
|
1724
|
+
* if (event.payload.type === 'hover') {
|
|
1725
|
+
* console.log('User hovering', event.payload.paths);
|
|
1726
|
+
* } else if (event.payload.type === 'drop') {
|
|
1727
|
+
* console.log('User dropped', event.payload.paths);
|
|
1728
|
+
* } else {
|
|
1729
|
+
* console.log('File drop cancelled');
|
|
1730
|
+
* }
|
|
1731
|
+
* });
|
|
1732
|
+
*
|
|
1733
|
+
* // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
|
|
1734
|
+
* unlisten();
|
|
1735
|
+
* ```
|
|
1736
|
+
*
|
|
1737
|
+
* @returns A promise resolving to a function to unlisten to the event.
|
|
1738
|
+
* Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
|
|
1739
|
+
*/
|
|
1740
|
+
async onFileDropEvent(handler) {
|
|
1741
|
+
const unlistenFileDrop = await this.listen(TauriEvent.WINDOW_FILE_DROP, (event) => {
|
|
1742
|
+
handler({ ...event, payload: { type: 'drop', paths: event.payload } });
|
|
1743
|
+
});
|
|
1744
|
+
const unlistenFileHover = await this.listen(TauriEvent.WINDOW_FILE_DROP_HOVER, (event) => {
|
|
1745
|
+
handler({ ...event, payload: { type: 'hover', paths: event.payload } });
|
|
1746
|
+
});
|
|
1747
|
+
const unlistenCancel = await this.listen(TauriEvent.WINDOW_FILE_DROP_CANCELLED, (event) => {
|
|
1748
|
+
handler({ ...event, payload: { type: 'cancel' } });
|
|
1749
|
+
});
|
|
1750
|
+
return () => {
|
|
1751
|
+
unlistenFileDrop();
|
|
1752
|
+
unlistenFileHover();
|
|
1753
|
+
unlistenCancel();
|
|
1754
|
+
};
|
|
1755
|
+
}
|
|
1756
|
+
/**
|
|
1757
|
+
* Listen to the system theme change.
|
|
1758
|
+
*
|
|
1759
|
+
* @example
|
|
1760
|
+
* ```typescript
|
|
1761
|
+
* import { getCurrent } from "@tauri-apps/api/window";
|
|
1762
|
+
* const unlisten = await getCurrent().onThemeChanged(({ payload: theme }) => {
|
|
1763
|
+
* console.log('New theme: ' + theme);
|
|
1764
|
+
* });
|
|
1765
|
+
*
|
|
1766
|
+
* // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
|
|
1767
|
+
* unlisten();
|
|
1768
|
+
* ```
|
|
1769
|
+
*
|
|
1770
|
+
* @returns A promise resolving to a function to unlisten to the event.
|
|
1771
|
+
* Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
|
|
1772
|
+
*/
|
|
1773
|
+
async onThemeChanged(handler) {
|
|
1774
|
+
return this.listen(TauriEvent.WINDOW_THEME_CHANGED, handler);
|
|
1775
|
+
}
|
|
1776
|
+
}
|
|
1777
|
+
/**
|
|
1778
|
+
* Platform-specific window effects
|
|
1779
|
+
*
|
|
1780
|
+
* @since 2.0.0
|
|
1781
|
+
*/
|
|
1782
|
+
var Effect;
|
|
1783
|
+
(function (Effect) {
|
|
1784
|
+
/**
|
|
1785
|
+
* A default material appropriate for the view's effectiveAppearance. **macOS 10.14-**
|
|
1786
|
+
*
|
|
1787
|
+
* @deprecated since macOS 10.14. You should instead choose an appropriate semantic material.
|
|
1788
|
+
*/
|
|
1789
|
+
Effect["AppearanceBased"] = "appearanceBased";
|
|
1790
|
+
/**
|
|
1791
|
+
* **macOS 10.14-**
|
|
1792
|
+
*
|
|
1793
|
+
* @deprecated since macOS 10.14. Use a semantic material instead.
|
|
1794
|
+
*/
|
|
1795
|
+
Effect["Light"] = "light";
|
|
1796
|
+
/**
|
|
1797
|
+
* **macOS 10.14-**
|
|
1798
|
+
*
|
|
1799
|
+
* @deprecated since macOS 10.14. Use a semantic material instead.
|
|
1800
|
+
*/
|
|
1801
|
+
Effect["Dark"] = "dark";
|
|
1802
|
+
/**
|
|
1803
|
+
* **macOS 10.14-**
|
|
1804
|
+
*
|
|
1805
|
+
* @deprecated since macOS 10.14. Use a semantic material instead.
|
|
1806
|
+
*/
|
|
1807
|
+
Effect["MediumLight"] = "mediumLight";
|
|
1808
|
+
/**
|
|
1809
|
+
* **macOS 10.14-**
|
|
1810
|
+
*
|
|
1811
|
+
* @deprecated since macOS 10.14. Use a semantic material instead.
|
|
1812
|
+
*/
|
|
1813
|
+
Effect["UltraDark"] = "ultraDark";
|
|
1814
|
+
/**
|
|
1815
|
+
* **macOS 10.10+**
|
|
1816
|
+
*/
|
|
1817
|
+
Effect["Titlebar"] = "titlebar";
|
|
1818
|
+
/**
|
|
1819
|
+
* **macOS 10.10+**
|
|
1820
|
+
*/
|
|
1821
|
+
Effect["Selection"] = "selection";
|
|
1822
|
+
/**
|
|
1823
|
+
* **macOS 10.11+**
|
|
1824
|
+
*/
|
|
1825
|
+
Effect["Menu"] = "menu";
|
|
1826
|
+
/**
|
|
1827
|
+
* **macOS 10.11+**
|
|
1828
|
+
*/
|
|
1829
|
+
Effect["Popover"] = "popover";
|
|
1830
|
+
/**
|
|
1831
|
+
* **macOS 10.11+**
|
|
1832
|
+
*/
|
|
1833
|
+
Effect["Sidebar"] = "sidebar";
|
|
1834
|
+
/**
|
|
1835
|
+
* **macOS 10.14+**
|
|
1836
|
+
*/
|
|
1837
|
+
Effect["HeaderView"] = "headerView";
|
|
1838
|
+
/**
|
|
1839
|
+
* **macOS 10.14+**
|
|
1840
|
+
*/
|
|
1841
|
+
Effect["Sheet"] = "sheet";
|
|
1842
|
+
/**
|
|
1843
|
+
* **macOS 10.14+**
|
|
1844
|
+
*/
|
|
1845
|
+
Effect["WindowBackground"] = "windowBackground";
|
|
1846
|
+
/**
|
|
1847
|
+
* **macOS 10.14+**
|
|
1848
|
+
*/
|
|
1849
|
+
Effect["HudWindow"] = "hudWindow";
|
|
1850
|
+
/**
|
|
1851
|
+
* **macOS 10.14+**
|
|
1852
|
+
*/
|
|
1853
|
+
Effect["FullScreenUI"] = "fullScreenUI";
|
|
1854
|
+
/**
|
|
1855
|
+
* **macOS 10.14+**
|
|
1856
|
+
*/
|
|
1857
|
+
Effect["Tooltip"] = "tooltip";
|
|
1858
|
+
/**
|
|
1859
|
+
* **macOS 10.14+**
|
|
1860
|
+
*/
|
|
1861
|
+
Effect["ContentBackground"] = "contentBackground";
|
|
1862
|
+
/**
|
|
1863
|
+
* **macOS 10.14+**
|
|
1864
|
+
*/
|
|
1865
|
+
Effect["UnderWindowBackground"] = "underWindowBackground";
|
|
1866
|
+
/**
|
|
1867
|
+
* **macOS 10.14+**
|
|
1868
|
+
*/
|
|
1869
|
+
Effect["UnderPageBackground"] = "underPageBackground";
|
|
1870
|
+
/**
|
|
1871
|
+
* **Windows 11 Only**
|
|
1872
|
+
*/
|
|
1873
|
+
Effect["Mica"] = "mica";
|
|
1874
|
+
/**
|
|
1875
|
+
* **Windows 7/10/11(22H1) Only**
|
|
1876
|
+
*
|
|
1877
|
+
* ## Notes
|
|
1878
|
+
*
|
|
1879
|
+
* This effect has bad performance when resizing/dragging the window on Windows 11 build 22621.
|
|
1880
|
+
*/
|
|
1881
|
+
Effect["Blur"] = "blur";
|
|
1882
|
+
/**
|
|
1883
|
+
* **Windows 10/11**
|
|
1884
|
+
*
|
|
1885
|
+
* ## Notes
|
|
1886
|
+
*
|
|
1887
|
+
* This effect has bad performance when resizing/dragging the window on Windows 10 v1903+ and Windows 11 build 22000.
|
|
1888
|
+
*/
|
|
1889
|
+
Effect["Acrylic"] = "acrylic";
|
|
1890
|
+
/**
|
|
1891
|
+
* Tabbed effect that matches the system dark perefence **Windows 11 Only**
|
|
1892
|
+
*/
|
|
1893
|
+
Effect["Tabbed"] = "tabbed";
|
|
1894
|
+
/**
|
|
1895
|
+
* Tabbed effect with dark mode but only if dark mode is enabled on the system **Windows 11 Only**
|
|
1896
|
+
*/
|
|
1897
|
+
Effect["TabbedDark"] = "tabbedDark";
|
|
1898
|
+
/**
|
|
1899
|
+
* Tabbed effect with light mode **Windows 11 Only**
|
|
1900
|
+
*/
|
|
1901
|
+
Effect["TabbedLight"] = "tabbedLight";
|
|
1902
|
+
})(Effect || (Effect = {}));
|
|
1903
|
+
/**
|
|
1904
|
+
* Window effect state **macOS only**
|
|
1905
|
+
*
|
|
1906
|
+
* @see https://developer.apple.com/documentation/appkit/nsvisualeffectview/state
|
|
1907
|
+
*
|
|
1908
|
+
* @since 2.0.0
|
|
1909
|
+
*/
|
|
1910
|
+
var EffectState;
|
|
1911
|
+
(function (EffectState) {
|
|
1912
|
+
/**
|
|
1913
|
+
* Make window effect state follow the window's active state **macOS only**
|
|
1914
|
+
*/
|
|
1915
|
+
EffectState["FollowsWindowActiveState"] = "followsWindowActiveState";
|
|
1916
|
+
/**
|
|
1917
|
+
* Make window effect state always active **macOS only**
|
|
1918
|
+
*/
|
|
1919
|
+
EffectState["Active"] = "active";
|
|
1920
|
+
/**
|
|
1921
|
+
* Make window effect state always inactive **macOS only**
|
|
1922
|
+
*/
|
|
1923
|
+
EffectState["Inactive"] = "inactive";
|
|
1924
|
+
})(EffectState || (EffectState = {}));
|
|
1925
|
+
function mapPhysicalPosition(m) {
|
|
1926
|
+
return new PhysicalPosition(m.x, m.y);
|
|
1927
|
+
}
|
|
1928
|
+
function mapPhysicalSize(m) {
|
|
1929
|
+
return new PhysicalSize(m.width, m.height);
|
|
1930
|
+
}
|
|
10
1931
|
|
|
11
1932
|
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
|
12
1933
|
// SPDX-License-Identifier: Apache-2.0
|
|
@@ -25,7 +1946,7 @@ var StateFlags;
|
|
|
25
1946
|
* Save the state of all open windows to disk.
|
|
26
1947
|
*/
|
|
27
1948
|
async function saveWindowState(flags) {
|
|
28
|
-
return
|
|
1949
|
+
return invoke("plugin:window-state|save_window_state", {
|
|
29
1950
|
flags,
|
|
30
1951
|
});
|
|
31
1952
|
}
|
|
@@ -33,7 +1954,7 @@ async function saveWindowState(flags) {
|
|
|
33
1954
|
* Restore the state for the specified window from disk.
|
|
34
1955
|
*/
|
|
35
1956
|
async function restoreState(label, flags) {
|
|
36
|
-
return
|
|
1957
|
+
return invoke("plugin:window-state|restore_state", {
|
|
37
1958
|
label,
|
|
38
1959
|
flags,
|
|
39
1960
|
});
|
|
@@ -42,7 +1963,7 @@ async function restoreState(label, flags) {
|
|
|
42
1963
|
* Restore the state for the current window from disk.
|
|
43
1964
|
*/
|
|
44
1965
|
async function restoreStateCurrent(flags) {
|
|
45
|
-
return restoreState(
|
|
1966
|
+
return restoreState(getCurrent().label, flags);
|
|
46
1967
|
}
|
|
47
1968
|
|
|
48
1969
|
export { StateFlags, restoreState, restoreStateCurrent, saveWindowState };
|