dsh-notify-tray 0.1.7 → 0.1.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/lib/client.js CHANGED
@@ -42,15 +42,14 @@ window.__ModuleLoader__.load({
42
42
  return true
43
43
  }
44
44
 
45
- // slots / locale / configForms carry the settings page; the poller only needs the first two.
45
+ // Settings mount independently once the layout and host namespace are ready.
46
46
  var inject = ['uiWorkspace', 'sessions', 'slots', 'locale', 'configForms']
47
47
 
48
48
  // ------------------------------------------------------------------------
49
- // Settings page: the plugin's own page inside DSH's Plugins screen, in the
50
- // same frame the official "子智能体 / Agent 循环" pages use — a SettingsForm
49
+ // Settings page: a sidebar entry opens a main panel containing a SettingsForm
51
50
  // over the `notify-tray` settings namespace (the `.volatile()` fields of
52
51
  // lib/index.js Config, served by @deepseek-ai/dsh-settings), grouped into
53
- // sections with toggles, segmented choices and number fields, one Save.
52
+ // sections with toggles, segmented choices and number fields, saved automatically.
54
53
  // Plain React.createElement, so no build step is needed.
55
54
  // ------------------------------------------------------------------------
56
55
  function mountSettingsPage(ctx, require) {
@@ -62,8 +61,8 @@ window.__ModuleLoader__.load({
62
61
  const NS = 'notify-tray'
63
62
  /** Dictionary namespace owned by this page. */
64
63
  const LOCALE_NS = 'notify-tray.settings'
65
- /** The package page (`plugins.bundle.config` is keyed by package name). */
66
- const PACKAGE_KEY = 'dsh-notify-tray'
64
+ /** The sidebar id and main slot key must match for layout navigation. */
65
+ const PANEL_ID = 'notify-tray'
67
66
  const CATALOG_ROUTE = 'notify-tray/catalog'
68
67
  const REFRESH_ROUTE = 'notify-tray/refresh'
69
68
  const TRAY_ROUTE = 'notify-tray/tray'
@@ -106,6 +105,33 @@ window.__ModuleLoader__.load({
106
105
  }
107
106
 
108
107
  const zh = {
108
+ title: '小鲸鱼通知站',
109
+ autoSave: '自动保存已开启',
110
+ saved: '设置已保存',
111
+ pendingSave: '等待保存…',
112
+ fixSettings: '请检查输入后自动保存',
113
+ retrySave: '重试保存',
114
+ updateTitle: '版本更新',
115
+ updateHint: '打开此页自动检查,发现兼容的正式版后可一键更新。',
116
+ checkUpdate: '检查更新',
117
+ installUpdate: '立即更新',
118
+ update_idle: '准备检查更新',
119
+ update_checking: '正在检查新版本…',
120
+ update_available: '发现可用的新版本',
121
+ update_current: '已是最新正式版',
122
+ update_blocked: '有新版本,但暂无适合当前 DSH 的正式版',
123
+ update_unavailable: '当前 DSH 未提供可用的插件更新权限或接口。',
124
+ update_updating: '正在更新,请稍候…',
125
+ update_updated: '更新已完成',
126
+ update_restart: '更新已安装,重启 DSH 后生效',
127
+ update_error: '检查或更新失败,可重新检查后再试',
128
+ update_unknown: '更新结果尚未确认,请到插件管理页查看,避免重复操作。',
129
+ update_restored: '更新失败,DSH 已恢复旧版本;如提示需要重启,请重启 DSH。',
130
+ update_broken: '更新与恢复均未完成,请到插件管理页处理。',
131
+ updateSaveFirst: '设置尚未保存,请先检查输入或重试保存。',
132
+ installedVersion: '当前版本',
133
+ newVersion: '新版本',
134
+
109
135
  summary: '任务做完或需要你时提醒你,状态栏里看进度和花费。',
110
136
  summary_win32: '任务做完或需要你时弹通知,顺便算算今天花了多少。Windows 没有状态栏,小鲸鱼只用通知来找你。',
111
137
  sectionNotify: '提醒我',
@@ -123,8 +149,8 @@ window.__ModuleLoader__.load({
123
149
 
124
150
  sectionTray: '状态栏小鲸鱼',
125
151
  tray: '显示小鲸鱼',
126
- trayHint: '保存后立即生效。',
127
- trayHint_linux: 'UOS / Deepin / 麒麟 / KDE 自带托盘;GNOME 要装 AppIndicator 扩展。保存后立即生效。',
152
+ trayHint: '更改后自动保存并生效。',
153
+ trayHint_linux: 'UOS / Deepin / 麒麟 / KDE 自带托盘;GNOME 要装 AppIndicator 扩展。更改后自动保存并生效。',
128
154
  trayHiddenNote: '状态栏图标已从它的菜单里隐藏。',
129
155
  trayShowAgain: '重新显示状态栏图标',
130
156
  trayShowing: '正在显示…',
@@ -254,12 +280,38 @@ window.__ModuleLoader__.load({
254
280
  reset: '恢复默认',
255
281
  readOnly: '本部署的设置为只读。',
256
282
  unavailable: '小鲸鱼还没加载好,暂时不能配置。',
257
- save: '保存',
258
283
  saving: '保存中…',
259
- saveFailed: '没保存成功,值还留着,改改再试。',
284
+ saveFailed: '设置未保存,修改已保留,请重试。',
260
285
  invalidNumber: '请填数字;留空表示用默认值。',
261
286
  }
262
287
  const en = {
288
+ title: 'Whale Notify Station',
289
+ autoSave: 'Autosave is on',
290
+ saved: 'Settings saved',
291
+ pendingSave: 'Waiting to save…',
292
+ fixSettings: 'Check your input to save automatically',
293
+ retrySave: 'Retry saving',
294
+ updateTitle: 'Updates',
295
+ updateHint: 'Checks when you open this page. Install a compatible stable release with one click.',
296
+ checkUpdate: 'Check for updates',
297
+ installUpdate: 'Update now',
298
+ update_idle: 'Ready to check for updates',
299
+ update_checking: 'Checking for updates…',
300
+ update_available: 'A new version is available',
301
+ update_current: 'You have the latest stable version',
302
+ update_blocked: 'Newer versions exist, but no compatible stable release is available',
303
+ update_unavailable: 'Plugin update access or APIs are unavailable in this DSH instance.',
304
+ update_updating: 'Updating, please wait…',
305
+ update_updated: 'Update complete',
306
+ update_restart: 'Update installed. Restart DSH to use it.',
307
+ update_error: 'Check or update failed. Check again to retry.',
308
+ update_unknown: 'The update outcome is unknown. Check plugin management before trying again.',
309
+ update_restored: 'Update failed; DSH restored the previous version. Restart DSH if requested.',
310
+ update_broken: 'Update and recovery did not complete. Open plugin management to resolve this.',
311
+ updateSaveFirst: 'Settings are not saved. Check your input or retry saving first.',
312
+ installedVersion: 'Installed',
313
+ newVersion: 'New version',
314
+
263
315
  summary: 'Notifies you when a task finishes or needs you; the status bar shows progress and spend.',
264
316
  summary_win32: 'Notifies you when a task finishes or needs you, and keeps count of today\'s spend. Windows has no status bar, so the whale reaches you through notifications only.',
265
317
  sectionNotify: 'Notify me',
@@ -277,8 +329,8 @@ window.__ModuleLoader__.load({
277
329
 
278
330
  sectionTray: 'Status-bar whale',
279
331
  tray: 'Show the whale',
280
- trayHint: 'Takes effect as soon as you save.',
281
- trayHint_linux: 'Built into UOS / Deepin / Kylin / KDE; GNOME needs the AppIndicator extension. Takes effect as soon as you save.',
332
+ trayHint: 'Changes are saved and applied automatically.',
333
+ trayHint_linux: 'Built into UOS / Deepin / Kylin / KDE; GNOME needs the AppIndicator extension. Changes are saved and applied automatically.',
282
334
  trayHiddenNote: 'The status-bar icon was hidden from its own menu.',
283
335
  trayShowAgain: 'Show the status-bar icon again',
284
336
  trayShowing: 'Showing…',
@@ -408,7 +460,6 @@ window.__ModuleLoader__.load({
408
460
  reset: 'Reset to default',
409
461
  readOnly: 'This deployment stores settings read-only.',
410
462
  unavailable: 'The whale is not loaded yet, so it cannot be configured right now.',
411
- save: 'Save',
412
463
  saving: 'Saving…',
413
464
  saveFailed: 'The deployment did not accept these values; they were left for you to correct.',
414
465
  invalidNumber: 'Enter a number, or leave blank to use the default.',
@@ -434,16 +485,19 @@ window.__ModuleLoader__.load({
434
485
  const BOOLS = ['notifyCompleted', 'notifyChoice', 'notifyInput', 'notifyApproval', 'notifyFailed', 'suppressWhenFocused', 'sound', 'tray', 'showSpendInTitle', 'planAutoQuota']
435
486
  const CHOICES = ['channel', 'titleStyle', 'spendSource', 'currency', 'priceSource', 'customPriceCurrency', 'planPeriod', 'planCurrency']
436
487
  const NUMBERS = ['errorHoldMinutes', 'balancePollMinutes', 'customInput', 'customCacheRead', 'customOutput', 'exchangeRate', 'planPrice', 'planBalance', 'quotaPollMinutes']
437
- const TEXTS = ['planProvider', 'planId', 'planName', 'planQuota', 'planRemaining', 'planResetAt', 'planApiKeyEnv', 'planQuotaUrl']
438
- const FIELDS = [...BOOLS, ...CHOICES, ...NUMBERS, ...TEXTS]
488
+ const TEXTS = ['planProvider', 'planId', 'planName', 'planQuota', 'planRemaining', 'planResetAt']
489
+ const QUOTA_FIELDS = ['planApiKeyEnv', 'planQuotaUrl']
490
+ const FIELDS = [...BOOLS, ...CHOICES, ...NUMBERS, ...TEXTS, ...QUOTA_FIELDS]
439
491
  /** The five "notify me when" switches, shown as one row of checkboxes. */
440
492
  const NOTIFY_FIELDS = ['notifyCompleted', 'notifyChoice', 'notifyInput', 'notifyApproval', 'notifyFailed']
441
493
  /** Fields behind the "Advanced" fold (counted for its "n changed" tag). */
442
494
  const ADVANCED_FIELDS = ['channel', 'suppressWhenFocused', 'showSpendInTitle', 'errorHoldMinutes', 'spendSource', 'currency', 'balancePollMinutes', 'priceSource', 'customInput', 'customCacheRead', 'customOutput', 'customPriceCurrency', 'exchangeRate', 'planAutoQuota', 'quotaPollMinutes', 'planQuotaUrl']
443
495
  const TRAY_FIELDS = ['showSpendInTitle', 'errorHoldMinutes']
444
496
  /** Plan fields a preset fills in; switching provider clears them. */
445
- const PRESET_FIELDS = ['planId', 'planName', 'planPrice', 'planCurrency', 'planPeriod', 'planQuota', 'planQuotaUrl']
497
+ const PRESET_FIELDS = ['planId', 'planName', 'planPrice', 'planCurrency', 'planPeriod', 'planQuota']
446
498
 
499
+ // The form model clears staged edits when a save resolves. Keep edits made
500
+ // during that request and replay them before submitting the next batch.
447
501
  class Controller {
448
502
  constructor(scope) {
449
503
  this.form = new ui.SettingsFormModel(scope, [
@@ -451,22 +505,187 @@ window.__ModuleLoader__.load({
451
505
  ...CHOICES.map(choiceField),
452
506
  ...NUMBERS.map(f => ui.settingsNumberField(f)),
453
507
  ...TEXTS.map(textField),
508
+ // An explicit blank masks a credential or endpoint inherited from the deployment.
509
+ ...QUOTA_FIELDS.map(field => ({ ...textField(field), parse: text => ({ kind: 'set', value: text.trim() }) })),
454
510
  ])
455
- this.store = this.form.bind(() => this.projection())
511
+ this.actions = this.form.actions()
512
+ this.listeners = new Set()
513
+ this.pending = new Map()
514
+ this.notice = null
515
+ this.noticeSeq = 0
516
+ this.disposed = false
517
+ this.inFlight = false
518
+ this.formStore = this.form.bind(() => this.projection())
519
+ this.unsubscribe = this.formStore.subscribe?.(() => this.publish())
520
+ this.store = {
521
+ getSnapshot: () => this.snapshot,
522
+ subscribe: listener => { this.listeners.add(listener); return () => this.listeners.delete(listener) },
523
+ }
524
+ this.publish()
456
525
  }
457
526
 
458
527
  projection() {
459
528
  const fields = {}
460
529
  for (const f of FIELDS) fields[f] = this.form.field(f)
461
- return { ...this.form.shell(), fields }
530
+ return { ...this.form.shell(), fields, notice: this.notice }
531
+ }
532
+
533
+ publish() {
534
+ if (this.disposed) return
535
+ this.snapshot = this.projection()
536
+ for (const listener of this.listeners) listener()
537
+ }
538
+
539
+ change(field, text, reset = false) {
540
+ if (this.disposed || !this.form.shell().writable) return
541
+ this.notice = null
542
+ if (this.inFlight) this.pending.set(field, { text, reset })
543
+ if (reset) this.actions.resetField(field)
544
+ else this.actions.edit(field, text)
545
+ this.publish()
546
+ this.schedule()
547
+ }
548
+
549
+ schedule() {
550
+ clearTimeout(this.timer)
551
+ this.timer = setTimeout(() => { this.flush() }, 500)
552
+ }
553
+
554
+ async flush() {
555
+ clearTimeout(this.timer)
556
+ if (this.disposed) return false
557
+ // Used by refresh/update actions to wait for every pending setting.
558
+ if (this.inFlight) {
559
+ await this.saving
560
+ return this.flush()
561
+ }
562
+ const state = this.form.shell()
563
+ if (!state.available || !state.writable || state.invalid) return false
564
+ if (!state.dirty) return true
565
+ this.inFlight = true
566
+ this.notice = null
567
+ this.pending.clear()
568
+ this.saving = (async () => {
569
+ try {
570
+ // actions().save() returns void in DSH; save() is the awaitable method.
571
+ await this.form.save()
572
+ if (this.disposed) return false
573
+ const failed = this.form.shell().failed
574
+ const pending = [...this.pending]
575
+ this.pending.clear()
576
+ for (const [field, change] of pending) {
577
+ if (change.reset) this.actions.resetField(field)
578
+ else this.actions.edit(field, change.text)
579
+ }
580
+ const after = this.form.shell()
581
+ this.notice = failed ? { id: ++this.noticeSeq, kind: 'saveFailed' }
582
+ : !after.dirty ? { id: ++this.noticeSeq, kind: 'saved' } : null
583
+ // Do not loop on a rejection. An explicit retry or a new edit retries.
584
+ if (!failed && after.dirty && !after.invalid) this.schedule()
585
+ return !failed && !after.dirty
586
+ } catch (error) {
587
+ if (!this.disposed) this.notice = { id: ++this.noticeSeq, kind: 'saveFailed' }
588
+ return false
589
+ } finally {
590
+ this.inFlight = false
591
+ this.publish()
592
+ }
593
+ })()
594
+ return this.saving
462
595
  }
463
596
 
464
597
  inject() {
465
- return { hooks: { notifyTray: this.store }, ...this.form.actions() }
598
+ return {
599
+ hooks: { notifyTray: this.store },
600
+ edit: (field, text) => this.change(field, text),
601
+ resetField: field => this.change(field, '', true),
602
+ flush: () => this.flush(),
603
+ retrySave: () => this.flush(),
604
+ dismissNotice: id => { if (this.notice?.id === id) { this.notice = null; this.publish() } },
605
+ }
466
606
  }
467
607
 
468
- dispose() { this.form.dispose() }
608
+ dispose() {
609
+ this.disposed = true
610
+ clearTimeout(this.timer)
611
+ this.unsubscribe?.()
612
+ this.listeners.clear()
613
+ this.form.dispose()
614
+ }
469
615
  }
616
+ exports.__SettingsController = Controller
617
+
618
+ // All update decisions and package mutations belong to DSH's plugin manager.
619
+ // The browser never runs a shell or chooses an unverified registry version.
620
+ class UpdateController {
621
+ constructor(getManager, flush) {
622
+ this.getManager = getManager
623
+ this.flush = flush
624
+ this.listeners = new Set()
625
+ this.snapshot = { phase: 'idle' }
626
+ this.disposed = false
627
+ this.store = {
628
+ getSnapshot: () => this.snapshot,
629
+ subscribe: listener => { this.listeners.add(listener); return () => this.listeners.delete(listener) },
630
+ }
631
+ }
632
+
633
+ patch(change) {
634
+ if (this.disposed) return
635
+ this.snapshot = { ...this.snapshot, ...change }
636
+ for (const listener of this.listeners) listener()
637
+ }
638
+
639
+ async check() {
640
+ if (this.disposed || ['checking', 'updating', 'restart'].includes(this.snapshot.phase)) return
641
+ const manager = this.getManager()
642
+ if (!manager?.listVersions || !manager?.updateBundle) return this.patch({ phase: 'unavailable' })
643
+ this.patch({ phase: 'checking', candidate: undefined, error: undefined })
644
+ try {
645
+ const inventory = await manager.listBundles()
646
+ if (!inventory.ok) throw new Error(inventory.error?.message || 'Plugin inventory unavailable')
647
+ const pkg = inventory.value.find(pkg => pkg.name === 'dsh-notify-tray')
648
+ if (!pkg) return this.patch({ phase: 'unavailable' })
649
+ this.patch({ installed: pkg.version })
650
+ if (!pkg.updatable) return this.patch({ phase: /^(?:link:|file:|git|https?:|\/)/u.test(pkg.source || '') ? 'local' : 'unavailable' })
651
+ const answer = await manager.listVersions('dsh-notify-tray', {})
652
+ if (!answer.ok) throw new Error(answer.error?.message || 'Version check failed')
653
+ const list = answer.value
654
+ if (list.status !== 'listed') throw new Error(list.reason || 'Version check refused')
655
+ const candidate = list.versions.find(v => v.bundle && !v.incompatible && !v.deprecated && !v.prerelease)
656
+ this.patch({ phase: candidate ? 'available' : list.versions.length ? 'blocked' : 'current', installed: list.installed, candidate: candidate?.version, registry: list.registry })
657
+ } catch (error) {
658
+ this.patch({ phase: 'error', error: String(error.message || error) })
659
+ }
660
+ }
661
+
662
+ async update() {
663
+ if (this.disposed || this.snapshot.phase !== 'available') return
664
+ const { candidate, registry } = this.snapshot
665
+ this.patch({ phase: 'updating', error: undefined })
666
+ try {
667
+ if (!await this.flush()) return this.patch({ phase: 'available', error: 'updateSaveFirst' })
668
+ if (this.disposed) return
669
+ const manager = this.getManager()
670
+ const answer = await manager.updateBundle('dsh-notify-tray', candidate, { registry })
671
+ if (!answer.ok) return this.patch({ phase: 'unknown', error: answer.error?.message })
672
+ const result = answer.value
673
+ const application = result.result?.application
674
+ if (application === 'applied' || application === 'restart-required') {
675
+ this.patch({ phase: application === 'restart-required' ? 'restart' : 'updated', installed: candidate, candidate: undefined })
676
+ } else {
677
+ const restored = result.restore?.application
678
+ this.patch({ phase: restored === 'applied' || restored === 'restart-required' ? 'restored' : restored ? 'broken' : 'error', error: result.result?.error?.diagnostic || result.result?.error?.code || application })
679
+ }
680
+ } catch (error) {
681
+ // A disconnected client cannot assume an update failed; the host may still finish it.
682
+ this.patch({ phase: 'unknown', error: String(error.message || error) })
683
+ }
684
+ }
685
+
686
+ dispose() { this.disposed = true; this.listeners.clear() }
687
+ }
688
+ exports.__UpdateController = UpdateController
470
689
 
471
690
  // ---- live data: catalog once, host state while the page is open ------------------
472
691
  const live = { catalog: undefined, state: undefined, listeners: new Set() }
@@ -513,7 +732,7 @@ window.__ModuleLoader__.load({
513
732
  const S = {
514
733
  section: { marginTop: 28 },
515
734
  sectionTitle: { fontSize: 15, fontWeight: 600, margin: '0 0 4px' },
516
- row: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 16, padding: '10px 0', borderBottom: '1px solid color-mix(in srgb, currentColor 10%, transparent)' },
735
+ row: { display: 'flex', flexWrap: 'wrap', alignItems: 'center', justifyContent: 'space-between', gap: 16, padding: '10px 0', borderBottom: '1px solid color-mix(in srgb, currentColor 10%, transparent)' },
517
736
  rowText: { minWidth: 0 },
518
737
  label: { fontSize: 14 },
519
738
  hint: { margin: '2px 0 0', opacity: 0.6, fontSize: 12 },
@@ -523,7 +742,7 @@ window.__ModuleLoader__.load({
523
742
  grid: { display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(200px, 1fr))', gap: '8px 16px', marginTop: 12 },
524
743
  card: { border: '1px solid var(--dsw-alias-border-l3, color-mix(in srgb, currentColor 12%, transparent))', borderRadius: 'var(--dsw-radius-lg, 10px)', padding: '12px 14px', margin: '12px 0', fontSize: 13, lineHeight: '20px' },
525
744
  cardTitle: { fontSize: 12, fontWeight: 500, opacity: 0.65, marginBottom: 4 },
526
- mono: { fontFamily: 'var(--ds-font-family-code, ui-monospace, monospace)', fontSize: 13 },
745
+ mono: { overflowWrap: 'anywhere', fontFamily: 'var(--ds-font-family-code, ui-monospace, monospace)', fontSize: 13 },
527
746
  muted: { opacity: 0.65 },
528
747
  error: { color: 'var(--dsw-alias-state-error-primary, #d33)' },
529
748
  select: { boxSizing: 'border-box', border: '.5px solid var(--dsw-alias-border-l4, color-mix(in srgb, currentColor 25%, transparent))', borderRadius: 'var(--dsw-radius-md, 6px)', width: 180, maxWidth: '100%', height: 32, font: 'inherit', background: 'var(--dsw-alias-bg-layer-1, transparent)', color: 'var(--dsw-alias-label-primary, inherit)', padding: '0 10px', fontSize: 14, lineHeight: '22px', cursor: 'pointer' },
@@ -532,7 +751,7 @@ window.__ModuleLoader__.load({
532
751
  lines: { margin: '6px 0 0', paddingLeft: 18, fontSize: 12, opacity: 0.75 },
533
752
  checks: { display: 'flex', flexWrap: 'wrap', gap: '8px 18px', marginTop: 10 },
534
753
  check: { display: 'inline-flex', alignItems: 'center', gap: 6, fontSize: 13 },
535
- spendCard: { display: 'flex', alignItems: 'center', gap: 16, border: '1px solid var(--dsw-alias-border-l3, color-mix(in srgb, currentColor 12%, transparent))', borderRadius: 'var(--dsw-radius-lg, 10px)', padding: '12px 14px', margin: '4px 0' },
754
+ spendCard: { display: 'flex', flexWrap: 'wrap', alignItems: 'center', gap: 16, border: '1px solid var(--dsw-alias-border-l3, color-mix(in srgb, currentColor 12%, transparent))', borderRadius: 'var(--dsw-radius-lg, 10px)', padding: '12px 14px', margin: '4px 0' },
536
755
  spendValue: { fontSize: 22, fontWeight: 600, lineHeight: '28px' },
537
756
  keyRow: { display: 'flex', alignItems: 'flex-start', gap: 8, flexWrap: 'wrap' },
538
757
  disclosure: { display: 'flex', alignItems: 'center', gap: 6, width: '100%', font: 'inherit', fontSize: 13, color: 'inherit', background: 'none', border: 0, padding: '10px 0', cursor: 'pointer', textAlign: 'left' },
@@ -624,9 +843,9 @@ window.__ModuleLoader__.load({
624
843
  }, options.map(([value, label]) => h('option', { key: value, value }, label)))
625
844
  }
626
845
 
627
- function Section({ title, children }) {
628
- return h('section', { style: S.section },
629
- h('h4', { style: S.sectionTitle }, title),
846
+ function Section({ title, icon = 'settings', children }) {
847
+ return h('section', { className: 'dnt-card' },
848
+ h('h2', { className: 'dnt-card-title' }, h('span', { className: 'dnt-section-icon' }, h(Icon, { name: icon })), title),
630
849
  children)
631
850
  }
632
851
 
@@ -737,7 +956,7 @@ window.__ModuleLoader__.load({
737
956
  const [busy, setBusy] = React.useState(false)
738
957
  const refresh = () => {
739
958
  setBusy(true)
740
- fetchJson(REFRESH_ROUTE, { method: 'POST' }).then(() => loadState()).catch(() => {}).then(() => setBusy(false))
959
+ common.flush().then(saved => saved ? fetchJson(REFRESH_ROUTE, { method: 'POST' }).then(() => loadState()) : undefined).catch(() => {}).then(() => setBusy(false))
741
960
  }
742
961
  const choosePlan = id => {
743
962
  edit('planId', id)
@@ -748,19 +967,14 @@ window.__ModuleLoader__.load({
748
967
  edit('planCurrency', next.currency)
749
968
  edit('planPeriod', next.period)
750
969
  edit('planQuota', next.quotaText ?? '')
751
- resetField('planQuotaUrl')
970
+ edit('planQuotaUrl', '')
752
971
  }
753
972
  const chooseProvider = id => {
754
973
  edit('planProvider', id)
755
974
  for (const name of PRESET_FIELDS) resetField(name)
756
- // Suggest the provider's usual key reference, unless the user typed their own name.
757
- const current = f.planApiKeyEnv.text
758
- const suggested = !current || providers.some(p => p.keyEnv === current)
759
975
  const nextProvider = providers.find(p => p.id === id)
760
- if (suggested) {
761
- if (nextProvider?.keyEnv) edit('planApiKeyEnv', nextProvider.keyEnv)
762
- else resetField('planApiKeyEnv')
763
- }
976
+ edit('planApiKeyEnv', nextProvider?.keyEnv ?? '')
977
+ edit('planQuotaUrl', '')
764
978
  }
765
979
  const providerOptions = [['none', t('providerNone')], ...providers.map(p => [p.id, p.name]), ['custom', t('providerCustom')]]
766
980
  const planOptions = [...plans.map(p => [p.id, `${p.name}${p.price ? ` · ${SYM[p.currency] ?? ''}${p.price}` : ''}`]), ['', t('planCustom')]]
@@ -853,36 +1067,139 @@ window.__ModuleLoader__.load({
853
1067
  h(TextField, { name: 'planQuotaUrl', field: f.planQuotaUrl, placeholder: quotaSpec?.url ?? 'https://…', ...common }))) : null))
854
1068
  }
855
1069
 
1070
+ const PAGE_CSS = `
1071
+ .dnt-page { --dnt-accent: #5085b2; --dnt-border: color-mix(in srgb, currentColor 11%, transparent); height: 100%; min-height: 0; overflow-y: auto; }
1072
+ .dnt-content { max-width: 1040px; margin: auto; padding: 30px 26px 48px; }
1073
+ .dnt-hero { display: flex; align-items: center; gap: 18px; padding: 22px; margin-bottom: 24px; border-radius: 20px; background: linear-gradient(115deg, color-mix(in srgb, var(--dnt-accent) 12%, transparent), color-mix(in srgb, var(--dnt-accent) 2%, transparent)); border: 1px solid var(--dnt-border); }
1074
+ .dnt-mascot { box-sizing: border-box; width: 80px; height: 80px; padding: 8px; flex: none; border-radius: 22px; border: 1px solid var(--dnt-border); background: var(--dsw-alias-bg-layer-1, #fff); box-shadow: 0 3px 10px #00000006; }
1075
+ .dnt-mascot-window { width: 100%; height: 100%; overflow: hidden; border-radius: 15px; background: #050505; }
1076
+ .dnt-mascot-sprite { display: block; width: 100%; height: 100%; object-fit: contain; transform-origin: center bottom; animation: dnt-peek 7s cubic-bezier(.22, 1, .36, 1) infinite; }
1077
+ .dnt-heading { margin: 0; font-size: 24px; font-weight: 650; letter-spacing: -.4px; }
1078
+ .dnt-subtitle { margin: 7px 0 10px; opacity: .62; font-size: 13px; line-height: 1.6; }
1079
+ .dnt-status { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; opacity: .8; }
1080
+ .dnt-status[data-busy=true] svg { animation: dnt-spin 1.4s linear infinite; }
1081
+ .dnt-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr)); gap: 18px; margin-bottom: 18px; }
1082
+ .dnt-card { min-width: 0; border: 1px solid var(--dnt-border); border-radius: 16px; padding: 20px; margin-bottom: 18px; background: var(--dsw-alias-bg-layer-1, transparent); transition: border-color .2s, box-shadow .2s; }
1083
+ .dnt-grid > .dnt-card { margin-bottom: 0; }
1084
+ .dnt-card:hover { border-color: color-mix(in srgb, var(--dnt-accent) 36%, transparent); box-shadow: 0 4px 18px #00000004; }
1085
+ .dnt-card-title { display: flex; align-items: center; gap: 9px; font-size: 14px; font-weight: 600; margin: 0 0 16px; }
1086
+ .dnt-section-icon { display: inline-flex; color: var(--dnt-accent); padding: 7px; border-radius: 10px; background: color-mix(in srgb, var(--dnt-accent) 9%, transparent); }
1087
+ .dnt-page button { transition: background .15s, opacity .15s; }
1088
+ .dnt-page button:hover:not(:disabled) { filter: brightness(.94); }
1089
+ .dnt-page button:focus-visible, .dnt-page select:focus-visible { outline: 2px solid var(--dnt-accent); outline-offset: 3px; }
1090
+ .dnt-update-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 14px; }
1091
+ .dnt-update-actions { display: flex; flex-wrap: wrap; gap: 8px; }
1092
+ .dnt-update-version { display: inline-flex; gap: 7px; font-size: 12px; font-weight: 500; margin-bottom: 8px; }
1093
+ .dnt-update-version span { padding: 3px 8px; border-radius: 6px; background: color-mix(in srgb, var(--dnt-accent) 9%, transparent); }
1094
+ .dnt-note { font-size: 12px; line-height: 1.6; opacity: .7; margin: 0; overflow-wrap: anywhere; }
1095
+ .dnt-alert { border-radius: 10px; padding: 10px 14px; margin-bottom: 16px; background: color-mix(in srgb, #d68036 10%, transparent); font-size: 13px; }
1096
+ @keyframes dnt-peek {
1097
+ 0%, 8% { transform: translateY(32%); }
1098
+ 13% { transform: translateY(0); }
1099
+ 18% { transform: translateY(2%); }
1100
+ 24%, 48% { transform: translateY(0); }
1101
+ 76%, 100% { transform: translateY(32%); }
1102
+ }
1103
+ @keyframes dnt-spin { to { transform: rotate(360deg); } }
1104
+ @media (max-width: 1000px) { .dnt-grid { grid-template-columns: 1fr; } }
1105
+ @media (max-width: 600px) { .dnt-content { padding: 16px 12px 28px; } .dnt-hero { padding: 16px; gap: 10px; } .dnt-heading { font-size: 20px; } .dnt-mascot { width: 60px; height: 60px; padding: 6px; border-radius: 18px; } .dnt-mascot-window { border-radius: 11px; } .dnt-card { padding: 16px; } }
1106
+ @media (prefers-reduced-motion: reduce) { .dnt-page *, .dnt-page *::before { animation: none !important; transition: none !important; } }
1107
+ `
1108
+
1109
+ function Icon({ name, size = 16 }) {
1110
+ const paths = {
1111
+ bell: 'M18 8a6 6 0 0 0-12 0c0 7-3 7-3 9h18c0-2-3-2-3-9M10 21h4',
1112
+ chart: 'M4 3v17h17M8 15v-4m5 4V7m5 8V4',
1113
+ settings: 'M4 6h16M4 12h16M4 18h16M8 3v6m8 0v6m-6 0v6',
1114
+ update: 'M20 7v5h-5M4 17v-5h5M6 7a7 7 0 0 1 12-1l2 3M4 15l2 3a7 7 0 0 0 12-1',
1115
+ check: 'm5 12 4 4L19 6',
1116
+ }
1117
+ return h('svg', { width: size, height: size, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', strokeWidth: 1.7, strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': true }, h('path', { d: paths[name] || paths.settings }))
1118
+ }
1119
+
856
1120
  function Page(props) {
857
- if (props.view === 'summary') return platformT(props.t, currentPlatform())('summary')
858
- return h(FullPage, props)
1121
+ const liveData = useLive()
1122
+ const state = props.useNotifyTray(snapshot => snapshot)
1123
+ const busy = state.saving || state.dirty
1124
+ const status = !state.available ? 'unavailable' : !state.writable ? 'readOnly' : state.notice?.kind === 'saveFailed' ? 'saveFailed' : state.invalid ? 'fixSettings' : state.saving ? 'saving' : state.dirty ? 'pendingSave' : 'autoSave'
1125
+ return h('div', { className: 'dnt-page' },
1126
+ h('style', null, PAGE_CSS),
1127
+ h('div', { className: 'dnt-content' },
1128
+ h('header', { className: 'dnt-hero' },
1129
+ h(PeekingMascot),
1130
+ h('div', null,
1131
+ h('h1', { className: 'dnt-heading' }, props.t('title')),
1132
+ h('p', { className: 'dnt-subtitle' }, platformT(props.t, currentPlatform())('summary')),
1133
+ h('span', { className: 'dnt-status', role: 'status', 'data-busy': busy }, h(Icon, { name: busy ? 'update' : 'check', size: 13 }), props.t(status)))),
1134
+ h(FullPage, { ...props, liveData }),
1135
+ h(UpdatePanel, props)))
1136
+ }
1137
+
1138
+ function PeekingMascot() {
1139
+ const [ready, setReady] = React.useState(false)
1140
+ return h('div', { className: 'dnt-mascot', 'aria-hidden': true },
1141
+ h('div', { className: 'dnt-mascot-window' },
1142
+ h('img', {
1143
+ className: 'dnt-mascot-sprite',
1144
+ src: 'notify-tray/mascot?v=peeking-2',
1145
+ alt: '',
1146
+ draggable: false,
1147
+ style: { animationPlayState: ready ? 'running' : 'paused' },
1148
+ onLoad: () => setReady(true),
1149
+ })))
1150
+ }
1151
+
1152
+ function UpdatePanel(props) {
1153
+ const t = props.t
1154
+ const state = props.useNotifyUpdate(snapshot => snapshot)
1155
+ React.useEffect(() => { props.checkUpdate() }, [])
1156
+ const busy = state.phase === 'checking' || state.phase === 'updating'
1157
+ return h(Section, { title: t('updateTitle'), icon: 'update' },
1158
+ h('div', { className: 'dnt-update-row' },
1159
+ h('div', { style: { flex: '1 1 240px', minWidth: 0 } },
1160
+ state.installed ? h('div', { className: 'dnt-update-version' },
1161
+ h('span', null, `${t('installedVersion')} ${state.installed}`),
1162
+ state.candidate ? h('span', null, `${t('newVersion')} ${state.candidate}`) : null) : null,
1163
+ state.phase !== 'local' ? h('p', { className: 'dnt-note', role: 'status' }, t(`update_${state.phase}`)) : null,
1164
+ state.error ? h('p', { className: 'dnt-note', style: S.error, role: 'alert' }, state.error === 'updateSaveFirst' ? t(state.error) : state.error) : null),
1165
+ h('div', { className: 'dnt-update-actions' },
1166
+ h('button', { type: 'button', style: S.button, disabled: busy || state.phase === 'restart', onClick: props.checkUpdate }, t('checkUpdate')),
1167
+ state.phase === 'available' ? h('button', { type: 'button', style: { ...S.button, background: 'var(--dnt-accent)', color: '#fff', borderColor: 'transparent' }, onClick: props.installUpdate }, t('installUpdate')) : null)),
1168
+ h('p', { className: 'dnt-note', style: { marginTop: 12 } }, t('updateHint')))
1169
+ }
1170
+
1171
+ function WhaleIcon({ size = 16 }) {
1172
+ return h('svg', { width: size, height: size, viewBox: '0 0 24 24', fill: 'none', 'aria-hidden': true },
1173
+ h('path', { d: 'M3 12c0-3.3 2.7-6 6-6s6 2.7 6 6h2c0-2 1.5-3.5 4-4v5c0 4-4 7-9 7s-9-3-9-8Z M8.5 11a1 1 0 1 0-2 0 1 1 0 0 0 2 0Z', fill: 'currentColor', fillRule: 'evenodd' }),
1174
+ h('path', { d: 'M10 5V2m0 3 3-2', stroke: 'currentColor', strokeWidth: 1.5, strokeLinecap: 'round' }))
859
1175
  }
860
1176
 
861
1177
  function FullPage(props) {
862
1178
  const state = props.useNotifyTray(snapshot => snapshot)
863
- const liveData = useLive()
1179
+ const liveData = props.liveData
864
1180
  const platform = currentPlatform()
865
1181
  const features = (platform && FEATURES[platform]) || ALL_FEATURES
866
1182
  const t = platformT(props.t, platform)
867
1183
  const disabled = !state.writable
868
- const common = { t, disabled, edit: props.edit, resetField: props.resetField }
1184
+ const common = { t, disabled, edit: props.edit, resetField: props.resetField, flush: props.flush }
869
1185
  const f = state.fields
870
1186
  const toggle = name => h(ToggleRow, { key: name, name, field: f[name], ...common })
871
1187
  const titleStyle = f.titleStyle.text || 'text'
872
- return h(ui.SettingsForm, {
873
- labels: { unavailable: t('unavailable'), readOnly: t('readOnly'), saveFailed: t('saveFailed'), save: t('save'), saving: t('saving') },
874
- state,
875
- onSave: props.save,
876
- onDiscard: props.discard,
877
- },
878
- h(Section, { title: t('sectionNotify') },
1188
+ if (!state.available) return h('p', { role: 'status', className: 'dnt-alert' }, t('unavailable'))
1189
+ return h('div', null,
1190
+ !state.writable ? h('p', { role: 'status', className: 'dnt-alert' }, t('readOnly')) : null,
1191
+ state.notice?.kind === 'saveFailed' ? h('div', { role: 'alert', className: 'dnt-alert' }, t('saveFailed'), ' ',
1192
+ h('button', { type: 'button', style: S.button, disabled: state.saving || !state.writable || state.invalid, onClick: props.retrySave }, t('retrySave'))) : null,
1193
+ state.notice ? h(ui.Toast, { key: state.notice.id, text: t(state.notice.kind), tone: state.notice.kind === 'saved' ? 'success' : undefined, holdMs: 2200, onDone: () => { if (state.notice.kind === 'saved') props.dismissNotice(state.notice.id) } }) : null,
1194
+ h('div', { className: 'dnt-grid' },
1195
+ h(Section, { title: t('sectionNotify'), icon: 'bell' },
879
1196
  h(CheckRow, { label: 'notifyWhen', names: NOTIFY_FIELDS, f, ...common }),
880
1197
  toggle('sound')),
881
- features.tray ? h(Section, { title: t('sectionTray') },
1198
+ features.tray ? h(Section, { title: t('sectionTray'), icon: 'settings' },
882
1199
  toggle('tray'),
883
1200
  h(TrayStatus, { t, state: liveData.state }),
884
- features.menuBarTitle ? h(ChoiceRow, { name: 'titleStyle', field: f.titleStyle, hint: `titleStyleHint_${titleStyle}`, ...common, options: [['text', 'titleText'], ['count', 'titleCount'], ['icon', 'titleIcon']] }) : null) : null,
885
- h(Section, { title: t('sectionMoney') },
1201
+ features.menuBarTitle ? h(ChoiceRow, { name: 'titleStyle', field: f.titleStyle, hint: `titleStyleHint_${titleStyle}`, ...common, options: [['text', 'titleText'], ['count', 'titleCount'], ['icon', 'titleIcon']] }) : null) : null),
1202
+ h(Section, { title: t('sectionMoney'), icon: 'chart' },
886
1203
  h(SpendCard, { t, state: liveData.state }),
887
1204
  h(PlanSection, { t, f, common, state: liveData.state, catalog: liveData.catalog })),
888
1205
  h(AdvancedSection, { t, f, common, features, state: liveData.state, catalog: liveData.catalog }))
@@ -892,18 +1209,31 @@ window.__ModuleLoader__.load({
892
1209
  const t = ctx.locale.bind(LOCALE_NS)
893
1210
  ctx.effect(() => ctx.locale.register(LOCALE_NS, { zh: { ...zh, CNY: '¥ 人民币', USD: '$ 美元' }, en: { ...en, CNY: '¥ CNY', USD: '$ USD' } }), 'notify-tray: settings dictionaries')
894
1211
  const card = new Controller(ctx.configForms.get(NS))
1212
+ const updater = new UpdateController(() => ctx.get?.('remote.pluginManager') || ctx.remote?.pluginManager, () => card.flush())
1213
+ ctx.effect(() => () => updater.dispose(), 'notify-tray: updates')
895
1214
  ctx.effect(() => () => card.dispose(), 'notify-tray: settings form')
896
- // One door only: the package page itself (what "插件 → 小鲸鱼通知站" opens,
897
- // keyed by package name). The component row deliberately gets no
898
- // `plugins.row.config` entry, so there is no second, identical page
899
- // behind the row's "›".
900
- ctx.effect(() => ctx.configForms.whileServed([NS], () => ctx.slots.inject('plugins.bundle.config', () => ctx.slots.register({
901
- name: 'plugins.bundle.config',
902
- key: PACKAGE_KEY,
903
- locale: LOCALE_NS,
904
- inject: () => card.inject(),
905
- }, Page))), 'notify-tray: settings on the package page')
906
- void t
1215
+ // DSH owns sidebar navigation and README rendering on the plugin page.
1216
+ // Register no plugin-detail config/actions: settings have one entrance.
1217
+ ctx.inject(['layout'], pageCtx => {
1218
+ pageCtx.effect(() => pageCtx.configForms.whileServed([NS], () => {
1219
+ const stopMain = pageCtx.slots.inject('main', () => pageCtx.slots.register({
1220
+ name: 'main',
1221
+ key: PANEL_ID,
1222
+ locale: LOCALE_NS,
1223
+ inject: () => {
1224
+ const face = card.inject()
1225
+ return { ...face, hooks: { ...face.hooks, notifyUpdate: updater.store }, checkUpdate: () => updater.check(), installUpdate: () => updater.update() }
1226
+ },
1227
+ }, Page))
1228
+ const stopSidebar = pageCtx.slots.inject('sidebar.panellist', () => pageCtx.slots.register({
1229
+ name: 'sidebar.panellist',
1230
+ id: PANEL_ID,
1231
+ order: 11,
1232
+ label: () => t('title'),
1233
+ }, WhaleIcon))
1234
+ return () => { stopSidebar(); stopMain() }
1235
+ }), 'notify-tray: sidebar settings')
1236
+ })
907
1237
  }
908
1238
 
909
1239