tauri-notice-window 1.0.13 → 1.0.15

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/README.md CHANGED
@@ -11,6 +11,7 @@ A reusable React library for cross-window notification management in Tauri v2+ a
11
11
  - **One-at-a-Time Display**: Only one notice window shown at a time
12
12
  - **Customizable Routes**: Configurable router prefix for notice pages
13
13
  - **URL Validation & 404 Fallback**: Automatic validation with customizable error pages for invalid routes
14
+ - **Auto-Close for Borderless Windows**: Stuck borderless windows auto-close after configurable timeout
14
15
  - **Type Safety**: Full TypeScript support
15
16
  - **Easy Integration**: Simple hooks API
16
17
  - **Tauri v2 Ready**: Uses latest Tauri v2 window APIs
@@ -125,6 +126,7 @@ function App() {
125
126
  defaultHeight: 300, // default height of the notice window
126
127
  notFoundUrl: '/404', // custom 404 page when route is invalid (optional)
127
128
  defaultDecorations: true, // show window title bar by default (optional)
129
+ loadTimeout: 4000, // auto-close timeout for borderless windows in ms (optional)
128
130
  })
129
131
 
130
132
  // Initialize the system
@@ -619,6 +621,7 @@ interface NoticeConfig {
619
621
  defaultHeight: number // Default window height (default: 300)
620
622
  notFoundUrl?: string // Custom 404 page URL for invalid routes (default: '/404')
621
623
  defaultDecorations?: boolean // Show window title bar by default (default: true)
624
+ loadTimeout?: number // Auto-close timeout in ms for borderless windows (default: 4000)
622
625
  }
623
626
  ```
624
627
 
@@ -711,6 +714,7 @@ setNoticeConfig({
711
714
  defaultHeight: 400,
712
715
  notFoundUrl: '/error', // Custom 404 page
713
716
  defaultDecorations: false, // Hide title bar globally
717
+ loadTimeout: 4000, // Auto-close stuck borderless windows after 4s
714
718
  })
715
719
  ```
716
720
 
@@ -1043,6 +1047,8 @@ await showNotice({
1043
1047
  })
1044
1048
 
1045
1049
  // Borderless window (no title bar)
