tauri-notice-window 1.0.7 → 1.0.9
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 +444 -1
- package/dist/components/NoticeLayout.d.ts.map +1 -1
- 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.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +359 -289
- package/dist/index.js.map +1 -1
- package/dist/stores/messageQueueStore.d.ts +1 -0
- package/dist/stores/messageQueueStore.d.ts.map +1 -1
- package/dist/types/message.d.ts +2 -0
- package/dist/types/message.d.ts.map +1 -1
- package/dist/utils/db.d.ts.map +1 -1
- package/dist/utils/noticeWindow.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,6 +8,7 @@ A reusable React library for cross-window notification management in Tauri v2+ a
|
|
|
8
8
|
- **Persistent Queue**: Messages survive app restarts with IndexedDB (Dexie)
|
|
9
9
|
- **One-at-a-Time Display**: Only one notice window shown at a time
|
|
10
10
|
- **Customizable Routes**: Configurable router prefix for notice pages
|
|
11
|
+
- **URL Validation & 404 Fallback**: Automatic validation with customizable error pages for invalid routes
|
|
11
12
|
- **Type Safety**: Full TypeScript support
|
|
12
13
|
- **Easy Integration**: Simple hooks API
|
|
13
14
|
- **Tauri v2 Ready**: Uses latest Tauri v2 window APIs
|
|
@@ -120,6 +121,7 @@ function App() {
|
|
|
120
121
|
databaseName: 'tauri-notice-db', // default
|
|
121
122
|
defaultWidth: 400, // default width of the notice window
|
|
122
123
|
defaultHeight: 300, // default height of the notice window
|
|
124
|
+
notFoundUrl: '/404', // custom 404 page when route is invalid (optional)
|
|
123
125
|
})
|
|
124
126
|
|
|
125
127
|
// Initialize the system
|
|
@@ -177,6 +179,403 @@ export default function AnnouncementNotice() {
|
|
|
177
179
|
}
|
|
178
180
|
```
|
|
179
181
|
|
|
182
|
+
### 4. Create a 404 Error Page (Optional)
|
|
183
|
+
|
|
184
|
+
If a notice window URL is invalid, the library will automatically show a 404 page. Create a custom 404 component:
|
|
185
|
+
|
|
186
|
+
```typescript
|
|
187
|
+
// app/404/page.tsx or notice/404/page.tsx
|
|
188
|
+
import { useCloseNotice } from 'tauri-notice-window'
|
|
189
|
+
|
|
190
|
+
export default function NotFound() {
|
|
191
|
+
const { closeNotice } = useCloseNotice()
|
|
192
|
+
|
|
193
|
+
return (
|
|
194
|
+
<div className="error-container">
|
|
195
|
+
<h1>404 - Page Not Found</h1>
|
|
196
|
+
<p>The requested notice page could not be found.</p>
|
|
197
|
+
<button onClick={closeNotice}>Close</button>
|
|
198
|
+
</div>
|
|
199
|
+
)
|
|
200
|
+
}
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
Then configure the 404 URL during initialization:
|
|
204
|
+
|
|
205
|
+
```typescript
|
|
206
|
+
setNoticeConfig({
|
|
207
|
+
routePrefix: '/notice',
|
|
208
|
+
notFoundUrl: '/notice/404', // or '/404' depending on your routing setup
|
|
209
|
+
})
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
**How it works:**
|
|
213
|
+
- Before creating a WebviewWindow, the library validates the URL
|
|
214
|
+
- Invalid URLs (empty, malformed, or wrong protocol) trigger the fallback
|
|
215
|
+
- A warning is logged to the console for debugging
|
|
216
|
+
- The 404 page is shown instead of a broken window
|
|
217
|
+
|
|
218
|
+
#### 404 Configuration Examples
|
|
219
|
+
|
|
220
|
+
**Example 1: Basic Setup with Default 404**
|
|
221
|
+
|
|
222
|
+
```typescript
|
|
223
|
+
import { initializeNoticeSystem, setNoticeConfig } from 'tauri-notice-window'
|
|
224
|
+
|
|
225
|
+
// Use default /404 fallback
|
|
226
|
+
setNoticeConfig({
|
|
227
|
+
routePrefix: '/notice',
|
|
228
|
+
// notFoundUrl defaults to '/404' if not specified
|
|
229
|
+
})
|
|
230
|
+
|
|
231
|
+
initializeNoticeSystem()
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
**Example 2: Custom 404 Route**
|
|
235
|
+
|
|
236
|
+
```typescript
|
|
237
|
+
// With custom 404 page inside notice route
|
|
238
|
+
setNoticeConfig({
|
|
239
|
+
routePrefix: '/notice',
|
|
240
|
+
notFoundUrl: '/notice/error',
|
|
241
|
+
})
|
|
242
|
+
|
|
243
|
+
// Create the error page at /notice/error
|
|
244
|
+
// app/notice/error/page.tsx
|
|
245
|
+
import { useCloseNotice } from 'tauri-notice-window'
|
|
246
|
+
|
|
247
|
+
export default function NoticeError() {
|
|
248
|
+
const { closeNotice } = useCloseNotice()
|
|
249
|
+
|
|
250
|
+
return (
|
|
251
|
+
<div className="error-page">
|
|
252
|
+
<h2>Oops! Something went wrong</h2>
|
|
253
|
+
<p>This notification type is not supported.</p>
|
|
254
|
+
<button onClick={closeNotice}>Dismiss</button>
|
|
255
|
+
</div>
|
|
256
|
+
)
|
|
257
|
+
}
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
**Example 3: Using External URL as 404 Fallback**
|
|
261
|
+
|
|
262
|
+
```typescript
|
|
263
|
+
// You can use absolute URLs for the 404 page
|
|
264
|
+
setNoticeConfig({
|
|
265
|
+
routePrefix: '/notice',
|
|
266
|
+
notFoundUrl: 'https://yourapp.com/error',
|
|
267
|
+
})
|
|
268
|
+
|
|
269
|
+
// Or use Tauri's custom protocol
|
|
270
|
+
setNoticeConfig({
|
|
271
|
+
routePrefix: '/notice',
|
|
272
|
+
notFoundUrl: 'tauri://localhost/error',
|
|
273
|
+
})
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
**Example 4: Styled 404 Component**
|
|
277
|
+
|
|
278
|
+
```typescript
|
|
279
|
+
// app/notice/404/page.tsx
|
|
280
|
+
import { useCloseNotice, useMessageQueue } from 'tauri-notice-window'
|
|
281
|
+
|
|
282
|
+
export default function NotFound() {
|
|
283
|
+
const { closeNotice } = useCloseNotice()
|
|
284
|
+
const { queueLength } = useMessageQueue()
|
|
285
|
+
|
|
286
|
+
return (
|
|
287
|
+
<div style={{
|
|
288
|
+
display: 'flex',
|
|
289
|
+
flexDirection: 'column',
|
|
290
|
+
alignItems: 'center',
|
|
291
|
+
justifyContent: 'center',
|
|
292
|
+
height: '100vh',
|
|
293
|
+
padding: '20px',
|
|
294
|
+
backgroundColor: '#f5f5f5',
|
|
295
|
+
}}>
|
|
296
|
+
<h1 style={{ fontSize: '48px', margin: '0' }}>404</h1>
|
|
297
|
+
<p style={{ fontSize: '18px', color: '#666' }}>
|
|
298
|
+
Invalid notification type
|
|
299
|
+
</p>
|
|
300
|
+
{queueLength > 0 && (
|
|
301
|
+
<p style={{ fontSize: '14px', color: '#999' }}>
|
|
302
|
+
{queueLength} more notification{queueLength > 1 ? 's' : ''} in queue
|
|
303
|
+
</p>
|
|
304
|
+
)}
|
|
305
|
+
<button
|
|
306
|
+
onClick={closeNotice}
|
|
307
|
+
style={{
|
|
308
|
+
marginTop: '20px',
|
|
309
|
+
padding: '10px 20px',
|
|
310
|
+
fontSize: '16px',
|
|
311
|
+
cursor: 'pointer',
|
|
312
|
+
border: 'none',
|
|
313
|
+
borderRadius: '4px',
|
|
314
|
+
backgroundColor: '#007bff',
|
|
315
|
+
color: 'white',
|
|
316
|
+
}}
|
|
317
|
+
>
|
|
318
|
+
Close
|
|
319
|
+
</button>
|
|
320
|
+
</div>
|
|
321
|
+
)
|
|
322
|
+
}
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
**Example 5: URL Validation Scenarios**
|
|
326
|
+
|
|
327
|
+
The library validates URLs and automatically falls back to 404 in these cases:
|
|
328
|
+
|
|
329
|
+
```typescript
|
|
330
|
+
// These message types will trigger 404 fallback:
|
|
331
|
+
|
|
332
|
+
// ❌ Empty or undefined type
|
|
333
|
+
await showNotice({
|
|
334
|
+
id: '1',
|
|
335
|
+
title: 'Test',
|
|
336
|
+
type: '', // Empty string → Invalid
|
|
337
|
+
data: {},
|
|
338
|
+
})
|
|
339
|
+
|
|
340
|
+
// ❌ Invalid characters that break URL
|
|
341
|
+
await showNotice({
|
|
342
|
+
id: '2',
|
|
343
|
+
title: 'Test',
|
|
344
|
+
type: '../../../etc/passwd', // Path traversal → Invalid
|
|
345
|
+
data: {},
|
|
346
|
+
})
|
|
347
|
+
|
|
348
|
+
// ❌ If routePrefix is misconfigured
|
|
349
|
+
setNoticeConfig({
|
|
350
|
+
routePrefix: '', // Empty prefix creates invalid URL
|
|
351
|
+
})
|
|
352
|
+
|
|
353
|
+
// ✅ These URLs are VALID:
|
|
354
|
+
await showNotice({
|
|
355
|
+
id: '3',
|
|
356
|
+
title: 'Test',
|
|
357
|
+
type: 'announcement', // Creates: /notice/announcement?id=3
|
|
358
|
+
data: {},
|
|
359
|
+
})
|
|
360
|
+
|
|
361
|
+
// Valid URL patterns:
|
|
362
|
+
// - Starts with /
|
|
363
|
+
// - Starts with http:// or https://
|
|
364
|
+
// - Starts with tauri://
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
**Example 6: Debugging Invalid URLs**
|
|
368
|
+
|
|
369
|
+
When a URL validation fails, a console warning is logged:
|
|
370
|
+
|
|
371
|
+
```typescript
|
|
372
|
+
// Console output when validation fails:
|
|
373
|
+
// ⚠️ Invalid window URL: /notice/?id=123. Using fallback 404 page.
|
|
374
|
+
|
|
375
|
+
// To debug, check:
|
|
376
|
+
setNoticeConfig({
|
|
377
|
+
routePrefix: '/notice',
|
|
378
|
+
notFoundUrl: '/notice/404',
|
|
379
|
+
})
|
|
380
|
+
|
|
381
|
+
// Make sure your message has valid type:
|
|
382
|
+
await showNotice({
|
|
383
|
+
id: '123',
|
|
384
|
+
title: 'My Notice',
|
|
385
|
+
type: 'announcement', // Should match a route in your app
|
|
386
|
+
data: {},
|
|
387
|
+
})
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
**Example 7: Next.js App Router Setup**
|
|
391
|
+
|
|
392
|
+
```typescript
|
|
393
|
+
// app/layout.tsx
|
|
394
|
+
import { initializeNoticeSystem, setNoticeConfig } from 'tauri-notice-window'
|
|
395
|
+
|
|
396
|
+
export default function RootLayout({ children }) {
|
|
397
|
+
useEffect(() => {
|
|
398
|
+
setNoticeConfig({
|
|
399
|
+
routePrefix: '/notice',
|
|
400
|
+
notFoundUrl: '/notice/not-found', // Next.js App Router style
|
|
401
|
+
defaultWidth: 400,
|
|
402
|
+
defaultHeight: 300,
|
|
403
|
+
})
|
|
404
|
+
|
|
405
|
+
initializeNoticeSystem()
|
|
406
|
+
}, [])
|
|
407
|
+
|
|
408
|
+
return <html>{children}</html>
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
// Create: app/notice/not-found/page.tsx
|
|
412
|
+
import { useCloseNotice } from 'tauri-notice-window'
|
|
413
|
+
|
|
414
|
+
export default function NoticeNotFound() {
|
|
415
|
+
const { closeNotice } = useCloseNotice()
|
|
416
|
+
|
|
417
|
+
return (
|
|
418
|
+
<div className="p-6 text-center">
|
|
419
|
+
<h1 className="text-2xl font-bold mb-4">Page Not Found</h1>
|
|
420
|
+
<p className="mb-4">The notification page you're looking for doesn't exist.</p>
|
|
421
|
+
<button
|
|
422
|
+
onClick={closeNotice}
|
|
423
|
+
className="px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600"
|
|
424
|
+
>
|
|
425
|
+
Close Notification
|
|
426
|
+
</button>
|
|
427
|
+
</div>
|
|
428
|
+
)
|
|
429
|
+
}
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
**Example 8: React Router Setup**
|
|
433
|
+
|
|
434
|
+
```typescript
|
|
435
|
+
// App.tsx
|
|
436
|
+
import { BrowserRouter, Routes, Route } from 'react-router-dom'
|
|
437
|
+
import { initializeNoticeSystem, setNoticeConfig } from 'tauri-notice-window'
|
|
438
|
+
|
|
439
|
+
function App() {
|
|
440
|
+
useEffect(() => {
|
|
441
|
+
setNoticeConfig({
|
|
442
|
+
routePrefix: '/notice',
|
|
443
|
+
notFoundUrl: '/notice/404',
|
|
444
|
+
defaultWidth: 400,
|
|
445
|
+
defaultHeight: 300,
|
|
446
|
+
})
|
|
447
|
+
|
|
448
|
+
initializeNoticeSystem()
|
|
449
|
+
}, [])
|
|
450
|
+
|
|
451
|
+
return (
|
|
452
|
+
<BrowserRouter>
|
|
453
|
+
<Routes>
|
|
454
|
+
{/* Main app routes */}
|
|
455
|
+
<Route path="/" element={<Home />} />
|
|
456
|
+
|
|
457
|
+
{/* Notice routes */}
|
|
458
|
+
<Route path="/notice/announcement" element={<AnnouncementNotice />} />
|
|
459
|
+
<Route path="/notice/alert" element={<AlertNotice />} />
|
|
460
|
+
<Route path="/notice/404" element={<NoticeNotFound />} />
|
|
461
|
+
</Routes>
|
|
462
|
+
</BrowserRouter>
|
|
463
|
+
)
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
// NoticeNotFound.tsx
|
|
467
|
+
import { useCloseNotice } from 'tauri-notice-window'
|
|
468
|
+
|
|
469
|
+
export function NoticeNotFound() {
|
|
470
|
+
const { closeNotice } = useCloseNotice()
|
|
471
|
+
|
|
472
|
+
return (
|
|
473
|
+
<div className="error-container">
|
|
474
|
+
<h1>404 - Notification Not Found</h1>
|
|
475
|
+
<p>This notification type is not recognized.</p>
|
|
476
|
+
<button onClick={closeNotice}>Close</button>
|
|
477
|
+
</div>
|
|
478
|
+
)
|
|
479
|
+
}
|
|
480
|
+
```
|
|
481
|
+
|
|
482
|
+
**Example 9: Advanced Error Handling with Logging**
|
|
483
|
+
|
|
484
|
+
```typescript
|
|
485
|
+
// app/notice/error/page.tsx
|
|
486
|
+
import { useEffect } from 'react'
|
|
487
|
+
import { useCloseNotice, useMessageQueue } from 'tauri-notice-window'
|
|
488
|
+
|
|
489
|
+
export default function NoticeError() {
|
|
490
|
+
const { closeNotice } = useCloseNotice()
|
|
491
|
+
const { currentMessage } = useMessageQueue()
|
|
492
|
+
|
|
493
|
+
useEffect(() => {
|
|
494
|
+
// Log error for debugging
|
|
495
|
+
if (currentMessage) {
|
|
496
|
+
console.error('Invalid notice type:', {
|
|
497
|
+
id: currentMessage.id,
|
|
498
|
+
type: currentMessage.type,
|
|
499
|
+
timestamp: new Date().toISOString(),
|
|
500
|
+
})
|
|
501
|
+
|
|
502
|
+
// Optional: Send to error tracking service
|
|
503
|
+
// trackError('Invalid Notice Type', { messageId: currentMessage.id })
|
|
504
|
+
}
|
|
505
|
+
}, [currentMessage])
|
|
506
|
+
|
|
507
|
+
return (
|
|
508
|
+
<div className="error-page">
|
|
509
|
+
<div className="error-icon">⚠️</div>
|
|
510
|
+
<h1>Unable to Display Notification</h1>
|
|
511
|
+
<p>The notification type "{currentMessage?.type}" is not supported.</p>
|
|
512
|
+
<details>
|
|
513
|
+
<summary>Technical Details</summary>
|
|
514
|
+
<pre>{JSON.stringify(currentMessage, null, 2)}</pre>
|
|
515
|
+
</details>
|
|
516
|
+
<button onClick={closeNotice}>Dismiss</button>
|
|
517
|
+
</div>
|
|
518
|
+
)
|
|
519
|
+
}
|
|
520
|
+
```
|
|
521
|
+
|
|
522
|
+
**Example 10: Multi-Environment Configuration**
|
|
523
|
+
|
|
524
|
+
```typescript
|
|
525
|
+
// config/notice.config.ts
|
|
526
|
+
export const getNoticeConfig = () => {
|
|
527
|
+
const isDev = process.env.NODE_ENV === 'development'
|
|
528
|
+
|
|
529
|
+
return {
|
|
530
|
+
routePrefix: '/notice',
|
|
531
|
+
notFoundUrl: isDev
|
|
532
|
+
? '/notice/dev-404' // Detailed error in dev
|
|
533
|
+
: '/notice/404', // Simple error in production
|
|
534
|
+
defaultWidth: 400,
|
|
535
|
+
defaultHeight: 300,
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
// app/layout.tsx
|
|
540
|
+
import { initializeNoticeSystem, setNoticeConfig } from 'tauri-notice-window'
|
|
541
|
+
import { getNoticeConfig } from '@/config/notice.config'
|
|
542
|
+
|
|
543
|
+
export default function RootLayout({ children }) {
|
|
544
|
+
useEffect(() => {
|
|
545
|
+
setNoticeConfig(getNoticeConfig())
|
|
546
|
+
initializeNoticeSystem()
|
|
547
|
+
}, [])
|
|
548
|
+
|
|
549
|
+
return <html>{children}</html>
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
// app/notice/dev-404/page.tsx (Development-only)
|
|
553
|
+
export default function DevNotFound() {
|
|
554
|
+
const { closeNotice } = useCloseNotice()
|
|
555
|
+
const { currentMessage } = useMessageQueue()
|
|
556
|
+
|
|
557
|
+
return (
|
|
558
|
+
<div className="dev-error">
|
|
559
|
+
<h1>🔧 Development Error</h1>
|
|
560
|
+
<h2>Invalid Notice Route</h2>
|
|
561
|
+
<div className="error-details">
|
|
562
|
+
<p><strong>Route Attempted:</strong> /notice/{currentMessage?.type}</p>
|
|
563
|
+
<p><strong>Message ID:</strong> {currentMessage?.id}</p>
|
|
564
|
+
<p><strong>Title:</strong> {currentMessage?.title}</p>
|
|
565
|
+
</div>
|
|
566
|
+
<div className="fix-suggestion">
|
|
567
|
+
<h3>How to fix:</h3>
|
|
568
|
+
<ol>
|
|
569
|
+
<li>Create route at: app/notice/{currentMessage?.type}/page.tsx</li>
|
|
570
|
+
<li>Or update message.type to match existing route</li>
|
|
571
|
+
</ol>
|
|
572
|
+
</div>
|
|
573
|
+
<button onClick={closeNotice}>Close</button>
|
|
574
|
+
</div>
|
|
575
|
+
)
|
|
576
|
+
}
|
|
577
|
+
```
|
|
578
|
+
|
|
180
579
|
## API Reference
|
|
181
580
|
|
|
182
581
|
### Types
|
|
@@ -214,6 +613,7 @@ interface NoticeConfig {
|
|
|
214
613
|
databaseName: string // Database name (default: 'tauri-notice-db')
|
|
215
614
|
defaultWidth: number // Default window width (default: 400)
|
|
216
615
|
defaultHeight: number // Default window height (default: 300)
|
|
616
|
+
notFoundUrl?: string // Custom 404 page URL for invalid routes (default: '/404')
|
|
217
617
|
}
|
|
218
618
|
```
|
|
219
619
|
|
|
@@ -304,9 +704,12 @@ setNoticeConfig({
|
|
|
304
704
|
databaseName: 'my-app-notices',
|
|
305
705
|
defaultWidth: 500,
|
|
306
706
|
defaultHeight: 400,
|
|
707
|
+
notFoundUrl: '/error', // Custom 404 page
|
|
307
708
|
})
|
|
308
709
|
```
|
|
309
710
|
|
|
711
|
+
**URL Validation:** Before creating a WebviewWindow, the library validates the window URL. If the URL is invalid (empty, malformed, or doesn't start with `/`, `http://`, `https://`, or `tauri://`), it automatically falls back to the `notFoundUrl` and logs a warning.
|
|
712
|
+
|
|
310
713
|
### Database Utilities
|
|
311
714
|
|
|
312
715
|
For advanced use cases, direct database access is available:
|
|
@@ -338,7 +741,7 @@ const message = await getMessage('123')
|
|
|
338
741
|
|
|
339
742
|
#### deleteMessageById()
|
|
340
743
|
|
|
341
|
-
Delete a message by ID.
|
|
744
|
+
Delete a message by ID. This will remove the message from both the database and the queue, preventing it from being displayed.
|
|
342
745
|
|
|
343
746
|
```typescript
|
|
344
747
|
import { deleteMessageById } from 'tauri-notice-window'
|
|
@@ -346,6 +749,8 @@ import { deleteMessageById } from 'tauri-notice-window'
|
|
|
346
749
|
await deleteMessageById('123')
|
|
347
750
|
```
|
|
348
751
|
|
|
752
|
+
**Note:** When a message is deleted, it is automatically removed from the zustand queue. If the deleted message was the current message being displayed, the window will be closed and the next message will be shown automatically.
|
|
753
|
+
|
|
349
754
|
#### hasMessage()
|
|
350
755
|
|
|
351
756
|
Check if a message exists in the database.
|
|
@@ -445,6 +850,44 @@ app/
|
|
|
445
850
|
|
|
446
851
|
## Advanced Usage
|
|
447
852
|
|
|
853
|
+
### Message Queue Validation
|
|
854
|
+
|
|
855
|
+
The library automatically validates messages in the queue before displaying them. If a message has been deleted from the database, it will be skipped and the next message will be shown instead.
|
|
856
|
+
|
|
857
|
+
```typescript
|
|
858
|
+
import { showNotice, deleteMessageById } from 'tauri-notice-window'
|
|
859
|
+
|
|
860
|
+
// Example 1: Delete a message in the queue
|
|
861
|
+
await showNotice({ id: '1', title: 'First', type: 'announcement', data: {} })
|
|
862
|
+
await showNotice({ id: '2', title: 'Second', type: 'announcement', data: {} })
|
|
863
|
+
await showNotice({ id: '3', title: 'Third', type: 'announcement', data: {} })
|
|
864
|
+
|
|
865
|
+
// If message '2' is deleted while in queue
|
|
866
|
+
await deleteMessageById('2')
|
|
867
|
+
|
|
868
|
+
// The queue will automatically skip message '2' and show message '3' next
|
|
869
|
+
// Console output: "Message 2 was deleted, skipping to next"
|
|
870
|
+
|
|
871
|
+
// Example 2: Delete the currently displayed message
|
|
872
|
+
await showNotice({ id: '4', title: 'Current', type: 'announcement', data: {} })
|
|
873
|
+
// Window for message '4' is now open and displayed
|
|
874
|
+
|
|
875
|
+
// Delete the currently open message
|
|
876
|
+
await deleteMessageById('4')
|
|
877
|
+
// Result: The window for message '4' is automatically closed
|
|
878
|
+
// The next message in the queue (if any) is shown immediately
|
|
879
|
+
```
|
|
880
|
+
|
|
881
|
+
**How it works:**
|
|
882
|
+
1. When `deleteMessageById()` is called, the message is removed from both the database and the zustand queue
|
|
883
|
+
2. If the deleted message has an open window, the window is automatically closed
|
|
884
|
+
3. Before showing any message, the system verifies it still exists in the database
|
|
885
|
+
4. If a message was deleted, it's automatically skipped and the next message is shown
|
|
886
|
+
5. The next message in the queue is displayed automatically after closing the deleted message's window
|
|
887
|
+
6. **Safety Layer:** If a window somehow opens for a deleted message, the `NoticeLayout` component detects this and automatically closes the window
|
|
888
|
+
|
|
889
|
+
This ensures that windows are never opened for deleted messages, and any open window for a deleted message is immediately closed.
|
|
890
|
+
|
|
448
891
|
### Server-Triggered Hide
|
|
449
892
|
|
|
450
893
|
```typescript
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NoticeLayout.d.ts","sourceRoot":"","sources":["../../src/components/NoticeLayout.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAC3D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"NoticeLayout.d.ts","sourceRoot":"","sources":["../../src/components/NoticeLayout.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAC3D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAInD;;GAEG;AACH,UAAU,iBAAiB;IACzB;;OAEG;IACH,QAAQ,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,SAAS,CAAA;IAC7C;;OAEG;IACH,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,IAAI,CAAA;IACvC;;OAEG;IACH,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,IAAI,CAAA;CACzC;AAED;;;GAGG;AACH,eAAO,MAAM,YAAY,GAAI,+BAA+B,iBAAiB,4CAoI5E,CAAA"}
|
|
@@ -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;
|
|
1
|
+
{"version":3,"file":"noticeConfig.d.ts","sourceRoot":"","sources":["../../src/config/noticeConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAyCpD;;;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 ye=require("zustand"),pe=require("zustand-sync"),_e=require("dexie"),g=require("react"),z=require("react/jsx-runtime"),Y="tauri-notice-config",H={routePrefix:"/notice",databaseName:"tauri-notice-db",defaultWidth:400,defaultHeight:300},K=()=>{try{const t=localStorage.getItem(Y);if(t)return{...H,...JSON.parse(t)}}catch(t){console.warn("Failed to load config from localStorage:",t)}return H},fe=t=>{try{localStorage.setItem(Y,JSON.stringify(t))}catch(e){console.warn("Failed to save config to localStorage:",e)}},me=t=>{const i={...K(),...t};fe(i)},E=()=>K();class ve extends _e{messages;constructor(e){super(e),this.version(1).stores({messages:"id, queueStatus, queuePosition, timestamp"})}}let S=null;const q=()=>{if(!S){const t=E();S=new ve(t.databaseName)}return S},h=()=>S||q(),X=async t=>{const e={...t,timestamp:new Date().toISOString(),isRead:!1,isShown:!1,queueStatus:"pending",queuePosition:0};await h().messages.put(e)},ee=async t=>!!await h().messages.get(t),te=async t=>{const e=await h().messages.get(t);return e?.isShown===!0||e?.queueStatus==="shown"},ie=async()=>await h().messages.where("queueStatus").equals("pending").sortBy("queuePosition"),We=async(t,e)=>{await h().messages.update(t,{queueStatus:e})},T=async t=>{await h().messages.update(t,{queueStatus:"shown",isShown:!0})},ne=async t=>{await h().messages.update(t,{queueStatus:"hidden"})},se=async t=>await h().messages.get(t),Se=async t=>{await h().messages.delete(t)},ae=async()=>{await h().messages.where("queueStatus").anyOf(["pending","showing"]).delete()},Ne=async t=>{const e=t.map(i=>h().messages.update(i.id,{queuePosition:i.position}));await Promise.all(e)},De=(t,e)=>({queue:[],currentMessage:null,isProcessing:!1,initialized:!1,activeWindowIds:[],enqueue:async i=>{const n=e();if(await te(i.id)){console.log(`Message ${i.id} was already shown, skipping`);return}if(await ee(i.id)||await X(i),!n.queue.some(u=>u.id===i.id)){const u=[...n.queue,i];t({queue:u}),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}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 ie();n.length>0&&(t({queue:n}),await e().showNext())},persistQueue:async()=>{const n=e().queue.map((a,r)=>({id:a.id,position:r}));await Ne(n)},clearOnLogout:async()=>{t({queue:[],currentMessage:null,isProcessing:!1,activeWindowIds:[],initialized:!1}),await ae()},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(r=>r!==a)})},isWindowActive:i=>{const n=e(),a=String(i);return n.activeWindowIds.includes(a)}}),d=ye.create()(pe.syncTabs(De,{name:"tauri-notice-queue"})),W={queueLength:t=>t.queue.length,currentMessage:t=>t.currentMessage,isProcessing:t=>t.isProcessing,queue:t=>t.queue},ze=()=>{const t=d(i=>i.enqueue);return{showNotice:g.useCallback(async i=>{await t(i)},[t])}};function Ae(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 A;const w="__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 Me{get rid(){return Ae(this,A,"f")}constructor(e){A.set(this,void 0),Oe(this,A,e)}async close(){return s("plugin:resources|close",{rid:this.rid})}}A=new WeakMap;class le{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 y(this.width*e,this.height*e)}[w](){return{width:this.width,height:this.height}}toJSON(){return this[w]()}}class y{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 le(this.width/e,this.height/e)}[w](){return{width:this.width,height:this.height}}toJSON(){return this[w]()}}class b{constructor(e){this.size=e}toLogical(e){return this.size instanceof le?this.size:this.size.toLogical(e)}toPhysical(e){return this.size instanceof y?this.size:this.size.toPhysical(e)}[w](){return{[`${this.size.type}`]:{width:this.size.width,height:this.size.height}}}toJSON(){return this[w]()}}class re{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 c(this.x*e,this.y*e)}[w](){return{x:this.x,y:this.y}}toJSON(){return this[w]()}}class c{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 re(this.x/e,this.y/e)}[w](){return{x:this.x,y:this.y}}toJSON(){return this[w]()}}class _{constructor(e){this.position=e}toLogical(e){return this.position instanceof re?this.position:this.position.toLogical(e)}toPhysical(e){return this.position instanceof c?this.position:this.position.toPhysical(e)}[w](){return{[`${this.position.type}`]:{x:this.position.x,y:this.position.y}}}toJSON(){return this[w]()}}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 oe(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(r=>async()=>oe(t,r))}async function F(t,e,i){return P(t,n=>{oe(t,n.id),e(n)},i)}async function ue(t,e){await s("plugin:event|emit",{event:t,payload:e})}async function ce(t,e,i){await s("plugin:event|emit_to",{target:typeof t=="string"?{kind:"AnyLabel",label:t}:t,event:e,payload:i})}class N extends Me{constructor(e){super(e)}static async new(e,i,n){return s("plugin:image|new",{rgba:O(e),width:i,height:n}).then(a=>new N(a))}static async fromBytes(e){return s("plugin:image|from_bytes",{bytes:O(e)}).then(i=>new N(i))}static async fromPath(e){return s("plugin:image|from_path",{path:e}).then(i=>new N(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 O(t){return t==null?null:typeof t=="string"?t:t instanceof N?t.rid:t}var R;(function(t){t[t.Critical=1]="Critical",t[t.Informational=2]="Informational"})(R||(R={}));class xe{constructor(e){this._preventDefault=!1,this.event=e.event,this.id=e.id}preventDefault(){this._preventDefault=!0}isPreventDefault(){return this._preventDefault}}var U;(function(t){t.None="none",t.Normal="normal",t.Indeterminate="indeterminate",t.Paused="paused",t.Error="error"})(U||(U={}));function de(){return new M(window.__TAURI_INTERNALS__.metadata.currentWindow.label,{skip:!0})}async function k(){return s("plugin:window|get_all_windows").then(t=>t.map(e=>new M(e,{skip:!0})))}const C=["tauri://created","tauri://error"];class M{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 k()).find(n=>n.label===e))!==null&&i!==void 0?i:null}static getCurrent(){return de()}static async getAll(){return k()}static async getFocusedWindow(){for(const e of await k())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)}:F(e,i,{target:{kind:"Window",label:this.label}})}async emit(e,i){if(C.includes(e)){for(const n of this.listeners[e]||[])n({event:e,id:-1,payload:i});return}return ue(e,i)}async emitTo(e,i,n){if(C.includes(i)){for(const a of this.listeners[i]||[])a({event:i,id:-1,payload:n});return}return ce(e,i,n)}_handleTauriEvent(e,i){return C.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 c(e))}async outerPosition(){return s("plugin:window|outer_position",{label:this.label}).then(e=>new c(e))}async innerSize(){return s("plugin:window|inner_size",{label:this.label}).then(e=>new y(e))}async outerSize(){return s("plugin:window|outer_size",{label:this.label}).then(e=>new y(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===R.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 b?e:new b(e)})}async setMinSize(e){return s("plugin:window|set_min_size",{label:this.label,value:e instanceof b?e:e?new b(e):null})}async setMaxSize(e){return s("plugin:window|set_max_size",{label:this.label,value:e instanceof b?e:e?new b(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 _?e:new _(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:O(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 _?e:new _(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?O(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 y(i.payload),e(i)})}async onMoved(e){return this.listen(o.WINDOW_MOVED,i=>{i.payload=new c(i.payload),e(i)})}async onCloseRequested(e){return this.listen(o.WINDOW_CLOSE_REQUESTED,async i=>{const n=new xe(i);await e(n),n.isPreventDefault()||await this.destroy()})}async onDragDropEvent(e){const i=await this.listen(o.DRAG_ENTER,l=>{e({...l,payload:{type:"enter",paths:l.payload.paths,position:new c(l.payload.position)}})}),n=await this.listen(o.DRAG_OVER,l=>{e({...l,payload:{type:"over",position:new c(l.payload.position)}})}),a=await this.listen(o.DRAG_DROP,l=>{e({...l,payload:{type:"drop",paths:l.payload.paths,position:new c(l.payload.position)}})}),r=await this.listen(o.DRAG_LEAVE,l=>{e({...l,payload:{type:"leave"}})});return()=>{i(),a(),n(),r()}}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 Q;(function(t){t.Disabled="disabled",t.Throttle="throttle",t.Suspend="suspend"})(Q||(Q={}));var j;(function(t){t.Default="default",t.FluentOverlay="fluentOverlay"})(j||(j={}));var V;(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"})(V||(V={}));var $;(function(t){t.FollowsWindowActiveState="followsWindowActiveState",t.Active="active",t.Inactive="inactive"})($||($={}));function Ie(t){return t===null?null:{name:t.name,scaleFactor:t.scaleFactor,position:new c(t.position),size:new y(t.size),workArea:{position:new c(t.workArea.position),size:new y(t.workArea.size)}}}async function ke(){return s("plugin:window|primary_monitor").then(Ie)}function we(){return new B(de(),window.__TAURI_INTERNALS__.metadata.currentWebview.label,{skip:!0})}async function J(){return s("plugin:webview|get_all_webviews").then(t=>t.map(e=>new B(new M(e.windowLabel,{skip:!0}),e.label,{skip:!0})))}const L=["tauri://created","tauri://error"];class B{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 J()).find(n=>n.label===e))!==null&&i!==void 0?i:null}static getCurrent(){return we()}static async getAll(){return J()}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)}:F(e,i,{target:{kind:"Webview",label:this.label}})}async emit(e,i){if(L.includes(e)){for(const n of this.listeners[e]||[])n({event:e,id:-1,payload:i});return}return ue(e,i)}async emitTo(e,i,n){if(L.includes(i)){for(const a of this.listeners[i]||[])a({event:i,id:-1,payload:n});return}return ce(e,i,n)}_handleTauriEvent(e,i){return L.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 c(e))}async size(){return s("plugin:webview|webview_size",{label:this.label}).then(e=>new y(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 b?e:new b(e)})}async setPosition(e){return s("plugin:webview|set_webview_position",{label:this.label,value:e instanceof _?e:new _(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,l=>{e({...l,payload:{type:"enter",paths:l.payload.paths,position:new c(l.payload.position)}})}),n=await this.listen(o.DRAG_OVER,l=>{e({...l,payload:{type:"over",position:new c(l.payload.position)}})}),a=await this.listen(o.DRAG_DROP,l=>{e({...l,payload:{type:"drop",paths:l.payload.paths,position:new c(l.payload.position)}})}),r=await this.listen(o.DRAG_LEAVE,l=>{e({...l,payload:{type:"leave"}})});return()=>{i(),a(),n(),r()}}}function Ce(){const t=we();return new f(t.label,{skip:!0})}async function Z(){return s("plugin:window|get_all_windows").then(t=>t.map(e=>new f(e,{skip:!0})))}class f{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 Z()).find(a=>a.label===e))!==null&&i!==void 0?i:null;return n?new f(n.label,{skip:!0}):null}static getCurrent(){return Ce()}static async getAll(){return Z()}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)}:F(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}))}}Le(f,[M,B]);function Le(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 D=new Map,Re=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,r=1080;try{const u=await ke();u?.size&&(a=u.size.width,r=u.size.height)}catch(u){console.warn("Failed to get monitor info, using defaults:",u)}switch(i?.position??"right-bottom"){case"right-bottom":return{x:a-t-n,y:r-e-n};case"right-top":return{x:a-t-n,y:n};case"left-bottom":return{x:n,y:r-e-n};case"left-top":return{x:n,y:n};case"center":return{x:(a-t)/2,y:(r-e)/2};default:return{x:a-t-n,y:r-e-n}}},he=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=E(),a=`notice-${e}`,r=`${n.routePrefix}/${t.type}?id=${t.id}`,l=t.min_width||n.defaultWidth,u=t.min_height||n.defaultHeight,{x:m,y:v}=await Re(l,u,t.windowPosition);try{const p=new f(a,{url:r,title:t.title,width:l,height:u,x:m,y:v,resizable:!0,decorations:!0,skipTaskbar:!1,alwaysOnTop:!0});D.set(e,p),i.addActiveWindow(e),p.once("tauri://destroyed",async()=>{D.delete(e),i.removeActiveWindow(e),await T(e),i.clearCurrent()}),console.log(`Created notice window: ${a}`)}catch(p){console.error("Failed to create notice window:",p),i.removeActiveWindow(e),i.clearCurrent()}},x=async t=>{const e=String(t),i=D.get(e),n=d.getState();if(i)try{await i.close(),D.delete(e),n.removeActiveWindow(e),await T(e),n.clearCurrent(),console.log(`Closed notice window: ${e}`)}catch(a){console.error("Failed to close notice window:",a)}},ge=async()=>{const t=Array.from(D.keys()).map(e=>x(e));await Promise.all(t)},be=()=>{let t=null;d.subscribe(e=>{const i=e.currentMessage;i&&i!==t?(t=i,he(i)):i||(t=null)}),console.log("Notice window system initialized")},Ee=()=>{const t=d(i=>i.currentMessage);return{closeNotice:g.useCallback(async()=>{t&&await x(t.id)},[t])}},qe=()=>{const t=d();return{hideNotice:g.useCallback(async i=>{await ne(i),await x(i),t.currentMessage?.id===i&&t.clearCurrent()},[t])}},Te=()=>{const t=d(i=>i.clearOnLogout);return{hideAllNotices:g.useCallback(async()=>{await ge(),await t()},[t])}},Fe=()=>{const t=d(W.queueLength),e=d(W.currentMessage),i=d(W.isProcessing),n=d(W.queue);return{queueLength:t,currentMessage:e,isProcessing:i,queue:n}},Be=({children:t,onLoad:e,onClose:i})=>{const[n,a]=g.useState(null),[r,l]=g.useState(!0),[u,m]=g.useState(null);return g.useEffect(()=>{(async()=>{try{const G=new URLSearchParams(window.location.search).get("id");if(!G){m("No message ID provided"),l(!1);return}const I=await se(G);if(!I){m("Message not found"),l(!1);return}a(I),l(!1),e&&e(I)}catch(p){console.error("Failed to load message:",p),m("Failed to load message"),l(!1)}})()},[e]),g.useEffect(()=>{if(!n||!i)return;const v=()=>{i(n)};return window.addEventListener("beforeunload",v),()=>{window.removeEventListener("beforeunload",v)}},[n,i]),r?z.jsx("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",height:"100vh",fontFamily:"system-ui, -apple-system, sans-serif"},children:"Loading..."}):u||!n?z.jsx("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",height:"100vh",fontFamily:"system-ui, -apple-system, sans-serif",color:"#ef4444"},children:u||"Message not found"}):z.jsx(z.Fragment,{children:t(n)})},Ge=async()=>{q(),be();const{initializeFromDatabase:t}=d.getState();await t(),console.log("Tauri Notice System initialized")};exports.NoticeLayout=Be;exports.clearPendingMessages=ae;exports.closeAllNoticeWindows=ge;exports.closeNoticeWindow=x;exports.createNoticeWindow=he;exports.deleteMessageById=Se;exports.getMessage=se;exports.getNoticeConfig=E;exports.getPendingMessages=ie;exports.hasMessage=ee;exports.initializeDatabase=q;exports.initializeNoticeSystem=Ge;exports.initializeNoticeWindowSystem=be;exports.isMessageShown=te;exports.markAsHidden=ne;exports.markAsShown=T;exports.messageQueueSelectors=W;exports.saveMessage=X;exports.setNoticeConfig=me;exports.useCloseNotice=Ee;exports.useHideAllNotices=Te;exports.useHideNotice=qe;exports.useMessageQueue=Fe;exports.useMessageQueueStore=d;exports.useNoticeWindow=ze;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const fe=require("zustand"),me=require("zustand-sync"),ve=require("dexie"),g=require("react"),z=require("react/jsx-runtime"),ne="tauri-notice-config",J={routePrefix:"/notice",databaseName:"tauri-notice-db",defaultWidth:400,defaultHeight:300,notFoundUrl:"/404"},se=()=>{try{const t=localStorage.getItem(ne);if(t)return{...J,...JSON.parse(t)}}catch(t){console.warn("Failed to load config from localStorage:",t)}return J},We=t=>{try{localStorage.setItem(ne,JSON.stringify(t))}catch(e){console.warn("Failed to save config to localStorage:",e)}},Se=t=>{const i={...se(),...t};We(i)},F=()=>se();class Ne extends ve{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 Ne(t.databaseName)}return D},h=()=>D||B(),ae=async t=>{const e={...t,timestamp:new Date().toISOString(),isRead:!1,isShown:!1,queueStatus:"pending",queuePosition:0};await h().messages.put(e)},re=async t=>!!await h().messages.get(t),le=async t=>{const e=await h().messages.get(t);return e?.isShown===!0||e?.queueStatus==="shown"},oe=async()=>await h().messages.where("queueStatus").equals("pending").sortBy("queuePosition"),ue=async(t,e)=>{await h().messages.update(t,{queueStatus:e})},U=async t=>{await h().messages.update(t,{queueStatus:"shown",isShown:!0})},ce=async t=>{await h().messages.update(t,{queueStatus:"hidden"})},Q=async t=>await h().messages.get(t),ze=async t=>{await h().messages.delete(t);try{const{useMessageQueueStore:e}=await Promise.resolve().then(()=>Oe),{removeFromQueue:i}=e.getState();i(t)}catch(e){console.warn("Failed to remove message from queue store:",e)}},de=async()=>{await h().messages.where("queueStatus").anyOf(["pending","showing"]).delete()},De=async t=>{const e=t.map(i=>h().messages.update(i.id,{queuePosition:i.position}));await Promise.all(e)},Ae=(t,e)=>({queue:[],currentMessage:null,isProcessing:!1,initialized:!1,activeWindowIds:[],enqueue:async i=>{const n=e();if(await le(i.id)){console.log(`Message ${i.id} was already shown, skipping`);return}if(await re(i.id)||await ae(i),!n.queue.some(u=>u.id===i.id)){const u=[...n.queue,i];t({queue:u}),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 Q(n.id)){console.log(`Message ${n.id} was deleted, skipping to next`),await e().showNext();return}t({currentMessage:n,isProcessing:!0}),await ue(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 oe();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 de()},removeFromQueue:i=>{const n=e(),a=n.queue.filter(l=>l.id!==i);t({queue:a}),n.currentMessage?.id===i&&(async()=>{try{const{closeNoticeWindow:r}=await Promise.resolve().then(()=>Fe);await r(i)}catch(r){console.warn("Failed to close notice window:",r),e().clearCurrent()}})()},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=fe.create()(me.syncTabs(Ae,{name:"tauri-notice-queue"})),f={queueLength:t=>t.queue.length,currentMessage:t=>t.currentMessage,isProcessing:t=>t.isProcessing,queue:t=>t.queue},Oe=Object.freeze(Object.defineProperty({__proto__:null,messageQueueSelectors:f,useMessageQueueStore:d},Symbol.toStringTag,{value:"Module"})),Pe=()=>{const t=d(i=>i.enqueue);return{showNotice:g.useCallback(async i=>{await t(i)},[t])}};function Me(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 xe(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 M;const w="__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 Ce{get rid(){return Me(this,M,"f")}constructor(e){M.set(this,void 0),xe(this,M,e)}async close(){return s("plugin:resources|close",{rid:this.rid})}}M=new WeakMap;class we{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 b(this.width*e,this.height*e)}[w](){return{width:this.width,height:this.height}}toJSON(){return this[w]()}}class b{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 we(this.width/e,this.height/e)}[w](){return{width:this.width,height:this.height}}toJSON(){return this[w]()}}class y{constructor(e){this.size=e}toLogical(e){return this.size instanceof we?this.size:this.size.toLogical(e)}toPhysical(e){return this.size instanceof b?this.size:this.size.toPhysical(e)}[w](){return{[`${this.size.type}`]:{width:this.size.width,height:this.size.height}}}toJSON(){return this[w]()}}class he{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 c(this.x*e,this.y*e)}[w](){return{x:this.x,y:this.y}}toJSON(){return this[w]()}}class c{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 he(this.x/e,this.y/e)}[w](){return{x:this.x,y:this.y}}toJSON(){return this[w]()}}class m{constructor(e){this.position=e}toLogical(e){return this.position instanceof he?this.position:this.position.toLogical(e)}toPhysical(e){return this.position instanceof c?this.position:this.position.toPhysical(e)}[w](){return{[`${this.position.type}`]:{x:this.position.x,y:this.position.y}}}toJSON(){return this[w]()}}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 ge(t,e){window.__TAURI_EVENT_PLUGIN_INTERNALS__.unregisterListener(t,e),await s("plugin:event|unlisten",{event:t,eventId:e})}async function C(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()=>ge(t,l))}async function j(t,e,i){return C(t,n=>{ge(t,n.id),e(n)},i)}async function ye(t,e){await s("plugin:event|emit",{event:t,payload:e})}async function be(t,e,i){await s("plugin:event|emit_to",{target:typeof t=="string"?{kind:"AnyLabel",label:t}:t,event:e,payload:i})}class A extends Ce{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 A(a))}static async fromBytes(e){return s("plugin:image|from_bytes",{bytes:k(e)}).then(i=>new A(i))}static async fromPath(e){return s("plugin:image|from_path",{path:e}).then(i=>new A(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 A?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 Z;(function(t){t.None="none",t.Normal="normal",t.Indeterminate="indeterminate",t.Paused="paused",t.Error="error"})(Z||(Z={}));function pe(){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 pe()}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)}:C(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)}:j(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 ye(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 be(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 c(e))}async outerPosition(){return s("plugin:window|outer_position",{label:this.label}).then(e=>new c(e))}async innerSize(){return s("plugin:window|inner_size",{label:this.label}).then(e=>new b(e))}async outerSize(){return s("plugin:window|outer_size",{label:this.label}).then(e=>new b(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 y?e:new y(e)})}async setMinSize(e){return s("plugin:window|set_min_size",{label:this.label,value:e instanceof y?e:e?new y(e):null})}async setMaxSize(e){return s("plugin:window|set_max_size",{label:this.label,value:e instanceof y?e:e?new y(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 m?e:new m(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 m?e:new m(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 b(i.payload),e(i)})}async onMoved(e){return this.listen(o.WINDOW_MOVED,i=>{i.payload=new c(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 c(r.payload.position)}})}),n=await this.listen(o.DRAG_OVER,r=>{e({...r,payload:{type:"over",position:new c(r.payload.position)}})}),a=await this.listen(o.DRAG_DROP,r=>{e({...r,payload:{type:"drop",paths:r.payload.paths,position:new c(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 Y;(function(t){t.Disabled="disabled",t.Throttle="throttle",t.Suspend="suspend"})(Y||(Y={}));var K;(function(t){t.Default="default",t.FluentOverlay="fluentOverlay"})(K||(K={}));var X;(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"})(X||(X={}));var ee;(function(t){t.FollowsWindowActiveState="followsWindowActiveState",t.Active="active",t.Inactive="inactive"})(ee||(ee={}));function Le(t){return t===null?null:{name:t.name,scaleFactor:t.scaleFactor,position:new c(t.position),size:new b(t.size),workArea:{position:new c(t.workArea.position),size:new b(t.workArea.size)}}}async function Ee(){return s("plugin:window|primary_monitor").then(Le)}function _e(){return new G(pe(),window.__TAURI_INTERNALS__.metadata.currentWebview.label,{skip:!0})}async function te(){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 te()).find(n=>n.label===e))!==null&&i!==void 0?i:null}static getCurrent(){return _e()}static async getAll(){return te()}async listen(e,i){return this._handleTauriEvent(e,i)?()=>{const n=this.listeners[e];n.splice(n.indexOf(i),1)}:C(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)}:j(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 ye(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 be(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 c(e))}async size(){return s("plugin:webview|webview_size",{label:this.label}).then(e=>new b(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 y?e:new y(e)})}async setPosition(e){return s("plugin:webview|set_webview_position",{label:this.label,value:e instanceof m?e:new m(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 c(r.payload.position)}})}),n=await this.listen(o.DRAG_OVER,r=>{e({...r,payload:{type:"over",position:new c(r.payload.position)}})}),a=await this.listen(o.DRAG_DROP,r=>{e({...r,payload:{type:"drop",paths:r.payload.paths,position:new c(r.payload.position)}})}),l=await this.listen(o.DRAG_LEAVE,r=>{e({...r,payload:{type:"leave"}})});return()=>{i(),a(),n(),l()}}}function x(){const t=_e();return new v(t.label,{skip:!0})}async function ie(){return s("plugin:window|get_all_windows").then(t=>t.map(e=>new v(e,{skip:!0})))}class v{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 ie()).find(a=>a.label===e))!==null&&i!==void 0?i:null;return n?new v(n.label,{skip:!0}):null}static getCurrent(){return x()}static async getAll(){return ie()}async listen(e,i){return this._handleTauriEvent(e,i)?()=>{const n=this.listeners[e];n.splice(n.indexOf(i),1)}:C(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)}:j(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(v,[I,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 O=new Map,Te=t=>{if(!t||t.trim()==="")return!1;try{return!!(t.startsWith("/")||t.startsWith("http://")||t.startsWith("https://")||t.startsWith("tauri://"))}catch{return!1}},qe=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 u=await Ee();u?.size&&(a=u.size.width,l=u.size.height)}catch(u){console.warn("Failed to get monitor info, using defaults:",u)}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}}},H=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}`;Te(l)||(console.warn(`Invalid window URL: ${l}. Using fallback 404 page.`),l=n.notFoundUrl||"/404");const r=t.min_width||n.defaultWidth,u=t.min_height||n.defaultHeight,{x:W,y:S}=await qe(r,u,t.windowPosition);try{const p=new v(a,{url:l,title:t.title,width:r,height:u,x:W,y:S,resizable:!0,decorations:!0,skipTaskbar:!1,alwaysOnTop:!0});O.set(e,p),i.addActiveWindow(e),p.once("tauri://destroyed",async()=>{O.delete(e),i.removeActiveWindow(e),await U(e),i.clearCurrent()}),console.log(`Created notice window: ${a}`)}catch(p){console.error("Failed to create notice window:",p),i.removeActiveWindow(e),i.clearCurrent()}},P=async t=>{const e=String(t),i=O.get(e),n=d.getState();if(i)try{await i.close(),O.delete(e),n.removeActiveWindow(e),await U(e),n.clearCurrent(),console.log(`Closed notice window: ${e}`)}catch(a){console.error("Failed to close notice window:",a)}},V=async()=>{const t=Array.from(O.keys()).map(e=>P(e));await Promise.all(t)},$=()=>{let t=null;d.subscribe(e=>{const i=e.currentMessage;i&&i!==t?(t=i,H(i)):i||(t=null)}),console.log("Notice window system initialized")},Fe=Object.freeze(Object.defineProperty({__proto__:null,closeAllNoticeWindows:V,closeNoticeWindow:P,createNoticeWindow:H,initializeNoticeWindowSystem:$},Symbol.toStringTag,{value:"Module"})),Be=()=>{const t=d(i=>i.currentMessage);return{closeNotice:g.useCallback(async()=>{t&&await P(t.id)},[t])}},Ue=()=>{const t=d();return{hideNotice:g.useCallback(async i=>{await ce(i),await P(i),t.currentMessage?.id===i&&t.clearCurrent()},[t])}},Qe=()=>{const t=d(i=>i.clearOnLogout);return{hideAllNotices:g.useCallback(async()=>{await V(),await t()},[t])}},je=()=>{const t=d(f.queueLength),e=d(f.currentMessage),i=d(f.isProcessing),n=d(f.queue);return{queueLength:t,currentMessage:e,isProcessing:i,queue:n}},Ge=({children:t,onLoad:e,onClose:i})=>{const[n,a]=g.useState(null),[l,r]=g.useState(!0),[u,W]=g.useState(null);return g.useEffect(()=>{(async()=>{try{const _=new URLSearchParams(window.location.search).get("id");if(!_){W("No message ID provided"),r(!1),setTimeout(async()=>{try{await x().close()}catch(N){console.error("Failed to close window:",N)}},1e3);return}const L=await Q(_);if(!L){console.log(`Message ${_} not found in database, closing window`),W("Message not found"),r(!1),setTimeout(async()=>{try{await x().close()}catch(N){console.error("Failed to close window:",N)}},500);return}a(L),r(!1),e&&e(L)}catch(p){console.error("Failed to load message:",p),W("Failed to load message"),r(!1),setTimeout(async()=>{try{await x().close()}catch(_){console.error("Failed to close window:",_)}},1e3)}})()},[e]),g.useEffect(()=>{if(!n||!i)return;const S=()=>{i(n)};return window.addEventListener("beforeunload",S),()=>{window.removeEventListener("beforeunload",S)}},[n,i]),l?z.jsx("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",height:"100vh",fontFamily:"system-ui, -apple-system, sans-serif"},children:"Loading..."}):u?z.jsx("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",height:"100vh",fontFamily:"system-ui, -apple-system, sans-serif",color:"#ef4444"},children:u}):n?z.jsx(z.Fragment,{children:t(n)}):z.jsx("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",height:"100vh",fontFamily:"system-ui, -apple-system, sans-serif",color:"#ef4444"},children:"Closing window..."})},He=async()=>{B(),$();const{initializeFromDatabase:t}=d.getState();await t(),console.log("Tauri Notice System initialized")};exports.NoticeLayout=Ge;exports.clearPendingMessages=de;exports.closeAllNoticeWindows=V;exports.closeNoticeWindow=P;exports.createNoticeWindow=H;exports.deleteMessageById=ze;exports.getMessage=Q;exports.getNoticeConfig=F;exports.getPendingMessages=oe;exports.hasMessage=re;exports.initializeDatabase=B;exports.initializeNoticeSystem=He;exports.initializeNoticeWindowSystem=$;exports.isMessageShown=le;exports.markAsHidden=ce;exports.markAsShown=U;exports.messageQueueSelectors=f;exports.saveMessage=ae;exports.setNoticeConfig=Se;exports.updateQueueStatus=ue;exports.useCloseNotice=Be;exports.useHideAllNotices=Qe;exports.useHideNotice=Ue;exports.useMessageQueue=je;exports.useMessageQueueStore=d;exports.useNoticeWindow=Pe;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|