dsh-notify-yimit 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.en.md +97 -97
- package/README.md +96 -94
- package/cordis.patch.yml +6 -6
- package/lib/client.js +1369 -790
- package/lib/index.js +1098 -716
- package/lib/toast-host.ps1 +496 -329
- package/lib/typert.host.js +227 -158
- package/package.json +56 -50
package/lib/client.js
CHANGED
|
@@ -1,790 +1,1369 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* dsh-notify-yimit 浏览器端 bundle
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* dsh-notify-yimit 浏览器端 bundle。
|
|
3
|
+
* 语言跟随:接入 `locale` 服务(由 dsh 框架注入),完全对齐 dsh-market 的标准用法;
|
|
4
|
+
* 旧宿主无该服务时降级到 navigator/localStorage 轮询,绝不阻塞启动。
|
|
5
|
+
*/
|
|
6
|
+
window.__ModuleLoader__.load({
|
|
7
|
+
id: 'dsh-notify-yimit',
|
|
8
|
+
factory: (require) => {
|
|
9
|
+
var module = {
|
|
10
|
+
exports: {}
|
|
11
|
+
}
|
|
12
|
+
var exports = module.exports
|
|
13
|
+
Object.defineProperty(exports, Symbol.toStringTag, {
|
|
14
|
+
value: 'Module'
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
const React = require('react')
|
|
18
|
+
const {
|
|
19
|
+
createElement: el,
|
|
20
|
+
Fragment,
|
|
21
|
+
useState,
|
|
22
|
+
useEffect,
|
|
23
|
+
useRef,
|
|
24
|
+
useCallback,
|
|
25
|
+
useSyncExternalStore
|
|
26
|
+
} = React
|
|
27
|
+
|
|
28
|
+
const css = [
|
|
29
|
+
'/* dsh-notify-yimit: 设置页与自定义通知浮层 */',
|
|
30
|
+
'.dn-root{display:flex;flex-direction:column;gap:20px;padding:4px 2px 24px;font-size:13px;color:var(--dsw-alias-label-primary)}',
|
|
31
|
+
'.dn-block{display:flex;flex-direction:column;gap:10px}',
|
|
32
|
+
'.dn-title{font-size:13px;font-weight:600;margin:0}',
|
|
33
|
+
'.dn-note{font-size:12px;line-height:20px;color:var(--dsw-alias-label-tertiary);margin:0}',
|
|
34
|
+
'.dn-row{display:flex;align-items:center;gap:10px}',
|
|
35
|
+
'.dn-label{font-size:13px;color:var(--dsw-alias-label-secondary);flex:none}',
|
|
36
|
+
'.dn-switch{position:relative;width:38px;height:22px;border-radius:999px;background:var(--dsw-alias-bg-layer-3);border:1px solid var(--dsw-alias-border-l2);cursor:pointer;padding:0;flex:none;transition:background .15s ease,border-color .15s ease}',
|
|
37
|
+
'.dn-switch[data-on="true"]{background:var(--dsw-alias-state-business-primary);border-color:transparent}',
|
|
38
|
+
'.dn-switch::after{content:"";position:absolute;top:2px;left:2px;width:16px;height:16px;border-radius:50%;background:var(--dsw-alias-label-secondary);transition:transform .15s ease,background .15s ease}',
|
|
39
|
+
'.dn-switch[data-on="true"]::after{transform:translateX(16px);background:var(--dsw-alias-label-primary-inverted)}',
|
|
40
|
+
'.dn-seg{display:flex;gap:2px;padding:2px;border-radius:10px;background:var(--dsw-alias-bg-layer-2);border:1px solid var(--dsw-alias-border-l1);max-width:520px}',
|
|
41
|
+
'.dn-seg-btn{flex:1;font:inherit;font-size:13px;color:var(--dsw-alias-label-secondary);border:0;border-radius:8px;padding:6px 10px;cursor:pointer;background:transparent;transition:background .15s ease,color .15s ease;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}',
|
|
42
|
+
'.dn-seg-btn:hover{color:var(--dsw-alias-label-primary);background:var(--dsw-alias-interactive-bg-hover)}',
|
|
43
|
+
// 选中态用主题主色 + 反色文字:浅色模式下与背景对比也足够清晰(此前浅色下
|
|
44
|
+
// 白底+深灰与容器太接近,深色正常)。
|
|
45
|
+
'.dn-seg-btn[data-on="true"]{background:var(--dsw-alias-state-business-primary);color:var(--dsw-alias-label-primary-inverted);box-shadow:var(--dsw-shadow-lv1)}',
|
|
46
|
+
'.dn-seg-btn[data-on="true"]:hover{background:var(--dsw-alias-state-business-primary);color:var(--dsw-alias-label-primary-inverted)}',
|
|
47
|
+
'.dn-seg-btn:disabled{opacity:.45;cursor:not-allowed}',
|
|
48
|
+
'.dn-seg-btn:disabled:hover{background:transparent;color:var(--dsw-alias-label-secondary)}',
|
|
49
|
+
'.dn-collapse{display:grid;grid-template-rows:1fr;opacity:1;transition:grid-template-rows .24s ease,opacity .2s ease}',
|
|
50
|
+
'.dn-collapse[data-open="false"]{grid-template-rows:0fr;opacity:0}',
|
|
51
|
+
'.dn-collapse>.dn-collapse-body{overflow:hidden;min-height:0}',
|
|
52
|
+
'.dn-collapse>.dn-collapse-body>.dn-block{min-width:0}',
|
|
53
|
+
'.dn-kind-list{display:flex;flex-direction:column;gap:8px}',
|
|
54
|
+
'.dn-kind-row{display:flex;align-items:center;gap:12px;padding:8px 12px;border:1px solid var(--dsw-alias-border-l1);border-radius:10px;background:var(--dsw-alias-bg-layer-1)}',
|
|
55
|
+
// 每类型的背景/文字/开关项右对齐(预览块留在左侧)
|
|
56
|
+
'.dn-kind-row>.dn-kind-field:first-of-type{margin-left:auto}',
|
|
57
|
+
// 样式预览:纯色块内嵌类型文字,始终用配置的背景/文字色(内联样式,不受主题影响)
|
|
58
|
+
'.dn-kind-preview{flex:none;min-width:72px;text-align:center;font-size:12px;font-weight:600;line-height:22px;padding:2px 10px;border-radius:6px;white-space:nowrap;box-shadow:inset 0 0 0 1px rgba(0,0,0,.08)}',
|
|
59
|
+
'.dn-kind-field{display:flex;align-items:center;gap:6px;font-size:12px;color:var(--dsw-alias-label-tertiary);flex:none}',
|
|
60
|
+
'.dn-input{font:inherit;font-size:13px;color:var(--dsw-alias-label-primary);background:var(--dsw-alias-bg-base);border:1px solid var(--dsw-alias-border-l1);border-radius:8px;padding:5px 10px;outline:none;max-width:120px}',
|
|
61
|
+
'.dn-input:focus{border-color:var(--dsw-alias-state-business-primary)}',
|
|
62
|
+
'.dn-input[type=color]{padding:2px 4px;width:48px;height:28px;cursor:pointer;max-width:none}',
|
|
63
|
+
'.dn-input:disabled{opacity:.45;cursor:not-allowed}',
|
|
64
|
+
// 浏览器选择器:原生 select 的展开列表为系统绘制、无法贴合主题,改为自绘下拉,
|
|
65
|
+
// 触发器与弹层都走 --dsw-* 变量,深浅色模式下与设置页风格一致。
|
|
66
|
+
'.dn-bselect{position:relative;width:280px;max-width:100%;flex:none}',
|
|
67
|
+
'.dn-bselect-trigger{display:flex;align-items:center;justify-content:space-between;gap:8px;width:100%;font:inherit;font-size:13px;color:var(--dsw-alias-label-primary);background:var(--dsw-alias-bg-base);border:1px solid var(--dsw-alias-border-l1);border-radius:8px;padding:5px 10px;cursor:pointer;outline:none}',
|
|
68
|
+
'.dn-bselect-trigger:hover:not(:disabled){border-color:var(--dsw-alias-border-l2)}',
|
|
69
|
+
'.dn-bselect-trigger.open{border-color:var(--dsw-alias-state-business-primary)}',
|
|
70
|
+
'.dn-bselect-trigger:disabled{opacity:.45;cursor:not-allowed}',
|
|
71
|
+
'.dn-bselect-value{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}',
|
|
72
|
+
'.dn-bselect-arrow{flex:none;font-size:10px;color:var(--dsw-alias-label-tertiary)}',
|
|
73
|
+
'.dn-bselect-pop{position:absolute;top:calc(100% + 4px);left:0;right:0;z-index:100;background:var(--dsw-alias-bg-base);border:1px solid var(--dsw-alias-border-l1);border-radius:10px;box-shadow:var(--dsw-shadow-lv3);padding:4px;max-height:240px;overflow:auto}',
|
|
74
|
+
'.dn-bselect-opt{display:block;width:100%;text-align:left;font:inherit;font-size:13px;color:var(--dsw-alias-label-primary);background:transparent;border:0;border-radius:7px;padding:6px 10px;cursor:pointer;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}',
|
|
75
|
+
'.dn-bselect-opt:hover{background:var(--dsw-alias-interactive-bg-hover)}',
|
|
76
|
+
'.dn-bselect-opt.sel{color:var(--dsw-alias-state-business-primary);font-weight:600}',
|
|
77
|
+
'.dn-color-preview{font-size:12px;color:var(--dsw-alias-label-tertiary);font-family:var(--dsw-font-mono)}',
|
|
78
|
+
'.dn-btn{font:inherit;font-size:13px;color:var(--dsw-alias-label-primary);background:var(--dsw-alias-button-elevated-fill);border:1px solid var(--dsw-alias-border-l1);border-radius:8px;padding:6px 14px;cursor:pointer}',
|
|
79
|
+
'.dn-btn:hover{background:var(--dsw-alias-interactive-bg-hover)}',
|
|
80
|
+
'.dn-btn.primary{background:var(--dsw-alias-state-business-primary);border-color:transparent;color:var(--dsw-alias-label-primary-inverted)}',
|
|
81
|
+
'.dn-btn.primary:hover{opacity:0.88}',
|
|
82
|
+
'.dn-btn:disabled{opacity:.5;cursor:not-allowed}',
|
|
83
|
+
'.dn-msg{font-size:12px;line-height:18px;padding:8px 12px;border-radius:8px;border:1px solid var(--dsw-alias-border-l1)}',
|
|
84
|
+
'.dn-msg.ok{color:var(--dsw-alias-state-success-primary)}',
|
|
85
|
+
'.dn-msg.err{color:var(--dsw-alias-state-error-primary)}',
|
|
86
|
+
'.dn-divider{height:1px;background:var(--dsw-alias-border-l1)}',
|
|
87
|
+
'.dn-layer{position:fixed;top:16px;right:16px;z-index:9999;display:flex;flex-direction:column;align-items:flex-end;gap:10px;pointer-events:none}',
|
|
88
|
+
'.dn-card{pointer-events:auto;width:320px;max-width:calc(100vw - 32px);border-radius:12px;box-shadow:var(--dsw-shadow-lv3);border:1px solid var(--dsw-alias-border-l2);background:var(--dn-bg,#20272f);color:var(--dn-fg,#e6edf3);overflow:hidden;animation:dn-in .18s ease}',
|
|
89
|
+
'@keyframes dn-in{from{opacity:0;transform:translateX(24px)}to{opacity:1;transform:translateX(0)}}',
|
|
90
|
+
'.dn-card-head{display:flex;align-items:center;justify-content:space-between;gap:8px;padding:10px 12px 6px}',
|
|
91
|
+
'.dn-card-title{font-size:13px;font-weight:600;line-height:20px;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}',
|
|
92
|
+
'.dn-card-kind{flex:none;font-size:11px;line-height:18px;border-radius:999px;padding:0 8px;border:1px solid currentColor;opacity:.85}',
|
|
93
|
+
'.dn-card-body{padding:0 12px 8px;font-size:13px;line-height:20px;word-break:break-word;max-height:120px;overflow:hidden;display:-webkit-box;-webkit-line-clamp:4;-webkit-box-orient:vertical}',
|
|
94
|
+
'.dn-card-actions{display:flex;align-items:center;gap:6px;padding:6px 12px 10px}',
|
|
95
|
+
'.dn-card-btn{font:inherit;font-size:12px;line-height:18px;border-radius:6px;padding:4px 10px;cursor:pointer;border:1px solid rgba(128,128,128,0.35);border:1px solid color-mix(in srgb,currentColor 35%,transparent);background:transparent;background:color-mix(in srgb,currentColor 12%,transparent);color:inherit}',
|
|
96
|
+
'.dn-card-btn:hover{background:rgba(128,128,128,0.12);background:color-mix(in srgb,currentColor 12%,transparent)}',
|
|
97
|
+
'.dn-card-btn.primary{background:rgba(128,128,128,0.18);background:color-mix(in srgb,currentColor 18%,transparent)}',
|
|
98
|
+
'.dn-card-bar{height:2px;background:rgba(128,128,128,0.25);background:color-mix(in srgb,currentColor 25%,transparent);transform-origin:left}',
|
|
99
|
+
'@media (prefers-reduced-motion: reduce){.dn-card{animation:none}}',
|
|
100
|
+
].join('\n')
|
|
101
|
+
|
|
102
|
+
const cssTagId = 'dsh-notify-yimit/client.css'
|
|
103
|
+
if (typeof document !== 'undefined' && document.querySelector('style[data-plugin-css=' + JSON
|
|
104
|
+
.stringify(cssTagId) + ']') === null) {
|
|
105
|
+
const tag = document.createElement('style')
|
|
106
|
+
tag.dataset.plugin = 'dsh-notify-yimit'
|
|
107
|
+
tag.dataset.pluginCss = cssTagId
|
|
108
|
+
tag.textContent = css
|
|
109
|
+
document.head.appendChild(tag)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const NS = 'dsh-notify-yimit'
|
|
113
|
+
|
|
114
|
+
const zh = {
|
|
115
|
+
sectionLabel: '通知',
|
|
116
|
+
enabledLabel: '启用通知插件',
|
|
117
|
+
enabledNote: '关闭后不产生任何通知(设置仍会保存)。',
|
|
118
|
+
modeLabel: '通知方式',
|
|
119
|
+
modeSystem: 'Windows 系统通知',
|
|
120
|
+
modeCustom: '插件自定义样式通知',
|
|
121
|
+
modeOff: '关闭',
|
|
122
|
+
modeNote: '系统通知由浏览器弹出、可在系统通知中心查看;自定义通知为桌面右下角浮窗(不依赖浏览器页面)。',
|
|
123
|
+
browserLabel: '跳转会话浏览器',
|
|
124
|
+
browserDefault: '默认浏览器(系统)',
|
|
125
|
+
browserNote: '「跳转会话」始终打开浏览器并定位到该会话;可选指定浏览器打开(默认=系统默认浏览器)。',
|
|
126
|
+
customTitle: '自定义通知设置',
|
|
127
|
+
colorsTitle: '每种通知的样式',
|
|
128
|
+
colorBg: '背景',
|
|
129
|
+
colorFg: '文字',
|
|
130
|
+
maxVisibleLabel: '同时最多显示数量',
|
|
131
|
+
durationLabel: '通知显示时长(秒)',
|
|
132
|
+
bgColorLabel: '背景颜色',
|
|
133
|
+
textColorLabel: '文字颜色',
|
|
134
|
+
systemTitle: '系统通知',
|
|
135
|
+
permissionGranted: '已获得系统通知权限',
|
|
136
|
+
permissionDenied: '系统通知权限被拒绝,请在浏览器设置中允许本页面通知',
|
|
137
|
+
permissionDefault: '系统通知需要浏览器通知权限',
|
|
138
|
+
requestPermission: '申请通知权限',
|
|
139
|
+
triggerNote: '触发场景:任务完成、任务出错、运行中(实时内容)、等待审批、等待回答。通知标题为对话标题;点击通知或跳转按钮可打开对应会话。',
|
|
140
|
+
toastStyleTitle: '通知窗口样式',
|
|
141
|
+
toastGapLabel: '通知间距(px)',
|
|
142
|
+
enterEdit: '进入编辑模式',
|
|
143
|
+
endEdit: '完成编辑',
|
|
144
|
+
editHint: '拖动样板窗调整位置;拖拽窗口边缘调整宽度;完成后点击「完成编辑」保存。',
|
|
145
|
+
resetPosition: '恢复默认位置',
|
|
146
|
+
saveHint: '所有设置修改后自动保存。',
|
|
147
|
+
saved: '已保存',
|
|
148
|
+
saveFailed: '保存失败:{message}',
|
|
149
|
+
loading: '正在读取配置…',
|
|
150
|
+
rpcFailed: '读取配置失败:{message}',
|
|
151
|
+
kindCompleted: '已完成',
|
|
152
|
+
kindError: '出错',
|
|
153
|
+
kindRunning: '运行中',
|
|
154
|
+
kindApproval: '待审批',
|
|
155
|
+
kindQuestion: '待回答',
|
|
156
|
+
ignore: '忽略',
|
|
157
|
+
jump: '跳转会话',
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const en = {
|
|
161
|
+
sectionLabel: 'Notifications',
|
|
162
|
+
enabledLabel: 'Enable notification plugin',
|
|
163
|
+
enabledNote: 'When disabled, no notifications are produced (settings are still saved).',
|
|
164
|
+
modeLabel: 'Notification style',
|
|
165
|
+
modeSystem: 'Windows system notifications',
|
|
166
|
+
modeCustom: 'Custom in-app notifications',
|
|
167
|
+
modeOff: 'Off',
|
|
168
|
+
modeNote: 'System notifications are shown by the browser and live in the system notification center; custom notifications are desktop toasts at the bottom-right (independent of the browser page).',
|
|
169
|
+
browserLabel: 'Browser for jumping to a session',
|
|
170
|
+
browserDefault: 'Default browser (system)',
|
|
171
|
+
browserNote: '"Jump to session" always opens the browser and navigates to the session; optionally pick a specific browser (default = system default).',
|
|
172
|
+
customTitle: 'Custom notification settings',
|
|
173
|
+
colorsTitle: 'Style per notification type',
|
|
174
|
+
colorBg: 'BG',
|
|
175
|
+
colorFg: 'FG',
|
|
176
|
+
maxVisibleLabel: 'Max simultaneously visible',
|
|
177
|
+
durationLabel: 'Display duration (seconds)',
|
|
178
|
+
bgColorLabel: 'Background color',
|
|
179
|
+
textColorLabel: 'Text color',
|
|
180
|
+
systemTitle: 'System notifications',
|
|
181
|
+
permissionGranted: 'System notification permission granted',
|
|
182
|
+
permissionDenied: 'System notification permission denied — allow notifications for this site in your browser settings',
|
|
183
|
+
permissionDefault: 'System notifications need browser notification permission',
|
|
184
|
+
requestPermission: 'Request permission',
|
|
185
|
+
triggerNote: 'Triggers: task completed, task failed, running (live activity), awaiting approval, awaiting answer. The title is the conversation title; clicking the notification or the jump button opens the session.',
|
|
186
|
+
toastStyleTitle: 'Toast window style',
|
|
187
|
+
toastGapLabel: 'Toast gap (px)',
|
|
188
|
+
enterEdit: 'Enter edit mode',
|
|
189
|
+
endEdit: 'Finish editing',
|
|
190
|
+
editHint: 'Drag the sample window to reposition; drag its edges to resize the width; click "Finish editing" to save.',
|
|
191
|
+
resetPosition: 'Reset to default position',
|
|
192
|
+
saveHint: 'All settings changes are auto-saved.',
|
|
193
|
+
saved: 'Saved',
|
|
194
|
+
saveFailed: 'Save failed: {message}',
|
|
195
|
+
loading: 'Loading config…',
|
|
196
|
+
rpcFailed: 'Failed to load config: {message}',
|
|
197
|
+
kindCompleted: 'Done',
|
|
198
|
+
kindError: 'Failed',
|
|
199
|
+
kindRunning: 'Running',
|
|
200
|
+
kindApproval: 'Approval',
|
|
201
|
+
kindQuestion: 'Question',
|
|
202
|
+
ignore: 'Ignore',
|
|
203
|
+
jump: 'Open',
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// ===== 兼容层:ctx.locale 可用时直接用,不可用时降级为外部 store =====
|
|
207
|
+
let __localeService = null
|
|
208
|
+
let __fallbackUnsub = null
|
|
209
|
+
const __fallbackListeners = new Set()
|
|
210
|
+
let __fallbackLocale = 'en'
|
|
211
|
+
|
|
212
|
+
function detectLocaleId() {
|
|
213
|
+
try {
|
|
214
|
+
if (typeof localStorage !== 'undefined') {
|
|
215
|
+
const sl = localStorage.getItem('dsh-language') || localStorage.getItem('language') ||
|
|
216
|
+
localStorage.getItem('i18nextLng') || localStorage.getItem('locale')
|
|
217
|
+
if (sl) return String(sl).toLowerCase().startsWith('zh') ? 'zh' : 'en'
|
|
218
|
+
}
|
|
219
|
+
} catch {}
|
|
220
|
+
if (typeof document !== 'undefined' && document.documentElement && typeof document
|
|
221
|
+
.documentElement.lang === 'string' && document.documentElement.lang) {
|
|
222
|
+
return document.documentElement.lang.toLowerCase().startsWith('zh') ? 'zh' : 'en'
|
|
223
|
+
}
|
|
224
|
+
const lang = typeof navigator !== 'undefined' && typeof navigator.language === 'string' ?
|
|
225
|
+
navigator.language : ''
|
|
226
|
+
return lang.toLowerCase().startsWith('zh') ? 'zh' : 'en'
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// 外部 store:供 useSyncExternalStore 使用,统一走 ctx.locale 或降级源
|
|
230
|
+
const localeStore = {
|
|
231
|
+
subscribe(cb) {
|
|
232
|
+
if (__localeService && typeof __localeService.subscribe === 'function') {
|
|
233
|
+
return __localeService.subscribe(cb)
|
|
234
|
+
}
|
|
235
|
+
__fallbackListeners.add(cb)
|
|
236
|
+
if (__fallbackUnsub === null) {
|
|
237
|
+
__fallbackLocale = detectLocaleId()
|
|
238
|
+
__fallbackUnsub = setInterval(() => {
|
|
239
|
+
const next = detectLocaleId()
|
|
240
|
+
if (next !== __fallbackLocale) {
|
|
241
|
+
__fallbackLocale = next
|
|
242
|
+
for (const fn of [...__fallbackListeners]) fn()
|
|
243
|
+
}
|
|
244
|
+
}, 500)
|
|
245
|
+
}
|
|
246
|
+
return () => {
|
|
247
|
+
__fallbackListeners.delete(cb)
|
|
248
|
+
if (__fallbackListeners.size === 0 && __fallbackUnsub !== null) {
|
|
249
|
+
clearInterval(__fallbackUnsub);
|
|
250
|
+
__fallbackUnsub = null
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
},
|
|
254
|
+
getSnapshot() {
|
|
255
|
+
if (__localeService && typeof __localeService.getSnapshot === 'function') {
|
|
256
|
+
return __localeService.getSnapshot()
|
|
257
|
+
}
|
|
258
|
+
return {
|
|
259
|
+
active: __fallbackLocale,
|
|
260
|
+
locales: ['zh', 'en'],
|
|
261
|
+
revision: 0
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
function currentLangId() {
|
|
267
|
+
try {
|
|
268
|
+
const snap = localeStore.getSnapshot()
|
|
269
|
+
const active = String(snap?.active ?? snap?.locale ?? snap?.language ?? __fallbackLocale ??
|
|
270
|
+
'en')
|
|
271
|
+
return active.toLowerCase().startsWith('zh') ? 'zh' : 'en'
|
|
272
|
+
} catch {
|
|
273
|
+
return 'en'
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function makeT() {
|
|
278
|
+
const dict = () => currentLangId() === 'zh' ? zh : en
|
|
279
|
+
return (key, vars) => {
|
|
280
|
+
const d = dict()
|
|
281
|
+
let text = d[key] ?? en[key] ?? key
|
|
282
|
+
if (vars)
|
|
283
|
+
for (const name of Object.keys(vars)) text = text.split('{' + name + '}').join(
|
|
284
|
+
String(vars[name]))
|
|
285
|
+
return text
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
function fail(path) {
|
|
290
|
+
throw new Error('dsh-notify-yimit: Invalid server data (' + path + ')')
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function needStr(v, path) {
|
|
294
|
+
if (typeof v !== 'string') fail(path);
|
|
295
|
+
return v
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
function needNum(v, path) {
|
|
299
|
+
if (typeof v !== 'number' || !Number.isFinite(v)) fail(path);
|
|
300
|
+
return v
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function needBool(v, path) {
|
|
304
|
+
if (typeof v !== 'boolean') fail(path);
|
|
305
|
+
return v
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
function parseConfig(v, path) {
|
|
309
|
+
if (v === null || typeof v !== 'object' || Array.isArray(v)) fail(path)
|
|
310
|
+
const kindColors = (key, fallbackBg, fallbackFg) => {
|
|
311
|
+
const entry = v.colors !== null && typeof v.colors === 'object' && !Array.isArray(v
|
|
312
|
+
.colors) ? v.colors[key] : undefined
|
|
313
|
+
return {
|
|
314
|
+
bg: typeof entry?.bg === 'string' ? entry.bg : fallbackBg,
|
|
315
|
+
fg: typeof entry?.fg === 'string' ? entry.fg : fallbackFg,
|
|
316
|
+
enabled: entry?.enabled !== false
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
const topBg = typeof v.bgColor === 'string' ? v.bgColor : '#20272f'
|
|
320
|
+
const topFg = typeof v.textColor === 'string' ? v.textColor : '#e6edf3'
|
|
321
|
+
return {
|
|
322
|
+
enabled: v.enabled === true,
|
|
323
|
+
mode: v.mode === 'system' || v.mode === 'custom' || v.mode === 'off' ? v.mode : 'off',
|
|
324
|
+
maxVisible: typeof v.maxVisible === 'number' ? v.maxVisible : 3,
|
|
325
|
+
durationMs: typeof v.durationMs === 'number' ? v.durationMs : 8000,
|
|
326
|
+
browser: typeof v.browser === 'string' ? v.browser : '',
|
|
327
|
+
bgColor: topBg,
|
|
328
|
+
textColor: topFg,
|
|
329
|
+
locale: v.locale === 'zh' || v.locale === 'en' ? v.locale : 'en',
|
|
330
|
+
toast: {
|
|
331
|
+
width: typeof v.toast?.width === 'number' ? v.toast.width : 340,
|
|
332
|
+
gap: typeof v.toast?.gap === 'number' ? v.toast.gap : 12,
|
|
333
|
+
position: v.toast !== null && typeof v.toast === 'object' && v.toast.position !== null &&
|
|
334
|
+
typeof v.toast.position === 'object' && !Array.isArray(v.toast.position) &&
|
|
335
|
+
typeof v.toast.position.left === 'number' && typeof v.toast.position.top === 'number'
|
|
336
|
+
? { left: v.toast.position.left, top: v.toast.position.top }
|
|
337
|
+
: null,
|
|
338
|
+
},
|
|
339
|
+
colors: {
|
|
340
|
+
completed: kindColors('completed', topBg, topFg),
|
|
341
|
+
error: kindColors('error', topBg, topFg),
|
|
342
|
+
running: kindColors('running', topBg, topFg),
|
|
343
|
+
approval: kindColors('approval', topBg, topFg),
|
|
344
|
+
question: kindColors('question', topBg, topFg),
|
|
345
|
+
},
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
function parseEvent(v, path) {
|
|
350
|
+
if (v === null || typeof v !== 'object' || Array.isArray(v)) fail(path)
|
|
351
|
+
return {
|
|
352
|
+
id: needStr(v.id, path + '.id'),
|
|
353
|
+
sessionId: needStr(v.sessionId, path + '.sessionId'),
|
|
354
|
+
title: typeof v.title === 'string' ? v.title : '',
|
|
355
|
+
kind: v.kind === 'completed' || v.kind === 'error' || v.kind === 'running' || v.kind ===
|
|
356
|
+
'approval' || v.kind === 'question' ? v.kind : 'running',
|
|
357
|
+
text: needStr(v.text, path + '.text'),
|
|
358
|
+
activity: typeof v.activity === 'string' ? v.activity : '',
|
|
359
|
+
at: needNum(v.at, path + '.at'),
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
function parseState(v, path) {
|
|
364
|
+
if (v === null || typeof v !== 'object' || Array.isArray(v)) fail(path)
|
|
365
|
+
return {
|
|
366
|
+
config: parseConfig(v.config, path + '.config'),
|
|
367
|
+
events: Array.isArray(v.events) ? v.events.map((e, i) => parseEvent(e, path + '.events[' +
|
|
368
|
+
i + ']')) : []
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
const codecOf = (parse) => ({
|
|
373
|
+
parse
|
|
374
|
+
})
|
|
375
|
+
const stateCodec = codecOf((v) => parseState(v, 'state'))
|
|
376
|
+
const configCodec = codecOf((v) => parseConfig(v, 'config'))
|
|
377
|
+
const ackCodec = codecOf((v) => {
|
|
378
|
+
if (v === null || typeof v !== 'object') fail('ack');
|
|
379
|
+
return {
|
|
380
|
+
ok: v.ok === true
|
|
381
|
+
}
|
|
382
|
+
})
|
|
383
|
+
const patchCodec = codecOf((v) => {
|
|
384
|
+
if (v === null || typeof v !== 'object' || Array.isArray(v)) fail('patch');
|
|
385
|
+
return v
|
|
386
|
+
})
|
|
387
|
+
const browsersCodec = codecOf((v) => {
|
|
388
|
+
if (v === null || typeof v !== 'object' || !Array.isArray(v.browsers)) fail('browsers')
|
|
389
|
+
return {
|
|
390
|
+
browsers: v.browsers.map((b, i) => ({
|
|
391
|
+
id: typeof b?.id === 'string' ? b.id : String(i),
|
|
392
|
+
name: typeof b?.name === 'string' ? b.name : '',
|
|
393
|
+
path: typeof b?.path === 'string' ? b.path : ''
|
|
394
|
+
}))
|
|
395
|
+
}
|
|
396
|
+
})
|
|
397
|
+
|
|
398
|
+
const CONTRIBUTION = {
|
|
399
|
+
package: 'dsh-notify-yimit',
|
|
400
|
+
descriptors: [{
|
|
401
|
+
id: 'dsh-notify-yimit#notify/getState',
|
|
402
|
+
service: 'notify',
|
|
403
|
+
namespace: 'notify',
|
|
404
|
+
method: 'getState',
|
|
405
|
+
invocation: {
|
|
406
|
+
kind: 'direct'
|
|
407
|
+
},
|
|
408
|
+
parameters: [],
|
|
409
|
+
result: {
|
|
410
|
+
mode: 'strict',
|
|
411
|
+
typeSymbol: 'dsh-notify-yimit#NotifyState',
|
|
412
|
+
schema: stateCodec
|
|
413
|
+
}
|
|
414
|
+
}, {
|
|
415
|
+
id: 'dsh-notify-yimit#notify/updateConfig',
|
|
416
|
+
service: 'notify',
|
|
417
|
+
namespace: 'notify',
|
|
418
|
+
method: 'updateConfig',
|
|
419
|
+
invocation: {
|
|
420
|
+
kind: 'direct'
|
|
421
|
+
},
|
|
422
|
+
parameters: [{
|
|
423
|
+
name: 'patch',
|
|
424
|
+
wire: 'patch',
|
|
425
|
+
source: 'json',
|
|
426
|
+
codec: {
|
|
427
|
+
mode: 'strict',
|
|
428
|
+
typeSymbol: 'dsh-notify-yimit#NotifyConfigPatch',
|
|
429
|
+
schema: patchCodec
|
|
430
|
+
}
|
|
431
|
+
}],
|
|
432
|
+
result: {
|
|
433
|
+
mode: 'strict',
|
|
434
|
+
typeSymbol: 'dsh-notify-yimit#NotifyConfig',
|
|
435
|
+
schema: configCodec
|
|
436
|
+
}
|
|
437
|
+
}, {
|
|
438
|
+
id: 'dsh-notify-yimit#notify/ackEvents',
|
|
439
|
+
service: 'notify',
|
|
440
|
+
namespace: 'notify',
|
|
441
|
+
method: 'ackEvents',
|
|
442
|
+
invocation: {
|
|
443
|
+
kind: 'direct'
|
|
444
|
+
},
|
|
445
|
+
parameters: [{
|
|
446
|
+
name: 'ids',
|
|
447
|
+
wire: 'ids',
|
|
448
|
+
source: 'json',
|
|
449
|
+
codec: {
|
|
450
|
+
mode: 'strict',
|
|
451
|
+
typeSymbol: 'dsh-notify-yimit#EventIds',
|
|
452
|
+
schema: codecOf((v) => Array.isArray(v) ? v.map((x) => String(
|
|
453
|
+
x)) : [])
|
|
454
|
+
}
|
|
455
|
+
}],
|
|
456
|
+
result: {
|
|
457
|
+
mode: 'strict',
|
|
458
|
+
typeSymbol: 'dsh-notify-yimit#AckResult',
|
|
459
|
+
schema: ackCodec
|
|
460
|
+
}
|
|
461
|
+
}, {
|
|
462
|
+
id: 'dsh-notify-yimit#notify/listBrowsers',
|
|
463
|
+
service: 'notify',
|
|
464
|
+
namespace: 'notify',
|
|
465
|
+
method: 'listBrowsers',
|
|
466
|
+
invocation: {
|
|
467
|
+
kind: 'direct'
|
|
468
|
+
},
|
|
469
|
+
parameters: [],
|
|
470
|
+
result: {
|
|
471
|
+
mode: 'strict',
|
|
472
|
+
typeSymbol: 'dsh-notify-yimit#BrowserList',
|
|
473
|
+
schema: browsersCodec
|
|
474
|
+
}
|
|
475
|
+
}, {
|
|
476
|
+
id: 'dsh-notify-yimit#notify/startEditMode',
|
|
477
|
+
service: 'notify',
|
|
478
|
+
namespace: 'notify',
|
|
479
|
+
method: 'startEditMode',
|
|
480
|
+
invocation: {
|
|
481
|
+
kind: 'direct'
|
|
482
|
+
},
|
|
483
|
+
parameters: [],
|
|
484
|
+
result: {
|
|
485
|
+
mode: 'strict',
|
|
486
|
+
typeSymbol: 'dsh-notify-yimit#AckResult',
|
|
487
|
+
schema: ackCodec
|
|
488
|
+
}
|
|
489
|
+
}, {
|
|
490
|
+
id: 'dsh-notify-yimit#notify/endEditMode',
|
|
491
|
+
service: 'notify',
|
|
492
|
+
namespace: 'notify',
|
|
493
|
+
method: 'endEditMode',
|
|
494
|
+
invocation: {
|
|
495
|
+
kind: 'direct'
|
|
496
|
+
},
|
|
497
|
+
parameters: [],
|
|
498
|
+
result: {
|
|
499
|
+
mode: 'strict',
|
|
500
|
+
typeSymbol: 'dsh-notify-yimit#AckResult',
|
|
501
|
+
schema: ackCodec
|
|
502
|
+
}
|
|
503
|
+
}]
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
function makeStore(initial) {
|
|
507
|
+
let snapshot = initial
|
|
508
|
+
const listeners = new Set()
|
|
509
|
+
return {
|
|
510
|
+
getSnapshot: () => snapshot,
|
|
511
|
+
subscribe: (fn) => {
|
|
512
|
+
listeners.add(fn);
|
|
513
|
+
return () => {
|
|
514
|
+
listeners.delete(fn)
|
|
515
|
+
}
|
|
516
|
+
},
|
|
517
|
+
set: (next) => {
|
|
518
|
+
if (next === snapshot) return;
|
|
519
|
+
snapshot = next;
|
|
520
|
+
for (const fn of [...listeners]) fn()
|
|
521
|
+
},
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
function kindLabel(kind, t) {
|
|
526
|
+
switch (kind) {
|
|
527
|
+
case 'completed':
|
|
528
|
+
return t('kindCompleted')
|
|
529
|
+
case 'error':
|
|
530
|
+
return t('kindError')
|
|
531
|
+
case 'approval':
|
|
532
|
+
return t('kindApproval')
|
|
533
|
+
case 'question':
|
|
534
|
+
return t('kindQuestion')
|
|
535
|
+
default:
|
|
536
|
+
return t('kindRunning')
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
function NotifyOverlay(props) {
|
|
541
|
+
const notifyStore = props.useNotify ? props.useNotify((s) => s) : undefined
|
|
542
|
+
const api = props.api
|
|
543
|
+
const sessions = props.sessions
|
|
544
|
+
const seenRef = useRef(new Set())
|
|
545
|
+
const config = notifyStore?.config
|
|
546
|
+
const events = notifyStore?.events
|
|
547
|
+
const openSession = useCallback((sessionId) => {
|
|
548
|
+
try {
|
|
549
|
+
if (typeof sessions?.open === 'function') sessions.open(sessionId)
|
|
550
|
+
} catch {
|
|
551
|
+
/* 静默 */ }
|
|
552
|
+
}, [sessions])
|
|
553
|
+
|
|
554
|
+
useEffect(() => {
|
|
555
|
+
const cleanup = setInterval(() => {
|
|
556
|
+
if (seenRef.current.size > 1000) seenRef.current.clear()
|
|
557
|
+
}, 60000)
|
|
558
|
+
return () => clearInterval(cleanup)
|
|
559
|
+
}, [])
|
|
560
|
+
|
|
561
|
+
useEffect(() => {
|
|
562
|
+
if (!config || !Array.isArray(events)) return
|
|
563
|
+
const fresh = events.filter((e) => !seenRef.current.has(e.id))
|
|
564
|
+
if (fresh.length === 0) return
|
|
565
|
+
for (const e of fresh) seenRef.current.add(e.id)
|
|
566
|
+
|
|
567
|
+
const ack = () => {
|
|
568
|
+
try {
|
|
569
|
+
api?.ackEvents(fresh.map((e) => e.id))
|
|
570
|
+
} catch {
|
|
571
|
+
/* 静默 */ }
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
if (config.enabled !== true || config.mode === 'off') {
|
|
575
|
+
ack();
|
|
576
|
+
return
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
if (config.mode === 'custom') {
|
|
580
|
+
if (typeof Notification === 'undefined' || Notification.permission !==
|
|
581
|
+
'granted') {
|
|
582
|
+
ack();
|
|
583
|
+
return
|
|
584
|
+
}
|
|
585
|
+
} else if (config.mode === 'system') {
|
|
586
|
+
if (typeof Notification === 'undefined' || Notification.permission ===
|
|
587
|
+
'denied') {
|
|
588
|
+
ack();
|
|
589
|
+
return
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
const request = Notification.permission === 'granted' ? Promise.resolve('granted') :
|
|
594
|
+
Notification.requestPermission()
|
|
595
|
+
request.then((permission) => {
|
|
596
|
+
if (permission !== 'granted') {
|
|
597
|
+
ack();
|
|
598
|
+
return
|
|
599
|
+
}
|
|
600
|
+
for (const e of fresh) {
|
|
601
|
+
let n
|
|
602
|
+
try {
|
|
603
|
+
n = new Notification(e.title && e.title.length > 0 ? e.title : e
|
|
604
|
+
.sessionId, {
|
|
605
|
+
body: e.text,
|
|
606
|
+
tag: e.kind === 'running' ?
|
|
607
|
+
`${e.sessionId}:${e.kind}` :
|
|
608
|
+
`${e.sessionId}:${e.kind}:${e.at}`,
|
|
609
|
+
silent: false,
|
|
610
|
+
})
|
|
611
|
+
} catch {
|
|
612
|
+
continue
|
|
613
|
+
}
|
|
614
|
+
n.onclick = () => {
|
|
615
|
+
try {
|
|
616
|
+
window.focus();
|
|
617
|
+
openSession(e.sessionId);
|
|
618
|
+
n.close()
|
|
619
|
+
} catch {
|
|
620
|
+
/* 静默 */ }
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
ack()
|
|
624
|
+
}).catch(() => ack())
|
|
625
|
+
}, [events, config, api, openSession])
|
|
626
|
+
|
|
627
|
+
return null
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
function Segmented(props) {
|
|
631
|
+
const {
|
|
632
|
+
value,
|
|
633
|
+
options,
|
|
634
|
+
onChange,
|
|
635
|
+
disabled
|
|
636
|
+
} = props
|
|
637
|
+
return el('div', {
|
|
638
|
+
className: 'dn-seg',
|
|
639
|
+
role: 'tablist'
|
|
640
|
+
},
|
|
641
|
+
options.map((entry) => el('button', {
|
|
642
|
+
key: entry[0],
|
|
643
|
+
type: 'button',
|
|
644
|
+
role: 'tab',
|
|
645
|
+
'aria-selected': String(value === entry[0]),
|
|
646
|
+
className: 'dn-seg-btn',
|
|
647
|
+
'data-on': String(value === entry[0]),
|
|
648
|
+
disabled: disabled === true,
|
|
649
|
+
onClick: () => {
|
|
650
|
+
if (value !== entry[0]) onChange(entry[0])
|
|
651
|
+
},
|
|
652
|
+
}, entry[1])))
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
/** 跳转浏览器选择器:原生 select 的展开列表无法贴合主题,自绘下拉(触发器 + 弹层)。 */
|
|
656
|
+
function BrowserSelect(props) {
|
|
657
|
+
const {
|
|
658
|
+
value,
|
|
659
|
+
options,
|
|
660
|
+
disabled,
|
|
661
|
+
onChange,
|
|
662
|
+
t
|
|
663
|
+
} = props
|
|
664
|
+
const [open, setOpen] = useState(false)
|
|
665
|
+
const wrapRef = useRef(null)
|
|
666
|
+
// 点击外部 / Esc 关闭弹层。
|
|
667
|
+
useEffect(() => {
|
|
668
|
+
if (!open) return
|
|
669
|
+
const onDown = (e) => {
|
|
670
|
+
if (wrapRef.current !== null && !wrapRef.current.contains(e.target)) setOpen(false)
|
|
671
|
+
}
|
|
672
|
+
const onKey = (e) => {
|
|
673
|
+
if (e.key === 'Escape') setOpen(false)
|
|
674
|
+
}
|
|
675
|
+
document.addEventListener('mousedown', onDown)
|
|
676
|
+
document.addEventListener('keydown', onKey)
|
|
677
|
+
return () => {
|
|
678
|
+
document.removeEventListener('mousedown', onDown)
|
|
679
|
+
document.removeEventListener('keydown', onKey)
|
|
680
|
+
}
|
|
681
|
+
}, [open])
|
|
682
|
+
|
|
683
|
+
const current = options.find((b) => b.path === value)
|
|
684
|
+
const pick = (path) => {
|
|
685
|
+
onChange(path)
|
|
686
|
+
setOpen(false)
|
|
687
|
+
}
|
|
688
|
+
return el('div', {
|
|
689
|
+
className: 'dn-bselect',
|
|
690
|
+
ref: wrapRef
|
|
691
|
+
},
|
|
692
|
+
el('button', {
|
|
693
|
+
type: 'button',
|
|
694
|
+
className: 'dn-bselect-trigger' + (open ? ' open' : ''),
|
|
695
|
+
disabled: disabled === true,
|
|
696
|
+
'aria-haspopup': 'listbox',
|
|
697
|
+
'aria-expanded': String(open),
|
|
698
|
+
onClick: () => {
|
|
699
|
+
if (disabled !== true) setOpen(!open)
|
|
700
|
+
},
|
|
701
|
+
},
|
|
702
|
+
el('span', {
|
|
703
|
+
className: 'dn-bselect-value'
|
|
704
|
+
}, current !== undefined ? current.name : t('browserDefault')),
|
|
705
|
+
el('span', {
|
|
706
|
+
className: 'dn-bselect-arrow'
|
|
707
|
+
}, open ? '▴' : '▾')),
|
|
708
|
+
open ? el('div', {
|
|
709
|
+
className: 'dn-bselect-pop',
|
|
710
|
+
role: 'listbox'
|
|
711
|
+
},
|
|
712
|
+
el('button', {
|
|
713
|
+
type: 'button',
|
|
714
|
+
role: 'option',
|
|
715
|
+
'aria-selected': String(value === ''),
|
|
716
|
+
className: 'dn-bselect-opt' + (value === '' ? ' sel' : ''),
|
|
717
|
+
onClick: () => pick(''),
|
|
718
|
+
}, t('browserDefault')),
|
|
719
|
+
options.map((b) => el('button', {
|
|
720
|
+
type: 'button',
|
|
721
|
+
role: 'option',
|
|
722
|
+
key: b.id,
|
|
723
|
+
'aria-selected': String(value === b.path),
|
|
724
|
+
className: 'dn-bselect-opt' + (value === b.path ? ' sel' : ''),
|
|
725
|
+
onClick: () => pick(b.path),
|
|
726
|
+
}, b.name)))
|
|
727
|
+
: null)
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
const KIND_ORDER = ['completed', 'error', 'running', 'approval', 'question']
|
|
731
|
+
|
|
732
|
+
function NotifySection(props) {
|
|
733
|
+
const notifyStore = props.useNotify ? props.useNotify((s) => s) : undefined
|
|
734
|
+
const api = props.api
|
|
735
|
+
// 关键:订阅 locale 变化,语言切换时本组件立即重渲染
|
|
736
|
+
useSyncExternalStore(localeStore.subscribe, localeStore.getSnapshot)
|
|
737
|
+
const t = makeT()
|
|
738
|
+
const state = notifyStore
|
|
739
|
+
const config = state?.config
|
|
740
|
+
const [msg, setMsg] = useState(null)
|
|
741
|
+
const [saving, setSaving] = useState(false)
|
|
742
|
+
const [permission, setPermission] = useState(typeof Notification !== 'undefined' ? Notification
|
|
743
|
+
.permission : 'unsupported')
|
|
744
|
+
// 通知窗口编辑模式(样板窗拖拽/缩放)
|
|
745
|
+
const [editing, setEditing] = useState(false)
|
|
746
|
+
// 最新值镜像:卸载清理时读取(避免空依赖闭包拿到陈旧值)。
|
|
747
|
+
const editingRef = useRef(false)
|
|
748
|
+
editingRef.current = editing
|
|
749
|
+
useEffect(() => () => {
|
|
750
|
+
// 离开通知设置页(组件卸载)时若仍在编辑模式,自动关闭样板窗。
|
|
751
|
+
if (editingRef.current) void api.endEditMode()
|
|
752
|
+
}, [])
|
|
753
|
+
|
|
754
|
+
const saveTimerRef = useRef(null)
|
|
755
|
+
const save = useCallback((patch) => {
|
|
756
|
+
if (saveTimerRef.current) clearTimeout(saveTimerRef.current)
|
|
757
|
+
saveTimerRef.current = setTimeout(async () => {
|
|
758
|
+
if (!api?.updateConfig) return
|
|
759
|
+
setSaving(true);
|
|
760
|
+
setMsg(null)
|
|
761
|
+
try {
|
|
762
|
+
await api.updateConfig(patch)
|
|
763
|
+
setMsg({
|
|
764
|
+
kind: 'ok',
|
|
765
|
+
text: t('saved')
|
|
766
|
+
})
|
|
767
|
+
} catch (error) {
|
|
768
|
+
setMsg({
|
|
769
|
+
kind: 'err',
|
|
770
|
+
text: t('saveFailed', {
|
|
771
|
+
message: error?.message ?? String(error)
|
|
772
|
+
})
|
|
773
|
+
})
|
|
774
|
+
} finally {
|
|
775
|
+
setSaving(false)
|
|
776
|
+
}
|
|
777
|
+
}, 300)
|
|
778
|
+
}, [api, t])
|
|
779
|
+
|
|
780
|
+
const requestPerm = useCallback(async () => {
|
|
781
|
+
if (typeof Notification === 'undefined' || Notification.permission ===
|
|
782
|
+
'granted') {
|
|
783
|
+
setPermission(typeof Notification !== 'undefined' ? Notification
|
|
784
|
+
.permission : 'unsupported')
|
|
785
|
+
return
|
|
786
|
+
}
|
|
787
|
+
try {
|
|
788
|
+
const result = await Notification.requestPermission();
|
|
789
|
+
setPermission(result)
|
|
790
|
+
} catch {
|
|
791
|
+
setPermission('denied')
|
|
792
|
+
}
|
|
793
|
+
}, [])
|
|
794
|
+
|
|
795
|
+
if (!config) return el('div', {
|
|
796
|
+
className: 'dn-root'
|
|
797
|
+
}, el('div', {
|
|
798
|
+
className: 'dn-note'
|
|
799
|
+
}, t('loading')))
|
|
800
|
+
|
|
801
|
+
const controlsDisabled = !config.enabled
|
|
802
|
+
|
|
803
|
+
const kindRows = KIND_ORDER.map((kind) => {
|
|
804
|
+
const entry = config.colors?. [kind] ?? {}
|
|
805
|
+
const bg = entry.bg || config.bgColor || '#20272f'
|
|
806
|
+
const fg = entry.fg || config.textColor || '#e6edf3'
|
|
807
|
+
const enabled = entry.enabled !== false
|
|
808
|
+
return el('div', {
|
|
809
|
+
key: kind,
|
|
810
|
+
className: 'dn-kind-row'
|
|
811
|
+
},
|
|
812
|
+
// 样式预览:类型文字显示在配置色的纯色块内(内联样式,不受深色模式影响)
|
|
813
|
+
el('span', {
|
|
814
|
+
className: 'dn-kind-preview',
|
|
815
|
+
style: {
|
|
816
|
+
background: bg,
|
|
817
|
+
color: fg
|
|
818
|
+
}
|
|
819
|
+
}, kindLabel(kind, t)),
|
|
820
|
+
el('label', {
|
|
821
|
+
className: 'dn-kind-field'
|
|
822
|
+
},
|
|
823
|
+
el('input', {
|
|
824
|
+
type: 'color',
|
|
825
|
+
className: 'dn-input',
|
|
826
|
+
title: t('colorBg'),
|
|
827
|
+
value: /^#[0-9a-fA-F]{6}$/.test(bg) ? bg : '#20272f',
|
|
828
|
+
disabled: controlsDisabled,
|
|
829
|
+
onChange: (e) => save({
|
|
830
|
+
colors: {
|
|
831
|
+
[kind]: {
|
|
832
|
+
...entry,
|
|
833
|
+
bg: e.target.value
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
})
|
|
837
|
+
}), t('colorBg')),
|
|
838
|
+
el('label', {
|
|
839
|
+
className: 'dn-kind-field'
|
|
840
|
+
},
|
|
841
|
+
el('input', {
|
|
842
|
+
type: 'color',
|
|
843
|
+
className: 'dn-input',
|
|
844
|
+
title: t('colorFg'),
|
|
845
|
+
value: /^#[0-9a-fA-F]{6}$/.test(fg) ? fg : '#e6edf3',
|
|
846
|
+
disabled: controlsDisabled,
|
|
847
|
+
onChange: (e) => save({
|
|
848
|
+
colors: {
|
|
849
|
+
[kind]: {
|
|
850
|
+
...entry,
|
|
851
|
+
fg: e.target.value
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
})
|
|
855
|
+
}), t('colorFg')),
|
|
856
|
+
// 每类型开关:控制该类型通知是否产生(默认全开)
|
|
857
|
+
el('label', {
|
|
858
|
+
className: 'dn-kind-field'
|
|
859
|
+
},
|
|
860
|
+
el('button', {
|
|
861
|
+
type: 'button',
|
|
862
|
+
role: 'switch',
|
|
863
|
+
'aria-checked': enabled,
|
|
864
|
+
'aria-label': kindLabel(kind, t),
|
|
865
|
+
className: 'dn-switch',
|
|
866
|
+
'data-on': String(enabled),
|
|
867
|
+
disabled: controlsDisabled,
|
|
868
|
+
onClick: () => save({
|
|
869
|
+
colors: {
|
|
870
|
+
[kind]: {
|
|
871
|
+
...entry,
|
|
872
|
+
enabled: !enabled
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
})
|
|
876
|
+
})))
|
|
877
|
+
})
|
|
878
|
+
|
|
879
|
+
const customOpen = config.mode === 'custom'
|
|
880
|
+
|
|
881
|
+
return el('div', {
|
|
882
|
+
className: 'dn-root'
|
|
883
|
+
},
|
|
884
|
+
el('div', {
|
|
885
|
+
className: 'dn-block'
|
|
886
|
+
},
|
|
887
|
+
el('div', {
|
|
888
|
+
className: 'dn-row'
|
|
889
|
+
},
|
|
890
|
+
el('button', {
|
|
891
|
+
type: 'button',
|
|
892
|
+
role: 'switch',
|
|
893
|
+
'aria-checked': config.enabled,
|
|
894
|
+
className: 'dn-switch',
|
|
895
|
+
'data-on': String(config.enabled),
|
|
896
|
+
onClick: () => save({
|
|
897
|
+
enabled: !config.enabled
|
|
898
|
+
})
|
|
899
|
+
}),
|
|
900
|
+
el('span', {
|
|
901
|
+
className: 'dn-label'
|
|
902
|
+
}, t('enabledLabel'))),
|
|
903
|
+
el('p', {
|
|
904
|
+
className: 'dn-note'
|
|
905
|
+
}, t('enabledNote'))),
|
|
906
|
+
el('div', {
|
|
907
|
+
className: 'dn-divider'
|
|
908
|
+
}),
|
|
909
|
+
el('div', {
|
|
910
|
+
className: 'dn-block'
|
|
911
|
+
},
|
|
912
|
+
el('p', {
|
|
913
|
+
className: 'dn-title'
|
|
914
|
+
}, t('modeLabel')),
|
|
915
|
+
el(Segmented, {
|
|
916
|
+
value: config.mode,
|
|
917
|
+
disabled: controlsDisabled,
|
|
918
|
+
onChange: (mode) => save({
|
|
919
|
+
mode
|
|
920
|
+
}),
|
|
921
|
+
options: [
|
|
922
|
+
['system', t('modeSystem')],
|
|
923
|
+
['custom', t('modeCustom')],
|
|
924
|
+
['off', t('modeOff')]
|
|
925
|
+
]
|
|
926
|
+
}),
|
|
927
|
+
el('p', {
|
|
928
|
+
className: 'dn-note'
|
|
929
|
+
}, t('modeNote'))),
|
|
930
|
+
(config.mode === 'system' || config.mode === 'custom') ? el('div', {
|
|
931
|
+
className: 'dn-block'
|
|
932
|
+
},
|
|
933
|
+
el('div', {
|
|
934
|
+
className: 'dn-row'
|
|
935
|
+
},
|
|
936
|
+
el('span', {
|
|
937
|
+
className: 'dn-label'
|
|
938
|
+
}, t('browserLabel')),
|
|
939
|
+
el(BrowserSelect, {
|
|
940
|
+
value: config.browser || '',
|
|
941
|
+
options: state?.browsers ?? [],
|
|
942
|
+
disabled: controlsDisabled,
|
|
943
|
+
onChange: (path) => save({
|
|
944
|
+
browser: path
|
|
945
|
+
}),
|
|
946
|
+
t
|
|
947
|
+
})),
|
|
948
|
+
el('p', {
|
|
949
|
+
className: 'dn-note'
|
|
950
|
+
}, t('browserNote'))
|
|
951
|
+
) : null,
|
|
952
|
+
el('div', {
|
|
953
|
+
className: 'dn-divider'
|
|
954
|
+
}),
|
|
955
|
+
config.mode === 'system' ? el('div', {
|
|
956
|
+
className: 'dn-block'
|
|
957
|
+
},
|
|
958
|
+
el('p', {
|
|
959
|
+
className: 'dn-title'
|
|
960
|
+
}, t('systemTitle')),
|
|
961
|
+
permission === 'granted' ? el('div', {
|
|
962
|
+
className: 'dn-msg ok'
|
|
963
|
+
}, t('permissionGranted')) :
|
|
964
|
+
permission === 'denied' ? el('div', {
|
|
965
|
+
className: 'dn-msg err'
|
|
966
|
+
}, t('permissionDenied')) :
|
|
967
|
+
el(Fragment, null,
|
|
968
|
+
el('p', {
|
|
969
|
+
className: 'dn-note'
|
|
970
|
+
}, t('permissionDefault')),
|
|
971
|
+
el('button', {
|
|
972
|
+
className: 'dn-btn primary',
|
|
973
|
+
disabled: controlsDisabled,
|
|
974
|
+
onClick: requestPerm
|
|
975
|
+
}, t('requestPermission')))
|
|
976
|
+
) : null,
|
|
977
|
+
el('div', {
|
|
978
|
+
className: 'dn-collapse',
|
|
979
|
+
'data-open': String(customOpen)
|
|
980
|
+
},
|
|
981
|
+
el('div', {
|
|
982
|
+
className: 'dn-collapse-body'
|
|
983
|
+
},
|
|
984
|
+
el('div', {
|
|
985
|
+
className: 'dn-block'
|
|
986
|
+
},
|
|
987
|
+
el('p', {
|
|
988
|
+
className: 'dn-title'
|
|
989
|
+
}, t('customTitle')),
|
|
990
|
+
el('div', {
|
|
991
|
+
className: 'dn-row'
|
|
992
|
+
},
|
|
993
|
+
el('span', {
|
|
994
|
+
className: 'dn-label'
|
|
995
|
+
}, t('maxVisibleLabel')),
|
|
996
|
+
el('input', {
|
|
997
|
+
type: 'number',
|
|
998
|
+
min: 1,
|
|
999
|
+
max: 20,
|
|
1000
|
+
className: 'dn-input',
|
|
1001
|
+
value: config.maxVisible,
|
|
1002
|
+
disabled: controlsDisabled,
|
|
1003
|
+
onChange: (e) => {
|
|
1004
|
+
const n = Math.max(1, Math.min(20, Math.floor(Number(e
|
|
1005
|
+
.target.value) || 1)))
|
|
1006
|
+
save({
|
|
1007
|
+
maxVisible: n
|
|
1008
|
+
})
|
|
1009
|
+
}
|
|
1010
|
+
})),
|
|
1011
|
+
el('div', {
|
|
1012
|
+
className: 'dn-row'
|
|
1013
|
+
},
|
|
1014
|
+
el('span', {
|
|
1015
|
+
className: 'dn-label'
|
|
1016
|
+
}, t('durationLabel')),
|
|
1017
|
+
el('input', {
|
|
1018
|
+
type: 'number',
|
|
1019
|
+
min: 1,
|
|
1020
|
+
max: 300,
|
|
1021
|
+
className: 'dn-input',
|
|
1022
|
+
value: Math.round(config.durationMs / 1000),
|
|
1023
|
+
disabled: controlsDisabled,
|
|
1024
|
+
onChange: (e) => {
|
|
1025
|
+
const s = Math.max(1, Math.min(300, Math.floor(Number(e
|
|
1026
|
+
.target.value) || 1)))
|
|
1027
|
+
save({
|
|
1028
|
+
durationMs: s * 1000
|
|
1029
|
+
})
|
|
1030
|
+
}
|
|
1031
|
+
})),
|
|
1032
|
+
el('p', {
|
|
1033
|
+
className: 'dn-title'
|
|
1034
|
+
}, t('colorsTitle')),
|
|
1035
|
+
el('div', {
|
|
1036
|
+
className: 'dn-kind-list'
|
|
1037
|
+
}, kindRows),
|
|
1038
|
+
el('div', {
|
|
1039
|
+
className: 'dn-divider'
|
|
1040
|
+
}),
|
|
1041
|
+
el('p', {
|
|
1042
|
+
className: 'dn-title'
|
|
1043
|
+
}, t('toastStyleTitle')),
|
|
1044
|
+
el('div', {
|
|
1045
|
+
className: 'dn-row'
|
|
1046
|
+
},
|
|
1047
|
+
el('span', {
|
|
1048
|
+
className: 'dn-label'
|
|
1049
|
+
}, t('toastGapLabel')),
|
|
1050
|
+
el('input', {
|
|
1051
|
+
type: 'number',
|
|
1052
|
+
min: 0,
|
|
1053
|
+
max: 60,
|
|
1054
|
+
className: 'dn-input',
|
|
1055
|
+
value: config.toast?.gap ?? 12,
|
|
1056
|
+
disabled: controlsDisabled,
|
|
1057
|
+
onChange: (e) => {
|
|
1058
|
+
const g = Math.max(0, Math.min(60, Math.floor(Number(e
|
|
1059
|
+
.target.value) || 0)))
|
|
1060
|
+
save({
|
|
1061
|
+
toast: {
|
|
1062
|
+
...(config.toast ?? {}),
|
|
1063
|
+
gap: g
|
|
1064
|
+
}
|
|
1065
|
+
})
|
|
1066
|
+
}
|
|
1067
|
+
})),
|
|
1068
|
+
el('div', {
|
|
1069
|
+
className: 'dn-row'
|
|
1070
|
+
},
|
|
1071
|
+
el('button', {
|
|
1072
|
+
className: 'dn-btn primary',
|
|
1073
|
+
disabled: controlsDisabled,
|
|
1074
|
+
onClick: () => {
|
|
1075
|
+
if (editing) {
|
|
1076
|
+
void api.endEditMode()
|
|
1077
|
+
setEditing(false)
|
|
1078
|
+
} else {
|
|
1079
|
+
setEditing(true)
|
|
1080
|
+
void api.startEditMode()
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
}, editing ? t('endEdit') : t('enterEdit')),
|
|
1084
|
+
el('button', {
|
|
1085
|
+
className: 'dn-btn',
|
|
1086
|
+
disabled: controlsDisabled || !config.toast?.position,
|
|
1087
|
+
onClick: () => {
|
|
1088
|
+
save({
|
|
1089
|
+
toast: {
|
|
1090
|
+
...(config.toast ?? {}),
|
|
1091
|
+
position: null
|
|
1092
|
+
}
|
|
1093
|
+
})
|
|
1094
|
+
// 编辑模式下:重开样板窗,让其在默认位置(右下)刷新显示。
|
|
1095
|
+
if (editing) void api.startEditMode()
|
|
1096
|
+
}
|
|
1097
|
+
}, t('resetPosition'))),
|
|
1098
|
+
el('p', {
|
|
1099
|
+
className: 'dn-note'
|
|
1100
|
+
}, t('editHint')))
|
|
1101
|
+
)),
|
|
1102
|
+
el('div', {
|
|
1103
|
+
className: 'dn-divider'
|
|
1104
|
+
}),
|
|
1105
|
+
el('p', {
|
|
1106
|
+
className: 'dn-note'
|
|
1107
|
+
}, t('triggerNote')),
|
|
1108
|
+
el('p', {
|
|
1109
|
+
className: 'dn-note'
|
|
1110
|
+
}, t('saveHint')),
|
|
1111
|
+
msg !== null ? el('div', {
|
|
1112
|
+
className: 'dn-msg ' + msg.kind
|
|
1113
|
+
}, msg.text) : null,
|
|
1114
|
+
saving ? el('div', {
|
|
1115
|
+
className: 'dn-note'
|
|
1116
|
+
}, '…') : null,
|
|
1117
|
+
)
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
// ===== 修改点:inject 数组改为 ['remote', 'locale'] =====
|
|
1121
|
+
const inject = ['remote', 'locale']
|
|
1122
|
+
|
|
1123
|
+
async function apply(ctx) {
|
|
1124
|
+
const remote = ctx.remote
|
|
1125
|
+
if (remote === undefined || typeof remote.$mount !== 'function') return
|
|
1126
|
+
const unmount = await remote.$mount(CONTRIBUTION)
|
|
1127
|
+
ctx.effect(() => () => {
|
|
1128
|
+
unmount()
|
|
1129
|
+
}, 'dsh-notify-yimit: remote contribution')
|
|
1130
|
+
|
|
1131
|
+
const notify = ctx.get('remote.notify')
|
|
1132
|
+
if (notify === undefined) return
|
|
1133
|
+
|
|
1134
|
+
const store = makeStore({
|
|
1135
|
+
config: null,
|
|
1136
|
+
events: [],
|
|
1137
|
+
browsers: []
|
|
1138
|
+
})
|
|
1139
|
+
|
|
1140
|
+
// 定义 loadBrowsers 和 reload(不依赖 api)
|
|
1141
|
+
const loadBrowsers = async () => {
|
|
1142
|
+
try {
|
|
1143
|
+
const result = await notify.listBrowsers()
|
|
1144
|
+
if (result !== null && typeof result === 'object' && result.ok === true) {
|
|
1145
|
+
const parsed = browsersCodec.parse(result.value)
|
|
1146
|
+
const state = store.getSnapshot()
|
|
1147
|
+
store.set({
|
|
1148
|
+
config: state.config,
|
|
1149
|
+
events: state.events,
|
|
1150
|
+
browsers: parsed.browsers
|
|
1151
|
+
})
|
|
1152
|
+
}
|
|
1153
|
+
} catch {
|
|
1154
|
+
/* 探测失败 */ }
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1157
|
+
let reloading = false
|
|
1158
|
+
const reload = async () => {
|
|
1159
|
+
if (reloading) return
|
|
1160
|
+
reloading = true
|
|
1161
|
+
try {
|
|
1162
|
+
const result = await notify.getState()
|
|
1163
|
+
if (result !== null && typeof result === 'object' && result.ok === true) {
|
|
1164
|
+
const prev = store.getSnapshot()
|
|
1165
|
+
store.set({
|
|
1166
|
+
...parseState(result.value, 'state'),
|
|
1167
|
+
browsers: prev.browsers
|
|
1168
|
+
})
|
|
1169
|
+
}
|
|
1170
|
+
} catch {
|
|
1171
|
+
/* 传输失败 */ } finally {
|
|
1172
|
+
reloading = false
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1176
|
+
// ===== 先定义 api(包含 updateConfig),供后续语言同步使用 =====
|
|
1177
|
+
const api = {
|
|
1178
|
+
reload,
|
|
1179
|
+
updateConfig: async (patch) => {
|
|
1180
|
+
const result = await notify.updateConfig(patch)
|
|
1181
|
+
if (result !== null && typeof result === 'object' && result.ok === true) {
|
|
1182
|
+
const state = store.getSnapshot()
|
|
1183
|
+
store.set({
|
|
1184
|
+
config: parseConfig(result.value, 'config'),
|
|
1185
|
+
events: state.events,
|
|
1186
|
+
browsers: state.browsers
|
|
1187
|
+
})
|
|
1188
|
+
}
|
|
1189
|
+
return result?.value
|
|
1190
|
+
},
|
|
1191
|
+
ackEvents: async (ids) => {
|
|
1192
|
+
try {
|
|
1193
|
+
await notify.ackEvents(ids)
|
|
1194
|
+
} catch {
|
|
1195
|
+
/* 静默 */ }
|
|
1196
|
+
},
|
|
1197
|
+
startEditMode: async () => {
|
|
1198
|
+
try {
|
|
1199
|
+
await notify.startEditMode()
|
|
1200
|
+
} catch {
|
|
1201
|
+
/* 静默 */ }
|
|
1202
|
+
},
|
|
1203
|
+
endEditMode: async () => {
|
|
1204
|
+
try {
|
|
1205
|
+
await notify.endEditMode()
|
|
1206
|
+
} catch {
|
|
1207
|
+
/* 静默 */ }
|
|
1208
|
+
},
|
|
1209
|
+
}
|
|
1210
|
+
|
|
1211
|
+
// ===== 现在设置 __localeService 并使用 api =====
|
|
1212
|
+
__localeService = ctx.locale
|
|
1213
|
+
|
|
1214
|
+
if (__localeService && typeof __localeService.register === 'function') {
|
|
1215
|
+
ctx.effect(() => __localeService.register(NS, {
|
|
1216
|
+
zh,
|
|
1217
|
+
en
|
|
1218
|
+
}), 'dsh-notify-yimit: dictionaries')
|
|
1219
|
+
}
|
|
1220
|
+
|
|
1221
|
+
if (__localeService && typeof __localeService.subscribe === 'function') {
|
|
1222
|
+
const syncToHost = () => {
|
|
1223
|
+
const newLang = currentLangId()
|
|
1224
|
+
if (api && typeof api.updateConfig === 'function') {
|
|
1225
|
+
void api.updateConfig({
|
|
1226
|
+
locale: newLang
|
|
1227
|
+
})
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
const unsub = __localeService.subscribe(syncToHost)
|
|
1231
|
+
ctx.effect(() => unsub, 'dsh-notify-yimit: locale sync')
|
|
1232
|
+
void syncToHost()
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1235
|
+
// 初始加载配置和浏览器列表
|
|
1236
|
+
void reload()
|
|
1237
|
+
void loadBrowsers()
|
|
1238
|
+
|
|
1239
|
+
ctx.effect(() => ctx.on('connection/reset', () => {
|
|
1240
|
+
void reload();
|
|
1241
|
+
void loadBrowsers()
|
|
1242
|
+
}), 'dsh-notify-yimit: reconnect reload')
|
|
1243
|
+
|
|
1244
|
+
const pollTimer = setInterval(() => {
|
|
1245
|
+
if (document.visibilityState === 'hidden') return
|
|
1246
|
+
void reload()
|
|
1247
|
+
}, 250)
|
|
1248
|
+
ctx.effect(() => () => {
|
|
1249
|
+
clearInterval(pollTimer)
|
|
1250
|
+
}, 'dsh-notify-yimit: poll timer')
|
|
1251
|
+
|
|
1252
|
+
const onVisible = () => {
|
|
1253
|
+
if (document.visibilityState === 'visible') void reload()
|
|
1254
|
+
}
|
|
1255
|
+
document.addEventListener('visibilitychange', onVisible)
|
|
1256
|
+
ctx.effect(() => () => {
|
|
1257
|
+
document.removeEventListener('visibilitychange', onVisible)
|
|
1258
|
+
}, 'dsh-notify-yimit: visibility reload')
|
|
1259
|
+
|
|
1260
|
+
const sessions = ctx.get('sessions')
|
|
1261
|
+
const slots = ctx.get('slots')
|
|
1262
|
+
if (slots === undefined) return
|
|
1263
|
+
|
|
1264
|
+
const openFromHash = () => {
|
|
1265
|
+
try {
|
|
1266
|
+
const m = /#dsh-notify-yimit\/session=([^&]+)/.exec(window.location.hash)
|
|
1267
|
+
if (m !== null && typeof sessions?.open === 'function') {
|
|
1268
|
+
sessions.open(decodeURIComponent(m[1]))
|
|
1269
|
+
const clean = window.location.href.split('#')[0]
|
|
1270
|
+
window.history.replaceState(null, '', clean)
|
|
1271
|
+
}
|
|
1272
|
+
} catch {
|
|
1273
|
+
/* 静默 */ }
|
|
1274
|
+
}
|
|
1275
|
+
window.addEventListener('hashchange', openFromHash)
|
|
1276
|
+
openFromHash()
|
|
1277
|
+
ctx.effect(() => () => window.removeEventListener('hashchange', openFromHash),
|
|
1278
|
+
'dsh-notify-yimit: hash listener')
|
|
1279
|
+
|
|
1280
|
+
const injected = () => ({
|
|
1281
|
+
hooks: {
|
|
1282
|
+
notify: store
|
|
1283
|
+
},
|
|
1284
|
+
api,
|
|
1285
|
+
sessions
|
|
1286
|
+
})
|
|
1287
|
+
const sectionInjected = () => ({
|
|
1288
|
+
hooks: {
|
|
1289
|
+
notify: store
|
|
1290
|
+
},
|
|
1291
|
+
api
|
|
1292
|
+
})
|
|
1293
|
+
|
|
1294
|
+
const sectionActive = {
|
|
1295
|
+
gen: 0,
|
|
1296
|
+
dispose: null
|
|
1297
|
+
}
|
|
1298
|
+
const registerSection = () => {
|
|
1299
|
+
if (sectionActive.dispose !== null) {
|
|
1300
|
+
sectionActive.dispose();
|
|
1301
|
+
sectionActive.dispose = null
|
|
1302
|
+
}
|
|
1303
|
+
sectionActive.gen += 1
|
|
1304
|
+
const gen = sectionActive.gen
|
|
1305
|
+
slots.inject('settings.section', () => {
|
|
1306
|
+
if (sectionActive.gen !== gen) return
|
|
1307
|
+
const dispose = slots.register({
|
|
1308
|
+
name: 'settings.section',
|
|
1309
|
+
id: 'dsh-notify-yimit',
|
|
1310
|
+
order: 60,
|
|
1311
|
+
label: () => makeT()('sectionLabel'),
|
|
1312
|
+
locale: NS,
|
|
1313
|
+
inject: sectionInjected
|
|
1314
|
+
}, NotifySection)
|
|
1315
|
+
if (sectionActive.gen !== gen) {
|
|
1316
|
+
dispose();
|
|
1317
|
+
return
|
|
1318
|
+
}
|
|
1319
|
+
sectionActive.dispose = dispose
|
|
1320
|
+
return () => {
|
|
1321
|
+
if (sectionActive.dispose === dispose) sectionActive.dispose =
|
|
1322
|
+
null
|
|
1323
|
+
dispose()
|
|
1324
|
+
}
|
|
1325
|
+
})
|
|
1326
|
+
}
|
|
1327
|
+
registerSection()
|
|
1328
|
+
|
|
1329
|
+
const overlayActive = {
|
|
1330
|
+
gen: 0,
|
|
1331
|
+
dispose: null
|
|
1332
|
+
}
|
|
1333
|
+
const registerOverlay = () => {
|
|
1334
|
+
if (overlayActive.dispose !== null) {
|
|
1335
|
+
overlayActive.dispose();
|
|
1336
|
+
overlayActive.dispose = null
|
|
1337
|
+
}
|
|
1338
|
+
overlayActive.gen += 1
|
|
1339
|
+
const gen = overlayActive.gen
|
|
1340
|
+
slots.inject('shell.overlay', () => {
|
|
1341
|
+
if (overlayActive.gen !== gen) return
|
|
1342
|
+
const dispose = slots.register({
|
|
1343
|
+
name: 'shell.overlay',
|
|
1344
|
+
id: 'dsh-notify-yimit',
|
|
1345
|
+
order: 10,
|
|
1346
|
+
inject: injected
|
|
1347
|
+
}, NotifyOverlay)
|
|
1348
|
+
if (overlayActive.gen !== gen) {
|
|
1349
|
+
dispose();
|
|
1350
|
+
return
|
|
1351
|
+
}
|
|
1352
|
+
overlayActive.dispose = dispose
|
|
1353
|
+
return () => {
|
|
1354
|
+
if (overlayActive.dispose === dispose) overlayActive.dispose =
|
|
1355
|
+
null
|
|
1356
|
+
dispose()
|
|
1357
|
+
}
|
|
1358
|
+
})
|
|
1359
|
+
}
|
|
1360
|
+
registerOverlay()
|
|
1361
|
+
|
|
1362
|
+
return () => {}
|
|
1363
|
+
}
|
|
1364
|
+
|
|
1365
|
+
exports.apply = apply
|
|
1366
|
+
exports.inject = inject
|
|
1367
|
+
return module.exports
|
|
1368
|
+
},
|
|
1369
|
+
})
|