tauri-notice-window 1.0.11 → 1.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config/noticeConfig.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +75 -73
- package/dist/index.js.map +1 -1
- package/dist/types/message.d.ts +4 -0
- package/dist/types/message.d.ts.map +1 -1
- package/dist/utils/noticeWindow.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -8,8 +8,10 @@ const K = "tauri-notice-config", Q = {
|
|
|
8
8
|
databaseName: "tauri-notice-db",
|
|
9
9
|
defaultWidth: 400,
|
|
10
10
|
defaultHeight: 300,
|
|
11
|
-
notFoundUrl: "/404"
|
|
11
|
+
notFoundUrl: "/404",
|
|
12
12
|
// Default 404 page
|
|
13
|
+
defaultDecorations: !0
|
|
14
|
+
// Show title bar by default
|
|
13
15
|
}, X = () => {
|
|
14
16
|
try {
|
|
15
17
|
const t = localStorage.getItem(K);
|
|
@@ -37,14 +39,14 @@ class ye extends de {
|
|
|
37
39
|
});
|
|
38
40
|
}
|
|
39
41
|
}
|
|
40
|
-
let
|
|
42
|
+
let W = null;
|
|
41
43
|
const te = () => {
|
|
42
|
-
if (!
|
|
44
|
+
if (!W) {
|
|
43
45
|
const t = ee();
|
|
44
|
-
|
|
46
|
+
W = new ye(t.databaseName);
|
|
45
47
|
}
|
|
46
|
-
return
|
|
47
|
-
},
|
|
48
|
+
return W;
|
|
49
|
+
}, g = () => W || te(), be = async (t) => {
|
|
48
50
|
const e = {
|
|
49
51
|
...t,
|
|
50
52
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -53,28 +55,28 @@ const te = () => {
|
|
|
53
55
|
queueStatus: "pending",
|
|
54
56
|
queuePosition: 0
|
|
55
57
|
};
|
|
56
|
-
await
|
|
57
|
-
}, pe = async (t) => !!await
|
|
58
|
-
const e = await
|
|
58
|
+
await g().messages.put(e);
|
|
59
|
+
}, pe = async (t) => !!await g().messages.get(t), _e = async (t) => {
|
|
60
|
+
const e = await g().messages.get(t);
|
|
59
61
|
return e?.isShown === !0 || e?.queueStatus === "shown";
|
|
60
|
-
}, fe = async () => await
|
|
61
|
-
await
|
|
62
|
+
}, fe = async () => await g().messages.where("queueStatus").equals("pending").sortBy("queuePosition"), me = async (t, e) => {
|
|
63
|
+
await g().messages.update(t, { queueStatus: e });
|
|
62
64
|
}, ve = async (t) => {
|
|
63
|
-
await
|
|
65
|
+
await g().messages.update(t, {
|
|
64
66
|
queueStatus: "shown",
|
|
65
67
|
isShown: !0
|
|
66
68
|
});
|
|
67
69
|
}, We = async (t) => {
|
|
68
|
-
await
|
|
70
|
+
await g().messages.update(t, {
|
|
69
71
|
queueStatus: "hidden"
|
|
70
72
|
});
|
|
71
|
-
}, ie = async (t) => await
|
|
72
|
-
await
|
|
73
|
-
},
|
|
74
|
-
await
|
|
75
|
-
},
|
|
73
|
+
}, ie = async (t) => await g().messages.get(t), Se = async (t) => {
|
|
74
|
+
await g().messages.delete(t);
|
|
75
|
+
}, De = async () => {
|
|
76
|
+
await g().messages.where("queueStatus").anyOf(["pending", "showing"]).delete();
|
|
77
|
+
}, Ae = async (t) => {
|
|
76
78
|
const e = t.map(
|
|
77
|
-
(i) =>
|
|
79
|
+
(i) => g().messages.update(i.id, { queuePosition: i.position })
|
|
78
80
|
);
|
|
79
81
|
await Promise.all(e);
|
|
80
82
|
}, Ne = (t, e) => ({
|
|
@@ -153,7 +155,7 @@ const te = () => {
|
|
|
153
155
|
id: a.id,
|
|
154
156
|
position: l
|
|
155
157
|
}));
|
|
156
|
-
await
|
|
158
|
+
await Ae(n);
|
|
157
159
|
},
|
|
158
160
|
// Clear all messages on logout
|
|
159
161
|
clearOnLogout: async () => {
|
|
@@ -163,7 +165,7 @@ const te = () => {
|
|
|
163
165
|
isProcessing: !1,
|
|
164
166
|
activeWindowIds: [],
|
|
165
167
|
initialized: !1
|
|
166
|
-
}), await
|
|
168
|
+
}), await De();
|
|
167
169
|
},
|
|
168
170
|
// Remove a specific message from the queue by ID (memory only)
|
|
169
171
|
removeFromQueue: async (i) => {
|
|
@@ -271,7 +273,7 @@ class ne {
|
|
|
271
273
|
* @since 2.0.0
|
|
272
274
|
*/
|
|
273
275
|
toPhysical(e) {
|
|
274
|
-
return new
|
|
276
|
+
return new b(this.width * e, this.height * e);
|
|
275
277
|
}
|
|
276
278
|
[d]() {
|
|
277
279
|
return {
|
|
@@ -283,7 +285,7 @@ class ne {
|
|
|
283
285
|
return this[d]();
|
|
284
286
|
}
|
|
285
287
|
}
|
|
286
|
-
class
|
|
288
|
+
class b {
|
|
287
289
|
constructor(...e) {
|
|
288
290
|
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]);
|
|
289
291
|
}
|
|
@@ -311,7 +313,7 @@ class y {
|
|
|
311
313
|
return this[d]();
|
|
312
314
|
}
|
|
313
315
|
}
|
|
314
|
-
class
|
|
316
|
+
class y {
|
|
315
317
|
constructor(e) {
|
|
316
318
|
this.size = e;
|
|
317
319
|
}
|
|
@@ -319,7 +321,7 @@ class g {
|
|
|
319
321
|
return this.size instanceof ne ? this.size : this.size.toLogical(e);
|
|
320
322
|
}
|
|
321
323
|
toPhysical(e) {
|
|
322
|
-
return this.size instanceof
|
|
324
|
+
return this.size instanceof b ? this.size : this.size.toPhysical(e);
|
|
323
325
|
}
|
|
324
326
|
[d]() {
|
|
325
327
|
return {
|
|
@@ -397,7 +399,7 @@ class w {
|
|
|
397
399
|
return this[d]();
|
|
398
400
|
}
|
|
399
401
|
}
|
|
400
|
-
class
|
|
402
|
+
class p {
|
|
401
403
|
constructor(e) {
|
|
402
404
|
this.position = e;
|
|
403
405
|
}
|
|
@@ -456,7 +458,7 @@ async function le(t, e, i) {
|
|
|
456
458
|
payload: i
|
|
457
459
|
});
|
|
458
460
|
}
|
|
459
|
-
class
|
|
461
|
+
class S extends xe {
|
|
460
462
|
/**
|
|
461
463
|
* Creates an Image from a resource ID. For internal use only.
|
|
462
464
|
*
|
|
@@ -471,7 +473,7 @@ class A extends xe {
|
|
|
471
473
|
rgba: x(e),
|
|
472
474
|
width: i,
|
|
473
475
|
height: n
|
|
474
|
-
}).then((a) => new
|
|
476
|
+
}).then((a) => new S(a));
|
|
475
477
|
}
|
|
476
478
|
/**
|
|
477
479
|
* Creates a new image using the provided bytes by inferring the file format.
|
|
@@ -489,7 +491,7 @@ class A extends xe {
|
|
|
489
491
|
static async fromBytes(e) {
|
|
490
492
|
return s("plugin:image|from_bytes", {
|
|
491
493
|
bytes: x(e)
|
|
492
|
-
}).then((i) => new
|
|
494
|
+
}).then((i) => new S(i));
|
|
493
495
|
}
|
|
494
496
|
/**
|
|
495
497
|
* Creates a new image using the provided path.
|
|
@@ -504,7 +506,7 @@ class A extends xe {
|
|
|
504
506
|
* ```
|
|
505
507
|
*/
|
|
506
508
|
static async fromPath(e) {
|
|
507
|
-
return s("plugin:image|from_path", { path: e }).then((i) => new
|
|
509
|
+
return s("plugin:image|from_path", { path: e }).then((i) => new S(i));
|
|
508
510
|
}
|
|
509
511
|
/** Returns the RGBA data for this image, in row-major order from top to bottom. */
|
|
510
512
|
async rgba() {
|
|
@@ -518,7 +520,7 @@ class A extends xe {
|
|
|
518
520
|
}
|
|
519
521
|
}
|
|
520
522
|
function x(t) {
|
|
521
|
-
return t == null ? null : typeof t == "string" ? t : t instanceof
|
|
523
|
+
return t == null ? null : typeof t == "string" ? t : t instanceof S ? t.rid : t;
|
|
522
524
|
}
|
|
523
525
|
var q;
|
|
524
526
|
(function(t) {
|
|
@@ -788,7 +790,7 @@ class k {
|
|
|
788
790
|
async innerSize() {
|
|
789
791
|
return s("plugin:window|inner_size", {
|
|
790
792
|
label: this.label
|
|
791
|
-
}).then((e) => new
|
|
793
|
+
}).then((e) => new b(e));
|
|
792
794
|
}
|
|
793
795
|
/**
|
|
794
796
|
* The physical size of the entire window.
|
|
@@ -804,7 +806,7 @@ class k {
|
|
|
804
806
|
async outerSize() {
|
|
805
807
|
return s("plugin:window|outer_size", {
|
|
806
808
|
label: this.label
|
|
807
|
-
}).then((e) => new
|
|
809
|
+
}).then((e) => new b(e));
|
|
808
810
|
}
|
|
809
811
|
/**
|
|
810
812
|
* Gets the window's current fullscreen state.
|
|
@@ -1455,7 +1457,7 @@ class k {
|
|
|
1455
1457
|
async setSize(e) {
|
|
1456
1458
|
return s("plugin:window|set_size", {
|
|
1457
1459
|
label: this.label,
|
|
1458
|
-
value: e instanceof
|
|
1460
|
+
value: e instanceof y ? e : new y(e)
|
|
1459
1461
|
});
|
|
1460
1462
|
}
|
|
1461
1463
|
/**
|
|
@@ -1472,7 +1474,7 @@ class k {
|
|
|
1472
1474
|
async setMinSize(e) {
|
|
1473
1475
|
return s("plugin:window|set_min_size", {
|
|
1474
1476
|
label: this.label,
|
|
1475
|
-
value: e instanceof
|
|
1477
|
+
value: e instanceof y ? e : e ? new y(e) : null
|
|
1476
1478
|
});
|
|
1477
1479
|
}
|
|
1478
1480
|
/**
|
|
@@ -1489,7 +1491,7 @@ class k {
|
|
|
1489
1491
|
async setMaxSize(e) {
|
|
1490
1492
|
return s("plugin:window|set_max_size", {
|
|
1491
1493
|
label: this.label,
|
|
1492
|
-
value: e instanceof
|
|
1494
|
+
value: e instanceof y ? e : e ? new y(e) : null
|
|
1493
1495
|
});
|
|
1494
1496
|
}
|
|
1495
1497
|
/**
|
|
@@ -1531,7 +1533,7 @@ class k {
|
|
|
1531
1533
|
async setPosition(e) {
|
|
1532
1534
|
return s("plugin:window|set_position", {
|
|
1533
1535
|
label: this.label,
|
|
1534
|
-
value: e instanceof
|
|
1536
|
+
value: e instanceof p ? e : new p(e)
|
|
1535
1537
|
});
|
|
1536
1538
|
}
|
|
1537
1539
|
/**
|
|
@@ -1743,7 +1745,7 @@ class k {
|
|
|
1743
1745
|
async setCursorPosition(e) {
|
|
1744
1746
|
return s("plugin:window|set_cursor_position", {
|
|
1745
1747
|
label: this.label,
|
|
1746
|
-
value: e instanceof
|
|
1748
|
+
value: e instanceof p ? e : new p(e)
|
|
1747
1749
|
});
|
|
1748
1750
|
}
|
|
1749
1751
|
/**
|
|
@@ -1950,7 +1952,7 @@ class k {
|
|
|
1950
1952
|
*/
|
|
1951
1953
|
async onResized(e) {
|
|
1952
1954
|
return this.listen(o.WINDOW_RESIZED, (i) => {
|
|
1953
|
-
i.payload = new
|
|
1955
|
+
i.payload = new b(i.payload), e(i);
|
|
1954
1956
|
});
|
|
1955
1957
|
}
|
|
1956
1958
|
/**
|
|
@@ -2155,10 +2157,10 @@ function Ie(t) {
|
|
|
2155
2157
|
name: t.name,
|
|
2156
2158
|
scaleFactor: t.scaleFactor,
|
|
2157
2159
|
position: new w(t.position),
|
|
2158
|
-
size: new
|
|
2160
|
+
size: new b(t.size),
|
|
2159
2161
|
workArea: {
|
|
2160
2162
|
position: new w(t.workArea.position),
|
|
2161
|
-
size: new
|
|
2163
|
+
size: new b(t.workArea.size)
|
|
2162
2164
|
}
|
|
2163
2165
|
};
|
|
2164
2166
|
}
|
|
@@ -2387,7 +2389,7 @@ class B {
|
|
|
2387
2389
|
async size() {
|
|
2388
2390
|
return s("plugin:webview|webview_size", {
|
|
2389
2391
|
label: this.label
|
|
2390
|
-
}).then((e) => new
|
|
2392
|
+
}).then((e) => new b(e));
|
|
2391
2393
|
}
|
|
2392
2394
|
// Setters
|
|
2393
2395
|
/**
|
|
@@ -2419,7 +2421,7 @@ class B {
|
|
|
2419
2421
|
async setSize(e) {
|
|
2420
2422
|
return s("plugin:webview|set_webview_size", {
|
|
2421
2423
|
label: this.label,
|
|
2422
|
-
value: e instanceof
|
|
2424
|
+
value: e instanceof y ? e : new y(e)
|
|
2423
2425
|
});
|
|
2424
2426
|
}
|
|
2425
2427
|
/**
|
|
@@ -2436,7 +2438,7 @@ class B {
|
|
|
2436
2438
|
async setPosition(e) {
|
|
2437
2439
|
return s("plugin:webview|set_webview_position", {
|
|
2438
2440
|
label: this.label,
|
|
2439
|
-
value: e instanceof
|
|
2441
|
+
value: e instanceof p ? e : new p(e)
|
|
2440
2442
|
});
|
|
2441
2443
|
}
|
|
2442
2444
|
/**
|
|
@@ -2628,15 +2630,15 @@ class B {
|
|
|
2628
2630
|
}
|
|
2629
2631
|
function O() {
|
|
2630
2632
|
const t = ue();
|
|
2631
|
-
return new
|
|
2633
|
+
return new _(t.label, { skip: !0 });
|
|
2632
2634
|
}
|
|
2633
2635
|
async function Y() {
|
|
2634
|
-
return s("plugin:window|get_all_windows").then((t) => t.map((e) => new
|
|
2636
|
+
return s("plugin:window|get_all_windows").then((t) => t.map((e) => new _(e, {
|
|
2635
2637
|
// @ts-expect-error `skip` is not defined in the public API but it is handled by the constructor
|
|
2636
2638
|
skip: !0
|
|
2637
2639
|
})));
|
|
2638
2640
|
}
|
|
2639
|
-
class
|
|
2641
|
+
class _ {
|
|
2640
2642
|
/**
|
|
2641
2643
|
* Creates a new {@link Window} hosting a {@link Webview}.
|
|
2642
2644
|
* @example
|
|
@@ -2680,7 +2682,7 @@ class f {
|
|
|
2680
2682
|
static async getByLabel(e) {
|
|
2681
2683
|
var i;
|
|
2682
2684
|
const n = (i = (await Y()).find((a) => a.label === e)) !== null && i !== void 0 ? i : null;
|
|
2683
|
-
return n ? new
|
|
2685
|
+
return n ? new _(n.label, { skip: !0 }) : null;
|
|
2684
2686
|
}
|
|
2685
2687
|
/**
|
|
2686
2688
|
* Get an instance of `Webview` for the current webview.
|
|
@@ -2768,7 +2770,7 @@ class f {
|
|
|
2768
2770
|
return s("plugin:window|set_background_color", { color: e }).then(() => s("plugin:webview|set_webview_background_color", { color: e }));
|
|
2769
2771
|
}
|
|
2770
2772
|
}
|
|
2771
|
-
Ce(
|
|
2773
|
+
Ce(_, [k, B]);
|
|
2772
2774
|
function Ce(t, e) {
|
|
2773
2775
|
(Array.isArray(e) ? e : [e]).forEach((i) => {
|
|
2774
2776
|
Object.getOwnPropertyNames(i.prototype).forEach((n) => {
|
|
@@ -2841,25 +2843,25 @@ const D = /* @__PURE__ */ new Map(), Le = (t) => {
|
|
|
2841
2843
|
const n = ee(), a = `notice-${e}`;
|
|
2842
2844
|
let l = `${n.routePrefix}/${t.type}?id=${t.id}`;
|
|
2843
2845
|
Le(l) || (console.warn(`Invalid window URL: ${l}. Using fallback 404 page.`), l = n.notFoundUrl || "/404");
|
|
2844
|
-
const r = t.min_width || n.defaultWidth, u = t.min_height || n.defaultHeight, { x: m, y:
|
|
2846
|
+
const r = t.min_width || n.defaultWidth, u = t.min_height || n.defaultHeight, f = t.decorations ?? n.defaultDecorations ?? !0, { x: m, y: A } = await Ee(r, u, t.windowPosition);
|
|
2845
2847
|
try {
|
|
2846
|
-
const
|
|
2848
|
+
const h = new _(a, {
|
|
2847
2849
|
url: l,
|
|
2848
2850
|
title: t.title,
|
|
2849
2851
|
width: r,
|
|
2850
2852
|
height: u,
|
|
2851
2853
|
x: m,
|
|
2852
|
-
y:
|
|
2854
|
+
y: A,
|
|
2853
2855
|
resizable: !0,
|
|
2854
|
-
decorations:
|
|
2856
|
+
decorations: f,
|
|
2855
2857
|
skipTaskbar: !1,
|
|
2856
2858
|
alwaysOnTop: !0
|
|
2857
2859
|
});
|
|
2858
|
-
D.set(e,
|
|
2860
|
+
D.set(e, h), i.addActiveWindow(e), h.once("tauri://destroyed", async () => {
|
|
2859
2861
|
D.delete(e), i.removeActiveWindow(e), await i.markMessageAsShown(e), i.clearCurrent();
|
|
2860
2862
|
}), console.log(`Created notice window: ${a}`);
|
|
2861
|
-
} catch (
|
|
2862
|
-
console.error("Failed to create notice window:",
|
|
2863
|
+
} catch (h) {
|
|
2864
|
+
console.error("Failed to create notice window:", h), i.removeActiveWindow(e), i.clearCurrent();
|
|
2863
2865
|
}
|
|
2864
2866
|
}, U = async (t) => {
|
|
2865
2867
|
const e = String(t), i = D.get(e), n = c.getState();
|
|
@@ -2907,50 +2909,50 @@ const D = /* @__PURE__ */ new Map(), Le = (t) => {
|
|
|
2907
2909
|
queue: n
|
|
2908
2910
|
};
|
|
2909
2911
|
}, Ye = ({ children: t, onLoad: e, onClose: i }) => {
|
|
2910
|
-
const [n, a] = L(null), [l, r] = L(!0), [u,
|
|
2912
|
+
const [n, a] = L(null), [l, r] = L(!0), [u, f] = L(null);
|
|
2911
2913
|
return G(() => {
|
|
2912
2914
|
(async () => {
|
|
2913
2915
|
try {
|
|
2914
|
-
const
|
|
2915
|
-
if (!
|
|
2916
|
-
|
|
2916
|
+
const h = new URLSearchParams(window.location.search).get("id");
|
|
2917
|
+
if (!h) {
|
|
2918
|
+
f("No message ID provided"), r(!1), setTimeout(async () => {
|
|
2917
2919
|
try {
|
|
2918
2920
|
await O().close();
|
|
2919
|
-
} catch (
|
|
2920
|
-
console.error("Failed to close window:",
|
|
2921
|
+
} catch (v) {
|
|
2922
|
+
console.error("Failed to close window:", v);
|
|
2921
2923
|
}
|
|
2922
2924
|
}, 1e3);
|
|
2923
2925
|
return;
|
|
2924
2926
|
}
|
|
2925
|
-
const C = await ie(
|
|
2927
|
+
const C = await ie(h);
|
|
2926
2928
|
if (!C) {
|
|
2927
|
-
console.log(`Message ${
|
|
2929
|
+
console.log(`Message ${h} not found in database, closing window`), f("Message not found"), r(!1), setTimeout(async () => {
|
|
2928
2930
|
try {
|
|
2929
2931
|
await O().close();
|
|
2930
|
-
} catch (
|
|
2931
|
-
console.error("Failed to close window:",
|
|
2932
|
+
} catch (v) {
|
|
2933
|
+
console.error("Failed to close window:", v);
|
|
2932
2934
|
}
|
|
2933
2935
|
}, 500);
|
|
2934
2936
|
return;
|
|
2935
2937
|
}
|
|
2936
2938
|
a(C), r(!1), e && e(C);
|
|
2937
|
-
} catch (
|
|
2938
|
-
console.error("Failed to load message:",
|
|
2939
|
+
} catch (A) {
|
|
2940
|
+
console.error("Failed to load message:", A), f("Failed to load message"), r(!1), setTimeout(async () => {
|
|
2939
2941
|
try {
|
|
2940
2942
|
await O().close();
|
|
2941
|
-
} catch (
|
|
2942
|
-
console.error("Failed to close window:",
|
|
2943
|
+
} catch (h) {
|
|
2944
|
+
console.error("Failed to close window:", h);
|
|
2943
2945
|
}
|
|
2944
2946
|
}, 1e3);
|
|
2945
2947
|
}
|
|
2946
2948
|
})();
|
|
2947
2949
|
}, [e]), G(() => {
|
|
2948
2950
|
if (!n || !i) return;
|
|
2949
|
-
const
|
|
2951
|
+
const m = () => {
|
|
2950
2952
|
i(n);
|
|
2951
2953
|
};
|
|
2952
|
-
return window.addEventListener("beforeunload",
|
|
2953
|
-
window.removeEventListener("beforeunload",
|
|
2954
|
+
return window.addEventListener("beforeunload", m), () => {
|
|
2955
|
+
window.removeEventListener("beforeunload", m);
|
|
2954
2956
|
};
|
|
2955
2957
|
}, [n, i]), l ? /* @__PURE__ */ N("div", { style: {
|
|
2956
2958
|
display: "flex",
|