tauri-notice-window 1.0.6 → 1.0.8

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/index.d.ts CHANGED
@@ -14,8 +14,8 @@ export { NoticeLayout } from './components/NoticeLayout';
14
14
  export { setNoticeConfig, getNoticeConfig } from './config/noticeConfig';
15
15
  import { initializeNoticeWindowSystem, createNoticeWindow, closeNoticeWindow, closeAllNoticeWindows } from './utils/noticeWindow';
16
16
  export { initializeNoticeWindowSystem, createNoticeWindow, closeNoticeWindow, closeAllNoticeWindows, };
17
- import { initializeDatabase, saveMessage, hasMessage, isMessageShown, getPendingMessages, getMessage, markAsShown, markAsHidden, clearPendingMessages } from './utils/db';
18
- export { initializeDatabase, saveMessage, hasMessage, isMessageShown, getPendingMessages, getMessage, markAsShown, markAsHidden, clearPendingMessages, };
17
+ import { initializeDatabase, saveMessage, hasMessage, isMessageShown, getPendingMessages, getMessage, deleteMessageById, markAsShown, markAsHidden, clearPendingMessages } from './utils/db';
18
+ export { initializeDatabase, saveMessage, hasMessage, isMessageShown, getPendingMessages, getMessage, deleteMessageById, markAsShown, markAsHidden, clearPendingMessages, };
19
19
  /**
20
20
  * Initialize the complete notice window system
21
21
  * Call this once during app startup (e.g., in App.tsx or main layout)
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAG/F,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;AACxF,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,CAAA;AAGtD,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AACvD,OAAO,EAAE,aAAa,EA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rD,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAGzD,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAGxD,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAGxE,OAAO,EACL,4BAA4B,EAC5B,kBAAkB,EAClB,iBAAiB,EACjB,qBAAqB,EACtB,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EACL,4BAA4B,EAC5B,kBAAkB,EAClB,iBAAiB,EACjB,qBAAqB,GACtB,CAAA;AAED,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,UAAU,EACV,cAAc,EACd,kBAAkB,EAClB,UAAU,EACV,iBAAiB,EACjB,WAAW,EACX,YAAY,EACZ,oBAAoB,EACrB,MAAM,YAAY,CAAA;AACnB,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,UAAU,EACV,cAAc,EACd,kBAAkB,EAClB,UAAU,EACV,iBAAiB,EACjB,WAAW,EACX,YAAY,EACZ,oBAAoB,GACrB,CAAA;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,sBAAsB,QAAa,OAAO,CAAC,IAAI,CAY3D,CAAA"}
package/dist/index.js CHANGED
@@ -1,22 +1,24 @@
1
1
  import { create as oe } from "zustand";
2
2
  import { syncTabs as ue } from "zustand-sync";
3
3
  import ce from "dexie";
4
- import { useCallback as A, useState as I, useEffect as B } from "react";
4
+ import { useCallback as A, useState as x, useEffect as B } from "react";
5
5
  import { jsx as k, Fragment as de } from "react/jsx-runtime";
6
- const Z = "tauri-notice-config", G = {
6
+ const Z = "tauri-notice-config", U = {
7
7
  routePrefix: "/notice",
8
8
  databaseName: "tauri-notice-db",
9
9
  defaultWidth: 400,
10
- defaultHeight: 300
10
+ defaultHeight: 300,
11
+ notFoundUrl: "/404"
12
+ // Default 404 page
11
13
  }, Y = () => {
12
14
  try {
13
15
  const t = localStorage.getItem(Z);
14
16
  if (t)
15
- return { ...G, ...JSON.parse(t) };
17
+ return { ...U, ...JSON.parse(t) };
16
18
  } catch (t) {
17
19
  console.warn("Failed to load config from localStorage:", t);
18
20
  }
19
- return G;
21
+ return U;
20
22
  }, we = (t) => {
21
23
  try {
22
24
  localStorage.setItem(Z, JSON.stringify(t));
@@ -66,7 +68,9 @@ const X = () => {
66
68
  await h().messages.update(t, {
67
69
  queueStatus: "hidden"
68
70
  });
69
- }, me = async (t) => await h().messages.get(t), ve = async () => {
71
+ }, me = async (t) => await h().messages.get(t), He = async (t) => {
72
+ await h().messages.delete(t);
73
+ }, ve = async () => {
70
74
  await h().messages.where("queueStatus").anyOf(["pending", "showing"]).delete();
71
75
  }, We = async (t) => {
72
76
  const e = t.map(
@@ -183,7 +187,7 @@ const X = () => {
183
187
  currentMessage: (t) => t.currentMessage,
184
188
  isProcessing: (t) => t.isProcessing,
185
189
  queue: (t) => t.queue
186
- }, Ue = () => {
190
+ }, Ve = () => {
187
191
  const t = d((i) => i.enqueue);
188
192
  return { showNotice: A(
189
193
  async (i) => {
@@ -510,23 +514,23 @@ class Oe {
510
514
  return this._preventDefault;
511
515
  }
512
516
  }
513
- var U;
517
+ var G;
514
518
  (function(t) {
515
519
  t.None = "none", t.Normal = "normal", t.Indeterminate = "indeterminate", t.Paused = "paused", t.Error = "error";
516
- })(U || (U = {}));
520
+ })(G || (G = {}));
517
521
  function le() {
518
522
  return new P(window.__TAURI_INTERNALS__.metadata.currentWindow.label, {
519
523
  // @ts-expect-error `skip` is not defined in the public API but it is handled by the constructor
520
524
  skip: !0
521
525
  });
522
526
  }
523
- async function C() {
527
+ async function L() {
524
528
  return s("plugin:window|get_all_windows").then((t) => t.map((e) => new P(e, {
525
529
  // @ts-expect-error `skip` is not defined in the public API but it is handled by the constructor
526
530
  skip: !0
527
531
  })));
528
532
  }
529
- const L = ["tauri://created", "tauri://error"];
533
+ const M = ["tauri://created", "tauri://error"];
530
534
  class P {
531
535
  /**
532
536
  * Creates a new Window.
@@ -568,7 +572,7 @@ class P {
568
572
  */