1050
+ // Note: On macOS, uses titleBarStyle: 'overlay' internally for compatibility
1051
+ // On Windows/Linux, uses decorations: false
1046
1052
  await showNotice({
1047
1053
  id: '129',
1048
1054
  title: 'Borderless',
@@ -1064,6 +1070,18 @@ await showNotice({
1064
1070
  })
1065
1071
  ```
1066
1072
 
1073
+ **Auto-Close for Borderless Windows:**
1074
+
1075
+ When `decorations: false`, the window has no title bar, so users cannot manually close a stuck window. The library automatically closes borderless windows if they fail to load within `loadTimeout` (default: 4 seconds).
1076
+
1077
+ ```typescript
1078
+ // Customize or disable auto-close timeout
1079
+ setNoticeConfig({
1080
+ loadTimeout: 6000, // 6 seconds
1081
+ // loadTimeout: 0, // Disable auto-close
1082
+ })
1083
+ ```
1084
+
1067
1085
  ### Queue Status Display
1068
1086
 
1069
1087
  ```typescript
@@ -1 +1 @@
1
- {"version":3,"file":"noticeConfig.d.ts","sourceRoot":"","sources":["../../src/config/noticeConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AA0CpD;;;GAGG;AACH,eAAO,MAAM,eAAe,GAAI,WAAW,OAAO,CAAC,YAAY,CAAC,KAAG,IAIlE,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,eAAe,QAAO,YAElC,CAAA"}
1
+ {"version":3,"file":"noticeConfig.d.ts","sourceRoot":"","sources":["../../src/config/noticeConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AA2CpD;;;GAGG;AACH,eAAO,MAAM,eAAe,GAAI,WAAW,OAAO,CAAC,YAAY,CAAC,KAAG,IAIlE,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,eAAe,QAAO,YAElC,CAAA"}
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const we=require("zustand"),he=require("zustand-sync"),ge=require("dexie"),y=require("react"),W=require("react/jsx-runtime"),X="tauri-notice-config",H={routePrefix:"/notice",databaseName:"tauri-notice-db",defaultWidth:400,defaultHeight:300,notFoundUrl:"/404",defaultDecorations:!0},ee=()=>{try{const t=localStorage.getItem(X);if(t)return{...H,...JSON.parse(t)}}catch(t){console.warn("Failed to load config from localStorage:",t)}return H},ye=t=>{try{localStorage.setItem(X,JSON.stringify(t))}catch(e){console.warn("Failed to save config to localStorage:",e)}},be=t=>{const i={...ee(),...t};ye(i)},F=()=>ee();class pe extends ge{messages;constructor(e){super(e),this.version(1).stores({messages:"id, queueStatus, queuePosition, timestamp"})}}let A=null;const B=()=>{if(!A){const t=F();A=new pe(t.databaseName)}return A},g=()=>A||B(),_e=async t=>{const e={...t,timestamp:new Date().toISOString(),isRead:!1,isShown:!1,queueStatus:"pending",queuePosition:0};await g().messages.put(e)},fe=async t=>!!await g().messages.get(t),me=async t=>{const e=await g().messages.get(t);return e?.isShown===!0||e?.queueStatus==="shown"},te=async()=>await g().messages.where("queueStatus").equals("pending").sortBy("queuePosition"),ve=async(t,e)=>{await g().messages.update(t,{queueStatus:e})},Se=async t=>{await g().messages.update(t,{queueStatus:"shown",isShown:!0})},We=async t=>{await g().messages.update(t,{queueStatus:"hidden"})},U=async t=>await g().messages.get(t),Ne=async t=>{await g().messages.delete(t)},Ae=async()=>{await g().messages.where("queueStatus").anyOf(["pending","showing"]).delete()},De=async t=>{const e=t.map(i=>g().messages.update(i.id,{queuePosition:i.position}));await Promise.all(e)},ze=(t,e)=>({queue:[],currentMessage:null,isProcessing:!1,initialized:!1,activeWindowIds:[],enqueue:async i=>{const n=e();if(await me(i.id)){console.log(`Message ${i.id} was already shown, skipping`);return}if(await fe(i.id)||await _e(i),!n.queue.some(c=>c.id===i.id)){const c=[...n.queue,i];t({queue:c}),await e().persistQueue()}!n.isProcessing&&!n.currentMessage&&await e().showNext()},dequeue:()=>{const i=e();if(i.queue.length===0)return null;const[n,...a]=i.queue;return t({queue:a}),n},showNext:async()=>{if(e().isProcessing)return;const n=e().dequeue();if(!n){t({isProcessing:!1,currentMessage:null});return}if(!await U(n.id)){console.log(`Message ${n.id} was deleted, skipping to next`),await e().showNext();return}t({currentMessage:n,isProcessing:!0}),await ve(n.id,"showing"),await e().persistQueue()},clearCurrent:()=>{t({currentMessage:null,isProcessing:!1}),e().queue.length>0&&e().showNext()},setCurrentMessage:i=>{t({currentMessage:i})},setIsProcessing:i=>{t({isProcessing:i})},setQueue:i=>{t({queue:i})},initializeFromDatabase:async()=>{if(e().initialized)return;t({initialized:!0});const n=await te();n.length>0&&(t({queue:n}),await e().showNext())},persistQueue:async()=>{const n=e().queue.map((a,l)=>({id:a.id,position:l}));await De(n)},clearOnLogout:async()=>{t({queue:[],currentMessage:null,isProcessing:!1,activeWindowIds:[],initialized:!1}),await Ae()},removeFromQueue:async i=>{const n=e(),a=n.queue.filter(l=>l.id!==i);t({queue:a}),await e().persistQueue(),n.currentMessage?.id===i&&e().clearCurrent()},deleteMessage:async i=>{await Ne(i),await e().removeFromQueue(i)},hideMessage:async i=>{await We(i),await e().removeFromQueue(i)},markMessageAsShown:async i=>{await Se(i)},addActiveWindow:i=>{const n=e(),a=String(i);n.activeWindowIds.includes(a)||t({activeWindowIds:[...n.activeWindowIds,a]})},removeActiveWindow:i=>{const n=e(),a=String(i);t({activeWindowIds:n.activeWindowIds.filter(l=>l!==a)})},isWindowActive:i=>{const n=e(),a=String(i);return n.activeWindowIds.includes(a)}}),u=we.create()(he.syncTabs(ze,{name:"tauri-notice-queue"})),N={queueLength:t=>t.queue.length,currentMessage:t=>t.currentMessage,isProcessing:t=>t.isProcessing,queue:t=>t.queue},Me=()=>{const t=u(i=>i.enqueue);return{showNotice:y.useCallback(async i=>{await t(i)},[t])}};function xe(t,e,i,n){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");return i==="m"?n:i==="a"?n.call(t):n?n.value:e.get(t)}function Oe(t,e,i,n,a){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");return e.set(t,i),i}var x;const h="__TAURI_TO_IPC_KEY__";function ke(t,e=!1){return window.__TAURI_INTERNALS__.transformCallback(t,e)}async function s(t,e={},i){return window.__TAURI_INTERNALS__.invoke(t,e,i)}class Pe{get rid(){return xe(this,x,"f")}constructor(e){x.set(this,void 0),Oe(this,x,e)}async close(){return s("plugin:resources|close",{rid:this.rid})}}x=new WeakMap;class ie{constructor(...e){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])}toPhysical(e){return new _(this.width*e,this.height*e)}[h](){return{width:this.width,height:this.height}}toJSON(){return this[h]()}}class _{constructor(...e){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])}toLogical(e){return new ie(this.width/e,this.height/e)}[h](){return{width:this.width,height:this.height}}toJSON(){return this[h]()}}class p{constructor(e){this.size=e}toLogical(e){return this.size instanceof ie?this.size:this.size.toLogical(e)}toPhysical(e){return this.size instanceof _?this.size:this.size.toPhysical(e)}[h](){return{[`${this.size.type}`]:{width:this.size.width,height:this.size.height}}}toJSON(){return this[h]()}}class ne{constructor(...e){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])}toPhysical(e){return new d(this.x*e,this.y*e)}[h](){return{x:this.x,y:this.y}}toJSON(){return this[h]()}}class d{constructor(...e){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])}toLogical(e){return new ne(this.x/e,this.y/e)}[h](){return{x:this.x,y:this.y}}toJSON(){return this[h]()}}class f{constructor(e){this.position=e}toLogical(e){return this.position instanceof ne?this.position:this.position.toLogical(e)}toPhysical(e){return this.position instanceof d?this.position:this.position.toPhysical(e)}[h](){return{[`${this.position.type}`]:{x:this.position.x,y:this.position.y}}}toJSON(){return this[h]()}}var o;(function(t){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"})(o||(o={}));async function se(t,e){window.__TAURI_EVENT_PLUGIN_INTERNALS__.unregisterListener(t,e),await s("plugin:event|unlisten",{event:t,eventId:e})}async function P(t,e,i){var n;const a=typeof i?.target=="string"?{kind:"AnyLabel",label:i.target}:(n=i?.target)!==null&&n!==void 0?n:{kind:"Any"};return s("plugin:event|listen",{event:t,target:a,handler:ke(e)}).then(l=>async()=>se(t,l))}async function Q(t,e,i){return P(t,n=>{se(t,n.id),e(n)},i)}async function ae(t,e){await s("plugin:event|emit",{event:t,payload:e})}async function re(t,e,i){await s("plugin:event|emit_to",{target:typeof t=="string"?{kind:"AnyLabel",label:t}:t,event:e,payload:i})}class D extends Pe{constructor(e){super(e)}static async new(e,i,n){return s("plugin:image|new",{rgba:k(e),width:i,height:n}).then(a=>new D(a))}static async fromBytes(e){return s("plugin:image|from_bytes",{bytes:k(e)}).then(i=>new D(i))}static async fromPath(e){return s("plugin:image|from_path",{path:e}).then(i=>new D(i))}async rgba(){return s("plugin:image|rgba",{rid:this.rid}).then(e=>new Uint8Array(e))}async size(){return s("plugin:image|size",{rid:this.rid})}}function k(t){return t==null?null:typeof t=="string"?t:t instanceof D?t.rid:t}var q;(function(t){t[t.Critical=1]="Critical",t[t.Informational=2]="Informational"})(q||(q={}));class Ie{constructor(e){this._preventDefault=!1,this.event=e.event,this.id=e.id}preventDefault(){this._preventDefault=!0}isPreventDefault(){return this._preventDefault}}var j;(function(t){t.None="none",t.Normal="normal",t.Indeterminate="indeterminate",t.Paused="paused",t.Error="error"})(j||(j={}));function le(){return new I(window.__TAURI_INTERNALS__.metadata.currentWindow.label,{skip:!0})}async function E(){return s("plugin:window|get_all_windows").then(t=>t.map(e=>new I(e,{skip:!0})))}const R=["tauri://created","tauri://error"];class I{constructor(e,i={}){var n;this.label=e,this.listeners=Object.create(null),i?.skip||s("plugin:window|create",{options:{...i,parent:typeof i.parent=="string"?i.parent:(n=i.parent)===null||n===void 0?void 0:n.label,label:e}}).then(async()=>this.emit("tauri://created")).catch(async a=>this.emit("tauri://error",a))}static async getByLabel(e){var i;return(i=(await E()).find(n=>n.label===e))!==null&&i!==void 0?i:null}static getCurrent(){return le()}static async getAll(){return E()}static async getFocusedWindow(){for(const e of await E())if(await e.isFocused())return e;return null}async listen(e,i){return this._handleTauriEvent(e,i)?()=>{const n=this.listeners[e];n.splice(n.indexOf(i),1)}:P(e,i,{target:{kind:"Window",label:this.label}})}async once(e,i){return this._handleTauriEvent(e,i)?()=>{const n=this.listeners[e];n.splice(n.indexOf(i),1)}:Q(e,i,{target:{kind:"Window",label:this.label}})}async emit(e,i){if(R.includes(e)){for(const n of this.listeners[e]||[])n({event:e,id:-1,payload:i});return}return ae(e,i)}async emitTo(e,i,n){if(R.includes(i)){for(const a of this.listeners[i]||[])a({event:i,id:-1,payload:n});return}return re(e,i,n)}_handleTauriEvent(e,i){return R.includes(e)?(e in this.listeners?this.listeners[e].push(i):this.listeners[e]=[i],!0):!1}async scaleFactor(){return s("plugin:window|scale_factor",{label:this.label})}async innerPosition(){return s("plugin:window|inner_position",{label:this.label}).then(e=>new d(e))}async outerPosition(){return s("plugin:window|outer_position",{label:this.label}).then(e=>new d(e))}async innerSize(){return s("plugin:window|inner_size",{label:this.label}).then(e=>new _(e))}async outerSize(){return s("plugin:window|outer_size",{label:this.label}).then(e=>new _(e))}async isFullscreen(){return s("plugin:window|is_fullscreen",{label:this.label})}async isMinimized(){return s("plugin:window|is_minimized",{label:this.label})}async isMaximized(){return s("plugin:window|is_maximized",{label:this.label})}async isFocused(){return s("plugin:window|is_focused",{label:this.label})}async isDecorated(){return s("plugin:window|is_decorated",{label:this.label})}async isResizable(){return s("plugin:window|is_resizable",{label:this.label})}async isMaximizable(){return s("plugin:window|is_maximizable",{label:this.label})}async isMinimizable(){return s("plugin:window|is_minimizable",{label:this.label})}async isClosable(){return s("plugin:window|is_closable",{label:this.label})}async isVisible(){return s("plugin:window|is_visible",{label:this.label})}async title(){return s("plugin:window|title",{label:this.label})}async theme(){return s("plugin:window|theme",{label:this.label})}async isAlwaysOnTop(){return s("plugin:window|is_always_on_top",{label:this.label})}async center(){return s("plugin:window|center",{label:this.label})}async requestUserAttention(e){let i=null;return e&&(e===q.Critical?i={type:"Critical"}:i={type:"Informational"}),s("plugin:window|request_user_attention",{label:this.label,value:i})}async setResizable(e){return s("plugin:window|set_resizable",{label:this.label,value:e})}async setEnabled(e){return s("plugin:window|set_enabled",{label:this.label,value:e})}async isEnabled(){return s("plugin:window|is_enabled",{label:this.label})}async setMaximizable(e){return s("plugin:window|set_maximizable",{label:this.label,value:e})}async setMinimizable(e){return s("plugin:window|set_minimizable",{label:this.label,value:e})}async setClosable(e){return s("plugin:window|set_closable",{label:this.label,value:e})}async setTitle(e){return s("plugin:window|set_title",{label:this.label,value:e})}async maximize(){return s("plugin:window|maximize",{label:this.label})}async unmaximize(){return s("plugin:window|unmaximize",{label:this.label})}async toggleMaximize(){return s("plugin:window|toggle_maximize",{label:this.label})}async minimize(){return s("plugin:window|minimize",{label:this.label})}async unminimize(){return s("plugin:window|unminimize",{label:this.label})}async show(){return s("plugin:window|show",{label:this.label})}async hide(){return s("plugin:window|hide",{label:this.label})}async close(){return s("plugin:window|close",{label:this.label})}async destroy(){return s("plugin:window|destroy",{label:this.label})}async setDecorations(e){return s("plugin:window|set_decorations",{label:this.label,value:e})}async setShadow(e){return s("plugin:window|set_shadow",{label:this.label,value:e})}async setEffects(e){return s("plugin:window|set_effects",{label:this.label,value:e})}async clearEffects(){return s("plugin:window|set_effects",{label:this.label,value:null})}async setAlwaysOnTop(e){return s("plugin:window|set_always_on_top",{label:this.label,value:e})}async setAlwaysOnBottom(e){return s("plugin:window|set_always_on_bottom",{label:this.label,value:e})}async setContentProtected(e){return s("plugin:window|set_content_protected",{label:this.label,value:e})}async setSize(e){return s("plugin:window|set_size",{label:this.label,value:e instanceof p?e:new p(e)})}async setMinSize(e){return s("plugin:window|set_min_size",{label:this.label,value:e instanceof p?e:e?new p(e):null})}async setMaxSize(e){return s("plugin:window|set_max_size",{label:this.label,value:e instanceof p?e:e?new p(e):null})}async setSizeConstraints(e){function i(n){return n?{Logical:n}:null}return s("plugin:window|set_size_constraints",{label:this.label,value:{minWidth:i(e?.minWidth),minHeight:i(e?.minHeight),maxWidth:i(e?.maxWidth),maxHeight:i(e?.maxHeight)}})}async setPosition(e){return s("plugin:window|set_position",{label:this.label,value:e instanceof f?e:new f(e)})}async setFullscreen(e){return s("plugin:window|set_fullscreen",{label:this.label,value:e})}async setSimpleFullscreen(e){return s("plugin:window|set_simple_fullscreen",{label:this.label,value:e})}async setFocus(){return s("plugin:window|set_focus",{label:this.label})}async setFocusable(e){return s("plugin:window|set_focusable",{label:this.label,value:e})}async setIcon(e){return s("plugin:window|set_icon",{label:this.label,value:k(e)})}async setSkipTaskbar(e){return s("plugin:window|set_skip_taskbar",{label:this.label,value:e})}async setCursorGrab(e){return s("plugin:window|set_cursor_grab",{label:this.label,value:e})}async setCursorVisible(e){return s("plugin:window|set_cursor_visible",{label:this.label,value:e})}async setCursorIcon(e){return s("plugin:window|set_cursor_icon",{label:this.label,value:e})}async setBackgroundColor(e){return s("plugin:window|set_background_color",{color:e})}async setCursorPosition(e){return s("plugin:window|set_cursor_position",{label:this.label,value:e instanceof f?e:new f(e)})}async setIgnoreCursorEvents(e){return s("plugin:window|set_ignore_cursor_events",{label:this.label,value:e})}async startDragging(){return s("plugin:window|start_dragging",{label:this.label})}async startResizeDragging(e){return s("plugin:window|start_resize_dragging",{label:this.label,value:e})}async setBadgeCount(e){return s("plugin:window|set_badge_count",{label:this.label,value:e})}async setBadgeLabel(e){return s("plugin:window|set_badge_label",{label:this.label,value:e})}async setOverlayIcon(e){return s("plugin:window|set_overlay_icon",{label:this.label,value:e?k(e):void 0})}async setProgressBar(e){return s("plugin:window|set_progress_bar",{label:this.label,value:e})}async setVisibleOnAllWorkspaces(e){return s("plugin:window|set_visible_on_all_workspaces",{label:this.label,value:e})}async setTitleBarStyle(e){return s("plugin:window|set_title_bar_style",{label:this.label,value:e})}async setTheme(e){return s("plugin:window|set_theme",{label:this.label,value:e})}async onResized(e){return this.listen(o.WINDOW_RESIZED,i=>{i.payload=new _(i.payload),e(i)})}async onMoved(e){return this.listen(o.WINDOW_MOVED,i=>{i.payload=new d(i.payload),e(i)})}async onCloseRequested(e){return this.listen(o.WINDOW_CLOSE_REQUESTED,async i=>{const n=new Ie(i);await e(n),n.isPreventDefault()||await this.destroy()})}async onDragDropEvent(e){const i=await this.listen(o.DRAG_ENTER,r=>{e({...r,payload:{type:"enter",paths:r.payload.paths,position:new d(r.payload.position)}})}),n=await this.listen(o.DRAG_OVER,r=>{e({...r,payload:{type:"over",position:new d(r.payload.position)}})}),a=await this.listen(o.DRAG_DROP,r=>{e({...r,payload:{type:"drop",paths:r.payload.paths,position:new d(r.payload.position)}})}),l=await this.listen(o.DRAG_LEAVE,r=>{e({...r,payload:{type:"leave"}})});return()=>{i(),a(),n(),l()}}async onFocusChanged(e){const i=await this.listen(o.WINDOW_FOCUS,a=>{e({...a,payload:!0})}),n=await this.listen(o.WINDOW_BLUR,a=>{e({...a,payload:!1})});return()=>{i(),n()}}async onScaleChanged(e){return this.listen(o.WINDOW_SCALE_FACTOR_CHANGED,e)}async onThemeChanged(e){return this.listen(o.WINDOW_THEME_CHANGED,e)}}var V;(function(t){t.Disabled="disabled",t.Throttle="throttle",t.Suspend="suspend"})(V||(V={}));var $;(function(t){t.Default="default",t.FluentOverlay="fluentOverlay"})($||($={}));var J;(function(t){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"})(J||(J={}));var Z;(function(t){t.FollowsWindowActiveState="followsWindowActiveState",t.Active="active",t.Inactive="inactive"})(Z||(Z={}));function Ce(t){return t===null?null:{name:t.name,scaleFactor:t.scaleFactor,position:new d(t.position),size:new _(t.size),workArea:{position:new d(t.workArea.position),size:new _(t.workArea.size)}}}async function Le(){return s("plugin:window|primary_monitor").then(Ce)}function oe(){return new G(le(),window.__TAURI_INTERNALS__.metadata.currentWebview.label,{skip:!0})}async function Y(){return s("plugin:webview|get_all_webviews").then(t=>t.map(e=>new G(new I(e.windowLabel,{skip:!0}),e.label,{skip:!0})))}const T=["tauri://created","tauri://error"];class G{constructor(e,i,n){this.window=e,this.label=i,this.listeners=Object.create(null),n?.skip||s("plugin:webview|create_webview",{windowLabel:e.label,options:{...n,label:i}}).then(async()=>this.emit("tauri://created")).catch(async a=>this.emit("tauri://error",a))}static async getByLabel(e){var i;return(i=(await Y()).find(n=>n.label===e))!==null&&i!==void 0?i:null}static getCurrent(){return oe()}static async getAll(){return Y()}async listen(e,i){return this._handleTauriEvent(e,i)?()=>{const n=this.listeners[e];n.splice(n.indexOf(i),1)}:P(e,i,{target:{kind:"Webview",label:this.label}})}async once(e,i){return this._handleTauriEvent(e,i)?()=>{const n=this.listeners[e];n.splice(n.indexOf(i),1)}:Q(e,i,{target:{kind:"Webview",label:this.label}})}async emit(e,i){if(T.includes(e)){for(const n of this.listeners[e]||[])n({event:e,id:-1,payload:i});return}return ae(e,i)}async emitTo(e,i,n){if(T.includes(i)){for(const a of this.listeners[i]||[])a({event:i,id:-1,payload:n});return}return re(e,i,n)}_handleTauriEvent(e,i){return T.includes(e)?(e in this.listeners?this.listeners[e].push(i):this.listeners[e]=[i],!0):!1}async position(){return s("plugin:webview|webview_position",{label:this.label}).then(e=>new d(e))}async size(){return s("plugin:webview|webview_size",{label:this.label}).then(e=>new _(e))}async close(){return s("plugin:webview|webview_close",{label:this.label})}async setSize(e){return s("plugin:webview|set_webview_size",{label:this.label,value:e instanceof p?e:new p(e)})}async setPosition(e){return s("plugin:webview|set_webview_position",{label:this.label,value:e instanceof f?e:new f(e)})}async setFocus(){return s("plugin:webview|set_webview_focus",{label:this.label})}async setAutoResize(e){return s("plugin:webview|set_webview_auto_resize",{label:this.label,value:e})}async hide(){return s("plugin:webview|webview_hide",{label:this.label})}async show(){return s("plugin:webview|webview_show",{label:this.label})}async setZoom(e){return s("plugin:webview|set_webview_zoom",{label:this.label,value:e})}async reparent(e){return s("plugin:webview|reparent",{label:this.label,window:typeof e=="string"?e:e.label})}async clearAllBrowsingData(){return s("plugin:webview|clear_all_browsing_data")}async setBackgroundColor(e){return s("plugin:webview|set_webview_background_color",{color:e})}async onDragDropEvent(e){const i=await this.listen(o.DRAG_ENTER,r=>{e({...r,payload:{type:"enter",paths:r.payload.paths,position:new d(r.payload.position)}})}),n=await this.listen(o.DRAG_OVER,r=>{e({...r,payload:{type:"over",position:new d(r.payload.position)}})}),a=await this.listen(o.DRAG_DROP,r=>{e({...r,payload:{type:"drop",paths:r.payload.paths,position:new d(r.payload.position)}})}),l=await this.listen(o.DRAG_LEAVE,r=>{e({...r,payload:{type:"leave"}})});return()=>{i(),a(),n(),l()}}}function O(){const t=oe();return new m(t.label,{skip:!0})}async function K(){return s("plugin:window|get_all_windows").then(t=>t.map(e=>new m(e,{skip:!0})))}class m{constructor(e,i={}){var n;this.label=e,this.listeners=Object.create(null),i?.skip||s("plugin:webview|create_webview_window",{options:{...i,parent:typeof i.parent=="string"?i.parent:(n=i.parent)===null||n===void 0?void 0:n.label,label:e}}).then(async()=>this.emit("tauri://created")).catch(async a=>this.emit("tauri://error",a))}static async getByLabel(e){var i;const n=(i=(await K()).find(a=>a.label===e))!==null&&i!==void 0?i:null;return n?new m(n.label,{skip:!0}):null}static getCurrent(){return O()}static async getAll(){return K()}async listen(e,i){return this._handleTauriEvent(e,i)?()=>{const n=this.listeners[e];n.splice(n.indexOf(i),1)}:P(e,i,{target:{kind:"WebviewWindow",label:this.label}})}async once(e,i){return this._handleTauriEvent(e,i)?()=>{const n=this.listeners[e];n.splice(n.indexOf(i),1)}:Q(e,i,{target:{kind:"WebviewWindow",label:this.label}})}async setBackgroundColor(e){return s("plugin:window|set_background_color",{color:e}).then(()=>s("plugin:webview|set_webview_background_color",{color:e}))}}Ee(m,[I,G]);function Ee(t,e){(Array.isArray(e)?e:[e]).forEach(i=>{Object.getOwnPropertyNames(i.prototype).forEach(n=>{var a;typeof t.prototype=="object"&&t.prototype&&n in t.prototype||Object.defineProperty(t.prototype,n,(a=Object.getOwnPropertyDescriptor(i.prototype,n))!==null&&a!==void 0?a:Object.create(null))})})}const z=new Map,Re=t=>{if(!t||t.trim()==="")return!1;try{return!!(t.startsWith("/")||t.startsWith("http://")||t.startsWith("https://")||t.startsWith("tauri://"))}catch{return!1}},Te=async(t,e,i)=>{const n=i?.padding??20;if(i?.x!==void 0&&i?.y!==void 0)return{x:i.x,y:i.y};let a=1920,l=1080;try{const c=await Le();c?.size&&(a=c.size.width,l=c.size.height)}catch(c){console.warn("Failed to get monitor info, using defaults:",c)}switch(i?.position??"right-bottom"){case"right-bottom":return{x:a-t-n,y:l-e-n};case"right-top":return{x:a-t-n,y:n};case"left-bottom":return{x:n,y:l-e-n};case"left-top":return{x:n,y:n};case"center":return{x:(a-t)/2,y:(l-e)/2};default:return{x:a-t-n,y:l-e-n}}},ue=async t=>{const e=String(t.id),i=u.getState();if(i.isWindowActive(e)){console.log(`Notice window already open for message: ${e}`);return}const n=F(),a=`notice-${e}`;let l=`${n.routePrefix}/${t.type}?id=${t.id}`;Re(l)||(console.warn(`Invalid window URL: ${l}. Using fallback 404 page.`),l=n.notFoundUrl||"/404");const r=t.min_width||n.defaultWidth,c=t.min_height||n.defaultHeight,b=t.decorations??n.defaultDecorations??!0,{x:v,y:M}=await Te(r,c,t.windowPosition);try{const w=new m(a,{url:l,title:t.title,width:r,height:c,x:v,y:M,resizable:!0,decorations:b,transparent:!b,visible:b,skipTaskbar:!1,alwaysOnTop:!0});z.set(e,w),i.addActiveWindow(e),b||w.once("tauri://created",async()=>{await w.show()}),w.once("tauri://destroyed",async()=>{z.delete(e),i.removeActiveWindow(e),await i.markMessageAsShown(e),i.clearCurrent()}),console.log(`Created notice window: ${a}`)}catch(w){console.error("Failed to create notice window:",w),i.removeActiveWindow(e),i.clearCurrent()}},C=async t=>{const e=String(t),i=z.get(e),n=u.getState();if(i)try{await i.close(),z.delete(e),n.removeActiveWindow(e),await n.markMessageAsShown(e),n.clearCurrent(),console.log(`Closed notice window: ${e}`)}catch(a){console.error("Failed to close notice window:",a)}},ce=async()=>{const t=Array.from(z.keys()).map(e=>C(e));await Promise.all(t)},de=()=>{let t=null;u.subscribe(e=>{const i=e.currentMessage;i&&i!==t?(t=i,ue(i)):i||(t=null)}),console.log("Notice window system initialized")},qe=()=>{const t=u(i=>i.currentMessage);return{closeNotice:y.useCallback(async()=>{t&&await C(t.id)},[t])}},Fe=()=>{const t=u(i=>i.hideMessage);return{hideNotice:y.useCallback(async i=>{await t(i),await C(i)},[t])}},Be=()=>{const t=u(i=>i.clearOnLogout);return{hideAllNotices:y.useCallback(async()=>{await ce(),await t()},[t])}},Ue=()=>{const t=u(N.queueLength),e=u(N.currentMessage),i=u(N.isProcessing),n=u(N.queue);return{queueLength:t,currentMessage:e,isProcessing:i,queue:n}},Qe=({children:t,onLoad:e,onClose:i})=>{const[n,a]=y.useState(null),[l,r]=y.useState(!0),[c,b]=y.useState(null);return y.useEffect(()=>{(async()=>{try{const w=new URLSearchParams(window.location.search).get("id");if(!w){b("No message ID provided"),r(!1),setTimeout(async()=>{try{await O().close()}catch(S){console.error("Failed to close window:",S)}},1e3);return}const L=await U(w);if(!L){console.log(`Message ${w} not found in database, closing window`),b("Message not found"),r(!1),setTimeout(async()=>{try{await O().close()}catch(S){console.error("Failed to close window:",S)}},500);return}a(L),r(!1),e&&e(L)}catch(M){console.error("Failed to load message:",M),b("Failed to load message"),r(!1),setTimeout(async()=>{try{await O().close()}catch(w){console.error("Failed to close window:",w)}},1e3)}})()},[e]),y.useEffect(()=>{if(!n||!i)return;const v=()=>{i(n)};return window.addEventListener("beforeunload",v),()=>{window.removeEventListener("beforeunload",v)}},[n,i]),l?W.jsx("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",height:"100vh",fontFamily:"system-ui, -apple-system, sans-serif"},children:"Loading..."}):c?W.jsx("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",height:"100vh",fontFamily:"system-ui, -apple-system, sans-serif",color:"#ef4444"},children:c}):n?W.jsx(W.Fragment,{children:t(n)}):W.jsx("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",height:"100vh",fontFamily:"system-ui, -apple-system, sans-serif",color:"#ef4444"},children:"Closing window..."})},Ge=async()=>{B(),de();const{initializeFromDatabase:t}=u.getState();await t(),console.log("Tauri Notice System initialized")},He=async t=>{await u.getState().deleteMessage(t)},je=async t=>{await u.getState().hideMessage(t)},Ve=async t=>{await u.getState().markMessageAsShown(t)};exports.NoticeLayout=Qe;exports.closeAllNoticeWindows=ce;exports.closeNoticeWindow=C;exports.createNoticeWindow=ue;exports.deleteMessageById=He;exports.getMessage=U;exports.getNoticeConfig=F;exports.getPendingMessages=te;exports.hideMessageById=je;exports.initializeDatabase=B;exports.initializeNoticeSystem=Ge;exports.initializeNoticeWindowSystem=de;exports.markMessageAsShown=Ve;exports.messageQueueSelectors=N;exports.setNoticeConfig=be;exports.useCloseNotice=qe;exports.useHideAllNotices=Be;exports.useHideNotice=Fe;exports.useMessageQueue=Ue;exports.useMessageQueueStore=u;exports.useNoticeWindow=Me;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ge=require("zustand"),ye=require("zustand-sync"),be=require("dexie"),p=require("react"),N=require("react/jsx-runtime"),te="tauri-notice-config",$={routePrefix:"/notice",databaseName:"tauri-notice-db",defaultWidth:400,defaultHeight:300,notFoundUrl:"/404",defaultDecorations:!0,loadTimeout:4e3},ie=()=>{try{const t=localStorage.getItem(te);if(t)return{...$,...JSON.parse(t)}}catch(t){console.warn("Failed to load config from localStorage:",t)}return $},pe=t=>{try{localStorage.setItem(te,JSON.stringify(t))}catch(e){console.warn("Failed to save config to localStorage:",e)}},_e=t=>{const i={...ie(),...t};pe(i)},F=()=>ie();class fe extends be{messages;constructor(e){super(e),this.version(1).stores({messages:"id, queueStatus, queuePosition, timestamp"})}}let D=null;const B=()=>{if(!D){const t=F();D=new fe(t.databaseName)}return D},y=()=>D||B(),me=async t=>{const e={...t,timestamp:new Date().toISOString(),isRead:!1,isShown:!1,queueStatus:"pending",queuePosition:0};await y().messages.put(e)},ve=async t=>!!await y().messages.get(t),Se=async t=>{const e=await y().messages.get(t);return e?.isShown===!0||e?.queueStatus==="shown"},ne=async()=>await y().messages.where("queueStatus").equals("pending").sortBy("queuePosition"),We=async(t,e)=>{await y().messages.update(t,{queueStatus:e})},Ne=async t=>{await y().messages.update(t,{queueStatus:"shown",isShown:!0})},Ae=async t=>{await y().messages.update(t,{queueStatus:"hidden"})},U=async t=>await y().messages.get(t),De=async t=>{await y().messages.delete(t)},ze=async()=>{await y().messages.where("queueStatus").anyOf(["pending","showing"]).delete()},Me=async t=>{const e=t.map(i=>y().messages.update(i.id,{queuePosition:i.position}));await Promise.all(e)},Oe=(t,e)=>({queue:[],currentMessage:null,isProcessing:!1,initialized:!1,activeWindowIds:[],enqueue:async i=>{const n=e();if(await Se(i.id)){console.log(`Message ${i.id} was already shown, skipping`);return}if(await ve(i.id)||await me(i),!n.queue.some(w=>w.id===i.id)){const w=[...n.queue,i];t({queue:w}),await e().persistQueue()}!n.isProcessing&&!n.currentMessage&&await e().showNext()},dequeue:()=>{const i=e();if(i.queue.length===0)return null;const[n,...a]=i.queue;return t({queue:a}),n},showNext:async()=>{if(e().isProcessing)return;const n=e().dequeue();if(!n){t({isProcessing:!1,currentMessage:null});return}if(!await U(n.id)){console.log(`Message ${n.id} was deleted, skipping to next`),await e().showNext();return}t({currentMessage:n,isProcessing:!0}),await We(n.id,"showing"),await e().persistQueue()},clearCurrent:()=>{t({currentMessage:null,isProcessing:!1}),e().queue.length>0&&e().showNext()},setCurrentMessage:i=>{t({currentMessage:i})},setIsProcessing:i=>{t({isProcessing:i})},setQueue:i=>{t({queue:i})},initializeFromDatabase:async()=>{if(e().initialized)return;t({initialized:!0});const n=await ne();n.length>0&&(t({queue:n}),await e().showNext())},persistQueue:async()=>{const n=e().queue.map((a,l)=>({id:a.id,position:l}));await Me(n)},clearOnLogout:async()=>{t({queue:[],currentMessage:null,isProcessing:!1,activeWindowIds:[],initialized:!1}),await ze()},removeFromQueue:async i=>{const n=e(),a=n.queue.filter(l=>l.id!==i);t({queue:a}),await e().persistQueue(),n.currentMessage?.id===i&&e().clearCurrent()},deleteMessage:async i=>{await De(i),await e().removeFromQueue(i)},hideMessage:async i=>{await Ae(i),await e().removeFromQueue(i)},markMessageAsShown:async i=>{await Ne(i)},addActiveWindow:i=>{const n=e(),a=String(i);n.activeWindowIds.includes(a)||t({activeWindowIds:[...n.activeWindowIds,a]})},removeActiveWindow:i=>{const n=e(),a=String(i);t({activeWindowIds:n.activeWindowIds.filter(l=>l!==a)})},isWindowActive:i=>{const n=e(),a=String(i);return n.activeWindowIds.includes(a)}}),d=ge.create()(ye.syncTabs(Oe,{name:"tauri-notice-queue"})),A={queueLength:t=>t.queue.length,currentMessage:t=>t.currentMessage,isProcessing:t=>t.isProcessing,queue:t=>t.queue},xe=()=>{const t=d(i=>i.enqueue);return{showNotice:p.useCallback(async i=>{await t(i)},[t])}};function ke(t,e,i,n){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");return i==="m"?n:i==="a"?n.call(t):n?n.value:e.get(t)}function Ie(t,e,i,n,a){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");return e.set(t,i),i}var x;const g="__TAURI_TO_IPC_KEY__";function Pe(t,e=!1){return window.__TAURI_INTERNALS__.transformCallback(t,e)}async function s(t,e={},i){return window.__TAURI_INTERNALS__.invoke(t,e,i)}class Ce{get rid(){return ke(this,x,"f")}constructor(e){x.set(this,void 0),Ie(this,x,e)}async close(){return s("plugin:resources|close",{rid:this.rid})}}x=new WeakMap;class se{constructor(...e){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])}toPhysical(e){return new f(this.width*e,this.height*e)}[g](){return{width:this.width,height:this.height}}toJSON(){return this[g]()}}class f{constructor(...e){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])}toLogical(e){return new se(this.width/e,this.height/e)}[g](){return{width:this.width,height:this.height}}toJSON(){return this[g]()}}class _{constructor(e){this.size=e}toLogical(e){return this.size instanceof se?this.size:this.size.toLogical(e)}toPhysical(e){return this.size instanceof f?this.size:this.size.toPhysical(e)}[g](){return{[`${this.size.type}`]:{width:this.size.width,height:this.size.height}}}toJSON(){return this[g]()}}class ae{constructor(...e){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])}toPhysical(e){return new h(this.x*e,this.y*e)}[g](){return{x:this.x,y:this.y}}toJSON(){return this[g]()}}class h{constructor(...e){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])}toLogical(e){return new ae(this.x/e,this.y/e)}[g](){return{x:this.x,y:this.y}}toJSON(){return this[g]()}}class v{constructor(e){this.position=e}toLogical(e){return this.position instanceof ae?this.position:this.position.toLogical(e)}toPhysical(e){return this.position instanceof h?this.position:this.position.toPhysical(e)}[g](){return{[`${this.position.type}`]:{x:this.position.x,y:this.position.y}}}toJSON(){return this[g]()}}var o;(function(t){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"})(o||(o={}));async function re(t,e){window.__TAURI_EVENT_PLUGIN_INTERNALS__.unregisterListener(t,e),await s("plugin:event|unlisten",{event:t,eventId:e})}async function P(t,e,i){var n;const a=typeof i?.target=="string"?{kind:"AnyLabel",label:i.target}:(n=i?.target)!==null&&n!==void 0?n:{kind:"Any"};return s("plugin:event|listen",{event:t,target:a,handler:Pe(e)}).then(l=>async()=>re(t,l))}async function Q(t,e,i){return P(t,n=>{re(t,n.id),e(n)},i)}async function le(t,e){await s("plugin:event|emit",{event:t,payload:e})}async function oe(t,e,i){await s("plugin:event|emit_to",{target:typeof t=="string"?{kind:"AnyLabel",label:t}:t,event:e,payload:i})}class z extends Ce{constructor(e){super(e)}static async new(e,i,n){return s("plugin:image|new",{rgba:I(e),width:i,height:n}).then(a=>new z(a))}static async fromBytes(e){return s("plugin:image|from_bytes",{bytes:I(e)}).then(i=>new z(i))}static async fromPath(e){return s("plugin:image|from_path",{path:e}).then(i=>new z(i))}async rgba(){return s("plugin:image|rgba",{rid:this.rid}).then(e=>new Uint8Array(e))}async size(){return s("plugin:image|size",{rid:this.rid})}}function I(t){return t==null?null:typeof t=="string"?t:t instanceof z?t.rid:t}var q;(function(t){t[t.Critical=1]="Critical",t[t.Informational=2]="Informational"})(q||(q={}));class Le{constructor(e){this._preventDefault=!1,this.event=e.event,this.id=e.id}preventDefault(){this._preventDefault=!0}isPreventDefault(){return this._preventDefault}}var V;(function(t){t.None="none",t.Normal="normal",t.Indeterminate="indeterminate",t.Paused="paused",t.Error="error"})(V||(V={}));function ue(){return new C(window.__TAURI_INTERNALS__.metadata.currentWindow.label,{skip:!0})}async function T(){return s("plugin:window|get_all_windows").then(t=>t.map(e=>new C(e,{skip:!0})))}const E=["tauri://created","tauri://error"];class C{constructor(e,i={}){var n;this.label=e,this.listeners=Object.create(null),i?.skip||s("plugin:window|create",{options:{...i,parent:typeof i.parent=="string"?i.parent:(n=i.parent)===null||n===void 0?void 0:n.label,label:e}}).then(async()=>this.emit("tauri://created")).catch(async a=>this.emit("tauri://error",a))}static async getByLabel(e){var i;return(i=(await T()).find(n=>n.label===e))!==null&&i!==void 0?i:null}static getCurrent(){return ue()}static async getAll(){return T()}static async getFocusedWindow(){for(const e of await T())if(await e.isFocused())return e;return null}async listen(e,i){return this._handleTauriEvent(e,i)?()=>{const n=this.listeners[e];n.splice(n.indexOf(i),1)}:P(e,i,{target:{kind:"Window",label:this.label}})}async once(e,i){return this._handleTauriEvent(e,i)?()=>{const n=this.listeners[e];n.splice(n.indexOf(i),1)}:Q(e,i,{target:{kind:"Window",label:this.label}})}async emit(e,i){if(E.includes(e)){for(const n of this.listeners[e]||[])n({event:e,id:-1,payload:i});return}return le(e,i)}async emitTo(e,i,n){if(E.includes(i)){for(const a of this.listeners[i]||[])a({event:i,id:-1,payload:n});return}return oe(e,i,n)}_handleTauriEvent(e,i){return E.includes(e)?(e in this.listeners?this.listeners[e].push(i):this.listeners[e]=[i],!0):!1}async scaleFactor(){return s("plugin:window|scale_factor",{label:this.label})}async innerPosition(){return s("plugin:window|inner_position",{label:this.label}).then(e=>new h(e))}async outerPosition(){return s("plugin:window|outer_position",{label:this.label}).then(e=>new h(e))}async innerSize(){return s("plugin:window|inner_size",{label:this.label}).then(e=>new f(e))}async outerSize(){return s("plugin:window|outer_size",{label:this.label}).then(e=>new f(e))}async isFullscreen(){return s("plugin:window|is_fullscreen",{label:this.label})}async isMinimized(){return s("plugin:window|is_minimized",{label:this.label})}async isMaximized(){return s("plugin:window|is_maximized",{label:this.label})}async isFocused(){return s("plugin:window|is_focused",{label:this.label})}async isDecorated(){return s("plugin:window|is_decorated",{label:this.label})}async isResizable(){return s("plugin:window|is_resizable",{label:this.label})}async isMaximizable(){return s("plugin:window|is_maximizable",{label:this.label})}async isMinimizable(){return s("plugin:window|is_minimizable",{label:this.label})}async isClosable(){return s("plugin:window|is_closable",{label:this.label})}async isVisible(){return s("plugin:window|is_visible",{label:this.label})}async title(){return s("plugin:window|title",{label:this.label})}async theme(){return s("plugin:window|theme",{label:this.label})}async isAlwaysOnTop(){return s("plugin:window|is_always_on_top",{label:this.label})}async center(){return s("plugin:window|center",{label:this.label})}async requestUserAttention(e){let i=null;return e&&(e===q.Critical?i={type:"Critical"}:i={type:"Informational"}),s("plugin:window|request_user_attention",{label:this.label,value:i})}async setResizable(e){return s("plugin:window|set_resizable",{label:this.label,value:e})}async setEnabled(e){return s("plugin:window|set_enabled",{label:this.label,value:e})}async isEnabled(){return s("plugin:window|is_enabled",{label:this.label})}async setMaximizable(e){return s("plugin:window|set_maximizable",{label:this.label,value:e})}async setMinimizable(e){return s("plugin:window|set_minimizable",{label:this.label,value:e})}async setClosable(e){return s("plugin:window|set_closable",{label:this.label,value:e})}async setTitle(e){return s("plugin:window|set_title",{label:this.label,value:e})}async maximize(){return s("plugin:window|maximize",{label:this.label})}async unmaximize(){return s("plugin:window|unmaximize",{label:this.label})}async toggleMaximize(){return s("plugin:window|toggle_maximize",{label:this.label})}async minimize(){return s("plugin:window|minimize",{label:this.label})}async unminimize(){return s("plugin:window|unminimize",{label:this.label})}async show(){return s("plugin:window|show",{label:this.label})}async hide(){return s("plugin:window|hide",{label:this.label})}async close(){return s("plugin:window|close",{label:this.label})}async destroy(){return s("plugin:window|destroy",{label:this.label})}async setDecorations(e){return s("plugin:window|set_decorations",{label:this.label,value:e})}async setShadow(e){return s("plugin:window|set_shadow",{label:this.label,value:e})}async setEffects(e){return s("plugin:window|set_effects",{label:this.label,value:e})}async clearEffects(){return s("plugin:window|set_effects",{label:this.label,value:null})}async setAlwaysOnTop(e){return s("plugin:window|set_always_on_top",{label:this.label,value:e})}async setAlwaysOnBottom(e){return s("plugin:window|set_always_on_bottom",{label:this.label,value:e})}async setContentProtected(e){return s("plugin:window|set_content_protected",{label:this.label,value:e})}async setSize(e){return s("plugin:window|set_size",{label:this.label,value:e instanceof _?e:new _(e)})}async setMinSize(e){return s("plugin:window|set_min_size",{label:this.label,value:e instanceof _?e:e?new _(e):null})}async setMaxSize(e){return s("plugin:window|set_max_size",{label:this.label,value:e instanceof _?e:e?new _(e):null})}async setSizeConstraints(e){function i(n){return n?{Logical:n}:null}return s("plugin:window|set_size_constraints",{label:this.label,value:{minWidth:i(e?.minWidth),minHeight:i(e?.minHeight),maxWidth:i(e?.maxWidth),maxHeight:i(e?.maxHeight)}})}async setPosition(e){return s("plugin:window|set_position",{label:this.label,value:e instanceof v?e:new v(e)})}async setFullscreen(e){return s("plugin:window|set_fullscreen",{label:this.label,value:e})}async setSimpleFullscreen(e){return s("plugin:window|set_simple_fullscreen",{label:this.label,value:e})}async setFocus(){return s("plugin:window|set_focus",{label:this.label})}async setFocusable(e){return s("plugin:window|set_focusable",{label:this.label,value:e})}async setIcon(e){return s("plugin:window|set_icon",{label:this.label,value:I(e)})}async setSkipTaskbar(e){return s("plugin:window|set_skip_taskbar",{label:this.label,value:e})}async setCursorGrab(e){return s("plugin:window|set_cursor_grab",{label:this.label,value:e})}async setCursorVisible(e){return s("plugin:window|set_cursor_visible",{label:this.label,value:e})}async setCursorIcon(e){return s("plugin:window|set_cursor_icon",{label:this.label,value:e})}async setBackgroundColor(e){return s("plugin:window|set_background_color",{color:e})}async setCursorPosition(e){return s("plugin:window|set_cursor_position",{label:this.label,value:e instanceof v?e:new v(e)})}async setIgnoreCursorEvents(e){return s("plugin:window|set_ignore_cursor_events",{label:this.label,value:e})}async startDragging(){return s("plugin:window|start_dragging",{label:this.label})}async startResizeDragging(e){return s("plugin:window|start_resize_dragging",{label:this.label,value:e})}async setBadgeCount(e){return s("plugin:window|set_badge_count",{label:this.label,value:e})}async setBadgeLabel(e){return s("plugin:window|set_badge_label",{label:this.label,value:e})}async setOverlayIcon(e){return s("plugin:window|set_overlay_icon",{label:this.label,value:e?I(e):void 0})}async setProgressBar(e){return s("plugin:window|set_progress_bar",{label:this.label,value:e})}async setVisibleOnAllWorkspaces(e){return s("plugin:window|set_visible_on_all_workspaces",{label:this.label,value:e})}async setTitleBarStyle(e){return s("plugin:window|set_title_bar_style",{label:this.label,value:e})}async setTheme(e){return s("plugin:window|set_theme",{label:this.label,value:e})}async onResized(e){return this.listen(o.WINDOW_RESIZED,i=>{i.payload=new f(i.payload),e(i)})}async onMoved(e){return this.listen(o.WINDOW_MOVED,i=>{i.payload=new h(i.payload),e(i)})}async onCloseRequested(e){return this.listen(o.WINDOW_CLOSE_REQUESTED,async i=>{const n=new Le(i);await e(n),n.isPreventDefault()||await this.destroy()})}async onDragDropEvent(e){const i=await this.listen(o.DRAG_ENTER,r=>{e({...r,payload:{type:"enter",paths:r.payload.paths,position:new h(r.payload.position)}})}),n=await this.listen(o.DRAG_OVER,r=>{e({...r,payload:{type:"over",position:new h(r.payload.position)}})}),a=await this.listen(o.DRAG_DROP,r=>{e({...r,payload:{type:"drop",paths:r.payload.paths,position:new h(r.payload.position)}})}),l=await this.listen(o.DRAG_LEAVE,r=>{e({...r,payload:{type:"leave"}})});return()=>{i(),a(),n(),l()}}async onFocusChanged(e){const i=await this.listen(o.WINDOW_FOCUS,a=>{e({...a,payload:!0})}),n=await this.listen(o.WINDOW_BLUR,a=>{e({...a,payload:!1})});return()=>{i(),n()}}async onScaleChanged(e){return this.listen(o.WINDOW_SCALE_FACTOR_CHANGED,e)}async onThemeChanged(e){return this.listen(o.WINDOW_THEME_CHANGED,e)}}var J;(function(t){t.Disabled="disabled",t.Throttle="throttle",t.Suspend="suspend"})(J||(J={}));var Z;(function(t){t.Default="default",t.FluentOverlay="fluentOverlay"})(Z||(Z={}));var Y;(function(t){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"})(Y||(Y={}));var K;(function(t){t.FollowsWindowActiveState="followsWindowActiveState",t.Active="active",t.Inactive="inactive"})(K||(K={}));function Te(t){return t===null?null:{name:t.name,scaleFactor:t.scaleFactor,position:new h(t.position),size:new f(t.size),workArea:{position:new h(t.workArea.position),size:new f(t.workArea.size)}}}async function Ee(){return s("plugin:window|primary_monitor").then(Te)}function ce(){return new G(ue(),window.__TAURI_INTERNALS__.metadata.currentWebview.label,{skip:!0})}async function X(){return s("plugin:webview|get_all_webviews").then(t=>t.map(e=>new G(new C(e.windowLabel,{skip:!0}),e.label,{skip:!0})))}const R=["tauri://created","tauri://error"];class G{constructor(e,i,n){this.window=e,this.label=i,this.listeners=Object.create(null),n?.skip||s("plugin:webview|create_webview",{windowLabel:e.label,options:{...n,label:i}}).then(async()=>this.emit("tauri://created")).catch(async a=>this.emit("tauri://error",a))}static async getByLabel(e){var i;return(i=(await X()).find(n=>n.label===e))!==null&&i!==void 0?i:null}static getCurrent(){return ce()}static async getAll(){return X()}async listen(e,i){return this._handleTauriEvent(e,i)?()=>{const n=this.listeners[e];n.splice(n.indexOf(i),1)}:P(e,i,{target:{kind:"Webview",label:this.label}})}async once(e,i){return this._handleTauriEvent(e,i)?()=>{const n=this.listeners[e];n.splice(n.indexOf(i),1)}:Q(e,i,{target:{kind:"Webview",label:this.label}})}async emit(e,i){if(R.includes(e)){for(const n of this.listeners[e]||[])n({event:e,id:-1,payload:i});return}return le(e,i)}async emitTo(e,i,n){if(R.includes(i)){for(const a of this.listeners[i]||[])a({event:i,id:-1,payload:n});return}return oe(e,i,n)}_handleTauriEvent(e,i){return R.includes(e)?(e in this.listeners?this.listeners[e].push(i):this.listeners[e]=[i],!0):!1}async position(){return s("plugin:webview|webview_position",{label:this.label}).then(e=>new h(e))}async size(){return s("plugin:webview|webview_size",{label:this.label}).then(e=>new f(e))}async close(){return s("plugin:webview|webview_close",{label:this.label})}async setSize(e){return s("plugin:webview|set_webview_size",{label:this.label,value:e instanceof _?e:new _(e)})}async setPosition(e){return s("plugin:webview|set_webview_position",{label:this.label,value:e instanceof v?e:new v(e)})}async setFocus(){return s("plugin:webview|set_webview_focus",{label:this.label})}async setAutoResize(e){return s("plugin:webview|set_webview_auto_resize",{label:this.label,value:e})}async hide(){return s("plugin:webview|webview_hide",{label:this.label})}async show(){return s("plugin:webview|webview_show",{label:this.label})}async setZoom(e){return s("plugin:webview|set_webview_zoom",{label:this.label,value:e})}async reparent(e){return s("plugin:webview|reparent",{label:this.label,window:typeof e=="string"?e:e.label})}async clearAllBrowsingData(){return s("plugin:webview|clear_all_browsing_data")}async setBackgroundColor(e){return s("plugin:webview|set_webview_background_color",{color:e})}async onDragDropEvent(e){const i=await this.listen(o.DRAG_ENTER,r=>{e({...r,payload:{type:"enter",paths:r.payload.paths,position:new h(r.payload.position)}})}),n=await this.listen(o.DRAG_OVER,r=>{e({...r,payload:{type:"over",position:new h(r.payload.position)}})}),a=await this.listen(o.DRAG_DROP,r=>{e({...r,payload:{type:"drop",paths:r.payload.paths,position:new h(r.payload.position)}})}),l=await this.listen(o.DRAG_LEAVE,r=>{e({...r,payload:{type:"leave"}})});return()=>{i(),a(),n(),l()}}}function k(){const t=ce();return new S(t.label,{skip:!0})}async function ee(){return s("plugin:window|get_all_windows").then(t=>t.map(e=>new S(e,{skip:!0})))}class S{constructor(e,i={}){var n;this.label=e,this.listeners=Object.create(null),i?.skip||s("plugin:webview|create_webview_window",{options:{...i,parent:typeof i.parent=="string"?i.parent:(n=i.parent)===null||n===void 0?void 0:n.label,label:e}}).then(async()=>this.emit("tauri://created")).catch(async a=>this.emit("tauri://error",a))}static async getByLabel(e){var i;const n=(i=(await ee()).find(a=>a.label===e))!==null&&i!==void 0?i:null;return n?new S(n.label,{skip:!0}):null}static getCurrent(){return k()}static async getAll(){return ee()}async listen(e,i){return this._handleTauriEvent(e,i)?()=>{const n=this.listeners[e];n.splice(n.indexOf(i),1)}:P(e,i,{target:{kind:"WebviewWindow",label:this.label}})}async once(e,i){return this._handleTauriEvent(e,i)?()=>{const n=this.listeners[e];n.splice(n.indexOf(i),1)}:Q(e,i,{target:{kind:"WebviewWindow",label:this.label}})}async setBackgroundColor(e){return s("plugin:window|set_background_color",{color:e}).then(()=>s("plugin:webview|set_webview_background_color",{color:e}))}}Re(S,[C,G]);function Re(t,e){(Array.isArray(e)?e:[e]).forEach(i=>{Object.getOwnPropertyNames(i.prototype).forEach(n=>{var a;typeof t.prototype=="object"&&t.prototype&&n in t.prototype||Object.defineProperty(t.prototype,n,(a=Object.getOwnPropertyDescriptor(i.prototype,n))!==null&&a!==void 0?a:Object.create(null))})})}const M=new Map,qe=()=>navigator.platform.toLowerCase().includes("mac")||navigator.userAgent.toLowerCase().includes("mac"),Fe=t=>{if(!t||t.trim()==="")return!1;try{return!!(t.startsWith("/")||t.startsWith("http://")||t.startsWith("https://")||t.startsWith("tauri://"))}catch{return!1}},Be=async(t,e,i)=>{const n=i?.padding??20;if(i?.x!==void 0&&i?.y!==void 0)return{x:i.x,y:i.y};let a=1920,l=1080;try{const w=await Ee();w?.size&&(a=w.size.width,l=w.size.height)}catch(w){console.warn("Failed to get monitor info, using defaults:",w)}switch(i?.position??"right-bottom"){case"right-bottom":return{x:a-t-n,y:l-e-n};case"right-top":return{x:a-t-n,y:n};case"left-bottom":return{x:n,y:l-e-n};case"left-top":return{x:n,y:n};case"center":return{x:(a-t)/2,y:(l-e)/2};default:return{x:a-t-n,y:l-e-n}}},de=async t=>{const e=String(t.id),i=d.getState();if(i.isWindowActive(e)){console.log(`Notice window already open for message: ${e}`);return}const n=F(),a=`notice-${e}`;let l=`${n.routePrefix}/${t.type}?id=${t.id}`;Fe(l)||(console.warn(`Invalid window URL: ${l}. Using fallback 404 page.`),l=n.notFoundUrl||"/404");const r=t.min_width||n.defaultWidth,w=t.min_height||n.defaultHeight,m=t.decorations??n.defaultDecorations??!0,{x:W,y:O}=await Be(r,w,t.windowPosition);try{const u={url:l,title:t.title,width:r,height:w,x:W,y:O,resizable:!0,skipTaskbar:!1,alwaysOnTop:!0};m?u.decorations=!0:qe()?(u.decorations=!0,u.titleBarStyle="overlay",u.hiddenTitle=!0):(u.decorations=!1,u.transparent=!0);const b=new S(a,u);M.set(e,b),i.addActiveWindow(e);let c=null;const H=n.loadTimeout??1e4;!m&&H>0&&(c=setTimeout(async()=>{console.warn(`Notice window ${a} load timeout - auto closing`);try{await b.close()}catch{}},H)),b.once("tauri://created",()=>{c&&(clearTimeout(c),c=null),console.log(`Notice window created successfully: ${a}`)}),b.once("tauri://error",async j=>{if(console.error(`Notice window error: ${a}`,j),c&&(clearTimeout(c),c=null),!m)try{await b.close()}catch{}}),b.once("tauri://destroyed",async()=>{c&&(clearTimeout(c),c=null),M.delete(e),i.removeActiveWindow(e),await i.markMessageAsShown(e),i.clearCurrent()}),console.log(`Created notice window: ${a}`)}catch(u){console.error("Failed to create notice window:",u),i.removeActiveWindow(e),i.clearCurrent()}},L=async t=>{const e=String(t),i=M.get(e),n=d.getState();if(i)try{await i.close(),M.delete(e),n.removeActiveWindow(e),await n.markMessageAsShown(e),n.clearCurrent(),console.log(`Closed notice window: ${e}`)}catch(a){console.error("Failed to close notice window:",a)}},we=async()=>{const t=Array.from(M.keys()).map(e=>L(e));await Promise.all(t)},he=()=>{let t=null;d.subscribe(e=>{const i=e.currentMessage;i&&i!==t?(t=i,de(i)):i||(t=null)}),console.log("Notice window system initialized")},Ue=()=>{const t=d(i=>i.currentMessage);return{closeNotice:p.useCallback(async()=>{t&&await L(t.id)},[t])}},Qe=()=>{const t=d(i=>i.hideMessage);return{hideNotice:p.useCallback(async i=>{await t(i),await L(i)},[t])}},Ge=()=>{const t=d(i=>i.clearOnLogout);return{hideAllNotices:p.useCallback(async()=>{await we(),await t()},[t])}},He=()=>{const t=d(A.queueLength),e=d(A.currentMessage),i=d(A.isProcessing),n=d(A.queue);return{queueLength:t,currentMessage:e,isProcessing:i,queue:n}},je=({children:t,onLoad:e,onClose:i})=>{const[n,a]=p.useState(null),[l,r]=p.useState(!0),[w,m]=p.useState(null);return p.useEffect(()=>{(async()=>{try{const u=new URLSearchParams(window.location.search).get("id");if(!u){m("No message ID provided"),r(!1),setTimeout(async()=>{try{await k().close()}catch(c){console.error("Failed to close window:",c)}},1e3);return}const b=await U(u);if(!b){console.log(`Message ${u} not found in database, closing window`),m("Message not found"),r(!1),setTimeout(async()=>{try{await k().close()}catch(c){console.error("Failed to close window:",c)}},500);return}a(b),r(!1),e&&e(b)}catch(O){console.error("Failed to load message:",O),m("Failed to load message"),r(!1),setTimeout(async()=>{try{await k().close()}catch(u){console.error("Failed to close window:",u)}},1e3)}})()},[e]),p.useEffect(()=>{if(!n||!i)return;const W=()=>{i(n)};return window.addEventListener("beforeunload",W),()=>{window.removeEventListener("beforeunload",W)}},[n,i]),l?N.jsx("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",height:"100vh",fontFamily:"system-ui, -apple-system, sans-serif"},children:"Loading..."}):w?N.jsx("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",height:"100vh",fontFamily:"system-ui, -apple-system, sans-serif",color:"#ef4444"},children:w}):n?N.jsx(N.Fragment,{children:t(n)}):N.jsx("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",height:"100vh",fontFamily:"system-ui, -apple-system, sans-serif",color:"#ef4444"},children:"Closing window..."})},$e=async()=>{B(),he();const{initializeFromDatabase:t}=d.getState();await t(),console.log("Tauri Notice System initialized")},Ve=async t=>{await d.getState().deleteMessage(t)},Je=async t=>{await d.getState().hideMessage(t)},Ze=async t=>{await d.getState().markMessageAsShown(t)};exports.NoticeLayout=je;exports.closeAllNoticeWindows=we;exports.closeNoticeWindow=L;exports.createNoticeWindow=de;exports.deleteMessageById=Ve;exports.getMessage=U;exports.getNoticeConfig=F;exports.getPendingMessages=ne;exports.hideMessageById=Je;exports.initializeDatabase=B;exports.initializeNoticeSystem=$e;exports.initializeNoticeWindowSystem=he;exports.markMessageAsShown=Ze;exports.messageQueueSelectors=A;exports.setNoticeConfig=_e;exports.useCloseNotice=Ue;exports.useHideAllNotices=Ge;exports.useHideNotice=Qe;exports.useMessageQueue=He;exports.useMessageQueueStore=d;exports.useNoticeWindow=xe;
2
2
  //# sourceMappingURL=index.cjs.map