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