569
573
  static async getByLabel(e) {
570
574
  var i;
571
- return (i = (await C()).find((n) => n.label === e)) !== null && i !== void 0 ? i : null;
575
+ return (i = (await L()).find((n) => n.label === e)) !== null && i !== void 0 ? i : null;
572
576
  }
573
577
  /**
574
578
  * Get an instance of `Window` for the current window.
@@ -580,7 +584,7 @@ class P {
580
584
  * Gets a list of instances of `Window` for all available windows.
581
585
  */
582
586
  static async getAll() {
583
- return C();
587
+ return L();
584
588
  }
585
589
  /**
586
590
  * Gets the focused window.
@@ -593,7 +597,7 @@ class P {
593
597
  * @returns The Window instance or `undefined` if there is not any focused window.
594
598
  */
595
599
  static async getFocusedWindow() {
596
- for (const e of await C())
600
+ for (const e of await L())
597
601
  if (await e.isFocused())
598
602
  return e;
599
603
  return null;
@@ -664,7 +668,7 @@ class P {
664
668
  * @param payload Event payload.
665
669
  */
666
670
  async emit(e, i) {
667
- if (L.includes(e)) {
671
+ if (M.includes(e)) {
668
672
  for (const n of this.listeners[e] || [])
669
673
  n({
670
674
  event: e,
@@ -688,7 +692,7 @@ class P {
688
692
  * @param payload Event payload.
689
693
  */
690
694
  async emitTo(e, i, n) {
691
- if (L.includes(i)) {
695
+ if (M.includes(i)) {
692
696
  for (const a of this.listeners[i] || [])
693
697
  a({
694
698
  event: i,
@@ -701,7 +705,7 @@ class P {
701
705
  }
702
706
  /** @ignore */
703
707
  _handleTauriEvent(e, i) {
704
- return L.includes(e) ? (e in this.listeners ? this.listeners[e].push(i) : this.listeners[e] = [i], !0) : !1;
708
+ return M.includes(e) ? (e in this.listeners ? this.listeners[e].push(i) : this.listeners[e] = [i], !0) : !1;
705
709
  }
706
710
  // Getters
707
711
  /**
@@ -2113,14 +2117,14 @@ var H;
2113
2117
  (function(t) {
2114
2118
  t.Disabled = "disabled", t.Throttle = "throttle", t.Suspend = "suspend";
2115
2119
  })(H || (H = {}));
2116
- var Q;
2120
+ var V;
2117
2121
  (function(t) {
2118
2122
  t.Default = "default", t.FluentOverlay = "fluentOverlay";
2119
- })(Q || (Q = {}));
2120
- var V;
2123
+ })(V || (V = {}));
2124
+ var Q;
2121
2125
  (function(t) {
2122
2126
  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";
2123
- })(V || (V = {}));
2127
+ })(Q || (Q = {}));
2124
2128
  var j;
2125
2129
  (function(t) {
2126
2130
  t.FollowsWindowActiveState = "followsWindowActiveState", t.Active = "active", t.Inactive = "inactive";
@@ -2137,7 +2141,7 @@ function Pe(t) {
2137
2141
  }
2138
2142
  };
2139
2143
  }
2140
- async function xe() {
2144
+ async function Ie() {
2141
2145
  return s("plugin:window|primary_monitor").then(Pe);
2142
2146
  }
2143
2147
  function re() {
@@ -2155,7 +2159,7 @@ async function $() {
2155
2159
  skip: !0
2156
2160
  })));
2157
2161
  }
2158
- const M = ["tauri://created", "tauri://error"];
2162
+ const C = ["tauri://created", "tauri://error"];
2159
2163
  class T {
2160
2164
  /**
2161
2165
  * Creates a new Webview.
@@ -2292,7 +2296,7 @@ class T {
2292
2296
  * @param payload Event payload.
2293
2297
  */
2294
2298
  async emit(e, i) {
2295
- if (M.includes(e)) {
2299
+ if (C.includes(e)) {
2296
2300
  for (const n of this.listeners[e] || [])
2297
2301
  n({
2298
2302
  event: e,
@@ -2317,7 +2321,7 @@ class T {
2317
2321
  * @param payload Event payload.
2318
2322
  */
2319
2323
  async emitTo(e, i, n) {
2320
- if (M.includes(i)) {
2324
+ if (C.includes(i)) {
2321
2325
  for (const a of this.listeners[i] || [])
2322
2326
  a({
2323
2327
  event: i,
@@ -2330,7 +2334,7 @@ class T {
2330
2334
  }
2331
2335
  /** @ignore */
2332
2336
  _handleTauriEvent(e, i) {
2333
- return M.includes(e) ? (e in this.listeners ? this.listeners[e].push(i) : this.listeners[e] = [i], !0) : !1;
2337
+ return C.includes(e) ? (e in this.listeners ? this.listeners[e].push(i) : this.listeners[e] = [i], !0) : !1;
2334
2338
  }
2335
2339
  // Getters
2336
2340
  /**
@@ -2601,7 +2605,7 @@ class T {
2601
2605
  };
2602
2606
  }
2603
2607
  }
2604
- function Ie() {
2608
+ function xe() {
2605
2609
  const t = re();
2606
2610
  return new _(t.label, { skip: !0 });
2607
2611
  }
@@ -2661,7 +2665,7 @@ class _ {
2661
2665
  * Get an instance of `Webview` for the current webview.
2662
2666
  */
2663
2667
  static getCurrent() {
2664
- return Ie();
2668
+ return xe();
2665
2669
  }
2666
2670
  /**
2667
2671
  * Gets a list of instances of `Webview` for all available webviews.
@@ -2757,13 +2761,20 @@ function ke(t, e) {
2757
2761
  });
2758
2762
  });
2759
2763
  }
2760
- const S = /* @__PURE__ */ new Map(), Ce = async (t, e, i) => {
2764
+ const S = /* @__PURE__ */ new Map(), Le = (t) => {
2765
+ if (!t || t.trim() === "") return !1;
2766
+ try {
2767
+ return !!(t.startsWith("/") || t.startsWith("http://") || t.startsWith("https://") || t.startsWith("tauri://"));
2768
+ } catch {
2769
+ return !1;
2770
+ }
2771
+ }, Me = async (t, e, i) => {
2761
2772
  const n = i?.padding ?? 20;
2762
2773
  if (i?.x !== void 0 && i?.y !== void 0)
2763
2774
  return { x: i.x, y: i.y };
2764
2775
  let a = 1920, r = 1080;
2765
2776
  try {
2766
- const u = await xe();
2777
+ const u = await Ie();
2767
2778
  u?.size && (a = u.size.width, r = u.size.height);
2768
2779
  } catch (u) {
2769
2780
  console.warn("Failed to get monitor info, using defaults:", u);
@@ -2800,13 +2811,16 @@ const S = /* @__PURE__ */ new Map(), Ce = async (t, e, i) => {
2800
2811
  y: r - e - n
2801
2812
  };
2802
2813
  }
2803
- }, Le = async (t) => {
2814
+ }, Ce = async (t) => {
2804
2815
  const e = String(t.id), i = d.getState();
2805
2816
  if (i.isWindowActive(e)) {
2806
2817
  console.log(`Notice window already open for message: ${e}`);
2807
2818
  return;
2808
2819
  }
2809
- const n = K(), a = `notice-${e}`, r = `${n.routePrefix}/${t.type}?id=${t.id}`, l = t.min_width || n.defaultWidth, u = t.min_height || n.defaultHeight, { x: f, y: m } = await Ce(l, u, t.windowPosition);
2820
+ const n = K(), a = `notice-${e}`;
2821
+ let r = `${n.routePrefix}/${t.type}?id=${t.id}`;
2822
+ Le(r) || (console.warn(`Invalid window URL: ${r}. Using fallback 404 page.`), r = n.notFoundUrl || "/404");
2823
+ const l = t.min_width || n.defaultWidth, u = t.min_height || n.defaultHeight, { x: f, y: m } = await Me(l, u, t.windowPosition);
2810
2824
  try {
2811
2825
  const y = new _(a, {
2812
2826
  url: r,
@@ -2834,23 +2848,23 @@ const S = /* @__PURE__ */ new Map(), Ce = async (t, e, i) => {
2834
2848
  } catch (a) {
2835
2849
  console.error("Failed to close notice window:", a);
2836
2850
  }
2837
- }, Me = async () => {
2851
+ }, Re = async () => {
2838
2852
  const t = Array.from(S.keys()).map(
2839
2853
  (e) => q(e)
2840
2854
  );
2841
2855
  await Promise.all(t);
2842
- }, Re = () => {
2856
+ }, Ee = () => {
2843
2857
  let t = null;
2844
2858
  d.subscribe((e) => {
2845
2859
  const i = e.currentMessage;
2846
- i && i !== t ? (t = i, Le(i)) : i || (t = null);
2860
+ i && i !== t ? (t = i, Ce(i)) : i || (t = null);
2847
2861
  }), console.log("Notice window system initialized");
2848
- }, He = () => {
2862
+ }, Qe = () => {
2849
2863
  const t = d((i) => i.currentMessage);
2850
2864
  return { closeNotice: A(async () => {
2851
2865
  t && await q(t.id);
2852
2866
  }, [t]) };
2853
- }, Qe = () => {
2867
+ }, je = () => {
2854
2868
  const t = d();
2855
2869
  return { hideNotice: A(
2856
2870
  async (i) => {
@@ -2858,12 +2872,12 @@ const S = /* @__PURE__ */ new Map(), Ce = async (t, e, i) => {
2858
2872
  },
2859
2873
  [t]
2860
2874
  ) };
2861
- }, Ve = () => {
2875
+ }, $e = () => {
2862
2876
  const t = d((i) => i.clearOnLogout);
2863
2877
  return { hideAllNotices: A(async () => {
2864
- await Me(), await t();
2878
+ await Re(), await t();
2865
2879
  }, [t]) };
2866
- }, je = () => {
2880
+ }, Je = () => {
2867
2881
  const t = d(D.queueLength), e = d(D.currentMessage), i = d(D.isProcessing), n = d(D.queue);
2868
2882
  return {
2869
2883
  queueLength: t,
@@ -2871,8 +2885,8 @@ const S = /* @__PURE__ */ new Map(), Ce = async (t, e, i) => {
2871
2885
  isProcessing: i,
2872
2886
  queue: n
2873
2887
  };
2874
- }, $e = ({ children: t, onLoad: e, onClose: i }) => {
2875
- const [n, a] = I(null), [r, l] = I(!0), [u, f] = I(null);
2888
+ }, Ze = ({ children: t, onLoad: e, onClose: i }) => {
2889
+ const [n, a] = x(null), [r, l] = x(!0), [u, f] = x(null);
2876
2890
  return B(() => {
2877
2891
  (async () => {
2878
2892
  try {
@@ -2881,12 +2895,12 @@ const S = /* @__PURE__ */ new Map(), Ce = async (t, e, i) => {
2881
2895
  f("No message ID provided"), l(!1);
2882
2896
  return;
2883
2897
  }
2884
- const x = await me(F);
2885
- if (!x) {
2898
+ const I = await me(F);
2899
+ if (!I) {
2886
2900
  f("Message not found"), l(!1);
2887
2901
  return;
2888
2902
  }
2889
- a(x), l(!1), e && e(x);
2903
+ a(I), l(!1), e && e(I);
2890
2904
  } catch (y) {
2891
2905
  console.error("Failed to load message:", y), f("Failed to load message"), l(!1);
2892
2906
  }
@@ -2913,35 +2927,36 @@ const S = /* @__PURE__ */ new Map(), Ce = async (t, e, i) => {
2913
2927
  fontFamily: "system-ui, -apple-system, sans-serif",
2914
2928
  color: "#ef4444"
2915
2929
  }, children: u || "Message not found" }) : /* @__PURE__ */ k(de, { children: t(n) });
2916
- }, Je = async () => {
2917
- X(), Re();
2930
+ }, Ye = async () => {
2931
+ X(), Ee();
2918
2932
  const { initializeFromDatabase: t } = d.getState();
2919
2933
  await t(), console.log("Tauri Notice System initialized");
2920
2934
  };
2921
2935
  export {
2922
- $e as NoticeLayout,
2936
+ Ze as NoticeLayout,
2923
2937
  ve as clearPendingMessages,
2924
- Me as closeAllNoticeWindows,
2938
+ Re as closeAllNoticeWindows,
2925
2939
  q as closeNoticeWindow,
2926
- Le as createNoticeWindow,
2940
+ Ce as createNoticeWindow,
2941
+ He as deleteMessageById,
2927
2942
  me as getMessage,
2928
2943
  K as getNoticeConfig,
2929
2944
  pe as getPendingMessages,
2930
2945
  be as hasMessage,
2931
2946
  X as initializeDatabase,
2932
- Je as initializeNoticeSystem,
2933
- Re as initializeNoticeWindowSystem,
2947
+ Ye as initializeNoticeSystem,
2948
+ Ee as initializeNoticeWindowSystem,
2934
2949
  ye as isMessageShown,
2935
2950
  fe as markAsHidden,
2936
2951
  ee as markAsShown,
2937
2952
  D as messageQueueSelectors,
2938
2953
  ge as saveMessage,
2939
2954
  Ge as setNoticeConfig,
2940
- He as useCloseNotice,
2941
- Ve as useHideAllNotices,
2942
- Qe as useHideNotice,
2943
- je as useMessageQueue,
2955
+ Qe as useCloseNotice,
2956
+ $e as useHideAllNotices,
2957
+ je as useHideNotice,
2958
+ Je as useMessageQueue,
2944
2959
  d as useMessageQueueStore,
2945
- Ue as useNoticeWindow
2960
+ Ve as useNoticeWindow
2946
2961
  };
2947
2962
  //# sourceMappingURL=index.js.map