@synnaxlabs/drift 0.53.0 → 0.54.0

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/tauri.js CHANGED
@@ -1,2812 +1,1183 @@
1
- import { K as H, L as T, r as g, M as te, N as ne, Y as se, b as le, O as j, E as ae } from "./state-CAgVbv4Z.js";
2
- function re(t, e, i, n) {
3
- if (typeof e == "function" ? t !== e || !n : !e.has(t)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
- return i === "m" ? n : i === "a" ? n.call(t) : n ? n.value : e.get(t);
1
+ import { c as e, f as t, l as n, o as r, p as i, r as a, s as o, u as s } from "./window-b_pX3pWi.js";
2
+ import { p as c } from "./state-Ne5iph6p.js";
3
+ //#region ../node_modules/.pnpm/@tauri-apps+api@2.10.1/node_modules/@tauri-apps/api/external/tslib/tslib.es6.js
4
+ function l(e, t, n, r) {
5
+ if (n === "a" && !r) throw TypeError("Private accessor was defined without a getter");
6
+ if (typeof t == "function" ? e !== t || !r : !t.has(e)) throw TypeError("Cannot read private member from an object whose class did not declare it");
7
+ return n === "m" ? r : n === "a" ? r.call(e) : r ? r.value : t.get(e);
5
8
  }
6
- function oe(t, e, i, n, l) {
7
- if (typeof e == "function" ? t !== e || !0 : !e.has(t)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
8
- return e.set(t, i), i;
9
+ function ee(e, t, n, r, i) {
10
+ if (r === "m") throw TypeError("Private method is not writable");
11
+ if (r === "a" && !i) throw TypeError("Private accessor was defined without a setter");
12
+ if (typeof t == "function" ? e !== t || !i : !t.has(e)) throw TypeError("Cannot write private member to an object whose class did not declare it");
13
+ return r === "a" ? i.call(e, n) : i ? i.value = n : t.set(e, n), n;
9
14
  }
10
- var W;
11
- const c = "__TAURI_TO_IPC_KEY__";
12
- function ue(t, e = !1) {
13
- return window.__TAURI_INTERNALS__.transformCallback(t, e);
15
+ //#endregion
16
+ //#region ../node_modules/.pnpm/@tauri-apps+api@2.10.1/node_modules/@tauri-apps/api/core.js
17
+ var u, d = "__TAURI_TO_IPC_KEY__";
18
+ function f(e, t = !1) {
19
+ return window.__TAURI_INTERNALS__.transformCallback(e, t);
14
20
  }
15
- async function s(t, e = {}, i) {
16
- return window.__TAURI_INTERNALS__.invoke(t, e, i);
21
+ async function p(e, t = {}, n) {
22
+ return window.__TAURI_INTERNALS__.invoke(e, t, n);
17
23
  }
18
- class ce {
19
- get rid() {
20
- return re(this, W, "f");
21
- }
22
- constructor(e) {
23
- W.set(this, void 0), oe(this, W, e);
24
- }
25
- /**
26
- * Destroys and cleans up this resource from memory.
27
- * **You should not call any method on this object anymore and should drop any reference to it.**
28
- */
29
- async close() {
30
- return s("plugin:resources|close", {
31
- rid: this.rid
32
- });
33
- }
34
- }
35
- W = /* @__PURE__ */ new WeakMap();
36
- var r;
37
- (function(t) {
38
- t.WINDOW_RESIZED = "tauri://resize", t.WINDOW_MOVED = "tauri://move", t.WINDOW_CLOSE_REQUESTED = "tauri://close-requested", t.WINDOW_DESTROYED = "tauri://destroyed", t.WINDOW_FOCUS = "tauri://focus", t.WINDOW_BLUR = "tauri://blur", t.WINDOW_SCALE_FACTOR_CHANGED = "tauri://scale-change", t.WINDOW_THEME_CHANGED = "tauri://theme-changed", t.WINDOW_CREATED = "tauri://window-created", t.WEBVIEW_CREATED = "tauri://webview-created", t.DRAG_ENTER = "tauri://drag-enter", t.DRAG_OVER = "tauri://drag-over", t.DRAG_DROP = "tauri://drag-drop", t.DRAG_LEAVE = "tauri://drag-leave";
39
- })(r || (r = {}));
40
- async function J(t, e) {
41
- window.__TAURI_EVENT_PLUGIN_INTERNALS__.unregisterListener(t, e), await s("plugin:event|unlisten", {
42
- event: t,
43
- eventId: e
44
- });
45
- }
46
- async function D(t, e, i) {
47
- var n;
48
- const l = typeof i?.target == "string" ? { kind: "AnyLabel", label: i.target } : (n = i?.target) !== null && n !== void 0 ? n : { kind: "Any" };
49
- return s("plugin:event|listen", {
50
- event: t,
51
- target: l,
52
- handler: ue(e)
53
- }).then((o) => async () => J(t, o));
54
- }
55
- async function N(t, e, i) {
56
- return D(t, (n) => {
57
- J(t, n.id), e(n);
58
- }, i);
59
- }
60
- async function k(t, e) {
61
- await s("plugin:event|emit", {
62
- event: t,
63
- payload: e
64
- });
65
- }
66
- async function q(t, e, i) {
67
- await s("plugin:event|emit_to", {
68
- target: typeof t == "string" ? { kind: "AnyLabel", label: t } : t,
69
- event: e,
70
- payload: i
71
- });
72
- }
73
- class _ {
74
- constructor(...e) {
75
- this.type = "Logical", e.length === 1 ? "Logical" in e[0] ? (this.width = e[0].Logical.width, this.height = e[0].Logical.height) : (this.width = e[0].width, this.height = e[0].height) : (this.width = e[0], this.height = e[1]);
76
- }
77
- /**
78
- * Converts the logical size to a physical one.
79
- * @example
80
- * ```typescript
81
- * import { LogicalSize } from '@tauri-apps/api/dpi';
82
- * import { getCurrentWindow } from '@tauri-apps/api/window';
83
- *
84
- * const appWindow = getCurrentWindow();
85
- * const factor = await appWindow.scaleFactor();
86
- * const size = new LogicalSize(400, 500);
87
- * const physical = size.toPhysical(factor);
88
- * ```
89
- *
90
- * @since 2.0.0
91
- */
92
- toPhysical(e) {
93
- return new w(this.width * e, this.height * e);
94
- }
95
- [c]() {
96
- return {
97
- width: this.width,
98
- height: this.height
99
- };
100
- }
101
- toJSON() {
102
- return this[c]();
103
- }
104
- }
105
- class w {
106
- constructor(...e) {
107
- this.type = "Physical", e.length === 1 ? "Physical" in e[0] ? (this.width = e[0].Physical.width, this.height = e[0].Physical.height) : (this.width = e[0].width, this.height = e[0].height) : (this.width = e[0], this.height = e[1]);
108
- }
109
- /**
110
- * Converts the physical size to a logical one.
111
- * @example
112
- * ```typescript
113
- * import { getCurrentWindow } from '@tauri-apps/api/window';
114
- * const appWindow = getCurrentWindow();
115
- * const factor = await appWindow.scaleFactor();
116
- * const size = await appWindow.innerSize(); // PhysicalSize
117
- * const logical = size.toLogical(factor);
118
- * ```
119
- */
120
- toLogical(e) {
121
- return new _(this.width / e, this.height / e);
122
- }
123
- [c]() {
124
- return {
125
- width: this.width,
126
- height: this.height
127
- };
128
- }
129
- toJSON() {
130
- return this[c]();
131
- }
132
- }
133
- class h {
134
- constructor(e) {
135
- this.size = e;
136
- }
137
- toLogical(e) {
138
- return this.size instanceof _ ? this.size : this.size.toLogical(e);
139
- }
140
- toPhysical(e) {
141
- return this.size instanceof w ? this.size : this.size.toPhysical(e);
142
- }
143
- [c]() {
144
- return {
145
- [`${this.size.type}`]: {
146
- width: this.size.width,
147
- height: this.size.height
148
- }
149
- };
150
- }
151
- toJSON() {
152
- return this[c]();
153
- }
154
- }
155
- class L {
156
- constructor(...e) {
157
- this.type = "Logical", e.length === 1 ? "Logical" in e[0] ? (this.x = e[0].Logical.x, this.y = e[0].Logical.y) : (this.x = e[0].x, this.y = e[0].y) : (this.x = e[0], this.y = e[1]);
158
- }
159
- /**
160
- * Converts the logical position to a physical one.
161
- * @example
162
- * ```typescript
163
- * import { LogicalPosition } from '@tauri-apps/api/dpi';
164
- * import { getCurrentWindow } from '@tauri-apps/api/window';
165
- *
166
- * const appWindow = getCurrentWindow();
167
- * const factor = await appWindow.scaleFactor();
168
- * const position = new LogicalPosition(400, 500);
169
- * const physical = position.toPhysical(factor);
170
- * ```
171
- *
172
- * @since 2.0.0
173
- */
174
- toPhysical(e) {
175
- return new u(this.x * e, this.y * e);
176
- }
177
- [c]() {
178
- return {
179
- x: this.x,
180
- y: this.y
181
- };
182
- }
183
- toJSON() {
184
- return this[c]();
185
- }
186
- }
187
- class u {
188
- constructor(...e) {
189
- this.type = "Physical", e.length === 1 ? "Physical" in e[0] ? (this.x = e[0].Physical.x, this.y = e[0].Physical.y) : (this.x = e[0].x, this.y = e[0].y) : (this.x = e[0], this.y = e[1]);
190
- }
191
- /**
192
- * Converts the physical position to a logical one.
193
- * @example
194
- * ```typescript
195
- * import { PhysicalPosition } from '@tauri-apps/api/dpi';
196
- * import { getCurrentWindow } from '@tauri-apps/api/window';
197
- *
198
- * const appWindow = getCurrentWindow();
199
- * const factor = await appWindow.scaleFactor();
200
- * const position = new PhysicalPosition(400, 500);
201
- * const physical = position.toLogical(factor);
202
- * ```
203
- *
204
- * @since 2.0.0
205
- */
206
- toLogical(e) {
207
- return new L(this.x / e, this.y / e);
208
- }
209
- [c]() {
210
- return {
211
- x: this.x,
212
- y: this.y
213
- };
214
- }
215
- toJSON() {
216
- return this[c]();
217
- }
24
+ var te = class {
25
+ get rid() {
26
+ return l(this, u, "f");
27
+ }
28
+ constructor(e) {
29
+ u.set(this, void 0), ee(this, u, e, "f");
30
+ }
31
+ async close() {
32
+ return p("plugin:resources|close", { rid: this.rid });
33
+ }
34
+ };
35
+ u = /* @__PURE__ */ new WeakMap();
36
+ //#endregion
37
+ //#region ../node_modules/.pnpm/@tauri-apps+api@2.10.1/node_modules/@tauri-apps/api/event.js
38
+ var m;
39
+ (function(e) {
40
+ e.WINDOW_RESIZED = "tauri://resize", e.WINDOW_MOVED = "tauri://move", e.WINDOW_CLOSE_REQUESTED = "tauri://close-requested", e.WINDOW_DESTROYED = "tauri://destroyed", e.WINDOW_FOCUS = "tauri://focus", e.WINDOW_BLUR = "tauri://blur", e.WINDOW_SCALE_FACTOR_CHANGED = "tauri://scale-change", e.WINDOW_THEME_CHANGED = "tauri://theme-changed", e.WINDOW_CREATED = "tauri://window-created", e.WEBVIEW_CREATED = "tauri://webview-created", e.DRAG_ENTER = "tauri://drag-enter", e.DRAG_OVER = "tauri://drag-over", e.DRAG_DROP = "tauri://drag-drop", e.DRAG_LEAVE = "tauri://drag-leave";
41
+ })(m ||= {});
42
+ async function h(e, t) {
43
+ window.__TAURI_EVENT_PLUGIN_INTERNALS__.unregisterListener(e, t), await p("plugin:event|unlisten", {
44
+ event: e,
45
+ eventId: t
46
+ });
218
47
  }
219
- class d {
220
- constructor(e) {
221
- this.position = e;
222
- }
223
- toLogical(e) {
224
- return this.position instanceof L ? this.position : this.position.toLogical(e);
225
- }
226
- toPhysical(e) {
227
- return this.position instanceof u ? this.position : this.position.toPhysical(e);
228
- }
229
- [c]() {
230
- return {
231
- [`${this.position.type}`]: {
232
- x: this.position.x,
233
- y: this.position.y
234
- }
235
- };
236
- }
237
- toJSON() {
238
- return this[c]();
239
- }
48
+ async function g(e, t, n) {
49
+ return p("plugin:event|listen", {
50
+ event: e,
51
+ target: typeof n?.target == "string" ? {
52
+ kind: "AnyLabel",
53
+ label: n.target
54
+ } : n?.target ?? { kind: "Any" },
55
+ handler: f(t)
56
+ }).then((t) => async () => h(e, t));
240
57
  }
241
- class f extends ce {
242
- /**
243
- * Creates an Image from a resource ID. For internal use only.
244
- *
245
- * @ignore
246
- */
247
- constructor(e) {
248
- super(e);
249
- }
250
- /** Creates a new Image using RGBA data, in row-major order from top to bottom, and with specified width and height. */
251
- static async new(e, i, n) {
252
- return s("plugin:image|new", {
253
- rgba: O(e),
254
- width: i,
255
- height: n
256
- }).then((l) => new f(l));
257
- }
258
- /**
259
- * Creates a new image using the provided bytes by inferring the file format.
260
- * If the format is known, prefer [@link Image.fromPngBytes] or [@link Image.fromIcoBytes].
261
- *
262
- * Only `ico` and `png` are supported (based on activated feature flag).
263
- *
264
- * Note that you need the `image-ico` or `image-png` Cargo features to use this API.
265
- * To enable it, change your Cargo.toml file:
266
- * ```toml
267
- * [dependencies]
268
- * tauri = { version = "...", features = ["...", "image-png"] }
269
- * ```
270
- */
271
- static async fromBytes(e) {
272
- return s("plugin:image|from_bytes", {
273
- bytes: O(e)
274
- }).then((i) => new f(i));
275
- }
276
- /**
277
- * Creates a new image using the provided path.
278
- *
279
- * Only `ico` and `png` are supported (based on activated feature flag).
280
- *
281
- * Note that you need the `image-ico` or `image-png` Cargo features to use this API.
282
- * To enable it, change your Cargo.toml file:
283
- * ```toml
284
- * [dependencies]
285
- * tauri = { version = "...", features = ["...", "image-png"] }
286
- * ```
287
- */
288
- static async fromPath(e) {
289
- return s("plugin:image|from_path", { path: e }).then((i) => new f(i));
290
- }
291
- /** Returns the RGBA data for this image, in row-major order from top to bottom. */
292
- async rgba() {
293
- return s("plugin:image|rgba", {
294
- rid: this.rid
295
- }).then((e) => new Uint8Array(e));
296
- }
297
- /** Returns the size of this image. */
298
- async size() {
299
- return s("plugin:image|size", { rid: this.rid });
300
- }
58
+ async function _(e, t, n) {
59
+ return g(e, (n) => {
60
+ h(e, n.id), t(n);
61
+ }, n);
301
62
  }
302
- function O(t) {
303
- return t == null ? null : typeof t == "string" ? t : t instanceof f ? t.rid : t;
63
+ async function v(e, t) {
64
+ await p("plugin:event|emit", {
65
+ event: e,
66
+ payload: t
67
+ });
304
68
  }
305
- var R;
306
- (function(t) {
307
- t[t.Critical = 1] = "Critical", t[t.Informational = 2] = "Informational";
308
- })(R || (R = {}));
309
- class he {
310
- constructor(e) {
311
- this._preventDefault = !1, this.event = e.event, this.id = e.id;
312
- }
313
- preventDefault() {
314
- this._preventDefault = !0;
315
- }
316
- isPreventDefault() {
317
- return this._preventDefault;
318
- }
69
+ async function y(e, t, n) {
70
+ await p("plugin:event|emit_to", {
71
+ target: typeof e == "string" ? {
72
+ kind: "AnyLabel",
73
+ label: e
74
+ } : e,
75
+ event: t,
76
+ payload: n
77
+ });
319
78
  }
320
- var M;
321
- (function(t) {
322
- t.None = "none", t.Normal = "normal", t.Indeterminate = "indeterminate", t.Paused = "paused", t.Error = "error";
323
- })(M || (M = {}));
324
- function Z() {
325
- return new P(window.__TAURI_INTERNALS__.metadata.currentWindow.label, {
326
- // @ts-expect-error `skip` is not defined in the public API but it is handled by the constructor
327
- skip: !0
328
- });
79
+ //#endregion
80
+ //#region ../node_modules/.pnpm/@tauri-apps+api@2.10.1/node_modules/@tauri-apps/api/dpi.js
81
+ var b = class {
82
+ constructor(...e) {
83
+ this.type = "Logical", e.length === 1 ? "Logical" in e[0] ? (this.width = e[0].Logical.width, this.height = e[0].Logical.height) : (this.width = e[0].width, this.height = e[0].height) : (this.width = e[0], this.height = e[1]);
84
+ }
85
+ toPhysical(e) {
86
+ return new x(this.width * e, this.height * e);
87
+ }
88
+ [d]() {
89
+ return {
90
+ width: this.width,
91
+ height: this.height
92
+ };
93
+ }
94
+ toJSON() {
95
+ return this[d]();
96
+ }
97
+ }, x = class {
98
+ constructor(...e) {
99
+ this.type = "Physical", e.length === 1 ? "Physical" in e[0] ? (this.width = e[0].Physical.width, this.height = e[0].Physical.height) : (this.width = e[0].width, this.height = e[0].height) : (this.width = e[0], this.height = e[1]);
100
+ }
101
+ toLogical(e) {
102
+ return new b(this.width / e, this.height / e);
103
+ }
104
+ [d]() {
105
+ return {
106
+ width: this.width,
107
+ height: this.height
108
+ };
109
+ }
110
+ toJSON() {
111
+ return this[d]();
112
+ }
113
+ }, S = class {
114
+ constructor(e) {
115
+ this.size = e;
116
+ }
117
+ toLogical(e) {
118
+ return this.size instanceof b ? this.size : this.size.toLogical(e);
119
+ }
120
+ toPhysical(e) {
121
+ return this.size instanceof x ? this.size : this.size.toPhysical(e);
122
+ }
123
+ [d]() {
124
+ return { [`${this.size.type}`]: {
125
+ width: this.size.width,
126
+ height: this.size.height
127
+ } };
128
+ }
129
+ toJSON() {
130
+ return this[d]();
131
+ }
132
+ }, C = class {
133
+ constructor(...e) {
134
+ this.type = "Logical", e.length === 1 ? "Logical" in e[0] ? (this.x = e[0].Logical.x, this.y = e[0].Logical.y) : (this.x = e[0].x, this.y = e[0].y) : (this.x = e[0], this.y = e[1]);
135
+ }
136
+ toPhysical(e) {
137
+ return new w(this.x * e, this.y * e);
138
+ }
139
+ [d]() {
140
+ return {
141
+ x: this.x,
142
+ y: this.y
143
+ };
144
+ }
145
+ toJSON() {
146
+ return this[d]();
147
+ }
148
+ }, w = class {
149
+ constructor(...e) {
150
+ this.type = "Physical", e.length === 1 ? "Physical" in e[0] ? (this.x = e[0].Physical.x, this.y = e[0].Physical.y) : (this.x = e[0].x, this.y = e[0].y) : (this.x = e[0], this.y = e[1]);
151
+ }
152
+ toLogical(e) {
153
+ return new C(this.x / e, this.y / e);
154
+ }
155
+ [d]() {
156
+ return {
157
+ x: this.x,
158
+ y: this.y
159
+ };
160
+ }
161
+ toJSON() {
162
+ return this[d]();
163
+ }
164
+ }, T = class {
165
+ constructor(e) {
166
+ this.position = e;
167
+ }
168
+ toLogical(e) {
169
+ return this.position instanceof C ? this.position : this.position.toLogical(e);
170
+ }
171
+ toPhysical(e) {
172
+ return this.position instanceof w ? this.position : this.position.toPhysical(e);
173
+ }
174
+ [d]() {
175
+ return { [`${this.position.type}`]: {
176
+ x: this.position.x,
177
+ y: this.position.y
178
+ } };
179
+ }
180
+ toJSON() {
181
+ return this[d]();
182
+ }
183
+ }, E = class e extends te {
184
+ constructor(e) {
185
+ super(e);
186
+ }
187
+ static async new(t, n, r) {
188
+ return p("plugin:image|new", {
189
+ rgba: D(t),
190
+ width: n,
191
+ height: r
192
+ }).then((t) => new e(t));
193
+ }
194
+ static async fromBytes(t) {
195
+ return p("plugin:image|from_bytes", { bytes: D(t) }).then((t) => new e(t));
196
+ }
197
+ static async fromPath(t) {
198
+ return p("plugin:image|from_path", { path: t }).then((t) => new e(t));
199
+ }
200
+ async rgba() {
201
+ return p("plugin:image|rgba", { rid: this.rid }).then((e) => new Uint8Array(e));
202
+ }
203
+ async size() {
204
+ return p("plugin:image|size", { rid: this.rid });
205
+ }
206
+ };
207
+ function D(e) {
208
+ return e == null ? null : typeof e == "string" ? e : e instanceof E ? e.rid : e;
329
209
  }
330
- async function I() {
331
- return s("plugin:window|get_all_windows").then((t) => t.map((e) => new P(e, {
332
- // @ts-expect-error `skip` is not defined in the public API but it is handled by the constructor
333
- skip: !0
334
- })));
210
+ //#endregion
211
+ //#region ../node_modules/.pnpm/@tauri-apps+api@2.10.1/node_modules/@tauri-apps/api/window.js
212
+ var O;
213
+ (function(e) {
214
+ e[e.Critical = 1] = "Critical", e[e.Informational = 2] = "Informational";
215
+ })(O ||= {});
216
+ var k = class {
217
+ constructor(e) {
218
+ this._preventDefault = !1, this.event = e.event, this.id = e.id;
219
+ }
220
+ preventDefault() {
221
+ this._preventDefault = !0;
222
+ }
223
+ isPreventDefault() {
224
+ return this._preventDefault;
225
+ }
226
+ }, A;
227
+ (function(e) {
228
+ e.None = "none", e.Normal = "normal", e.Indeterminate = "indeterminate", e.Paused = "paused", e.Error = "error";
229
+ })(A ||= {});
230
+ function j() {
231
+ return new P(window.__TAURI_INTERNALS__.metadata.currentWindow.label, { skip: !0 });
335
232
  }
336
- const E = ["tauri://created", "tauri://error"];
337
- class P {
338
- /**
339
- * Creates a new Window.
340
- * @example
341
- * ```typescript
342
- * import { Window } from '@tauri-apps/api/window';
343
- * const appWindow = new Window('my-label');
344
- * appWindow.once('tauri://created', function () {
345
- * // window successfully created
346
- * });
347
- * appWindow.once('tauri://error', function (e) {
348
- * // an error happened creating the window
349
- * });
350
- * ```
351
- *
352
- * @param label The unique window label. Must be alphanumeric: `a-zA-Z-/:_`.
353
- * @returns The {@link Window} instance to communicate with the window.
354
- */
355
- constructor(e, i = {}) {
356
- var n;
357
- this.label = e, this.listeners = /* @__PURE__ */ Object.create(null), i?.skip || s("plugin:window|create", {
358
- options: {
359
- ...i,
360
- parent: typeof i.parent == "string" ? i.parent : (n = i.parent) === null || n === void 0 ? void 0 : n.label,
361
- label: e
362
- }
363
- }).then(async () => this.emit("tauri://created")).catch(async (l) => this.emit("tauri://error", l));
364
- }
365
- /**
366
- * Gets the Window associated with the given label.
367
- * @example
368
- * ```typescript
369
- * import { Window } from '@tauri-apps/api/window';
370
- * const mainWindow = Window.getByLabel('main');
371
- * ```
372
- *
373
- * @param label The window label.
374
- * @returns The Window instance to communicate with the window or null if the window doesn't exist.
375
- */
376
- static async getByLabel(e) {
377
- var i;
378
- return (i = (await I()).find((n) => n.label === e)) !== null && i !== void 0 ? i : null;
379
- }
380
- /**
381
- * Get an instance of `Window` for the current window.
382
- */
383
- static getCurrent() {
384
- return Z();
385
- }
386
- /**
387
- * Gets a list of instances of `Window` for all available windows.
388
- */
389
- static async getAll() {
390
- return I();
391
- }
392
- /**
393
- * Gets the focused window.
394
- * @example
395
- * ```typescript
396
- * import { Window } from '@tauri-apps/api/window';
397
- * const focusedWindow = Window.getFocusedWindow();
398
- * ```
399
- *
400
- * @returns The Window instance or `undefined` if there is not any focused window.
401
- */
402
- static async getFocusedWindow() {
403
- for (const e of await I())
404
- if (await e.isFocused())
405
- return e;
406
- return null;
407
- }
408
- /**
409
- * Listen to an emitted event on this window.
410
- *
411
- * @example
412
- * ```typescript
413
- * import { getCurrentWindow } from '@tauri-apps/api/window';
414
- * const unlisten = await getCurrentWindow().listen<string>('state-changed', (event) => {
415
- * console.log(`Got error: ${payload}`);
416
- * });
417
- *
418
- * // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
419
- * unlisten();
420
- * ```
421
- *
422
- * @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`.
423
- * @param handler Event handler.
424
- * @returns A promise resolving to a function to unlisten to the event.
425
- * Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
426
- */
427
- async listen(e, i) {
428
- return this._handleTauriEvent(e, i) ? () => {
429
- const n = this.listeners[e];
430
- n.splice(n.indexOf(i), 1);
431
- } : D(e, i, {
432
- target: { kind: "Window", label: this.label }
433
- });
434
- }
435
- /**
436
- * Listen to an emitted event on this window only once.
437
- *
438
- * @example
439
- * ```typescript
440
- * import { getCurrentWindow } from '@tauri-apps/api/window';
441
- * const unlisten = await getCurrentWindow().once<null>('initialized', (event) => {
442
- * console.log(`Window initialized!`);
443
- * });
444
- *
445
- * // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
446
- * unlisten();
447
- * ```
448
- *
449
- * @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`.
450
- * @param handler Event handler.
451
- * @returns A promise resolving to a function to unlisten to the event.
452
- * Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
453
- */
454
- async once(e, i) {
455
- return this._handleTauriEvent(e, i) ? () => {
456
- const n = this.listeners[e];
457
- n.splice(n.indexOf(i), 1);
458
- } : N(e, i, {
459
- target: { kind: "Window", label: this.label }
460
- });
461
- }
462
- /**
463
- * Emits an event to all {@link EventTarget|targets}.
464
- * @example
465
- * ```typescript
466
- * import { getCurrentWindow } from '@tauri-apps/api/window';
467
- * await getCurrentWindow().emit('window-loaded', { loggedIn: true, token: 'authToken' });
468
- * ```
469
- *
470
- * @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`.
471
- * @param payload Event payload.
472
- */
473
- async emit(e, i) {
474
- if (E.includes(e)) {
475
- for (const n of this.listeners[e] || [])
476
- n({
477
- event: e,
478
- id: -1,
479
- payload: i
480
- });
481
- return;
482
- }
483
- return k(e, i);
484
- }
485
- /**
486
- * Emits an event to all {@link EventTarget|targets} matching the given target.
487
- *
488
- * @example
489
- * ```typescript
490
- * import { getCurrentWindow } from '@tauri-apps/api/window';
491
- * await getCurrentWindow().emit('main', 'window-loaded', { loggedIn: true, token: 'authToken' });
492
- * ```
493
- * @param target Label of the target Window/Webview/WebviewWindow or raw {@link EventTarget} object.
494
- * @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`.
495
- * @param payload Event payload.
496
- */
497
- async emitTo(e, i, n) {
498
- if (E.includes(i)) {
499
- for (const l of this.listeners[i] || [])
500
- l({
501
- event: i,
502
- id: -1,
503
- payload: n
504
- });
505
- return;
506
- }
507
- return q(e, i, n);
508
- }
509
- /** @ignore */
510
- _handleTauriEvent(e, i) {
511
- return E.includes(e) ? (e in this.listeners ? this.listeners[e].push(i) : this.listeners[e] = [i], !0) : !1;
512
- }
513
- // Getters
514
- /**
515
- * The scale factor that can be used to map physical pixels to logical pixels.
516
- * @example
517
- * ```typescript
518
- * import { getCurrentWindow } from '@tauri-apps/api/window';
519
- * const factor = await getCurrentWindow().scaleFactor();
520
- * ```
521
- *
522
- * @returns The window's monitor scale factor.
523
- */
524
- async scaleFactor() {
525
- return s("plugin:window|scale_factor", {
526
- label: this.label
527
- });
528
- }
529
- /**
530
- * The position of the top-left hand corner of the window's client area relative to the top-left hand corner of the desktop.
531
- * @example
532
- * ```typescript
533
- * import { getCurrentWindow } from '@tauri-apps/api/window';
534
- * const position = await getCurrentWindow().innerPosition();
535
- * ```
536
- *
537
- * @returns The window's inner position.
538
- */
539
- async innerPosition() {
540
- return s("plugin:window|inner_position", {
541
- label: this.label
542
- }).then((e) => new u(e));
543
- }
544
- /**
545
- * The position of the top-left hand corner of the window relative to the top-left hand corner of the desktop.
546
- * @example
547
- * ```typescript
548
- * import { getCurrentWindow } from '@tauri-apps/api/window';
549
- * const position = await getCurrentWindow().outerPosition();
550
- * ```
551
- *
552
- * @returns The window's outer position.
553
- */
554
- async outerPosition() {
555
- return s("plugin:window|outer_position", {
556
- label: this.label
557
- }).then((e) => new u(e));
558
- }
559
- /**
560
- * The physical size of the window's client area.
561
- * The client area is the content of the window, excluding the title bar and borders.
562
- * @example
563
- * ```typescript
564
- * import { getCurrentWindow } from '@tauri-apps/api/window';
565
- * const size = await getCurrentWindow().innerSize();
566
- * ```
567
- *
568
- * @returns The window's inner size.
569
- */
570
- async innerSize() {
571
- return s("plugin:window|inner_size", {
572
- label: this.label
573
- }).then((e) => new w(e));
574
- }
575
- /**
576
- * The physical size of the entire window.
577
- * These dimensions include the title bar and borders. If you don't want that (and you usually don't), use inner_size instead.
578
- * @example
579
- * ```typescript
580
- * import { getCurrentWindow } from '@tauri-apps/api/window';
581
- * const size = await getCurrentWindow().outerSize();
582
- * ```
583
- *
584
- * @returns The window's outer size.
585
- */
586
- async outerSize() {
587
- return s("plugin:window|outer_size", {
588
- label: this.label
589
- }).then((e) => new w(e));
590
- }
591
- /**
592
- * Gets the window's current fullscreen state.
593
- * @example
594
- * ```typescript
595
- * import { getCurrentWindow } from '@tauri-apps/api/window';
596
- * const fullscreen = await getCurrentWindow().isFullscreen();
597
- * ```
598
- *
599
- * @returns Whether the window is in fullscreen mode or not.
600
- */
601
- async isFullscreen() {
602
- return s("plugin:window|is_fullscreen", {
603
- label: this.label
604
- });
605
- }
606
- /**
607
- * Gets the window's current minimized state.
608
- * @example
609
- * ```typescript
610
- * import { getCurrentWindow } from '@tauri-apps/api/window';
611
- * const minimized = await getCurrentWindow().isMinimized();
612
- * ```
613
- */
614
- async isMinimized() {
615
- return s("plugin:window|is_minimized", {
616
- label: this.label
617
- });
618
- }
619
- /**
620
- * Gets the window's current maximized state.
621
- * @example
622
- * ```typescript
623
- * import { getCurrentWindow } from '@tauri-apps/api/window';
624
- * const maximized = await getCurrentWindow().isMaximized();
625
- * ```
626
- *
627
- * @returns Whether the window is maximized or not.
628
- */
629
- async isMaximized() {
630
- return s("plugin:window|is_maximized", {
631
- label: this.label
632
- });
633
- }
634
- /**
635
- * Gets the window's current focus state.
636
- * @example
637
- * ```typescript
638
- * import { getCurrentWindow } from '@tauri-apps/api/window';
639
- * const focused = await getCurrentWindow().isFocused();
640
- * ```
641
- *
642
- * @returns Whether the window is focused or not.
643
- */
644
- async isFocused() {
645
- return s("plugin:window|is_focused", {
646
- label: this.label
647
- });
648
- }
649
- /**
650
- * Gets the window's current decorated state.
651
- * @example
652
- * ```typescript
653
- * import { getCurrentWindow } from '@tauri-apps/api/window';
654
- * const decorated = await getCurrentWindow().isDecorated();
655
- * ```
656
- *
657
- * @returns Whether the window is decorated or not.
658
- */
659
- async isDecorated() {
660
- return s("plugin:window|is_decorated", {
661
- label: this.label
662
- });
663
- }
664
- /**
665
- * Gets the window's current resizable state.
666
- * @example
667
- * ```typescript
668
- * import { getCurrentWindow } from '@tauri-apps/api/window';
669
- * const resizable = await getCurrentWindow().isResizable();
670
- * ```
671
- *
672
- * @returns Whether the window is resizable or not.
673
- */
674
- async isResizable() {
675
- return s("plugin:window|is_resizable", {
676
- label: this.label
677
- });
678
- }
679
- /**
680
- * Gets the window's native maximize button state.
681
- *
682
- * #### Platform-specific
683
- *
684
- * - **Linux / iOS / Android:** Unsupported.
685
- *
686
- * @example
687
- * ```typescript
688
- * import { getCurrentWindow } from '@tauri-apps/api/window';
689
- * const maximizable = await getCurrentWindow().isMaximizable();
690
- * ```
691
- *
692
- * @returns Whether the window's native maximize button is enabled or not.
693
- */
694
- async isMaximizable() {
695
- return s("plugin:window|is_maximizable", {
696
- label: this.label
697
- });
698
- }
699
- /**
700
- * Gets the window's native minimize button state.
701
- *
702
- * #### Platform-specific
703
- *
704
- * - **Linux / iOS / Android:** Unsupported.
705
- *
706
- * @example
707
- * ```typescript
708
- * import { getCurrentWindow } from '@tauri-apps/api/window';
709
- * const minimizable = await getCurrentWindow().isMinimizable();
710
- * ```
711
- *
712
- * @returns Whether the window's native minimize button is enabled or not.
713
- */
714
- async isMinimizable() {
715
- return s("plugin:window|is_minimizable", {
716
- label: this.label
717
- });
718
- }
719
- /**
720
- * Gets the window's native close button state.
721
- *
722
- * #### Platform-specific
723
- *
724
- * - **iOS / Android:** Unsupported.
725
- *
726
- * @example
727
- * ```typescript
728
- * import { getCurrentWindow } from '@tauri-apps/api/window';
729
- * const closable = await getCurrentWindow().isClosable();
730
- * ```
731
- *
732
- * @returns Whether the window's native close button is enabled or not.
733
- */
734
- async isClosable() {
735
- return s("plugin:window|is_closable", {
736
- label: this.label
737
- });
738
- }
739
- /**
740
- * Gets the window's current visible state.
741
- * @example
742
- * ```typescript
743
- * import { getCurrentWindow } from '@tauri-apps/api/window';
744
- * const visible = await getCurrentWindow().isVisible();
745
- * ```
746
- *
747
- * @returns Whether the window is visible or not.
748
- */
749
- async isVisible() {
750
- return s("plugin:window|is_visible", {
751
- label: this.label
752
- });
753
- }
754
- /**
755
- * Gets the window's current title.
756
- * @example
757
- * ```typescript
758
- * import { getCurrentWindow } from '@tauri-apps/api/window';
759
- * const title = await getCurrentWindow().title();
760
- * ```
761
- */
762
- async title() {
763
- return s("plugin:window|title", {
764
- label: this.label
765
- });
766
- }
767
- /**
768
- * Gets the window's current theme.
769
- *
770
- * #### Platform-specific
771
- *
772
- * - **macOS:** Theme was introduced on macOS 10.14. Returns `light` on macOS 10.13 and below.
773
- *
774
- * @example
775
- * ```typescript
776
- * import { getCurrentWindow } from '@tauri-apps/api/window';
777
- * const theme = await getCurrentWindow().theme();
778
- * ```
779
- *
780
- * @returns The window theme.
781
- */
782
- async theme() {
783
- return s("plugin:window|theme", {
784
- label: this.label
785
- });
786
- }
787
- /**
788
- * Whether the window is configured to be always on top of other windows or not.
789
- * @example
790
- * ```typescript
791
- * import { getCurrentWindow } from '@tauri-apps/api/window';
792
- * const alwaysOnTop = await getCurrentWindow().isAlwaysOnTop();
793
- * ```
794
- *
795
- * @returns Whether the window is visible or not.
796
- */
797
- async isAlwaysOnTop() {
798
- return s("plugin:window|is_always_on_top", {
799
- label: this.label
800
- });
801
- }
802
- // Setters
803
- /**
804
- * Centers the window.
805
- * @example
806
- * ```typescript
807
- * import { getCurrentWindow } from '@tauri-apps/api/window';
808
- * await getCurrentWindow().center();
809
- * ```
810
- *
811
- * @returns A promise indicating the success or failure of the operation.
812
- */
813
- async center() {
814
- return s("plugin:window|center", {
815
- label: this.label
816
- });
817
- }
818
- /**
819
- * Requests user attention to the window, this has no effect if the application
820
- * is already focused. How requesting for user attention manifests is platform dependent,
821
- * see `UserAttentionType` for details.
822
- *
823
- * Providing `null` will unset the request for user attention. Unsetting the request for
824
- * user attention might not be done automatically by the WM when the window receives input.
825
- *
826
- * #### Platform-specific
827
- *
828
- * - **macOS:** `null` has no effect.
829
- * - **Linux:** Urgency levels have the same effect.
830
- * @example
831
- * ```typescript
832
- * import { getCurrentWindow } from '@tauri-apps/api/window';
833
- * await getCurrentWindow().requestUserAttention();
834
- * ```
835
- *
836
- * @returns A promise indicating the success or failure of the operation.
837
- */
838
- async requestUserAttention(e) {
839
- let i = null;
840
- return e && (e === R.Critical ? i = { type: "Critical" } : i = { type: "Informational" }), s("plugin:window|request_user_attention", {
841
- label: this.label,
842
- value: i
843
- });
844
- }
845
- /**
846
- * Updates the window resizable flag.
847
- * @example
848
- * ```typescript
849
- * import { getCurrentWindow } from '@tauri-apps/api/window';
850
- * await getCurrentWindow().setResizable(false);
851
- * ```
852
- *
853
- * @returns A promise indicating the success or failure of the operation.
854
- */
855
- async setResizable(e) {
856
- return s("plugin:window|set_resizable", {
857
- label: this.label,
858
- value: e
859
- });
860
- }
861
- /**
862
- * Enable or disable the window.
863
- * @example
864
- * ```typescript
865
- * import { getCurrentWindow } from '@tauri-apps/api/window';
866
- * await getCurrentWindow().setEnabled(false);
867
- * ```
868
- *
869
- * @returns A promise indicating the success or failure of the operation.
870
- *
871
- * @since 2.0.0
872
- */
873
- async setEnabled(e) {
874
- return s("plugin:window|set_enabled", {
875
- label: this.label,
876
- value: e
877
- });
878
- }
879
- /**
880
- * Whether the window is enabled or disabled.
881
- * @example
882
- * ```typescript
883
- * import { getCurrentWindow } from '@tauri-apps/api/window';
884
- * await getCurrentWindow().setEnabled(false);
885
- * ```
886
- *
887
- * @returns A promise indicating the success or failure of the operation.
888
- *
889
- * @since 2.0.0
890
- */
891
- async isEnabled() {
892
- return s("plugin:window|is_enabled", {
893
- label: this.label
894
- });
895
- }
896
- /**
897
- * Sets whether the window's native maximize button is enabled or not.
898
- * If resizable is set to false, this setting is ignored.
899
- *
900
- * #### Platform-specific
901
- *
902
- * - **macOS:** Disables the "zoom" button in the window titlebar, which is also used to enter fullscreen mode.
903
- * - **Linux / iOS / Android:** Unsupported.
904
- *
905
- * @example
906
- * ```typescript
907
- * import { getCurrentWindow } from '@tauri-apps/api/window';
908
- * await getCurrentWindow().setMaximizable(false);
909
- * ```
910
- *
911
- * @returns A promise indicating the success or failure of the operation.
912
- */
913
- async setMaximizable(e) {
914
- return s("plugin:window|set_maximizable", {
915
- label: this.label,
916
- value: e
917
- });
918
- }
919
- /**
920
- * Sets whether the window's native minimize button is enabled or not.
921
- *
922
- * #### Platform-specific
923
- *
924
- * - **Linux / iOS / Android:** Unsupported.
925
- *
926
- * @example
927
- * ```typescript
928
- * import { getCurrentWindow } from '@tauri-apps/api/window';
929
- * await getCurrentWindow().setMinimizable(false);
930
- * ```
931
- *
932
- * @returns A promise indicating the success or failure of the operation.
933
- */
934
- async setMinimizable(e) {
935
- return s("plugin:window|set_minimizable", {
936
- label: this.label,
937
- value: e
938
- });
939
- }
940
- /**
941
- * Sets whether the window's native close button is enabled or not.
942
- *
943
- * #### Platform-specific
944
- *
945
- * - **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
946
- * - **iOS / Android:** Unsupported.
947
- *
948
- * @example
949
- * ```typescript
950
- * import { getCurrentWindow } from '@tauri-apps/api/window';
951
- * await getCurrentWindow().setClosable(false);
952
- * ```
953
- *
954
- * @returns A promise indicating the success or failure of the operation.
955
- */
956
- async setClosable(e) {
957
- return s("plugin:window|set_closable", {
958
- label: this.label,
959
- value: e
960
- });
961
- }
962
- /**
963
- * Sets the window title.
964
- * @example
965
- * ```typescript
966
- * import { getCurrentWindow } from '@tauri-apps/api/window';
967
- * await getCurrentWindow().setTitle('Tauri');
968
- * ```
969
- *
970
- * @param title The new title
971
- * @returns A promise indicating the success or failure of the operation.
972
- */
973
- async setTitle(e) {
974
- return s("plugin:window|set_title", {
975
- label: this.label,
976
- value: e
977
- });
978
- }
979
- /**
980
- * Maximizes the window.
981
- * @example
982
- * ```typescript
983
- * import { getCurrentWindow } from '@tauri-apps/api/window';
984
- * await getCurrentWindow().maximize();
985
- * ```
986
- *
987
- * @returns A promise indicating the success or failure of the operation.
988
- */
989
- async maximize() {
990
- return s("plugin:window|maximize", {
991
- label: this.label
992
- });
993
- }
994
- /**
995
- * Unmaximizes the window.
996
- * @example
997
- * ```typescript
998
- * import { getCurrentWindow } from '@tauri-apps/api/window';
999
- * await getCurrentWindow().unmaximize();
1000
- * ```
1001
- *
1002
- * @returns A promise indicating the success or failure of the operation.
1003
- */
1004
- async unmaximize() {
1005
- return s("plugin:window|unmaximize", {
1006
- label: this.label
1007
- });
1008
- }
1009
- /**
1010
- * Toggles the window maximized state.
1011
- * @example
1012
- * ```typescript
1013
- * import { getCurrentWindow } from '@tauri-apps/api/window';
1014
- * await getCurrentWindow().toggleMaximize();
1015
- * ```
1016
- *
1017
- * @returns A promise indicating the success or failure of the operation.
1018
- */
1019
- async toggleMaximize() {
1020
- return s("plugin:window|toggle_maximize", {
1021
- label: this.label
1022
- });
1023
- }
1024
- /**
1025
- * Minimizes the window.
1026
- * @example
1027
- * ```typescript
1028
- * import { getCurrentWindow } from '@tauri-apps/api/window';
1029
- * await getCurrentWindow().minimize();
1030
- * ```
1031
- *
1032
- * @returns A promise indicating the success or failure of the operation.
1033
- */
1034
- async minimize() {
1035
- return s("plugin:window|minimize", {
1036
- label: this.label
1037
- });
1038
- }
1039
- /**
1040
- * Unminimizes the window.
1041
- * @example
1042
- * ```typescript
1043
- * import { getCurrentWindow } from '@tauri-apps/api/window';
1044
- * await getCurrentWindow().unminimize();
1045
- * ```
1046
- *
1047
- * @returns A promise indicating the success or failure of the operation.
1048
- */
1049
- async unminimize() {
1050
- return s("plugin:window|unminimize", {
1051
- label: this.label
1052
- });
1053
- }
1054
- /**
1055
- * Sets the window visibility to true.
1056
- * @example
1057
- * ```typescript
1058
- * import { getCurrentWindow } from '@tauri-apps/api/window';
1059
- * await getCurrentWindow().show();
1060
- * ```
1061
- *
1062
- * @returns A promise indicating the success or failure of the operation.
1063
- */
1064
- async show() {
1065
- return s("plugin:window|show", {
1066
- label: this.label
1067
- });
1068
- }
1069
- /**
1070
- * Sets the window visibility to false.
1071
- * @example
1072
- * ```typescript
1073
- * import { getCurrentWindow } from '@tauri-apps/api/window';
1074
- * await getCurrentWindow().hide();
1075
- * ```
1076
- *
1077
- * @returns A promise indicating the success or failure of the operation.
1078
- */
1079
- async hide() {
1080
- return s("plugin:window|hide", {
1081
- label: this.label
1082
- });
1083
- }
1084
- /**
1085
- * Closes the window.
1086
- *
1087
- * Note this emits a closeRequested event so you can intercept it. To force window close, use {@link Window.destroy}.
1088
- * @example
1089
- * ```typescript
1090
- * import { getCurrentWindow } from '@tauri-apps/api/window';
1091
- * await getCurrentWindow().close();
1092
- * ```
1093
- *
1094
- * @returns A promise indicating the success or failure of the operation.
1095
- */
1096
- async close() {
1097
- return s("plugin:window|close", {
1098
- label: this.label
1099
- });
1100
- }
1101
- /**
1102
- * Destroys the window. Behaves like {@link Window.close} but forces the window close instead of emitting a closeRequested event.
1103
- * @example
1104
- * ```typescript
1105
- * import { getCurrentWindow } from '@tauri-apps/api/window';
1106
- * await getCurrentWindow().destroy();
1107
- * ```
1108
- *
1109
- * @returns A promise indicating the success or failure of the operation.
1110
- */
1111
- async destroy() {
1112
- return s("plugin:window|destroy", {
1113
- label: this.label
1114
- });
1115
- }
1116
- /**
1117
- * Whether the window should have borders and bars.
1118
- * @example
1119
- * ```typescript
1120
- * import { getCurrentWindow } from '@tauri-apps/api/window';
1121
- * await getCurrentWindow().setDecorations(false);
1122
- * ```
1123
- *
1124
- * @param decorations Whether the window should have borders and bars.
1125
- * @returns A promise indicating the success or failure of the operation.
1126
- */
1127
- async setDecorations(e) {
1128
- return s("plugin:window|set_decorations", {
1129
- label: this.label,
1130
- value: e
1131
- });
1132
- }
1133
- /**
1134
- * Whether or not the window should have shadow.
1135
- *
1136
- * #### Platform-specific
1137
- *
1138
- * - **Windows:**
1139
- * - `false` has no effect on decorated window, shadows are always ON.
1140
- * - `true` will make undecorated window have a 1px white border,
1141
- * and on Windows 11, it will have a rounded corners.
1142
- * - **Linux:** Unsupported.
1143
- *
1144
- * @example
1145
- * ```typescript
1146
- * import { getCurrentWindow } from '@tauri-apps/api/window';
1147
- * await getCurrentWindow().setShadow(false);
1148
- * ```
1149
- *
1150
- * @returns A promise indicating the success or failure of the operation.
1151
- */
1152
- async setShadow(e) {
1153
- return s("plugin:window|set_shadow", {
1154
- label: this.label,
1155
- value: e
1156
- });
1157
- }
1158
- /**
1159
- * Set window effects.
1160
- */
1161
- async setEffects(e) {
1162
- return s("plugin:window|set_effects", {
1163
- label: this.label,
1164
- value: e
1165
- });
1166
- }
1167
- /**
1168
- * Clear any applied effects if possible.
1169
- */
1170
- async clearEffects() {
1171
- return s("plugin:window|set_effects", {
1172
- label: this.label,
1173
- value: null
1174
- });
1175
- }
1176
- /**
1177
- * Whether the window should always be on top of other windows.
1178
- * @example
1179
- * ```typescript
1180
- * import { getCurrentWindow } from '@tauri-apps/api/window';
1181
- * await getCurrentWindow().setAlwaysOnTop(true);
1182
- * ```
1183
- *
1184
- * @param alwaysOnTop Whether the window should always be on top of other windows or not.
1185
- * @returns A promise indicating the success or failure of the operation.
1186
- */
1187
- async setAlwaysOnTop(e) {
1188
- return s("plugin:window|set_always_on_top", {
1189
- label: this.label,
1190
- value: e
1191
- });
1192
- }
1193
- /**
1194
- * Whether the window should always be below other windows.
1195
- * @example
1196
- * ```typescript
1197
- * import { getCurrentWindow } from '@tauri-apps/api/window';
1198
- * await getCurrentWindow().setAlwaysOnBottom(true);
1199
- * ```
1200
- *
1201
- * @param alwaysOnBottom Whether the window should always be below other windows or not.
1202
- * @returns A promise indicating the success or failure of the operation.
1203
- */
1204
- async setAlwaysOnBottom(e) {
1205
- return s("plugin:window|set_always_on_bottom", {
1206
- label: this.label,
1207
- value: e
1208
- });
1209
- }
1210
- /**
1211
- * Prevents the window contents from being captured by other apps.
1212
- * @example
1213
- * ```typescript
1214
- * import { getCurrentWindow } from '@tauri-apps/api/window';
1215
- * await getCurrentWindow().setContentProtected(true);
1216
- * ```
1217
- *
1218
- * @returns A promise indicating the success or failure of the operation.
1219
- */
1220
- async setContentProtected(e) {
1221
- return s("plugin:window|set_content_protected", {
1222
- label: this.label,
1223
- value: e
1224
- });
1225
- }
1226
- /**
1227
- * Resizes the window with a new inner size.
1228
- * @example
1229
- * ```typescript
1230
- * import { getCurrentWindow, LogicalSize } from '@tauri-apps/api/window';
1231
- * await getCurrentWindow().setSize(new LogicalSize(600, 500));
1232
- * ```
1233
- *
1234
- * @param size The logical or physical inner size.
1235
- * @returns A promise indicating the success or failure of the operation.
1236
- */
1237
- async setSize(e) {
1238
- return s("plugin:window|set_size", {
1239
- label: this.label,
1240
- value: e instanceof h ? e : new h(e)
1241
- });
1242
- }
1243
- /**
1244
- * Sets the window minimum inner size. If the `size` argument is not provided, the constraint is unset.
1245
- * @example
1246
- * ```typescript
1247
- * import { getCurrentWindow, PhysicalSize } from '@tauri-apps/api/window';
1248
- * await getCurrentWindow().setMinSize(new PhysicalSize(600, 500));
1249
- * ```
1250
- *
1251
- * @param size The logical or physical inner size, or `null` to unset the constraint.
1252
- * @returns A promise indicating the success or failure of the operation.
1253
- */
1254
- async setMinSize(e) {
1255
- return s("plugin:window|set_min_size", {
1256
- label: this.label,
1257
- value: e instanceof h ? e : e ? new h(e) : null
1258
- });
1259
- }
1260
- /**
1261
- * Sets the window maximum inner size. If the `size` argument is undefined, the constraint is unset.
1262
- * @example
1263
- * ```typescript
1264
- * import { getCurrentWindow, LogicalSize } from '@tauri-apps/api/window';
1265
- * await getCurrentWindow().setMaxSize(new LogicalSize(600, 500));
1266
- * ```
1267
- *
1268
- * @param size The logical or physical inner size, or `null` to unset the constraint.
1269
- * @returns A promise indicating the success or failure of the operation.
1270
- */
1271
- async setMaxSize(e) {
1272
- return s("plugin:window|set_max_size", {
1273
- label: this.label,
1274
- value: e instanceof h ? e : e ? new h(e) : null
1275
- });
1276
- }
1277
- /**
1278
- * Sets the window inner size constraints.
1279
- * @example
1280
- * ```typescript
1281
- * import { getCurrentWindow } from '@tauri-apps/api/window';
1282
- * await getCurrentWindow().setSizeConstraints({ minWidth: 300 });
1283
- * ```
1284
- *
1285
- * @param constraints The logical or physical inner size, or `null` to unset the constraint.
1286
- * @returns A promise indicating the success or failure of the operation.
1287
- */
1288
- async setSizeConstraints(e) {
1289
- function i(n) {
1290
- return n ? { Logical: n } : null;
1291
- }
1292
- return s("plugin:window|set_size_constraints", {
1293
- label: this.label,
1294
- value: {
1295
- minWidth: i(e?.minWidth),
1296
- minHeight: i(e?.minHeight),
1297
- maxWidth: i(e?.maxWidth),
1298
- maxHeight: i(e?.maxHeight)
1299
- }
1300
- });
1301
- }
1302
- /**
1303
- * Sets the window outer position.
1304
- * @example
1305
- * ```typescript
1306
- * import { getCurrentWindow, LogicalPosition } from '@tauri-apps/api/window';
1307
- * await getCurrentWindow().setPosition(new LogicalPosition(600, 500));
1308
- * ```
1309
- *
1310
- * @param position The new position, in logical or physical pixels.
1311
- * @returns A promise indicating the success or failure of the operation.
1312
- */
1313
- async setPosition(e) {
1314
- return s("plugin:window|set_position", {
1315
- label: this.label,
1316
- value: e instanceof d ? e : new d(e)
1317
- });
1318
- }
1319
- /**
1320
- * Sets the window fullscreen state.
1321
- * @example
1322
- * ```typescript
1323
- * import { getCurrentWindow } from '@tauri-apps/api/window';
1324
- * await getCurrentWindow().setFullscreen(true);
1325
- * ```
1326
- *
1327
- * @param fullscreen Whether the window should go to fullscreen or not.
1328
- * @returns A promise indicating the success or failure of the operation.
1329
- */
1330
- async setFullscreen(e) {
1331
- return s("plugin:window|set_fullscreen", {
1332
- label: this.label,
1333
- value: e
1334
- });
1335
- }
1336
- /**
1337
- * On macOS, Toggles a fullscreen mode that doesn’t require a new macOS space. Returns a boolean indicating whether the transition was successful (this won’t work if the window was already in the native fullscreen).
1338
- * This is how fullscreen used to work on macOS in versions before Lion. And allows the user to have a fullscreen window without using another space or taking control over the entire monitor.
1339
- *
1340
- * On other platforms, this is the same as {@link Window.setFullscreen}.
1341
- *
1342
- * @param fullscreen Whether the window should go to simple fullscreen or not.
1343
- * @returns A promise indicating the success or failure of the operation.
1344
- */
1345
- async setSimpleFullscreen(e) {
1346
- return s("plugin:window|set_simple_fullscreen", {
1347
- label: this.label,
1348
- value: e
1349
- });
1350
- }
1351
- /**
1352
- * Bring the window to front and focus.
1353
- * @example
1354
- * ```typescript
1355
- * import { getCurrentWindow } from '@tauri-apps/api/window';
1356
- * await getCurrentWindow().setFocus();
1357
- * ```
1358
- *
1359
- * @returns A promise indicating the success or failure of the operation.
1360
- */
1361
- async setFocus() {
1362
- return s("plugin:window|set_focus", {
1363
- label: this.label
1364
- });
1365
- }
1366
- /**
1367
- * Sets whether the window can be focused.
1368
- *
1369
- * #### Platform-specific
1370
- *
1371
- * - **macOS**: If the window is already focused, it is not possible to unfocus it after calling `set_focusable(false)`.
1372
- * In this case, you might consider calling {@link Window.setFocus} but it will move the window to the back i.e. at the bottom in terms of z-order.
1373
- *
1374
- * @example
1375
- * ```typescript
1376
- * import { getCurrentWindow } from '@tauri-apps/api/window';
1377
- * await getCurrentWindow().setFocusable(true);
1378
- * ```
1379
- *
1380
- * @param focusable Whether the window can be focused.
1381
- * @returns A promise indicating the success or failure of the operation.
1382
- */
1383
- async setFocusable(e) {
1384
- return s("plugin:window|set_focusable", {
1385
- label: this.label,
1386
- value: e
1387
- });
1388
- }
1389
- /**
1390
- * Sets the window icon.
1391
- * @example
1392
- * ```typescript
1393
- * import { getCurrentWindow } from '@tauri-apps/api/window';
1394
- * await getCurrentWindow().setIcon('/tauri/awesome.png');
1395
- * ```
1396
- *
1397
- * Note that you may need the `image-ico` or `image-png` Cargo features to use this API.
1398
- * To enable it, change your Cargo.toml file:
1399
- * ```toml
1400
- * [dependencies]
1401
- * tauri = { version = "...", features = ["...", "image-png"] }
1402
- * ```
1403
- *
1404
- * @param icon Icon bytes or path to the icon file.
1405
- * @returns A promise indicating the success or failure of the operation.
1406
- */
1407
- async setIcon(e) {
1408
- return s("plugin:window|set_icon", {
1409
- label: this.label,
1410
- value: O(e)
1411
- });
1412
- }
1413
- /**
1414
- * Whether the window icon should be hidden from the taskbar or not.
1415
- *
1416
- * #### Platform-specific
1417
- *
1418
- * - **macOS:** Unsupported.
1419
- * @example
1420
- * ```typescript
1421
- * import { getCurrentWindow } from '@tauri-apps/api/window';
1422
- * await getCurrentWindow().setSkipTaskbar(true);
1423
- * ```
1424
- *
1425
- * @param skip true to hide window icon, false to show it.
1426
- * @returns A promise indicating the success or failure of the operation.
1427
- */
1428
- async setSkipTaskbar(e) {
1429
- return s("plugin:window|set_skip_taskbar", {
1430
- label: this.label,
1431
- value: e
1432
- });
1433
- }
1434
- /**
1435
- * Grabs the cursor, preventing it from leaving the window.
1436
- *
1437
- * There's no guarantee that the cursor will be hidden. You should
1438
- * hide it by yourself if you want so.
1439
- *
1440
- * #### Platform-specific
1441
- *
1442
- * - **Linux:** Unsupported.
1443
- * - **macOS:** This locks the cursor in a fixed location, which looks visually awkward.
1444
- * @example
1445
- * ```typescript
1446
- * import { getCurrentWindow } from '@tauri-apps/api/window';
1447
- * await getCurrentWindow().setCursorGrab(true);
1448
- * ```
1449
- *
1450
- * @param grab `true` to grab the cursor icon, `false` to release it.
1451
- * @returns A promise indicating the success or failure of the operation.
1452
- */
1453
- async setCursorGrab(e) {
1454
- return s("plugin:window|set_cursor_grab", {
1455
- label: this.label,
1456
- value: e
1457
- });
1458
- }
1459
- /**
1460
- * Modifies the cursor's visibility.
1461
- *
1462
- * #### Platform-specific
1463
- *
1464
- * - **Windows:** The cursor is only hidden within the confines of the window.
1465
- * - **macOS:** The cursor is hidden as long as the window has input focus, even if the cursor is
1466
- * outside of the window.
1467
- * @example
1468
- * ```typescript
1469
- * import { getCurrentWindow } from '@tauri-apps/api/window';
1470
- * await getCurrentWindow().setCursorVisible(false);
1471
- * ```
1472
- *
1473
- * @param visible If `false`, this will hide the cursor. If `true`, this will show the cursor.
1474
- * @returns A promise indicating the success or failure of the operation.
1475
- */
1476
- async setCursorVisible(e) {
1477
- return s("plugin:window|set_cursor_visible", {
1478
- label: this.label,
1479
- value: e
1480
- });
1481
- }
1482
- /**
1483
- * Modifies the cursor icon of the window.
1484
- * @example
1485
- * ```typescript
1486
- * import { getCurrentWindow } from '@tauri-apps/api/window';
1487
- * await getCurrentWindow().setCursorIcon('help');
1488
- * ```
1489
- *
1490
- * @param icon The new cursor icon.
1491
- * @returns A promise indicating the success or failure of the operation.
1492
- */
1493
- async setCursorIcon(e) {
1494
- return s("plugin:window|set_cursor_icon", {
1495
- label: this.label,
1496
- value: e
1497
- });
1498
- }
1499
- /**
1500
- * Sets the window background color.
1501
- *
1502
- * #### Platform-specific:
1503
- *
1504
- * - **Windows:** alpha channel is ignored.
1505
- * - **iOS / Android:** Unsupported.
1506
- *
1507
- * @returns A promise indicating the success or failure of the operation.
1508
- *
1509
- * @since 2.1.0
1510
- */
1511
- async setBackgroundColor(e) {
1512
- return s("plugin:window|set_background_color", { color: e });
1513
- }
1514
- /**
1515
- * Changes the position of the cursor in window coordinates.
1516
- * @example
1517
- * ```typescript
1518
- * import { getCurrentWindow, LogicalPosition } from '@tauri-apps/api/window';
1519
- * await getCurrentWindow().setCursorPosition(new LogicalPosition(600, 300));
1520
- * ```
1521
- *
1522
- * @param position The new cursor position.
1523
- * @returns A promise indicating the success or failure of the operation.
1524
- */
1525
- async setCursorPosition(e) {
1526
- return s("plugin:window|set_cursor_position", {
1527
- label: this.label,
1528
- value: e instanceof d ? e : new d(e)
1529
- });
1530
- }
1531
- /**
1532
- * Changes the cursor events behavior.
1533
- *
1534
- * @example
1535
- * ```typescript
1536
- * import { getCurrentWindow } from '@tauri-apps/api/window';
1537
- * await getCurrentWindow().setIgnoreCursorEvents(true);
1538
- * ```
1539
- *
1540
- * @param ignore `true` to ignore the cursor events; `false` to process them as usual.
1541
- * @returns A promise indicating the success or failure of the operation.
1542
- */
1543
- async setIgnoreCursorEvents(e) {
1544
- return s("plugin:window|set_ignore_cursor_events", {
1545
- label: this.label,
1546
- value: e
1547
- });
1548
- }
1549
- /**
1550
- * Starts dragging the window.
1551
- * @example
1552
- * ```typescript
1553
- * import { getCurrentWindow } from '@tauri-apps/api/window';
1554
- * await getCurrentWindow().startDragging();
1555
- * ```
1556
- *
1557
- * @return A promise indicating the success or failure of the operation.
1558
- */
1559
- async startDragging() {
1560
- return s("plugin:window|start_dragging", {
1561
- label: this.label
1562
- });
1563
- }
1564
- /**
1565
- * Starts resize-dragging the window.
1566
- * @example
1567
- * ```typescript
1568
- * import { getCurrentWindow } from '@tauri-apps/api/window';
1569
- * await getCurrentWindow().startResizeDragging();
1570
- * ```
1571
- *
1572
- * @return A promise indicating the success or failure of the operation.
1573
- */
1574
- async startResizeDragging(e) {
1575
- return s("plugin:window|start_resize_dragging", {
1576
- label: this.label,
1577
- value: e
1578
- });
1579
- }
1580
- /**
1581
- * Sets the badge count. It is app wide and not specific to this window.
1582
- *
1583
- * #### Platform-specific
1584
- *
1585
- * - **Windows**: Unsupported. Use @{linkcode Window.setOverlayIcon} instead.
1586
- *
1587
- * @example
1588
- * ```typescript
1589
- * import { getCurrentWindow } from '@tauri-apps/api/window';
1590
- * await getCurrentWindow().setBadgeCount(5);
1591
- * ```
1592
- *
1593
- * @param count The badge count. Use `undefined` to remove the badge.
1594
- * @return A promise indicating the success or failure of the operation.
1595
- */
1596
- async setBadgeCount(e) {
1597
- return s("plugin:window|set_badge_count", {
1598
- label: this.label,
1599
- value: e
1600
- });
1601
- }
1602
- /**
1603
- * Sets the badge cont **macOS only**.
1604
- *
1605
- * @example
1606
- * ```typescript
1607
- * import { getCurrentWindow } from '@tauri-apps/api/window';
1608
- * await getCurrentWindow().setBadgeLabel("Hello");
1609
- * ```
1610
- *
1611
- * @param label The badge label. Use `undefined` to remove the badge.
1612
- * @return A promise indicating the success or failure of the operation.
1613
- */
1614
- async setBadgeLabel(e) {
1615
- return s("plugin:window|set_badge_label", {
1616
- label: this.label,
1617
- value: e
1618
- });
1619
- }
1620
- /**
1621
- * Sets the overlay icon. **Windows only**
1622
- * The overlay icon can be set for every window.
1623
- *
1624
- *
1625
- * Note that you may need the `image-ico` or `image-png` Cargo features to use this API.
1626
- * To enable it, change your Cargo.toml file:
1627
- *
1628
- * ```toml
1629
- * [dependencies]
1630
- * tauri = { version = "...", features = ["...", "image-png"] }
1631
- * ```
1632
- *
1633
- * @example
1634
- * ```typescript
1635
- * import { getCurrentWindow } from '@tauri-apps/api/window';
1636
- * await getCurrentWindow().setOverlayIcon("/tauri/awesome.png");
1637
- * ```
1638
- *
1639
- * @param icon Icon bytes or path to the icon file. Use `undefined` to remove the overlay icon.
1640
- * @return A promise indicating the success or failure of the operation.
1641
- */
1642
- async setOverlayIcon(e) {
1643
- return s("plugin:window|set_overlay_icon", {
1644
- label: this.label,
1645
- value: e ? O(e) : void 0
1646
- });
1647
- }
1648
- /**
1649
- * Sets the taskbar progress state.
1650
- *
1651
- * #### Platform-specific
1652
- *
1653
- * - **Linux / macOS**: Progress bar is app-wide and not specific to this window.
1654
- * - **Linux**: Only supported desktop environments with `libunity` (e.g. GNOME).
1655
- *
1656
- * @example
1657
- * ```typescript
1658
- * import { getCurrentWindow, ProgressBarStatus } from '@tauri-apps/api/window';
1659
- * await getCurrentWindow().setProgressBar({
1660
- * status: ProgressBarStatus.Normal,
1661
- * progress: 50,
1662
- * });
1663
- * ```
1664
- *
1665
- * @return A promise indicating the success or failure of the operation.
1666
- */
1667
- async setProgressBar(e) {
1668
- return s("plugin:window|set_progress_bar", {
1669
- label: this.label,
1670
- value: e
1671
- });
1672
- }
1673
- /**
1674
- * Sets whether the window should be visible on all workspaces or virtual desktops.
1675
- *
1676
- * #### Platform-specific
1677
- *
1678
- * - **Windows / iOS / Android:** Unsupported.
1679
- *
1680
- * @since 2.0.0
1681
- */
1682
- async setVisibleOnAllWorkspaces(e) {
1683
- return s("plugin:window|set_visible_on_all_workspaces", {
1684
- label: this.label,
1685
- value: e
1686
- });
1687
- }
1688
- /**
1689
- * Sets the title bar style. **macOS only**.
1690
- *
1691
- * @since 2.0.0
1692
- */
1693
- async setTitleBarStyle(e) {
1694
- return s("plugin:window|set_title_bar_style", {
1695
- label: this.label,
1696
- value: e
1697
- });
1698
- }
1699
- /**
1700
- * Set window theme, pass in `null` or `undefined` to follow system theme
1701
- *
1702
- * #### Platform-specific
1703
- *
1704
- * - **Linux / macOS**: Theme is app-wide and not specific to this window.
1705
- * - **iOS / Android:** Unsupported.
1706
- *
1707
- * @since 2.0.0
1708
- */
1709
- async setTheme(e) {
1710
- return s("plugin:window|set_theme", {
1711
- label: this.label,
1712
- value: e
1713
- });
1714
- }
1715
- // Listeners
1716
- /**
1717
- * Listen to window resize.
1718
- *
1719
- * @example
1720
- * ```typescript
1721
- * import { getCurrentWindow } from "@tauri-apps/api/window";
1722
- * const unlisten = await getCurrentWindow().onResized(({ payload: size }) => {
1723
- * console.log('Window resized', size);
1724
- * });
1725
- *
1726
- * // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
1727
- * unlisten();
1728
- * ```
1729
- *
1730
- * @returns A promise resolving to a function to unlisten to the event.
1731
- * Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
1732
- */
1733
- async onResized(e) {
1734
- return this.listen(r.WINDOW_RESIZED, (i) => {
1735
- i.payload = new w(i.payload), e(i);
1736
- });
1737
- }
1738
- /**
1739
- * Listen to window move.
1740
- *
1741
- * @example
1742
- * ```typescript
1743
- * import { getCurrentWindow } from "@tauri-apps/api/window";
1744
- * const unlisten = await getCurrentWindow().onMoved(({ payload: position }) => {
1745
- * console.log('Window moved', position);
1746
- * });
1747
- *
1748
- * // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
1749
- * unlisten();
1750
- * ```
1751
- *
1752
- * @returns A promise resolving to a function to unlisten to the event.
1753
- * Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
1754
- */
1755
- async onMoved(e) {
1756
- return this.listen(r.WINDOW_MOVED, (i) => {
1757
- i.payload = new u(i.payload), e(i);
1758
- });
1759
- }
1760
- /**
1761
- * Listen to window close requested. Emitted when the user requests to closes the window.
1762
- *
1763
- * @example
1764
- * ```typescript
1765
- * import { getCurrentWindow } from "@tauri-apps/api/window";
1766
- * import { confirm } from '@tauri-apps/api/dialog';
1767
- * const unlisten = await getCurrentWindow().onCloseRequested(async (event) => {
1768
- * const confirmed = await confirm('Are you sure?');
1769
- * if (!confirmed) {
1770
- * // user did not confirm closing the window; let's prevent it
1771
- * event.preventDefault();
1772
- * }
1773
- * });
1774
- *
1775
- * // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
1776
- * unlisten();
1777
- * ```
1778
- *
1779
- * @returns A promise resolving to a function to unlisten to the event.
1780
- * Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
1781
- */
1782
- async onCloseRequested(e) {
1783
- return this.listen(r.WINDOW_CLOSE_REQUESTED, async (i) => {
1784
- const n = new he(i);
1785
- await e(n), n.isPreventDefault() || await this.destroy();
1786
- });
1787
- }
1788
- /**
1789
- * Listen to a file drop event.
1790
- * The listener is triggered when the user hovers the selected files on the webview,
1791
- * drops the files or cancels the operation.
1792
- *
1793
- * @example
1794
- * ```typescript
1795
- * import { getCurrentWindow } from "@tauri-apps/api/webview";
1796
- * const unlisten = await getCurrentWindow().onDragDropEvent((event) => {
1797
- * if (event.payload.type === 'over') {
1798
- * console.log('User hovering', event.payload.position);
1799
- * } else if (event.payload.type === 'drop') {
1800
- * console.log('User dropped', event.payload.paths);
1801
- * } else {
1802
- * console.log('File drop cancelled');
1803
- * }
1804
- * });
1805
- *
1806
- * // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
1807
- * unlisten();
1808
- * ```
1809
- *
1810
- * @returns A promise resolving to a function to unlisten to the event.
1811
- * Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
1812
- */
1813
- async onDragDropEvent(e) {
1814
- const i = await this.listen(r.DRAG_ENTER, (a) => {
1815
- e({
1816
- ...a,
1817
- payload: {
1818
- type: "enter",
1819
- paths: a.payload.paths,
1820
- position: new u(a.payload.position)
1821
- }
1822
- });
1823
- }), n = await this.listen(r.DRAG_OVER, (a) => {
1824
- e({
1825
- ...a,
1826
- payload: {
1827
- type: "over",
1828
- position: new u(a.payload.position)
1829
- }
1830
- });
1831
- }), l = await this.listen(r.DRAG_DROP, (a) => {
1832
- e({
1833
- ...a,
1834
- payload: {
1835
- type: "drop",
1836
- paths: a.payload.paths,
1837
- position: new u(a.payload.position)
1838
- }
1839
- });
1840
- }), o = await this.listen(r.DRAG_LEAVE, (a) => {
1841
- e({ ...a, payload: { type: "leave" } });
1842
- });
1843
- return () => {
1844
- i(), l(), n(), o();
1845
- };
1846
- }
1847
- /**
1848
- * Listen to window focus change.
1849
- *
1850
- * @example
1851
- * ```typescript
1852
- * import { getCurrentWindow } from "@tauri-apps/api/window";
1853
- * const unlisten = await getCurrentWindow().onFocusChanged(({ payload: focused }) => {
1854
- * console.log('Focus changed, window is focused? ' + focused);
1855
- * });
1856
- *
1857
- * // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
1858
- * unlisten();
1859
- * ```
1860
- *
1861
- * @returns A promise resolving to a function to unlisten to the event.
1862
- * Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
1863
- */
1864
- async onFocusChanged(e) {
1865
- const i = await this.listen(r.WINDOW_FOCUS, (l) => {
1866
- e({ ...l, payload: !0 });
1867
- }), n = await this.listen(r.WINDOW_BLUR, (l) => {
1868
- e({ ...l, payload: !1 });
1869
- });
1870
- return () => {
1871
- i(), n();
1872
- };
1873
- }
1874
- /**
1875
- * Listen to window scale change. Emitted when the window's scale factor has changed.
1876
- * The following user actions can cause DPI changes:
1877
- * - Changing the display's resolution.
1878
- * - Changing the display's scale factor (e.g. in Control Panel on Windows).
1879
- * - Moving the window to a display with a different scale factor.
1880
- *
1881
- * @example
1882
- * ```typescript
1883
- * import { getCurrentWindow } from "@tauri-apps/api/window";
1884
- * const unlisten = await getCurrentWindow().onScaleChanged(({ payload }) => {
1885
- * console.log('Scale changed', payload.scaleFactor, payload.size);
1886
- * });
1887
- *
1888
- * // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
1889
- * unlisten();
1890
- * ```
1891
- *
1892
- * @returns A promise resolving to a function to unlisten to the event.
1893
- * Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
1894
- */
1895
- async onScaleChanged(e) {
1896
- return this.listen(r.WINDOW_SCALE_FACTOR_CHANGED, e);
1897
- }
1898
- /**
1899
- * Listen to the system theme change.
1900
- *
1901
- * @example
1902
- * ```typescript
1903
- * import { getCurrentWindow } from "@tauri-apps/api/window";
1904
- * const unlisten = await getCurrentWindow().onThemeChanged(({ payload: theme }) => {
1905
- * console.log('New theme: ' + theme);
1906
- * });
1907
- *
1908
- * // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
1909
- * unlisten();
1910
- * ```
1911
- *
1912
- * @returns A promise resolving to a function to unlisten to the event.
1913
- * Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
1914
- */
1915
- async onThemeChanged(e) {
1916
- return this.listen(r.WINDOW_THEME_CHANGED, e);
1917
- }
233
+ async function M() {
234
+ return p("plugin:window|get_all_windows").then((e) => e.map((e) => new P(e, { skip: !0 })));
1918
235
  }
236
+ var N = ["tauri://created", "tauri://error"], P = class {
237
+ constructor(e, t = {}) {
238
+ this.label = e, this.listeners = Object.create(null), t?.skip || p("plugin:window|create", { options: {
239
+ ...t,
240
+ parent: typeof t.parent == "string" ? t.parent : t.parent?.label,
241
+ label: e
242
+ } }).then(async () => this.emit("tauri://created")).catch(async (e) => this.emit("tauri://error", e));
243
+ }
244
+ static async getByLabel(e) {
245
+ return (await M()).find((t) => t.label === e) ?? null;
246
+ }
247
+ static getCurrent() {
248
+ return j();
249
+ }
250
+ static async getAll() {
251
+ return M();
252
+ }
253
+ static async getFocusedWindow() {
254
+ for (let e of await M()) if (await e.isFocused()) return e;
255
+ return null;
256
+ }
257
+ async listen(e, t) {
258
+ return this._handleTauriEvent(e, t) ? () => {
259
+ let n = this.listeners[e];
260
+ n.splice(n.indexOf(t), 1);
261
+ } : g(e, t, { target: {
262
+ kind: "Window",
263
+ label: this.label
264
+ } });
265
+ }
266
+ async once(e, t) {
267
+ return this._handleTauriEvent(e, t) ? () => {
268
+ let n = this.listeners[e];
269
+ n.splice(n.indexOf(t), 1);
270
+ } : _(e, t, { target: {
271
+ kind: "Window",
272
+ label: this.label
273
+ } });
274
+ }
275
+ async emit(e, t) {
276
+ if (N.includes(e)) {
277
+ for (let n of this.listeners[e] || []) n({
278
+ event: e,
279
+ id: -1,
280
+ payload: t
281
+ });
282
+ return;
283
+ }
284
+ return v(e, t);
285
+ }
286
+ async emitTo(e, t, n) {
287
+ if (N.includes(t)) {
288
+ for (let e of this.listeners[t] || []) e({
289
+ event: t,
290
+ id: -1,
291
+ payload: n
292
+ });
293
+ return;
294
+ }
295
+ return y(e, t, n);
296
+ }
297
+ _handleTauriEvent(e, t) {
298
+ return N.includes(e) ? (e in this.listeners ? this.listeners[e].push(t) : this.listeners[e] = [t], !0) : !1;
299
+ }
300
+ async scaleFactor() {
301
+ return p("plugin:window|scale_factor", { label: this.label });
302
+ }
303
+ async innerPosition() {
304
+ return p("plugin:window|inner_position", { label: this.label }).then((e) => new w(e));
305
+ }
306
+ async outerPosition() {
307
+ return p("plugin:window|outer_position", { label: this.label }).then((e) => new w(e));
308
+ }
309
+ async innerSize() {
310
+ return p("plugin:window|inner_size", { label: this.label }).then((e) => new x(e));
311
+ }
312
+ async outerSize() {
313
+ return p("plugin:window|outer_size", { label: this.label }).then((e) => new x(e));
314
+ }
315
+ async isFullscreen() {
316
+ return p("plugin:window|is_fullscreen", { label: this.label });
317
+ }
318
+ async isMinimized() {
319
+ return p("plugin:window|is_minimized", { label: this.label });
320
+ }
321
+ async isMaximized() {
322
+ return p("plugin:window|is_maximized", { label: this.label });
323
+ }
324
+ async isFocused() {
325
+ return p("plugin:window|is_focused", { label: this.label });
326
+ }
327
+ async isDecorated() {
328
+ return p("plugin:window|is_decorated", { label: this.label });
329
+ }
330
+ async isResizable() {
331
+ return p("plugin:window|is_resizable", { label: this.label });
332
+ }
333
+ async isMaximizable() {
334
+ return p("plugin:window|is_maximizable", { label: this.label });
335
+ }
336
+ async isMinimizable() {
337
+ return p("plugin:window|is_minimizable", { label: this.label });
338
+ }
339
+ async isClosable() {
340
+ return p("plugin:window|is_closable", { label: this.label });
341
+ }
342
+ async isVisible() {
343
+ return p("plugin:window|is_visible", { label: this.label });
344
+ }
345
+ async title() {
346
+ return p("plugin:window|title", { label: this.label });
347
+ }
348
+ async theme() {
349
+ return p("plugin:window|theme", { label: this.label });
350
+ }
351
+ async isAlwaysOnTop() {
352
+ return p("plugin:window|is_always_on_top", { label: this.label });
353
+ }
354
+ async center() {
355
+ return p("plugin:window|center", { label: this.label });
356
+ }
357
+ async requestUserAttention(e) {
358
+ let t = null;
359
+ return e && (t = e === O.Critical ? { type: "Critical" } : { type: "Informational" }), p("plugin:window|request_user_attention", {
360
+ label: this.label,
361
+ value: t
362
+ });
363
+ }
364
+ async setResizable(e) {
365
+ return p("plugin:window|set_resizable", {
366
+ label: this.label,
367
+ value: e
368
+ });
369
+ }
370
+ async setEnabled(e) {
371
+ return p("plugin:window|set_enabled", {
372
+ label: this.label,
373
+ value: e
374
+ });
375
+ }
376
+ async isEnabled() {
377
+ return p("plugin:window|is_enabled", { label: this.label });
378
+ }
379
+ async setMaximizable(e) {
380
+ return p("plugin:window|set_maximizable", {
381
+ label: this.label,
382
+ value: e
383
+ });
384
+ }
385
+ async setMinimizable(e) {
386
+ return p("plugin:window|set_minimizable", {
387
+ label: this.label,
388
+ value: e
389
+ });
390
+ }
391
+ async setClosable(e) {
392
+ return p("plugin:window|set_closable", {
393
+ label: this.label,
394
+ value: e
395
+ });
396
+ }
397
+ async setTitle(e) {
398
+ return p("plugin:window|set_title", {
399
+ label: this.label,
400
+ value: e
401
+ });
402
+ }
403
+ async maximize() {
404
+ return p("plugin:window|maximize", { label: this.label });
405
+ }
406
+ async unmaximize() {
407
+ return p("plugin:window|unmaximize", { label: this.label });
408
+ }
409
+ async toggleMaximize() {
410
+ return p("plugin:window|toggle_maximize", { label: this.label });
411
+ }
412
+ async minimize() {
413
+ return p("plugin:window|minimize", { label: this.label });
414
+ }
415
+ async unminimize() {
416
+ return p("plugin:window|unminimize", { label: this.label });
417
+ }
418
+ async show() {
419
+ return p("plugin:window|show", { label: this.label });
420
+ }
421
+ async hide() {
422
+ return p("plugin:window|hide", { label: this.label });
423
+ }
424
+ async close() {
425
+ return p("plugin:window|close", { label: this.label });
426
+ }
427
+ async destroy() {
428
+ return p("plugin:window|destroy", { label: this.label });
429
+ }
430
+ async setDecorations(e) {
431
+ return p("plugin:window|set_decorations", {
432
+ label: this.label,
433
+ value: e
434
+ });
435
+ }
436
+ async setShadow(e) {
437
+ return p("plugin:window|set_shadow", {
438
+ label: this.label,
439
+ value: e
440
+ });
441
+ }
442
+ async setEffects(e) {
443
+ return p("plugin:window|set_effects", {
444
+ label: this.label,
445
+ value: e
446
+ });
447
+ }
448
+ async clearEffects() {
449
+ return p("plugin:window|set_effects", {
450
+ label: this.label,
451
+ value: null
452
+ });
453
+ }
454
+ async setAlwaysOnTop(e) {
455
+ return p("plugin:window|set_always_on_top", {
456
+ label: this.label,
457
+ value: e
458
+ });
459
+ }
460
+ async setAlwaysOnBottom(e) {
461
+ return p("plugin:window|set_always_on_bottom", {
462
+ label: this.label,
463
+ value: e
464
+ });
465
+ }
466
+ async setContentProtected(e) {
467
+ return p("plugin:window|set_content_protected", {
468
+ label: this.label,
469
+ value: e
470
+ });
471
+ }
472
+ async setSize(e) {
473
+ return p("plugin:window|set_size", {
474
+ label: this.label,
475
+ value: e instanceof S ? e : new S(e)
476
+ });
477
+ }
478
+ async setMinSize(e) {
479
+ return p("plugin:window|set_min_size", {
480
+ label: this.label,
481
+ value: e instanceof S ? e : e ? new S(e) : null
482
+ });
483
+ }
484
+ async setMaxSize(e) {
485
+ return p("plugin:window|set_max_size", {
486
+ label: this.label,
487
+ value: e instanceof S ? e : e ? new S(e) : null
488
+ });
489
+ }
490
+ async setSizeConstraints(e) {
491
+ function t(e) {
492
+ return e ? { Logical: e } : null;
493
+ }
494
+ return p("plugin:window|set_size_constraints", {
495
+ label: this.label,
496
+ value: {
497
+ minWidth: t(e?.minWidth),
498
+ minHeight: t(e?.minHeight),
499
+ maxWidth: t(e?.maxWidth),
500
+ maxHeight: t(e?.maxHeight)
501
+ }
502
+ });
503
+ }
504
+ async setPosition(e) {
505
+ return p("plugin:window|set_position", {
506
+ label: this.label,
507
+ value: e instanceof T ? e : new T(e)
508
+ });
509
+ }
510
+ async setFullscreen(e) {
511
+ return p("plugin:window|set_fullscreen", {
512
+ label: this.label,
513
+ value: e
514
+ });
515
+ }
516
+ async setSimpleFullscreen(e) {
517
+ return p("plugin:window|set_simple_fullscreen", {
518
+ label: this.label,
519
+ value: e
520
+ });
521
+ }
522
+ async setFocus() {
523
+ return p("plugin:window|set_focus", { label: this.label });
524
+ }
525
+ async setFocusable(e) {
526
+ return p("plugin:window|set_focusable", {
527
+ label: this.label,
528
+ value: e
529
+ });
530
+ }
531
+ async setIcon(e) {
532
+ return p("plugin:window|set_icon", {
533
+ label: this.label,
534
+ value: D(e)
535
+ });
536
+ }
537
+ async setSkipTaskbar(e) {
538
+ return p("plugin:window|set_skip_taskbar", {
539
+ label: this.label,
540
+ value: e
541
+ });
542
+ }
543
+ async setCursorGrab(e) {
544
+ return p("plugin:window|set_cursor_grab", {
545
+ label: this.label,
546
+ value: e
547
+ });
548
+ }
549
+ async setCursorVisible(e) {
550
+ return p("plugin:window|set_cursor_visible", {
551
+ label: this.label,
552
+ value: e
553
+ });
554
+ }
555
+ async setCursorIcon(e) {
556
+ return p("plugin:window|set_cursor_icon", {
557
+ label: this.label,
558
+ value: e
559
+ });
560
+ }
561
+ async setBackgroundColor(e) {
562
+ return p("plugin:window|set_background_color", { color: e });
563
+ }
564
+ async setCursorPosition(e) {
565
+ return p("plugin:window|set_cursor_position", {
566
+ label: this.label,
567
+ value: e instanceof T ? e : new T(e)
568
+ });
569
+ }
570
+ async setIgnoreCursorEvents(e) {
571
+ return p("plugin:window|set_ignore_cursor_events", {
572
+ label: this.label,
573
+ value: e
574
+ });
575
+ }
576
+ async startDragging() {
577
+ return p("plugin:window|start_dragging", { label: this.label });
578
+ }
579
+ async startResizeDragging(e) {
580
+ return p("plugin:window|start_resize_dragging", {
581
+ label: this.label,
582
+ value: e
583
+ });
584
+ }
585
+ async setBadgeCount(e) {
586
+ return p("plugin:window|set_badge_count", {
587
+ label: this.label,
588
+ value: e
589
+ });
590
+ }
591
+ async setBadgeLabel(e) {
592
+ return p("plugin:window|set_badge_label", {
593
+ label: this.label,
594
+ value: e
595
+ });
596
+ }
597
+ async setOverlayIcon(e) {
598
+ return p("plugin:window|set_overlay_icon", {
599
+ label: this.label,
600
+ value: e ? D(e) : void 0
601
+ });
602
+ }
603
+ async setProgressBar(e) {
604
+ return p("plugin:window|set_progress_bar", {
605
+ label: this.label,
606
+ value: e
607
+ });
608
+ }
609
+ async setVisibleOnAllWorkspaces(e) {
610
+ return p("plugin:window|set_visible_on_all_workspaces", {
611
+ label: this.label,
612
+ value: e
613
+ });
614
+ }
615
+ async setTitleBarStyle(e) {
616
+ return p("plugin:window|set_title_bar_style", {
617
+ label: this.label,
618
+ value: e
619
+ });
620
+ }
621
+ async setTheme(e) {
622
+ return p("plugin:window|set_theme", {
623
+ label: this.label,
624
+ value: e
625
+ });
626
+ }
627
+ async onResized(e) {
628
+ return this.listen(m.WINDOW_RESIZED, (t) => {
629
+ t.payload = new x(t.payload), e(t);
630
+ });
631
+ }
632
+ async onMoved(e) {
633
+ return this.listen(m.WINDOW_MOVED, (t) => {
634
+ t.payload = new w(t.payload), e(t);
635
+ });
636
+ }
637
+ async onCloseRequested(e) {
638
+ return this.listen(m.WINDOW_CLOSE_REQUESTED, async (t) => {
639
+ let n = new k(t);
640
+ await e(n), n.isPreventDefault() || await this.destroy();
641
+ });
642
+ }
643
+ async onDragDropEvent(e) {
644
+ let t = await this.listen(m.DRAG_ENTER, (t) => {
645
+ e({
646
+ ...t,
647
+ payload: {
648
+ type: "enter",
649
+ paths: t.payload.paths,
650
+ position: new w(t.payload.position)
651
+ }
652
+ });
653
+ }), n = await this.listen(m.DRAG_OVER, (t) => {
654
+ e({
655
+ ...t,
656
+ payload: {
657
+ type: "over",
658
+ position: new w(t.payload.position)
659
+ }
660
+ });
661
+ }), r = await this.listen(m.DRAG_DROP, (t) => {
662
+ e({
663
+ ...t,
664
+ payload: {
665
+ type: "drop",
666
+ paths: t.payload.paths,
667
+ position: new w(t.payload.position)
668
+ }
669
+ });
670
+ }), i = await this.listen(m.DRAG_LEAVE, (t) => {
671
+ e({
672
+ ...t,
673
+ payload: { type: "leave" }
674
+ });
675
+ });
676
+ return () => {
677
+ t(), r(), n(), i();
678
+ };
679
+ }
680
+ async onFocusChanged(e) {
681
+ let t = await this.listen(m.WINDOW_FOCUS, (t) => {
682
+ e({
683
+ ...t,
684
+ payload: !0
685
+ });
686
+ }), n = await this.listen(m.WINDOW_BLUR, (t) => {
687
+ e({
688
+ ...t,
689
+ payload: !1
690
+ });
691
+ });
692
+ return () => {
693
+ t(), n();
694
+ };
695
+ }
696
+ async onScaleChanged(e) {
697
+ return this.listen(m.WINDOW_SCALE_FACTOR_CHANGED, e);
698
+ }
699
+ async onThemeChanged(e) {
700
+ return this.listen(m.WINDOW_THEME_CHANGED, e);
701
+ }
702
+ }, ne;
703
+ (function(e) {
704
+ e.Disabled = "disabled", e.Throttle = "throttle", e.Suspend = "suspend";
705
+ })(ne ||= {});
706
+ var re;
707
+ (function(e) {
708
+ e.Default = "default", e.FluentOverlay = "fluentOverlay";
709
+ })(re ||= {});
1919
710
  var F;
1920
- (function(t) {
1921
- t.Disabled = "disabled", t.Throttle = "throttle", t.Suspend = "suspend";
1922
- })(F || (F = {}));
1923
- var B;
1924
- (function(t) {
1925
- t.Default = "default", t.FluentOverlay = "fluentOverlay";
1926
- })(B || (B = {}));
1927
- var V;
1928
- (function(t) {
1929
- t.AppearanceBased = "appearanceBased", t.Light = "light", t.Dark = "dark", t.MediumLight = "mediumLight", t.UltraDark = "ultraDark", t.Titlebar = "titlebar", t.Selection = "selection", t.Menu = "menu", t.Popover = "popover", t.Sidebar = "sidebar", t.HeaderView = "headerView", t.Sheet = "sheet", t.WindowBackground = "windowBackground", t.HudWindow = "hudWindow", t.FullScreenUI = "fullScreenUI", t.Tooltip = "tooltip", t.ContentBackground = "contentBackground", t.UnderWindowBackground = "underWindowBackground", t.UnderPageBackground = "underPageBackground", t.Mica = "mica", t.Blur = "blur", t.Acrylic = "acrylic", t.Tabbed = "tabbed", t.TabbedDark = "tabbedDark", t.TabbedLight = "tabbedLight";
1930
- })(V || (V = {}));
1931
- var U;
1932
- (function(t) {
1933
- t.FollowsWindowActiveState = "followsWindowActiveState", t.Active = "active", t.Inactive = "inactive";
1934
- })(U || (U = {}));
1935
- function we(t) {
1936
- return t === null ? null : {
1937
- name: t.name,
1938
- scaleFactor: t.scaleFactor,
1939
- position: new u(t.position),
1940
- size: new w(t.size),
1941
- workArea: {
1942
- position: new u(t.workArea.position),
1943
- size: new w(t.workArea.size)
1944
- }
1945
- };
1946
- }
1947
- async function be() {
1948
- return s("plugin:window|available_monitors").then((t) => t.map(we));
1949
- }
1950
- function Y() {
1951
- return new C(Z(), window.__TAURI_INTERNALS__.metadata.currentWebview.label, {
1952
- // @ts-expect-error `skip` is not defined in the public API but it is handled by the constructor
1953
- skip: !0
1954
- });
711
+ (function(e) {
712
+ e.AppearanceBased = "appearanceBased", e.Light = "light", e.Dark = "dark", e.MediumLight = "mediumLight", e.UltraDark = "ultraDark", e.Titlebar = "titlebar", e.Selection = "selection", e.Menu = "menu", e.Popover = "popover", e.Sidebar = "sidebar", e.HeaderView = "headerView", e.Sheet = "sheet", e.WindowBackground = "windowBackground", e.HudWindow = "hudWindow", e.FullScreenUI = "fullScreenUI", e.Tooltip = "tooltip", e.ContentBackground = "contentBackground", e.UnderWindowBackground = "underWindowBackground", e.UnderPageBackground = "underPageBackground", e.Mica = "mica", e.Blur = "blur", e.Acrylic = "acrylic", e.Tabbed = "tabbed", e.TabbedDark = "tabbedDark", e.TabbedLight = "tabbedLight";
713
+ })(F ||= {});
714
+ var I;
715
+ (function(e) {
716
+ e.FollowsWindowActiveState = "followsWindowActiveState", e.Active = "active", e.Inactive = "inactive";
717
+ })(I ||= {});
718
+ function L(e) {
719
+ return e === null ? null : {
720
+ name: e.name,
721
+ scaleFactor: e.scaleFactor,
722
+ position: new w(e.position),
723
+ size: new x(e.size),
724
+ workArea: {
725
+ position: new w(e.workArea.position),
726
+ size: new x(e.workArea.size)
727
+ }
728
+ };
1955
729
  }
1956
- async function G() {
1957
- return s("plugin:webview|get_all_webviews").then((t) => t.map((e) => new C(new P(e.windowLabel, {
1958
- // @ts-expect-error `skip` is not defined in the public API but it is handled by the constructor
1959
- skip: !0
1960
- }), e.label, {
1961
- // @ts-expect-error `skip` is not defined in the public API but it is handled by the constructor
1962
- skip: !0
1963
- })));
730
+ async function ie() {
731
+ return p("plugin:window|available_monitors").then((e) => e.map(L));
1964
732
  }
1965
- const A = ["tauri://created", "tauri://error"];
1966
- class C {
1967
- /**
1968
- * Creates a new Webview.
1969
- * @example
1970
- * ```typescript
1971
- * import { Window } from '@tauri-apps/api/window'
1972
- * import { Webview } from '@tauri-apps/api/webview'
1973
- * const appWindow = new Window('my-label')
1974
- *
1975
- * appWindow.once('tauri://created', async function() {
1976
- * const webview = new Webview(appWindow, 'my-label', {
1977
- * url: 'https://github.com/tauri-apps/tauri',
1978
- *
1979
- * // create a webview with specific logical position and size
1980
- * x: 0,
1981
- * y: 0,
1982
- * width: 800,
1983
- * height: 600,
1984
- * });
1985
- *
1986
- * webview.once('tauri://created', function () {
1987
- * // webview successfully created
1988
- * });
1989
- * webview.once('tauri://error', function (e) {
1990
- * // an error happened creating the webview
1991
- * });
1992
- * });
1993
- * ```
1994
- *
1995
- * @param window the window to add this webview to.
1996
- * @param label The unique webview label. Must be alphanumeric: `a-zA-Z-/:_`.
1997
- * @returns The {@link Webview} instance to communicate with the webview.
1998
- */
1999
- constructor(e, i, n) {
2000
- this.window = e, this.label = i, this.listeners = /* @__PURE__ */ Object.create(null), n?.skip || s("plugin:webview|create_webview", {
2001
- windowLabel: e.label,
2002
- options: {
2003
- ...n,
2004
- label: i
2005
- }
2006
- }).then(async () => this.emit("tauri://created")).catch(async (l) => this.emit("tauri://error", l));
2007
- }
2008
- /**
2009
- * Gets the Webview for the webview associated with the given label.
2010
- * @example
2011
- * ```typescript
2012
- * import { Webview } from '@tauri-apps/api/webview';
2013
- * const mainWebview = Webview.getByLabel('main');
2014
- * ```
2015
- *
2016
- * @param label The webview label.
2017
- * @returns The Webview instance to communicate with the webview or null if the webview doesn't exist.
2018
- */
2019
- static async getByLabel(e) {
2020
- var i;
2021
- return (i = (await G()).find((n) => n.label === e)) !== null && i !== void 0 ? i : null;
2022
- }
2023
- /**
2024
- * Get an instance of `Webview` for the current webview.
2025
- */
2026
- static getCurrent() {
2027
- return Y();
2028
- }
2029
- /**
2030
- * Gets a list of instances of `Webview` for all available webviews.
2031
- */
2032
- static async getAll() {
2033
- return G();
2034
- }
2035
- /**
2036
- * Listen to an emitted event on this webview.
2037
- *
2038
- * @example
2039
- * ```typescript
2040
- * import { getCurrentWebview } from '@tauri-apps/api/webview';
2041
- * const unlisten = await getCurrentWebview().listen<string>('state-changed', (event) => {
2042
- * console.log(`Got error: ${payload}`);
2043
- * });
2044
- *
2045
- * // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
2046
- * unlisten();
2047
- * ```
2048
- *
2049
- * @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`.
2050
- * @param handler Event handler.
2051
- * @returns A promise resolving to a function to unlisten to the event.
2052
- * Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
2053
- */
2054
- async listen(e, i) {
2055
- return this._handleTauriEvent(e, i) ? () => {
2056
- const n = this.listeners[e];
2057
- n.splice(n.indexOf(i), 1);
2058
- } : D(e, i, {
2059
- target: { kind: "Webview", label: this.label }
2060
- });
2061
- }
2062
- /**
2063
- * Listen to an emitted event on this webview only once.
2064
- *
2065
- * @example
2066
- * ```typescript
2067
- * import { getCurrentWebview } from '@tauri-apps/api/webview';
2068
- * const unlisten = await getCurrent().once<null>('initialized', (event) => {
2069
- * console.log(`Webview initialized!`);
2070
- * });
2071
- *
2072
- * // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
2073
- * unlisten();
2074
- * ```
2075
- *
2076
- * @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`.
2077
- * @param handler Event handler.
2078
- * @returns A promise resolving to a function to unlisten to the event.
2079
- * Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
2080
- */
2081
- async once(e, i) {
2082
- return this._handleTauriEvent(e, i) ? () => {
2083
- const n = this.listeners[e];
2084
- n.splice(n.indexOf(i), 1);
2085
- } : N(e, i, {
2086
- target: { kind: "Webview", label: this.label }
2087
- });
2088
- }
2089
- /**
2090
- * Emits an event to all {@link EventTarget|targets}.
2091
- *
2092
- * @example
2093
- * ```typescript
2094
- * import { getCurrentWebview } from '@tauri-apps/api/webview';
2095
- * await getCurrentWebview().emit('webview-loaded', { loggedIn: true, token: 'authToken' });
2096
- * ```
2097
- *
2098
- * @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`.
2099
- * @param payload Event payload.
2100
- */
2101
- async emit(e, i) {
2102
- if (A.includes(e)) {
2103
- for (const n of this.listeners[e] || [])
2104
- n({
2105
- event: e,
2106
- id: -1,
2107
- payload: i
2108
- });
2109
- return;
2110
- }
2111
- return k(e, i);
2112
- }
2113
- /**
2114
- * Emits an event to all {@link EventTarget|targets} matching the given target.
2115
- *
2116
- * @example
2117
- * ```typescript
2118
- * import { getCurrentWebview } from '@tauri-apps/api/webview';
2119
- * await getCurrentWebview().emitTo('main', 'webview-loaded', { loggedIn: true, token: 'authToken' });
2120
- * ```
2121
- *
2122
- * @param target Label of the target Window/Webview/WebviewWindow or raw {@link EventTarget} object.
2123
- * @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`.
2124
- * @param payload Event payload.
2125
- */
2126
- async emitTo(e, i, n) {
2127
- if (A.includes(i)) {
2128
- for (const l of this.listeners[i] || [])
2129
- l({
2130
- event: i,
2131
- id: -1,
2132
- payload: n
2133
- });
2134
- return;
2135
- }
2136
- return q(e, i, n);
2137
- }
2138
- /** @ignore */
2139
- _handleTauriEvent(e, i) {
2140
- return A.includes(e) ? (e in this.listeners ? this.listeners[e].push(i) : this.listeners[e] = [i], !0) : !1;
2141
- }
2142
- // Getters
2143
- /**
2144
- * The position of the top-left hand corner of the webview's client area relative to the top-left hand corner of the desktop.
2145
- * @example
2146
- * ```typescript
2147
- * import { getCurrentWebview } from '@tauri-apps/api/webview';
2148
- * const position = await getCurrentWebview().position();
2149
- * ```
2150
- *
2151
- * @returns The webview's position.
2152
- */
2153
- async position() {
2154
- return s("plugin:webview|webview_position", {
2155
- label: this.label
2156
- }).then((e) => new u(e));
2157
- }
2158
- /**
2159
- * The physical size of the webview's client area.
2160
- * The client area is the content of the webview, excluding the title bar and borders.
2161
- * @example
2162
- * ```typescript
2163
- * import { getCurrentWebview } from '@tauri-apps/api/webview';
2164
- * const size = await getCurrentWebview().size();
2165
- * ```
2166
- *
2167
- * @returns The webview's size.
2168
- */
2169
- async size() {
2170
- return s("plugin:webview|webview_size", {
2171
- label: this.label
2172
- }).then((e) => new w(e));
2173
- }
2174
- // Setters
2175
- /**
2176
- * Closes the webview.
2177
- * @example
2178
- * ```typescript
2179
- * import { getCurrentWebview } from '@tauri-apps/api/webview';
2180
- * await getCurrentWebview().close();
2181
- * ```
2182
- *
2183
- * @returns A promise indicating the success or failure of the operation.
2184
- */
2185
- async close() {
2186
- return s("plugin:webview|webview_close", {
2187
- label: this.label
2188
- });
2189
- }
2190
- /**
2191
- * Resizes the webview.
2192
- * @example
2193
- * ```typescript
2194
- * import { getCurrent, LogicalSize } from '@tauri-apps/api/webview';
2195
- * await getCurrentWebview().setSize(new LogicalSize(600, 500));
2196
- * ```
2197
- *
2198
- * @param size The logical or physical size.
2199
- * @returns A promise indicating the success or failure of the operation.
2200
- */
2201
- async setSize(e) {
2202
- return s("plugin:webview|set_webview_size", {
2203
- label: this.label,
2204
- value: e instanceof h ? e : new h(e)
2205
- });
2206
- }
2207
- /**
2208
- * Sets the webview position.
2209
- * @example
2210
- * ```typescript
2211
- * import { getCurrent, LogicalPosition } from '@tauri-apps/api/webview';
2212
- * await getCurrentWebview().setPosition(new LogicalPosition(600, 500));
2213
- * ```
2214
- *
2215
- * @param position The new position, in logical or physical pixels.
2216
- * @returns A promise indicating the success or failure of the operation.
2217
- */
2218
- async setPosition(e) {
2219
- return s("plugin:webview|set_webview_position", {
2220
- label: this.label,
2221
- value: e instanceof d ? e : new d(e)
2222
- });
2223
- }
2224
- /**
2225
- * Bring the webview to front and focus.
2226
- * @example
2227
- * ```typescript
2228
- * import { getCurrentWebview } from '@tauri-apps/api/webview';
2229
- * await getCurrentWebview().setFocus();
2230
- * ```
2231
- *
2232
- * @returns A promise indicating the success or failure of the operation.
2233
- */
2234
- async setFocus() {
2235
- return s("plugin:webview|set_webview_focus", {
2236
- label: this.label
2237
- });
2238
- }
2239
- /**
2240
- * Sets whether the webview should automatically grow and shrink its size and position when the parent window resizes.
2241
- * @example
2242
- * ```typescript
2243
- * import { getCurrentWebview } from '@tauri-apps/api/webview';
2244
- * await getCurrentWebview().setAutoResize(true);
2245
- * ```
2246
- *
2247
- * @returns A promise indicating the success or failure of the operation.
2248
- */
2249
- async setAutoResize(e) {
2250
- return s("plugin:webview|set_webview_auto_resize", {
2251
- label: this.label,
2252
- value: e
2253
- });
2254
- }
2255
- /**
2256
- * Hide the webview.
2257
- * @example
2258
- * ```typescript
2259
- * import { getCurrentWebview } from '@tauri-apps/api/webview';
2260
- * await getCurrentWebview().hide();
2261
- * ```
2262
- *
2263
- * @returns A promise indicating the success or failure of the operation.
2264
- */
2265
- async hide() {
2266
- return s("plugin:webview|webview_hide", {
2267
- label: this.label
2268
- });
2269
- }
2270
- /**
2271
- * Show the webview.
2272
- * @example
2273
- * ```typescript
2274
- * import { getCurrentWebview } from '@tauri-apps/api/webview';
2275
- * await getCurrentWebview().show();
2276
- * ```
2277
- *
2278
- * @returns A promise indicating the success or failure of the operation.
2279
- */
2280
- async show() {
2281
- return s("plugin:webview|webview_show", {
2282
- label: this.label
2283
- });
2284
- }
2285
- /**
2286
- * Set webview zoom level.
2287
- * @example
2288
- * ```typescript
2289
- * import { getCurrentWebview } from '@tauri-apps/api/webview';
2290
- * await getCurrentWebview().setZoom(1.5);
2291
- * ```
2292
- *
2293
- * @returns A promise indicating the success or failure of the operation.
2294
- */
2295
- async setZoom(e) {
2296
- return s("plugin:webview|set_webview_zoom", {
2297
- label: this.label,
2298
- value: e
2299
- });
2300
- }
2301
- /**
2302
- * Moves this webview to the given label.
2303
- * @example
2304
- * ```typescript
2305
- * import { getCurrentWebview } from '@tauri-apps/api/webview';
2306
- * await getCurrentWebview().reparent('other-window');
2307
- * ```
2308
- *
2309
- * @returns A promise indicating the success or failure of the operation.
2310
- */
2311
- async reparent(e) {
2312
- return s("plugin:webview|reparent", {
2313
- label: this.label,
2314
- window: typeof e == "string" ? e : e.label
2315
- });
2316
- }
2317
- /**
2318
- * Clears all browsing data for this webview.
2319
- * @example
2320
- * ```typescript
2321
- * import { getCurrentWebview } from '@tauri-apps/api/webview';
2322
- * await getCurrentWebview().clearAllBrowsingData();
2323
- * ```
2324
- *
2325
- * @returns A promise indicating the success or failure of the operation.
2326
- */
2327
- async clearAllBrowsingData() {
2328
- return s("plugin:webview|clear_all_browsing_data");
2329
- }
2330
- /**
2331
- * Specify the webview background color.
2332
- *
2333
- * #### Platfrom-specific:
2334
- *
2335
- * - **macOS / iOS**: Not implemented.
2336
- * - **Windows**:
2337
- * - On Windows 7, transparency is not supported and the alpha value will be ignored.
2338
- * - On Windows higher than 7: translucent colors are not supported so any alpha value other than `0` will be replaced by `255`
2339
- *
2340
- * @returns A promise indicating the success or failure of the operation.
2341
- *
2342
- * @since 2.1.0
2343
- */
2344
- async setBackgroundColor(e) {
2345
- return s("plugin:webview|set_webview_background_color", { color: e });
2346
- }
2347
- // Listeners
2348
- /**
2349
- * Listen to a file drop event.
2350
- * The listener is triggered when the user hovers the selected files on the webview,
2351
- * drops the files or cancels the operation.
2352
- *
2353
- * @example
2354
- * ```typescript
2355
- * import { getCurrentWebview } from "@tauri-apps/api/webview";
2356
- * const unlisten = await getCurrentWebview().onDragDropEvent((event) => {
2357
- * if (event.payload.type === 'over') {
2358
- * console.log('User hovering', event.payload.position);
2359
- * } else if (event.payload.type === 'drop') {
2360
- * console.log('User dropped', event.payload.paths);
2361
- * } else {
2362
- * console.log('File drop cancelled');
2363
- * }
2364
- * });
2365
- *
2366
- * // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
2367
- * unlisten();
2368
- * ```
2369
- *
2370
- * When the debugger panel is open, the drop position of this event may be inaccurate due to a known limitation.
2371
- * To retrieve the correct drop position, please detach the debugger.
2372
- *
2373
- * @returns A promise resolving to a function to unlisten to the event.
2374
- * Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
2375
- */
2376
- async onDragDropEvent(e) {
2377
- const i = await this.listen(r.DRAG_ENTER, (a) => {
2378
- e({
2379
- ...a,
2380
- payload: {
2381
- type: "enter",
2382
- paths: a.payload.paths,
2383
- position: new u(a.payload.position)
2384
- }
2385
- });
2386
- }), n = await this.listen(r.DRAG_OVER, (a) => {
2387
- e({
2388
- ...a,
2389
- payload: {
2390
- type: "over",
2391
- position: new u(a.payload.position)
2392
- }
2393
- });
2394
- }), l = await this.listen(r.DRAG_DROP, (a) => {
2395
- e({
2396
- ...a,
2397
- payload: {
2398
- type: "drop",
2399
- paths: a.payload.paths,
2400
- position: new u(a.payload.position)
2401
- }
2402
- });
2403
- }), o = await this.listen(r.DRAG_LEAVE, (a) => {
2404
- e({ ...a, payload: { type: "leave" } });
2405
- });
2406
- return () => {
2407
- i(), l(), n(), o();
2408
- };
2409
- }
733
+ //#endregion
734
+ //#region ../node_modules/.pnpm/@tauri-apps+api@2.10.1/node_modules/@tauri-apps/api/webview.js
735
+ function R() {
736
+ return new V(j(), window.__TAURI_INTERNALS__.metadata.currentWebview.label, { skip: !0 });
2410
737
  }
2411
- function $() {
2412
- const t = Y();
2413
- return new b(t.label, { skip: !0 });
738
+ async function z() {
739
+ return p("plugin:webview|get_all_webviews").then((e) => e.map((e) => new V(new P(e.windowLabel, { skip: !0 }), e.label, { skip: !0 })));
2414
740
  }
2415
- async function S() {
2416
- return s("plugin:window|get_all_windows").then((t) => t.map((e) => new b(e, {
2417
- // @ts-expect-error `skip` is not defined in the public API but it is handled by the constructor
2418
- skip: !0
2419
- })));
2420
- }
2421
- class b {
2422
- /**
2423
- * Creates a new {@link Window} hosting a {@link Webview}.
2424
- * @example
2425
- * ```typescript
2426
- * import { WebviewWindow } from '@tauri-apps/api/webviewWindow'
2427
- * const webview = new WebviewWindow('my-label', {
2428
- * url: 'https://github.com/tauri-apps/tauri'
2429
- * });
2430
- * webview.once('tauri://created', function () {
2431
- * // webview successfully created
2432
- * });
2433
- * webview.once('tauri://error', function (e) {
2434
- * // an error happened creating the webview
2435
- * });
2436
- * ```
2437
- *
2438
- * @param label The unique webview label. Must be alphanumeric: `a-zA-Z-/:_`.
2439
- * @returns The {@link WebviewWindow} instance to communicate with the window and webview.
2440
- */
2441
- constructor(e, i = {}) {
2442
- var n;
2443
- this.label = e, this.listeners = /* @__PURE__ */ Object.create(null), i?.skip || s("plugin:webview|create_webview_window", {
2444
- options: {
2445
- ...i,
2446
- parent: typeof i.parent == "string" ? i.parent : (n = i.parent) === null || n === void 0 ? void 0 : n.label,
2447
- label: e
2448
- }
2449
- }).then(async () => this.emit("tauri://created")).catch(async (l) => this.emit("tauri://error", l));
2450
- }
2451
- /**
2452
- * Gets the Webview for the webview associated with the given label.
2453
- * @example
2454
- * ```typescript
2455
- * import { WebviewWindow } from '@tauri-apps/api/webviewWindow';
2456
- * const mainWebview = WebviewWindow.getByLabel('main');
2457
- * ```
2458
- *
2459
- * @param label The webview label.
2460
- * @returns The Webview instance to communicate with the webview or null if the webview doesn't exist.
2461
- */
2462
- static async getByLabel(e) {
2463
- var i;
2464
- const n = (i = (await S()).find((l) => l.label === e)) !== null && i !== void 0 ? i : null;
2465
- return n ? new b(n.label, { skip: !0 }) : null;
2466
- }
2467
- /**
2468
- * Get an instance of `Webview` for the current webview.
2469
- */
2470
- static getCurrent() {
2471
- return $();
2472
- }
2473
- /**
2474
- * Gets a list of instances of `Webview` for all available webviews.
2475
- */
2476
- static async getAll() {
2477
- return S();
2478
- }
2479
- /**
2480
- * Listen to an emitted event on this webview window.
2481
- *
2482
- * @example
2483
- * ```typescript
2484
- * import { WebviewWindow } from '@tauri-apps/api/webviewWindow';
2485
- * const unlisten = await WebviewWindow.getCurrent().listen<string>('state-changed', (event) => {
2486
- * console.log(`Got error: ${payload}`);
2487
- * });
2488
- *
2489
- * // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
2490
- * unlisten();
2491
- * ```
2492
- *
2493
- * @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`.
2494
- * @param handler Event handler.
2495
- * @returns A promise resolving to a function to unlisten to the event.
2496
- * Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
2497
- */
2498
- async listen(e, i) {
2499
- return this._handleTauriEvent(e, i) ? () => {
2500
- const n = this.listeners[e];
2501
- n.splice(n.indexOf(i), 1);
2502
- } : D(e, i, {
2503
- target: { kind: "WebviewWindow", label: this.label }
2504
- });
2505
- }
2506
- /**
2507
- * Listen to an emitted event on this webview window only once.
2508
- *
2509
- * @example
2510
- * ```typescript
2511
- * import { WebviewWindow } from '@tauri-apps/api/webviewWindow';
2512
- * const unlisten = await WebviewWindow.getCurrent().once<null>('initialized', (event) => {
2513
- * console.log(`Webview initialized!`);
2514
- * });
2515
- *
2516
- * // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
2517
- * unlisten();
2518
- * ```
2519
- *
2520
- * @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`.
2521
- * @param handler Event handler.
2522
- * @returns A promise resolving to a function to unlisten to the event.
2523
- * Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
2524
- */
2525
- async once(e, i) {
2526
- return this._handleTauriEvent(e, i) ? () => {
2527
- const n = this.listeners[e];
2528
- n.splice(n.indexOf(i), 1);
2529
- } : N(e, i, {
2530
- target: { kind: "WebviewWindow", label: this.label }
2531
- });
2532
- }
2533
- /**
2534
- * Set the window and webview background color.
2535
- *
2536
- * #### Platform-specific:
2537
- *
2538
- * - **Android / iOS:** Unsupported for the window layer.
2539
- * - **macOS / iOS**: Not implemented for the webview layer.
2540
- * - **Windows**:
2541
- * - alpha channel is ignored for the window layer.
2542
- * - On Windows 7, alpha channel is ignored for the webview layer.
2543
- * - On Windows 8 and newer, if alpha channel is not `0`, it will be ignored.
2544
- *
2545
- * @returns A promise indicating the success or failure of the operation.
2546
- *
2547
- * @since 2.1.0
2548
- */
2549
- async setBackgroundColor(e) {
2550
- return s("plugin:window|set_background_color", { color: e }).then(() => s("plugin:webview|set_webview_background_color", { color: e }));
2551
- }
2552
- }
2553
- de(b, [P, C]);
2554
- function de(t, e) {
2555
- (Array.isArray(e) ? e : [e]).forEach((i) => {
2556
- Object.getOwnPropertyNames(i.prototype).forEach((n) => {
2557
- var l;
2558
- typeof t.prototype == "object" && t.prototype && n in t.prototype || Object.defineProperty(
2559
- t.prototype,
2560
- n,
2561
- // eslint-disable-next-line
2562
- (l = Object.getOwnPropertyDescriptor(i.prototype, n)) !== null && l !== void 0 ? l : /* @__PURE__ */ Object.create(null)
2563
- );
2564
- });
2565
- });
741
+ var B = ["tauri://created", "tauri://error"], V = class {
742
+ constructor(e, t, n) {
743
+ this.window = e, this.label = t, this.listeners = Object.create(null), n?.skip || p("plugin:webview|create_webview", {
744
+ windowLabel: e.label,
745
+ options: {
746
+ ...n,
747
+ label: t
748
+ }
749
+ }).then(async () => this.emit("tauri://created")).catch(async (e) => this.emit("tauri://error", e));
750
+ }
751
+ static async getByLabel(e) {
752
+ return (await z()).find((t) => t.label === e) ?? null;
753
+ }
754
+ static getCurrent() {
755
+ return R();
756
+ }
757
+ static async getAll() {
758
+ return z();
759
+ }
760
+ async listen(e, t) {
761
+ return this._handleTauriEvent(e, t) ? () => {
762
+ let n = this.listeners[e];
763
+ n.splice(n.indexOf(t), 1);
764
+ } : g(e, t, { target: {
765
+ kind: "Webview",
766
+ label: this.label
767
+ } });
768
+ }
769
+ async once(e, t) {
770
+ return this._handleTauriEvent(e, t) ? () => {
771
+ let n = this.listeners[e];
772
+ n.splice(n.indexOf(t), 1);
773
+ } : _(e, t, { target: {
774
+ kind: "Webview",
775
+ label: this.label
776
+ } });
777
+ }
778
+ async emit(e, t) {
779
+ if (B.includes(e)) {
780
+ for (let n of this.listeners[e] || []) n({
781
+ event: e,
782
+ id: -1,
783
+ payload: t
784
+ });
785
+ return;
786
+ }
787
+ return v(e, t);
788
+ }
789
+ async emitTo(e, t, n) {
790
+ if (B.includes(t)) {
791
+ for (let e of this.listeners[t] || []) e({
792
+ event: t,
793
+ id: -1,
794
+ payload: n
795
+ });
796
+ return;
797
+ }
798
+ return y(e, t, n);
799
+ }
800
+ _handleTauriEvent(e, t) {
801
+ return B.includes(e) ? (e in this.listeners ? this.listeners[e].push(t) : this.listeners[e] = [t], !0) : !1;
802
+ }
803
+ async position() {
804
+ return p("plugin:webview|webview_position", { label: this.label }).then((e) => new w(e));
805
+ }
806
+ async size() {
807
+ return p("plugin:webview|webview_size", { label: this.label }).then((e) => new x(e));
808
+ }
809
+ async close() {
810
+ return p("plugin:webview|webview_close", { label: this.label });
811
+ }
812
+ async setSize(e) {
813
+ return p("plugin:webview|set_webview_size", {
814
+ label: this.label,
815
+ value: e instanceof S ? e : new S(e)
816
+ });
817
+ }
818
+ async setPosition(e) {
819
+ return p("plugin:webview|set_webview_position", {
820
+ label: this.label,
821
+ value: e instanceof T ? e : new T(e)
822
+ });
823
+ }
824
+ async setFocus() {
825
+ return p("plugin:webview|set_webview_focus", { label: this.label });
826
+ }
827
+ async setAutoResize(e) {
828
+ return p("plugin:webview|set_webview_auto_resize", {
829
+ label: this.label,
830
+ value: e
831
+ });
832
+ }
833
+ async hide() {
834
+ return p("plugin:webview|webview_hide", { label: this.label });
835
+ }
836
+ async show() {
837
+ return p("plugin:webview|webview_show", { label: this.label });
838
+ }
839
+ async setZoom(e) {
840
+ return p("plugin:webview|set_webview_zoom", {
841
+ label: this.label,
842
+ value: e
843
+ });
844
+ }
845
+ async reparent(e) {
846
+ return p("plugin:webview|reparent", {
847
+ label: this.label,
848
+ window: typeof e == "string" ? e : e.label
849
+ });
850
+ }
851
+ async clearAllBrowsingData() {
852
+ return p("plugin:webview|clear_all_browsing_data");
853
+ }
854
+ async setBackgroundColor(e) {
855
+ return p("plugin:webview|set_webview_background_color", { color: e });
856
+ }
857
+ async onDragDropEvent(e) {
858
+ let t = await this.listen(m.DRAG_ENTER, (t) => {
859
+ e({
860
+ ...t,
861
+ payload: {
862
+ type: "enter",
863
+ paths: t.payload.paths,
864
+ position: new w(t.payload.position)
865
+ }
866
+ });
867
+ }), n = await this.listen(m.DRAG_OVER, (t) => {
868
+ e({
869
+ ...t,
870
+ payload: {
871
+ type: "over",
872
+ position: new w(t.payload.position)
873
+ }
874
+ });
875
+ }), r = await this.listen(m.DRAG_DROP, (t) => {
876
+ e({
877
+ ...t,
878
+ payload: {
879
+ type: "drop",
880
+ paths: t.payload.paths,
881
+ position: new w(t.payload.position)
882
+ }
883
+ });
884
+ }), i = await this.listen(m.DRAG_LEAVE, (t) => {
885
+ e({
886
+ ...t,
887
+ payload: { type: "leave" }
888
+ });
889
+ });
890
+ return () => {
891
+ t(), r(), n(), i();
892
+ };
893
+ }
894
+ };
895
+ //#endregion
896
+ //#region ../node_modules/.pnpm/@tauri-apps+api@2.10.1/node_modules/@tauri-apps/api/webviewWindow.js
897
+ function H() {
898
+ return new W(R().label, { skip: !0 });
2566
899
  }
2567
- const ye = (t) => JSON.stringify(t), pe = (t) => JSON.parse(t), z = "drift://action", ge = "tauri://error", _e = "tauri://created", fe = (t) => new Error(`Window not found: ${t}`), y = 250, ve = H.seconds(1), me = H.seconds(1), v = (t) => {
2568
- if (t != null)
2569
- return {
2570
- width: Math.max(t.width, y),
2571
- height: Math.max(t.height, y)
2572
- };
2573
- }, De = (t) => {
2574
- const { size: e, maxSize: i } = t;
2575
- return { ...t, maxSize: v(i), size: v(e) };
2576
- }, ze = async () => (await be()).map((e) => {
2577
- const i = m(e.position, e.scaleFactor), n = { width: e.size.width, height: e.size.height };
2578
- return j.construct(i, n);
2579
- }), x = async (t) => (await ze()).some((i) => j.contains(i, t));
2580
- class Se {
2581
- win;
2582
- unsubscribe;
2583
- fullscreenPoll = null;
2584
- monitorChangePoll = null;
2585
- /**
2586
- * @param window - The WebviewWindow to use as the underlying engine for this runtime.
2587
- * This should not be set in 99% of cases. Only use this if you know what you're doing.
2588
- */
2589
- constructor(e) {
2590
- this.win = e ?? $(), this.unsubscribe = {};
2591
- }
2592
- async configure() {
2593
- await this.startFullscreenPoll(), this.startMonitorChangePoll();
2594
- }
2595
- async startFullscreenPoll() {
2596
- if (T.getOS() !== "macOS") return;
2597
- let e = (await this.getProps()).fullscreen;
2598
- this.fullscreenPoll != null && clearInterval(this.fullscreenPoll), this.fullscreenPoll = setInterval(() => {
2599
- this.win.isFullscreen().then((i) => {
2600
- i !== e && (e = i, this.emit(
2601
- {
2602
- action: g({
2603
- label: this.win.label,
2604
- fullscreen: i
2605
- })
2606
- },
2607
- void 0,
2608
- "WHITELIST"
2609
- ).catch(console.error));
2610
- }).catch(console.error);
2611
- }, ve.milliseconds);
2612
- }
2613
- startMonitorChangePoll() {
2614
- T.getOS() !== "macOS" && (this.monitorChangePoll != null && clearInterval(this.monitorChangePoll), this.monitorChangePoll = setInterval(() => {
2615
- this.repositionIfOffScreen().catch(console.error);
2616
- }, me.milliseconds));
2617
- }
2618
- async repositionIfOffScreen() {
2619
- if (await this.win.isMinimized()) return;
2620
- const e = await this.win.scaleFactor(), i = m(await this.win.innerPosition(), e);
2621
- await x(i) || await this.win.center();
2622
- }
2623
- label() {
2624
- return this.win.label;
2625
- }
2626
- isMain() {
2627
- return this.win.label === te;
2628
- }
2629
- release() {
2630
- Object.values(this.unsubscribe).forEach((e) => e?.()), this.fullscreenPoll != null && clearInterval(this.fullscreenPoll), this.monitorChangePoll != null && clearInterval(this.monitorChangePoll), this.unsubscribe = {};
2631
- }
2632
- async emit(e, i, n = this.label()) {
2633
- const l = ye({ ...e, emitter: n });
2634
- if (i == null) return await k(z, l);
2635
- const o = await b.getByLabel(i);
2636
- if (o == null) throw fe(i);
2637
- await o.emit(z, l);
2638
- }
2639
- async subscribe(e) {
2640
- this.release(), await this.startFullscreenPoll(), this.startMonitorChangePoll(), this.unsubscribe[z] = await D(
2641
- z,
2642
- (n) => e(pe(n.payload))
2643
- );
2644
- const i = We();
2645
- for (const { key: n, handler: l, debounce: o } of i)
2646
- this.unsubscribe[n] = await this.win.listen(
2647
- n,
2648
- ne(() => {
2649
- l(this.win).then((a) => {
2650
- a != null && this.emit({ action: a }, void 0, "WHITELIST").catch(
2651
- console.error
2652
- );
2653
- }).catch(console.error);
2654
- }, o)
2655
- );
2656
- }
2657
- onCloseRequested(e) {
2658
- this.win.onCloseRequested((i) => {
2659
- i.preventDefault(), e();
2660
- });
2661
- }
2662
- async create(e, i) {
2663
- i = se.copy(i);
2664
- const { size: n, minSize: l, maxSize: o, position: a, ...Q } = De(i);
2665
- n?.width != null && (n.width = Math.max(n.width, y)), n?.height != null && (n.height = Math.max(n.height, y)), o?.width != null && (o.width = Math.max(o.width, y)), o?.height != null && (o.height = Math.max(o.height, y)), a != null && (await x(a) || (a.x = 0, a.y = 0));
2666
- try {
2667
- const p = new b(e, {
2668
- x: a?.x,
2669
- y: a?.y,
2670
- width: n?.width,
2671
- height: n?.height,
2672
- minWidth: l?.width,
2673
- minHeight: l?.height,
2674
- maxWidth: o?.width,
2675
- maxHeight: o?.height,
2676
- titleBarStyle: "overlay",
2677
- dragDropEnabled: !1,
2678
- ...Q
2679
- });
2680
- return await new Promise((X, ee) => {
2681
- p.once(ge, (ie) => ee(new Error(JSON.stringify(ie.payload)))), p.once(_e, () => X());
2682
- });
2683
- } catch (p) {
2684
- console.error(p);
2685
- }
2686
- }
2687
- async close(e) {
2688
- const i = await b.getByLabel(e);
2689
- if (i != null)
2690
- try {
2691
- await i.destroy();
2692
- } catch (n) {
2693
- console.error(n, e);
2694
- }
2695
- else {
2696
- const n = await S();
2697
- console.error(
2698
- "Window not found",
2699
- e,
2700
- n.map((l) => l.label)
2701
- );
2702
- }
2703
- }
2704
- async listLabels() {
2705
- return (await S()).map((i) => i.label);
2706
- }
2707
- async focus() {
2708
- return await this.win.setFocus();
2709
- }
2710
- async setMinimized(e) {
2711
- return e ? await this.win.minimize() : await this.win.unminimize();
2712
- }
2713
- async setMaximized(e) {
2714
- return e ? await this.win.maximize() : await this.win.unmaximize();
2715
- }
2716
- async setVisible(e) {
2717
- return e ? await this.win.show() : await this.win.hide();
2718
- }
2719
- async setFullscreen(e) {
2720
- await this.win.setFullscreen(e);
2721
- }
2722
- async center() {
2723
- return await this.win.center();
2724
- }
2725
- async setPosition(e) {
2726
- const i = new L(e.x, e.y);
2727
- await x(e) || (i.x = 0, i.y = 0), await this.win.setPosition(i);
2728
- }
2729
- async setSize(e) {
2730
- e = v(e), await this.win.setSize(new _(e.width, e.height));
2731
- }
2732
- async setMinSize(e) {
2733
- e = v(e), await this.win.setMinSize(new _(e.width, e.height));
2734
- }
2735
- async setMaxSize(e) {
2736
- e = v(e), await this.win.setMaxSize(new _(e.width, e.height));
2737
- }
2738
- async setResizable(e) {
2739
- return r.WINDOW_RESIZED in this.unsubscribe && !e && (this.unsubscribe[r.WINDOW_RESIZED]?.(), delete this.unsubscribe[r.WINDOW_RESIZED]), await this.win.setResizable(e);
2740
- }
2741
- async setSkipTaskbar(e) {
2742
- return await this.win.setSkipTaskbar(e);
2743
- }
2744
- async setAlwaysOnTop(e) {
2745
- return await this.win.setAlwaysOnTop(e);
2746
- }
2747
- async setTitle(e) {
2748
- return await this.win.setTitle(e);
2749
- }
2750
- async setDecorations(e) {
2751
- return await this.win.setDecorations(e);
2752
- }
2753
- async getProps() {
2754
- const e = await this.win.scaleFactor(), i = await this.win.isVisible();
2755
- return {
2756
- position: m(await this.win.innerPosition(), e),
2757
- size: K(await this.win.innerSize(), e),
2758
- maximized: await this.win.isMaximized(),
2759
- visible: i,
2760
- fullscreen: await this.win.isFullscreen()
2761
- };
2762
- }
900
+ async function U() {
901
+ return p("plugin:window|get_all_windows").then((e) => e.map((e) => new W(e, { skip: !0 })));
2763
902
  }
2764
- const We = () => [
2765
- {
2766
- key: r.WINDOW_RESIZED,
2767
- debounce: 200,
2768
- handler: async (t) => {
2769
- const e = await t.scaleFactor(), i = await t.isVisible(), n = {
2770
- label: t.label,
2771
- maximized: await t.isMaximized(),
2772
- visible: i,
2773
- minimized: !i,
2774
- position: m(await t.innerPosition(), e),
2775
- size: K(await t.innerSize(), e)
2776
- };
2777
- return g(n);
2778
- }
2779
- },
2780
- {
2781
- key: r.WINDOW_MOVED,
2782
- debounce: 200,
2783
- handler: async (t) => {
2784
- const e = await t?.scaleFactor();
2785
- if (e == null) return null;
2786
- const i = m(await t.innerPosition(), e), n = await t.isVisible(), l = {
2787
- label: t.label,
2788
- visible: n,
2789
- position: i
2790
- };
2791
- return g(l);
2792
- }
2793
- },
2794
- {
2795
- key: r.WINDOW_BLUR,
2796
- debounce: 0,
2797
- handler: async (t) => g({ focus: !1, label: t.label })
2798
- },
2799
- {
2800
- key: r.WINDOW_FOCUS,
2801
- debounce: 0,
2802
- handler: async (t) => g({
2803
- focus: !0,
2804
- visible: !0,
2805
- minimized: !1,
2806
- label: t.label
2807
- })
2808
- }
2809
- ], m = (t, e) => le.scale(t, 1 / e), K = (t, e) => ae.scale(t, 1 / e);
2810
- export {
2811
- Se as TauriRuntime
903
+ var W = class e {
904
+ constructor(e, t = {}) {
905
+ this.label = e, this.listeners = Object.create(null), t?.skip || p("plugin:webview|create_webview_window", { options: {
906
+ ...t,
907
+ parent: typeof t.parent == "string" ? t.parent : t.parent?.label,
908
+ label: e
909
+ } }).then(async () => this.emit("tauri://created")).catch(async (e) => this.emit("tauri://error", e));
910
+ }
911
+ static async getByLabel(t) {
912
+ let n = (await U()).find((e) => e.label === t) ?? null;
913
+ return n ? new e(n.label, { skip: !0 }) : null;
914
+ }
915
+ static getCurrent() {
916
+ return H();
917
+ }
918
+ static async getAll() {
919
+ return U();
920
+ }
921
+ async listen(e, t) {
922
+ return this._handleTauriEvent(e, t) ? () => {
923
+ let n = this.listeners[e];
924
+ n.splice(n.indexOf(t), 1);
925
+ } : g(e, t, { target: {
926
+ kind: "WebviewWindow",
927
+ label: this.label
928
+ } });
929
+ }
930
+ async once(e, t) {
931
+ return this._handleTauriEvent(e, t) ? () => {
932
+ let n = this.listeners[e];
933
+ n.splice(n.indexOf(t), 1);
934
+ } : _(e, t, { target: {
935
+ kind: "WebviewWindow",
936
+ label: this.label
937
+ } });
938
+ }
939
+ async setBackgroundColor(e) {
940
+ return p("plugin:window|set_background_color", { color: e }).then(() => p("plugin:webview|set_webview_background_color", { color: e }));
941
+ }
2812
942
  };
943
+ G(W, [P, V]);
944
+ function G(e, t) {
945
+ (Array.isArray(t) ? t : [t]).forEach((t) => {
946
+ Object.getOwnPropertyNames(t.prototype).forEach((n) => {
947
+ typeof e.prototype == "object" && e.prototype && n in e.prototype || Object.defineProperty(e.prototype, n, Object.getOwnPropertyDescriptor(t.prototype, n) ?? Object.create(null));
948
+ });
949
+ });
950
+ }
951
+ //#endregion
952
+ //#region src/serialization/index.ts
953
+ var K = (e) => JSON.stringify(e), q = (e) => JSON.parse(e), J = "drift://action", ae = "tauri://error", oe = "tauri://created", se = (e) => /* @__PURE__ */ Error(`Window not found: ${e}`), Y = 250, ce = o.seconds(1), le = o.seconds(1), X = (e) => {
954
+ if (e != null) return {
955
+ width: Math.max(e.width, Y),
956
+ height: Math.max(e.height, Y)
957
+ };
958
+ }, ue = (e) => {
959
+ let { size: t, maxSize: n } = e;
960
+ return {
961
+ ...e,
962
+ maxSize: X(n),
963
+ size: X(t)
964
+ };
965
+ }, de = async () => (await ie()).map((e) => {
966
+ let t = Q(e.position, e.scaleFactor), r = {
967
+ width: e.size.width,
968
+ height: e.size.height
969
+ };
970
+ return n.construct(t, r);
971
+ }), Z = async (e) => (await de()).some((t) => n.contains(t, e)), fe = class {
972
+ win;
973
+ unsubscribe;
974
+ fullscreenPoll = null;
975
+ monitorChangePoll = null;
976
+ constructor(e) {
977
+ this.win = e ?? H(), this.unsubscribe = {};
978
+ }
979
+ async configure() {
980
+ await this.startFullscreenPoll(), this.startMonitorChangePoll();
981
+ }
982
+ async startFullscreenPoll() {
983
+ if (i.getOS() !== "macOS") return;
984
+ let e = (await this.getProps()).fullscreen;
985
+ this.fullscreenPoll != null && clearInterval(this.fullscreenPoll), this.fullscreenPoll = setInterval(() => {
986
+ this.win.isFullscreen().then((t) => {
987
+ t !== e && (e = t, this.emit({ action: c({
988
+ label: this.win.label,
989
+ fullscreen: t
990
+ }) }, void 0, "WHITELIST").catch(console.error));
991
+ }).catch(console.error);
992
+ }, ce.milliseconds);
993
+ }
994
+ startMonitorChangePoll() {
995
+ i.getOS() !== "macOS" && (this.monitorChangePoll != null && clearInterval(this.monitorChangePoll), this.monitorChangePoll = setInterval(() => {
996
+ this.repositionIfOffScreen().catch(console.error);
997
+ }, le.milliseconds));
998
+ }
999
+ async repositionIfOffScreen() {
1000
+ if (await this.win.isMinimized()) return;
1001
+ let e = await this.win.scaleFactor();
1002
+ await Z(Q(await this.win.innerPosition(), e)) || await this.win.center();
1003
+ }
1004
+ label() {
1005
+ return this.win.label;
1006
+ }
1007
+ isMain() {
1008
+ return this.win.label === a;
1009
+ }
1010
+ release() {
1011
+ Object.values(this.unsubscribe).forEach((e) => e?.()), this.fullscreenPoll != null && clearInterval(this.fullscreenPoll), this.monitorChangePoll != null && clearInterval(this.monitorChangePoll), this.unsubscribe = {};
1012
+ }
1013
+ async emit(e, t, n = this.label()) {
1014
+ let r = K({
1015
+ ...e,
1016
+ emitter: n
1017
+ });
1018
+ if (t == null) return await v(J, r);
1019
+ let i = await W.getByLabel(t);
1020
+ if (i == null) throw se(t);
1021
+ await i.emit(J, r);
1022
+ }
1023
+ async subscribe(t) {
1024
+ this.release(), await this.startFullscreenPoll(), this.startMonitorChangePoll(), this.unsubscribe[J] = await g(J, (e) => t(q(e.payload)));
1025
+ let n = pe();
1026
+ for (let { key: t, handler: r, debounce: i } of n) this.unsubscribe[t] = await this.win.listen(t, e(() => {
1027
+ r(this.win).then((e) => {
1028
+ e != null && this.emit({ action: e }, void 0, "WHITELIST").catch(console.error);
1029
+ }).catch(console.error);
1030
+ }, i));
1031
+ }
1032
+ onCloseRequested(e) {
1033
+ this.win.onCloseRequested((t) => {
1034
+ t.preventDefault(), e();
1035
+ });
1036
+ }
1037
+ async create(e, t) {
1038
+ t = r.copy(t);
1039
+ let { size: n, minSize: i, maxSize: a, position: o, ...s } = ue(t);
1040
+ n?.width != null && (n.width = Math.max(n.width, Y)), n?.height != null && (n.height = Math.max(n.height, Y)), a?.width != null && (a.width = Math.max(a.width, Y)), a?.height != null && (a.height = Math.max(a.height, Y)), o != null && (await Z(o) || (o.x = 0, o.y = 0));
1041
+ try {
1042
+ let t = new W(e, {
1043
+ x: o?.x,
1044
+ y: o?.y,
1045
+ width: n?.width,
1046
+ height: n?.height,
1047
+ minWidth: i?.width,
1048
+ minHeight: i?.height,
1049
+ maxWidth: a?.width,
1050
+ maxHeight: a?.height,
1051
+ titleBarStyle: "overlay",
1052
+ dragDropEnabled: !1,
1053
+ ...s
1054
+ });
1055
+ return await new Promise((e, n) => {
1056
+ t.once(ae, (e) => n(Error(JSON.stringify(e.payload)))), t.once(oe, () => e());
1057
+ });
1058
+ } catch (e) {
1059
+ console.error(e);
1060
+ }
1061
+ }
1062
+ async close(e) {
1063
+ let t = await W.getByLabel(e);
1064
+ if (t != null) try {
1065
+ await t.destroy();
1066
+ } catch (t) {
1067
+ console.error(t, e);
1068
+ }
1069
+ else {
1070
+ let t = await U();
1071
+ console.error("Window not found", e, t.map((e) => e.label));
1072
+ }
1073
+ }
1074
+ async listLabels() {
1075
+ return (await U()).map((e) => e.label);
1076
+ }
1077
+ async focus() {
1078
+ return await this.win.setFocus();
1079
+ }
1080
+ async setMinimized(e) {
1081
+ return e ? await this.win.minimize() : await this.win.unminimize();
1082
+ }
1083
+ async setMaximized(e) {
1084
+ return e ? await this.win.maximize() : await this.win.unmaximize();
1085
+ }
1086
+ async setVisible(e) {
1087
+ return e ? await this.win.show() : await this.win.hide();
1088
+ }
1089
+ async setFullscreen(e) {
1090
+ await this.win.setFullscreen(e);
1091
+ }
1092
+ async center() {
1093
+ return await this.win.center();
1094
+ }
1095
+ async setPosition(e) {
1096
+ let t = new C(e.x, e.y);
1097
+ await Z(e) || (t.x = 0, t.y = 0), await this.win.setPosition(t);
1098
+ }
1099
+ async setSize(e) {
1100
+ e = X(e), await this.win.setSize(new b(e.width, e.height));
1101
+ }
1102
+ async setMinSize(e) {
1103
+ e = X(e), await this.win.setMinSize(new b(e.width, e.height));
1104
+ }
1105
+ async setMaxSize(e) {
1106
+ e = X(e), await this.win.setMaxSize(new b(e.width, e.height));
1107
+ }
1108
+ async setResizable(e) {
1109
+ return m.WINDOW_RESIZED in this.unsubscribe && !e && (this.unsubscribe[m.WINDOW_RESIZED]?.(), delete this.unsubscribe[m.WINDOW_RESIZED]), await this.win.setResizable(e);
1110
+ }
1111
+ async setSkipTaskbar(e) {
1112
+ return await this.win.setSkipTaskbar(e);
1113
+ }
1114
+ async setAlwaysOnTop(e) {
1115
+ return await this.win.setAlwaysOnTop(e);
1116
+ }
1117
+ async setTitle(e) {
1118
+ return await this.win.setTitle(e);
1119
+ }
1120
+ async setDecorations(e) {
1121
+ return await this.win.setDecorations(e);
1122
+ }
1123
+ async getProps() {
1124
+ let e = await this.win.scaleFactor(), t = await this.win.isVisible();
1125
+ return {
1126
+ position: Q(await this.win.innerPosition(), e),
1127
+ size: $(await this.win.innerSize(), e),
1128
+ maximized: await this.win.isMaximized(),
1129
+ visible: t,
1130
+ fullscreen: await this.win.isFullscreen()
1131
+ };
1132
+ }
1133
+ }, pe = () => [
1134
+ {
1135
+ key: m.WINDOW_RESIZED,
1136
+ debounce: 200,
1137
+ handler: async (e) => {
1138
+ let t = await e.scaleFactor(), n = await e.isVisible();
1139
+ return c({
1140
+ label: e.label,
1141
+ maximized: await e.isMaximized(),
1142
+ visible: n,
1143
+ minimized: !n,
1144
+ position: Q(await e.innerPosition(), t),
1145
+ size: $(await e.innerSize(), t)
1146
+ });
1147
+ }
1148
+ },
1149
+ {
1150
+ key: m.WINDOW_MOVED,
1151
+ debounce: 200,
1152
+ handler: async (e) => {
1153
+ let t = await e?.scaleFactor();
1154
+ if (t == null) return null;
1155
+ let n = Q(await e.innerPosition(), t), r = await e.isVisible();
1156
+ return c({
1157
+ label: e.label,
1158
+ visible: r,
1159
+ position: n
1160
+ });
1161
+ }
1162
+ },
1163
+ {
1164
+ key: m.WINDOW_BLUR,
1165
+ debounce: 0,
1166
+ handler: async (e) => c({
1167
+ focus: !1,
1168
+ label: e.label
1169
+ })
1170
+ },
1171
+ {
1172
+ key: m.WINDOW_FOCUS,
1173
+ debounce: 0,
1174
+ handler: async (e) => c({
1175
+ focus: !0,
1176
+ visible: !0,
1177
+ minimized: !1,
1178
+ label: e.label
1179
+ })
1180
+ }
1181
+ ], Q = (e, n) => t.scale(e, 1 / n), $ = (e, t) => s.scale(e, 1 / t);
1182
+ //#endregion
1183
+ export { fe as TauriRuntime };