dsh-bark-push 0.2.2 → 0.3.1

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/ui.js CHANGED
@@ -1,26 +1,3 @@
1
- /**
2
- * Self-contained management page for notification configuration and mute state.
3
- *
4
- * The page is served by the authenticated host route, so it uses only
5
- * same-origin fetch and no external assets. All dynamic values are written
6
- * through `textContent` or form values; server data never becomes HTML.
7
- *
8
- * Design intent: this is a notification-routing console embedded inside DSH
9
- * Settings. Hierarchy is status-first: a compact health strip, then sections
10
- * separated by hairline rules (not nested rounded cards), and each extra
11
- * channel is a single "lane" whose enabled state reads at a glance while its
12
- * parameters stay collapsed until needed.
13
- *
14
- * @module dsh-bark-push/ui
15
- */
16
-
17
- /**
18
- * Render the management page.
19
- * @param {object} options - render options.
20
- * @param {string} options.version - plugin version.
21
- * @param {boolean} [options.embedded] - compact layout for the Settings iframe.
22
- * @returns {string} complete HTML document.
23
- */
24
1
  export function renderUiPage({ version, embedded = false }) {
25
2
  const safeVersion = String(version ?? '').replace(/[^0-9A-Za-z._-]/g, '');
26
3
  return `<!doctype html>
@@ -28,187 +5,333 @@ export function renderUiPage({ version, embedded = false }) {
28
5
  <head>
29
6
  <meta charset="utf-8">
30
7
  <meta name="viewport" content="width=device-width, initial-scale=1">
31
- <title>推送通知 · DSH</title>
8
+ <title>通知 · DSH</title>
32
9
  <style>
33
10
  :root {
34
11
  color-scheme: light dark;
35
- --bg: #ffffff;
36
- --fg: #16181d;
37
- --muted: #6b7280;
38
- --line: #e5e7eb;
39
- --line-strong: #d5d9e0;
40
- --subtle: #f6f7f9;
41
- --accent: #3b6ef6;
12
+ --canvas: #f3f6fb;
13
+ --surface: #ffffff;
14
+ --surface-muted: #f7f9fc;
15
+ --ink: #172230;
16
+ --muted: #657487;
17
+ --line: #dce4ee;
18
+ --line-strong: #c5d0df;
19
+ --accent: #2457d6;
20
+ --accent-soft: #e8eeff;
42
21
  --on-accent: #ffffff;
43
- --ok: #16894f;
44
- --warn: #a66a00;
45
- --bad: #c0392b;
46
- --radius: 10px;
22
+ --ok: #0f7a56;
23
+ --warn: #9b5b00;
24
+ --bad: #b83d35;
25
+ --radius: 8px;
47
26
  }
48
27
  @media (prefers-color-scheme: dark) {
49
28
  :root {
50
- --bg: #16171b;
51
- --fg: #eceef3;
52
- --muted: #9aa1ad;
53
- --line: #2b2e36;
54
- --line-strong: #3a3e48;
55
- --subtle: #22252c;
56
- --accent: #7aa2ff;
57
- --on-accent: #0e1116;
58
- --ok: #5dd39e;
59
- --warn: #e3b341;
60
- --bad: #ff7b72;
29
+ --canvas: #10151c;
30
+ --surface: #171e27;
31
+ --surface-muted: #1d2631;
32
+ --ink: #ecf1f8;
33
+ --muted: #9aa8ba;
34
+ --line: #2a3543;
35
+ --line-strong: #3b4a5d;
36
+ --accent: #8bafff;
37
+ --accent-soft: #20345e;
38
+ --on-accent: #0d1420;
39
+ --ok: #5fd3a0;
40
+ --warn: #efb45e;
41
+ --bad: #ff8179;
61
42
  }
62
43
  }
63
44
  * { box-sizing: border-box; }
45
+ [hidden] { display: none !important; }
64
46
  html, body { margin: 0; }
65
47
  body {
66
- background: var(--bg);
67
- color: var(--fg);
68
- font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
48
+ background: var(--canvas);
49
+ color: var(--ink);
50
+ font: 13.5px/1.55 "Avenir Next", "Segoe UI Variable", "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
69
51
  font-feature-settings: "tnum" 1;
70
52
  }
71
- main { max-width: 860px; margin: 0 auto; padding: 30px 24px 72px; }
72
- body.embedded main { padding: 14px 16px 48px; }
73
-
74
- /* Page head: title, lead, health strip */
75
- .page-head h1 { font-size: 20px; font-weight: 650; letter-spacing: -0.01em; margin: 0 0 6px; display: flex; align-items: center; gap: 8px; }
76
- .page-head h1 svg { flex: none; }
77
- .lead { color: var(--muted); font-size: 13px; margin: 0 0 14px; max-width: 62ch; }
78
- .healthstrip { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 6px; }
79
- .pill { display: inline-flex; align-items: center; gap: 5px; border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
80
- .pill.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 42%, var(--line)); }
81
- .pill.bad { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 42%, var(--line)); }
82
- .pill.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 42%, var(--line)); }
83
- .hint { color: var(--muted); font-size: 12px; margin: 6px 0 0; }
84
-
85
- /* Sections: continuous surface, hairline separated, no nested cards */
86
- .section { padding: 20px 0; border-top: 1px solid var(--line); }
87
- .section:first-of-type { border-top: 0; padding-top: 14px; }
88
- .section-head { display: flex; align-items: baseline; gap: 10px; margin: 0 0 4px; }
89
- .section-head h2 { font-size: 15px; font-weight: 650; margin: 0; letter-spacing: -0.005em; }
90
- .section-head .count { font-size: 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 1px 8px; font-variant-numeric: tabular-nums; }
91
- .section-sub { color: var(--muted); font-size: 12.5px; margin: 0 0 14px; max-width: 66ch; }
92
-
93
- /* Field rows */
94
- .row { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 8px 16px; align-items: center; margin: 0 0 12px; }
95
- .row > label:first-child { color: var(--muted); font-size: 13px; }
96
- .row.wide { grid-template-columns: 1fr; }
97
- input[type=text], input[type=number], input[type=password], select, textarea {
98
- width: 100%; padding: 7px 10px; border: 1px solid var(--line-strong); border-radius: 8px;
99
- background: var(--bg); color: var(--fg); font: inherit; min-height: 34px;
100
- }
101
- textarea { min-height: 68px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
102
- input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible {
103
- outline: 2px solid var(--accent); outline-offset: 1px;
104
- }
105
- .checks { display: flex; flex-wrap: wrap; gap: 10px 18px; }
106
- .checks label { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
107
-
108
- /* Rule grid (notification toggles) */
109
- .rule-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px; }
110
- .rule { display: flex; gap: 9px; align-items: flex-start; border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; background: var(--subtle); }
111
- .rule input { margin-top: 2px; }
112
- .rule .rt { display: flex; flex-direction: column; gap: 1px; }
113
- .rule .rt b { font-weight: 550; font-size: 13px; }
114
- .rule .rt small { color: var(--muted); font-size: 12px; }
115
-
116
- /* Buttons */
53
+ button, input, textarea, select { font: inherit; }
117
54
  button {
118
- appearance: none; border: 1px solid var(--line-strong); background: var(--bg); color: var(--fg);
119
- border-radius: 8px; padding: 7px 12px; font: inherit; font-size: 13px; cursor: pointer; min-height: 32px;
55
+ appearance: none; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
56
+ border-radius: 6px; padding: 7px 11px; min-height: 34px; cursor: pointer; transition: border-color .15s ease, background .15s ease;
120
57
  }
121
58
  button:hover { border-color: var(--muted); }
122
- button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 550; }
59
+ button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
123
60
  button.primary:hover { filter: brightness(1.04); }
61
+ button.primary:disabled { background: var(--line); border-color: var(--line); color: var(--muted); opacity: 1; filter: none; }
124
62
  button.danger { color: var(--bad); }
125
63
  button.danger:hover { border-color: var(--bad); }
126
- button:disabled { opacity: .5; cursor: default; }
127
- .actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 14px; }
128
- .save-status { font-size: 12px; margin-left: 4px; }
64
+ button:disabled { opacity: .52; cursor: default; }
65
+ button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible {
66
+ outline: 2px solid var(--accent-soft); outline-offset: 1px; border-color: var(--accent);
67
+ }
68
+ input, textarea, select {
69
+ width: 100%; min-height: 35px; border: 1px solid var(--line-strong); border-radius: 6px;
70
+ background: var(--surface); color: var(--ink); padding: 7px 9px; font-size: 13px;
71
+ }
72
+ textarea { resize: vertical; }
73
+ input[type="checkbox"] { width: auto; min-height: 0; accent-color: var(--accent); }
74
+ .shell { max-width: 1080px; margin: 0 auto; padding: 22px 20px 52px; }
75
+ body.embedded .shell { padding: 14px 15px 38px; }
76
+ .topbar { display: flex; align-items: flex-end; gap: 26px; border-bottom: 1px solid var(--line); margin-bottom: 22px; }
77
+ .brand { display: flex; align-items: center; gap: 10px; padding: 0 0 13px; flex: none; }
78
+ .brand-mark { width: 29px; height: 29px; display: grid; place-items: center; flex: none; color: var(--accent); border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); }
79
+ .brand-mark svg { width: 16px; height: 16px; }
80
+ .brand strong { display: block; font-size: 14px; line-height: 1.25; font-weight: 650; letter-spacing: -.01em; }
81
+ .brand small { display: block; margin-top: 2px; color: var(--muted); font-size: 11px; }
82
+ .topnav { display: flex; align-items: center; gap: 2px; min-width: 0; overflow-x: auto; flex: 1; scrollbar-width: none; -ms-overflow-style: none; }
83
+ .topnav::-webkit-scrollbar { display: none; }
84
+ .topnav .nav-item { display: inline-flex; align-items: center; gap: 7px; width: auto; border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: transparent; color: var(--muted); padding: 13px 11px 12px; text-align: center; font-size: 13px; white-space: nowrap; }
85
+ .topnav .nav-item:hover { color: var(--ink); background: transparent; }
86
+ .topnav .nav-item[aria-current="page"] { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; background: transparent; box-shadow: none; }
87
+ .nav-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--warn); display: none; }
88
+ .nav-item[data-dirty="true"] .nav-dot { display: block; }
89
+ .top-meta { margin-left: auto; padding-bottom: 15px; color: var(--muted); font-size: 11px; white-space: nowrap; }
90
+ .stage { min-width: 0; }
91
+ .stage-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
92
+ .stage-copy h1 { margin: 0; font-size: 25px; line-height: 1.18; font-weight: 650; letter-spacing: -.03em; }
93
+ .lead { margin: 7px 0 0; color: var(--muted); font-size: 13px; max-width: 62ch; }
94
+ .savebar { position: sticky; top: 0; z-index: 6; display: flex; align-items: center; justify-content: space-between; gap: 16px; border: 1px solid var(--line); border-left: 3px solid var(--line-strong); border-radius: 7px; background: var(--surface); padding: 10px 12px; margin: 17px 0 4px; }
95
+ .savebar[data-state="dirty"] { border-left-color: var(--warn); }
96
+ .savebar[data-state="saved"] { border-left-color: var(--ok); }
97
+ .savebar-main { display: flex; align-items: center; gap: 10px; min-width: 0; }
98
+ .savebar-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--muted); }
99
+ .savebar[data-state="dirty"] .savebar-dot { background: var(--warn); box-shadow: 0 0 0 3px color-mix(in srgb, var(--warn) 16%, transparent); }
100
+ .savebar[data-state="saved"] .savebar-dot { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 14%, transparent); }
101
+ .savebar-copy { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
102
+ .savebar-copy strong { font-size: 13px; font-weight: 600; }
103
+ .savebar-copy small { color: var(--muted); font-size: 12px; }
104
+ .savebar[data-state="dirty"] .savebar-copy strong { color: var(--warn); }
105
+ .savebar-actions { display: flex; flex-wrap: wrap; gap: 8px; flex: none; }
106
+ .section-state { margin-left: auto; color: var(--muted); font-size: 12px; white-space: nowrap; }
107
+ .section-state[data-state="dirty"] { color: var(--warn); font-weight: 600; }
108
+ .section-state[data-state="saved"] { color: var(--ok); }
109
+ .section-state[data-state="saving"] { color: var(--muted); }
110
+ .view { padding-top: 8px; }
111
+ .section { padding: 23px 0; border-top: 1px solid var(--line); }
112
+ .section:first-child { border-top: 0; padding-top: 14px; }
113
+ .section-head { display: flex; align-items: baseline; gap: 10px; }
114
+ .section-head h2 { margin: 0; font-size: 16px; font-weight: 650; letter-spacing: -.012em; }
115
+ .section-sub { margin: 6px 0 0; color: var(--muted); font-size: 12.5px; max-width: 72ch; }
116
+ .count { font-size: 11px; line-height: 18px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 0 7px; font-variant-numeric: tabular-nums; }
117
+ .row { display: grid; grid-template-columns: 163px minmax(0, 1fr); gap: 14px; align-items: start; padding: 8px 0; max-width: 900px; }
118
+ .row > label { padding-top: 8px; color: var(--muted); font-size: 12px; }
119
+ .row.wide { grid-template-columns: 163px minmax(0, 1fr); }
120
+ .row > div { min-width: 0; }
121
+ .checks { display: flex; flex-wrap: wrap; gap: 8px 16px; padding-top: 8px; }
122
+ .checks label { display: inline-flex; gap: 6px; align-items: center; color: var(--ink); font-size: 13px; }
123
+ .hint { color: var(--muted); font-size: 12px; margin: 6px 0 0; }
124
+ .rule-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 26px; margin-top: 6px; }
125
+ .rule { display: flex; align-items: flex-start; gap: 10px; border-bottom: 1px solid var(--line); padding: 12px 0; }
126
+ .rule input { margin-top: 2px; }
127
+ .rule .rt { display: flex; flex-direction: column; gap: 1px; }
128
+ .rule .rt b { font-size: 13px; font-weight: 600; }
129
+ .rule .rt small { color: var(--muted); font-size: 12px; }
130
+ .stay-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 26px; margin-top: 8px; }
131
+ .stay { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--line); padding: 12px 0; min-width: 0; }
132
+ .stay .rt { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
133
+ .stay .rt b { font-size: 13px; font-weight: 600; }
134
+ .stay .rt small { color: var(--muted); font-size: 12px; }
135
+ .stay select { width: auto; min-width: 112px; max-width: 132px; min-height: 32px; padding: 4px 7px; }
136
+ .subhead { margin: 18px 0 2px; font-size: 12px; font-weight: 600; color: var(--muted); }
137
+ .actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 15px; }
138
+ .save-status { color: var(--muted); font-size: 12px; margin-left: 4px; }
129
139
  .save-status.ok { color: var(--ok); }
130
140
  .save-status.bad { color: var(--bad); }
131
141
  .save-status.warn { color: var(--warn); }
132
-
133
- /* Key list */
134
142
  .keylist { display: flex; flex-direction: column; gap: 3px; margin: 0 0 6px; color: var(--muted); }
135
- .keylist code { color: var(--fg); font-variant-numeric: tabular-nums; }
136
-
137
- /* Advanced disclosure */
138
- details.advanced { margin: 14px 0 2px; border: 1px solid var(--line); border-radius: var(--radius); padding: 2px 14px 10px; background: var(--subtle); }
139
- details.advanced > summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: 13px; padding: 9px 0; list-style: none; user-select: none; }
143
+ .keylist code { color: var(--ink); font-variant-numeric: tabular-nums; }
144
+ details.advanced { margin: 16px 0 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 1px 0 6px; }
145
+ details.advanced > summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: 12.5px; padding: 10px 0; list-style: none; user-select: none; }
140
146
  details.advanced > summary::-webkit-details-marker { display: none; }
141
147
  details.advanced > summary::before { content: '▸ '; }
142
148
  details.advanced[open] > summary::before { content: '▾ '; }
143
- .advanced-group { margin: 8px 0 2px; }
149
+ .advanced-group { margin: 6px 0 2px; }
144
150
  .advanced-group h3 { font-size: 12px; font-weight: 600; color: var(--muted); margin: 10px 0 8px; }
145
-
146
- /* Channel lanes */
147
- .lane { border: 1px solid var(--line); border-radius: var(--radius); background: var(--subtle); margin: 0 0 10px; }
148
- .lane-head { display: flex; align-items: center; gap: 10px; padding: 10px 12px; flex-wrap: wrap; }
149
- .lane .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 18%, transparent); }
150
- .lane[data-enabled="0"] .dot { background: transparent; border: 1.5px solid var(--muted); box-shadow: none; }
151
+ .lane { border-bottom: 1px solid var(--line); margin: 0; }
152
+ .lane-head { display: flex; align-items: center; gap: 10px; padding: 11px 0; flex-wrap: wrap; }
153
+ .lane .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--ok); }
154
+ .lane[data-enabled="0"] .dot { background: transparent; border: 1.5px solid var(--muted); }
151
155
  .lane[data-enabled="0"] .lane-name { color: var(--muted); }
152
- .lane-name { font-size: 14px; font-weight: 600; }
153
- .tag { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 0 6px; }
156
+ .lane-name { font-size: 13.5px; font-weight: 600; }
157
+ .tag { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 5px; padding: 0 6px; }
154
158
  .lane-grow { flex: 1; }
155
159
  .switch { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
156
- .lane-toggle { padding: 5px 10px; min-height: 28px; }
157
- .lane-head button { padding: 5px 10px; min-height: 28px; }
158
- .lane-fields { padding: 6px 12px 12px; border-top: 1px dashed var(--line); }
159
- .channel-field { display: grid; grid-template-columns: 190px minmax(0, 1fr); gap: 8px 14px; align-items: center; margin: 0 0 9px; }
160
- .channel-field > label { color: var(--muted); font-size: 13px; }
160
+ .lane-toggle { padding: 5px 9px; min-height: 28px; }
161
+ .lane-head button { padding: 5px 9px; min-height: 28px; }
162
+ .lane-fields { padding: 4px 12px 12px; border-top: 1px dashed var(--line); background: var(--surface-muted); }
163
+ .channel-field { display: grid; grid-template-columns: 175px minmax(0, 1fr); gap: 8px 14px; align-items: center; margin: 0 0 9px; }
164
+ .channel-field > label { color: var(--muted); font-size: 12.5px; }
161
165
  .channel-field .req { color: var(--bad); }
162
166
  .channel-add { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 14px; }
163
- .channel-add select { max-width: 260px; }
167
+ .channel-add select { max-width: 250px; }
164
168
  .empty-channel { border: 1px dashed var(--line-strong); border-radius: var(--radius); padding: 18px; color: var(--muted); font-size: 13px; text-align: center; }
165
-
166
- /* Test result breakdown */
167
169
  .test-result { margin-top: 10px; border-top: 1px dashed var(--line); padding-top: 10px; display: flex; flex-direction: column; gap: 5px; }
168
170
  .test-result .tr-title { font-size: 12.5px; font-weight: 600; }
169
171
  .test-result .tr-row { display: flex; align-items: center; gap: 8px; font-size: 12.5px; }
170
172
  .test-result .tr-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
171
173
  .test-result .tr-msg { color: var(--muted); font-size: 12px; }
172
-
173
- /* Mute lists */
174
- .lists { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
175
- @media (max-width: 720px) { .lists { grid-template-columns: 1fr; } .row { grid-template-columns: 1fr; } .channel-field { grid-template-columns: 1fr; } }
176
- .list-title { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); margin: 0 0 8px; }
177
- .list-title .count { font-size: 11px; line-height: 18px; border: 1px solid var(--line); border-radius: 999px; padding: 0 7px; font-variant-numeric: tabular-nums; }
178
- .list { max-height: 320px; overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); padding: 6px; }
179
- .item { display: flex; gap: 9px; align-items: flex-start; padding: 6px; border-radius: 8px; }
180
- .item:hover { background: var(--subtle); }
181
- .item .meta { min-width: 0; }
182
- .item .title { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
183
- .item .sub { color: var(--muted); font-size: 12px; line-height: 1.45; overflow-wrap: anywhere; word-break: break-word; }
174
+ .lists { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; margin-top: 10px; }
175
+ .lists > div { min-width: 0; }
176
+ .list-title { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 12.5px; color: var(--muted); margin: 0 0 8px; }
177
+ .list { min-width: 0; max-width: 100%; max-height: 320px; overflow-y: auto; overflow-x: hidden; border: 1px solid var(--line); border-radius: 6px; padding: 5px; background: var(--surface-muted); }
178
+ .item { display: flex; gap: 9px; align-items: flex-start; min-width: 0; max-width: 100%; overflow: hidden; padding: 6px; border-radius: 6px; }
179
+ .item:hover { background: var(--surface); }
180
+ .item > input { flex: none; }
181
+ .item .meta { min-width: 0; flex: 1 1 auto; overflow: hidden; }
182
+ .item .title { max-width: 100%; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
183
+ .item .sub { max-width: 100%; color: var(--muted); font-size: 12px; line-height: 1.45; overflow-wrap: anywhere; word-break: break-word; }
184
184
  .empty { color: var(--muted); padding: 10px; font-size: 13px; }
185
-
186
- .page-foot { color: var(--muted); font-size: 12px; margin-top: 30px; }
187
- code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
188
-
189
- @media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
190
-
185
+ .page-foot { color: var(--muted); font-size: 12px; margin-top: 30px; border-top: 1px solid var(--line); padding-top: 14px; }
186
+ code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .95em; }
187
+ .overview-hero { display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, .95fr); gap: 30px; border-bottom: 1px solid var(--line); padding: 20px 0 30px; }
188
+ .overview-copy h2 { margin: 0; max-width: 14ch; font-size: 28px; line-height: 1.2; font-weight: 650; letter-spacing: -.04em; }
189
+ .overview-copy p { max-width: 43ch; margin: 12px 0 0; color: var(--muted); font-size: 13px; }
190
+ .quick-links { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 20px; }
191
+ .quick-link { background: transparent; border-color: var(--line-strong); color: var(--ink); }
192
+ .quick-link:hover { border-color: var(--accent); color: var(--accent); }
193
+ .route-map { align-self: start; border: 1px solid var(--line); background: var(--surface); }
194
+ .route-source { padding: 17px 16px 15px; border-bottom: 1px solid var(--line); }
195
+ .route-source-label { display: block; color: var(--muted); font-size: 11px; }
196
+ .route-source strong { display: block; margin-top: 5px; font-size: 14px; font-weight: 600; }
197
+ .route-source small { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; }
198
+ .route-paths { display: grid; }
199
+ .route-row { display: grid; grid-template-columns: 8px minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
200
+ .route-row:last-child { border-bottom: 0; }
201
+ .route-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
202
+ .route-row:nth-child(2) .route-dot { background: var(--ok); }
203
+ .route-copy strong { display: block; font-size: 13px; font-weight: 600; }
204
+ .route-copy small { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; }
205
+ .route-state { font-size: 12px; color: var(--muted); }
206
+ .route-state[data-state="ok"] { color: var(--ok); }
207
+ .route-state[data-state="warn"] { color: var(--warn); }
208
+ .route-state[data-state="bad"] { color: var(--bad); }
209
+ .overview-summary { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; padding: 24px 0 0; }
210
+ .summary-block h2 { margin: 0 0 10px; font-size: 14px; font-weight: 600; }
211
+ .healthstrip { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; }
212
+ .pill { display: inline-flex; align-items: center; gap: 5px; border: 1px solid var(--line); border-radius: 999px; padding: 3px 9px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
213
+ .pill.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 42%, var(--line)); }
214
+ .pill.bad { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 42%, var(--line)); }
215
+ .pill.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 42%, var(--line)); }
216
+ .summary-text { margin: 0; color: var(--muted); font-size: 13px; }
191
217
  #toast {
192
218
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
193
- background: var(--fg); color: var(--bg); padding: 8px 14px; border-radius: 999px;
219
+ background: var(--ink); color: var(--canvas); padding: 8px 14px; border-radius: 999px;
194
220
  font-size: 13px; opacity: 0; pointer-events: none; transition: opacity .18s ease;
195
221
  max-width: 80vw; text-align: center; z-index: 10;
196
222
  }
197
223
  #toast.show { opacity: 1; }
198
224
  #toast.bad { background: var(--bad); color: #fff; }
225
+ @media (max-width: 900px) {
226
+ .shell { padding: 15px 16px 42px; }
227
+ .topbar { display: block; }
228
+ .brand { padding-bottom: 10px; }
229
+ .topnav { width: 100%; border-top: 1px solid var(--line); }
230
+ .topnav .nav-item { padding: 10px 10px 9px; }
231
+ .top-meta { display: none; }
232
+ .overview-hero { grid-template-columns: 1fr; gap: 22px; }
233
+ .overview-copy h2 { max-width: 18ch; font-size: 25px; }
234
+ }
235
+ @media (max-width: 720px) {
236
+ .savebar { align-items: flex-start; flex-direction: column; }
237
+ .savebar-actions { width: 100%; }
238
+ .savebar-actions button { flex: 1 1 auto; }
239
+ .row, .row.wide { grid-template-columns: 1fr; gap: 5px; }
240
+ .row > label { padding-top: 0; }
241
+ .rule-grid, .lists, .overview-summary { grid-template-columns: 1fr; }
242
+ .stay-grid { grid-template-columns: 1fr; }
243
+ .channel-field { grid-template-columns: 1fr; }
244
+ .stage-head { flex-direction: column; }
245
+ }
246
+ @media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
199
247
  </style>
200
248
  </head>
201
249
  <body class="${embedded ? 'embedded' : ''}">
202
- <main>
203
- <header class="page-head">
204
- <h1><svg xmlns="http://www.w3.org/2000/svg" width="21" height="21" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M10.268 21a2 2 0 0 0 3.464 0"/><path d="M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326"/></svg>推送通知</h1>
205
- <p class="lead">把 DSH 的回复、审批和选择请求推送到手机。默认使用 Bark,也可同时接入更多渠道;配置只保存在本机。</p>
206
- <div class="healthstrip" id="status"><span class="pill">读取中…</span></div>
207
- <p class="hint" id="warnings" hidden></p>
250
+ <main class="shell">
251
+ <header class="topbar">
252
+ <div class="brand">
253
+ <span class="brand-mark" aria-hidden="true"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M10.268 21a2 2 0 0 0 3.464 0"/><path d="M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326"/></svg></span>
254
+ <div><strong>Bark Push</strong><small>通知设置</small></div>
255
+ </div>
256
+ <nav class="topnav" aria-label="通知设置">
257
+ <button class="nav-item" type="button" data-goto="overview" aria-current="page"><span>概览</span><span class="nav-dot" aria-hidden="true"></span></button>
258
+ <button class="nav-item" type="button" data-goto="delivery"><span>推送渠道</span><span class="nav-dot" aria-hidden="true"></span></button>
259
+ <button class="nav-item" type="button" data-goto="rules"><span>通知规则</span><span class="nav-dot" aria-hidden="true"></span></button>
260
+ <button class="nav-item" type="button" data-goto="browser"><span>浏览器通知</span><span class="nav-dot" aria-hidden="true"></span></button>
261
+ <button class="nav-item" type="button" data-goto="mute"><span>静音管理</span><span class="nav-dot" aria-hidden="true"></span></button>
262
+ </nav>
263
+ <span class="top-meta">仅保存在本机</span>
208
264
  </header>
209
265
 
210
- <section class="section" id="section-default">
211
- <div class="section-head"><h2>默认渠道 · Bark</h2></div>
266
+ <div class="stage">
267
+ <header class="stage-head">
268
+ <div class="stage-copy">
269
+ <h1 id="stageTitle">概览</h1>
270
+ <p class="lead" id="stageLead">先确认通知链路,再进入具体设置。</p>
271
+ </div>
272
+ </header>
273
+
274
+ <div class="savebar" id="savebar" data-state="loading" role="status" aria-live="polite">
275
+ <div class="savebar-main">
276
+ <span class="savebar-dot" aria-hidden="true"></span>
277
+ <div class="savebar-copy">
278
+ <strong id="saveStateLabel">正在读取配置…</strong>
279
+ <small id="saveStateHint">读取完成后会显示保存状态</small>
280
+ </div>
281
+ </div>
282
+ <div class="savebar-actions">
283
+ <button class="primary" id="saveAll" type="button" disabled>保存更改</button>
284
+ <button id="discardAll" type="button" disabled>放弃</button>
285
+ </div>
286
+ </div>
287
+
288
+ <section class="view" id="panel-overview">
289
+ <div class="overview-hero">
290
+ <div class="overview-copy">
291
+ <h2>让每条重要通知,都有明确的去处。</h2>
292
+ <p>DSH 的回复、审批和选择请求,可以同时送达 Bark 与浏览器。两个通道独立开关,互不影响;配置是否有未保存的修改,始终写在页面上方。</p>
293
+ <div class="quick-links">
294
+ <button class="quick-link" type="button" data-goto="delivery">配置推送渠道</button>
295
+ <button class="quick-link" type="button" data-goto="rules">选择通知事件</button>
296
+ <button class="quick-link" type="button" data-goto="browser">设置浏览器通知</button>
297
+ </div>
298
+ </div>
299
+ <div class="route-map" aria-label="通知链路">
300
+ <div class="route-source">
301
+ <span class="route-source-label">事件来源</span>
302
+ <strong>DSH 会话</strong>
303
+ <small>回复、批准、选择</small>
304
+ </div>
305
+ <div class="route-paths">
306
+ <div class="route-row">
307
+ <span class="route-dot" aria-hidden="true"></span>
308
+ <div class="route-copy"><strong>Bark 推送</strong><small id="overviewPushMeta">正在读取…</small></div>
309
+ <span class="route-state" id="overviewPushState">…</span>
310
+ </div>
311
+ <div class="route-row">
312
+ <span class="route-dot" aria-hidden="true"></span>
313
+ <div class="route-copy"><strong>浏览器通知</strong><small id="overviewBrowserMeta">等待授权</small></div>
314
+ <span class="route-state" id="overviewBrowserState">…</span>
315
+ </div>
316
+ </div>
317
+ </div>
318
+ </div>
319
+ <div class="overview-summary">
320
+ <section class="summary-block">
321
+ <h2>当前状态</h2>
322
+ <div class="healthstrip" id="status"><span class="pill">读取中…</span></div>
323
+ <p class="hint" id="warnings" hidden></p>
324
+ </section>
325
+ <section class="summary-block">
326
+ <h2>最近动态</h2>
327
+ <p class="summary-text" id="overviewLast">还没有投递记录</p>
328
+ </section>
329
+ </div>
330
+ </section>
331
+
332
+ <section class="view" id="panel-delivery" hidden>
333
+ <section class="section" id="section-default">
334
+ <div class="section-head"><h2>默认渠道 · Bark</h2><span class="section-state" data-section-state="default">已保存</span></div>
212
335
  <p class="section-sub">Bark 是内置的第一渠道。填入服务器与 Device Key 即可使用;其余按需展开「高级选项」。</p>
213
336
  <div class="row"><label for="server">Bark Server</label><input id="server" type="text" placeholder="https://api.day.app"></div>
214
337
  <div class="row"><label>已配置 Device Key</label><div><div class="keylist" id="keylist"></div><p class="hint">页面只显示掩码;新增密钥逐行粘贴,保存后不再显示完整值。</p></div></div>
@@ -281,7 +404,7 @@ export function renderUiPage({ version, embedded = false }) {
281
404
  </details>
282
405
 
283
406
  <div class="actions">
284
- <button class="primary" id="save">保存全部更改</button>
407
+ <button class="primary" id="save">保存默认渠道</button>
285
408
  <button id="test">测试默认渠道</button>
286
409
  <button id="reset" class="danger">恢复默认</button>
287
410
  <button id="addKeys">追加密钥</button>
@@ -291,8 +414,23 @@ export function renderUiPage({ version, embedded = false }) {
291
414
  <div class="test-result" id="barkTestResult" hidden></div>
292
415
  </section>
293
416
 
294
- <section class="section" id="section-rules">
295
- <div class="section-head"><h2>通知规则</h2></div>
417
+ <section class="section" id="section-channels">
418
+ <div class="section-head"><h2>渠道</h2><span class="count" id="channelCount">0</span><span class="section-state" data-section-state="channels">已保存</span></div>
419
+ <p class="section-sub">Bark 之外可同时启用多个渠道,互不影响;点「参数」展开填写,点「测试」会先保存当前配置,再单独验证该渠道。</p>
420
+ <div id="channelList"></div>
421
+ <div class="channel-add">
422
+ <select id="channelTypeSelect" aria-label="渠道类型"></select>
423
+ <button id="addChannel">添加渠道</button>
424
+ <button id="saveChannels">保存渠道</button>
425
+ <span id="channelsSaveStatus" class="save-status" role="status" aria-live="polite"></span>
426
+ </div>
427
+ </section>
428
+
429
+ </section>
430
+
431
+ <section class="view" id="panel-rules" hidden>
432
+ <section class="section" id="section-rules">
433
+ <div class="section-head"><h2>通知规则</h2><span class="section-state" data-section-state="rules">已保存</span></div>
296
434
  <p class="section-sub">选择哪些事件需要推送。总开关关闭后不发送任何通知。</p>
297
435
  <div class="rule-grid">
298
436
  <label class="rule"><input id="enabled" type="checkbox"><span class="rt"><b>总开关</b><small>关闭后暂停全部推送</small></span></label>
@@ -302,25 +440,75 @@ export function renderUiPage({ version, embedded = false }) {
302
440
  <label class="rule"><input id="includeSubagents" type="checkbox"><span class="rt"><b>包含子代理</b><small>子代理会话也推送</small></span></label>
303
441
  </div>
304
442
  <div class="actions">
305
- <button id="saveRules">保存全部更改</button>
443
+ <button id="saveRules">保存规则</button>
306
444
  <span id="rulesSaveStatus" class="save-status" role="status" aria-live="polite"></span>
307
445
  </div>
308
446
  </section>
309
447
 
310
- <section class="section" id="section-channels">
311
- <div class="section-head"><h2>渠道</h2><span class="count" id="channelCount">0</span></div>
312
- <p class="section-sub">Bark 之外可同时启用多个渠道,互不影响;点「参数」展开填写,点「测试」单独验证该渠道。</p>
313
- <div id="channelList"></div>
314
- <div class="channel-add">
315
- <select id="channelTypeSelect" aria-label="渠道类型"></select>
316
- <button id="addChannel">添加渠道</button>
317
- <button id="saveChannels">保存全部更改</button>
318
- <span id="channelsSaveStatus" class="save-status" role="status" aria-live="polite"></span>
319
- </div>
320
- </section>
448
+ </section>
321
449
 
322
- <section class="section" id="section-mute">
323
- <div class="section-head"><h2>静音管理</h2></div>
450
+ <section class="view" id="panel-browser" hidden>
451
+ <section class="section" id="section-browser">
452
+ <div class="section-head"><h2>浏览器通知</h2><span class="section-state" data-section-state="browser">已保存</span></div>
453
+ <p class="section-sub">通过浏览器系统通知提醒回复、审批和选择请求;不依赖 Bark 或任何推送渠道。浏览器通知只在 DSH 页面打开时生效。</p>
454
+ <div class="healthstrip" id="browserPermissionStatus"><span class="pill">检查中…</span></div>
455
+ <div class="actions">
456
+ <button id="requestNotifyPermission">请求通知权限</button>
457
+ <button id="testBrowserNotify">发送测试通知</button>
458
+ </div>
459
+ <div class="rule-grid" style="margin-top:14px">
460
+ <label class="rule"><input id="browserNotifyEnabled" type="checkbox"><span class="rt"><b>启用浏览器通知</b><small>与推送通知总开关独立</small></span></label>
461
+ <label class="rule"><input id="browserNotifyOnReply" type="checkbox"><span class="rt"><b>回复完成</b><small>一轮结束时提醒</small></span></label>
462
+ <label class="rule"><input id="browserNotifyOnApproval" type="checkbox"><span class="rt"><b>需要批准</b><small>工具请求授权时提醒</small></span></label>
463
+ <label class="rule"><input id="browserNotifyOnQuestion" type="checkbox"><span class="rt"><b>等待选择</b><small>等待你回答时提醒</small></span></label>
464
+ <label class="rule"><input id="browserNotifySkipForeground" type="checkbox"><span class="rt"><b>前台免打扰</b><small>当前会话且页面在前台时不提醒</small></span></label>
465
+ </div>
466
+ <h3 class="subhead">通知停留</h3>
467
+ <p class="hint">自动消失的时长由浏览器和操作系统决定;常驻会保留到手动关闭。</p>
468
+ <div class="stay-grid">
469
+ <label class="stay"><span class="rt"><b>回复完成</b></span><select id="browserNotifyReplyPersistent" aria-label="回复完成通知停留">
470
+ <option value="auto">自动消失</option>
471
+ <option value="persistent">常驻</option>
472
+ </select></label>
473
+ <label class="stay"><span class="rt"><b>需要批准</b></span><select id="browserNotifyApprovalPersistent" aria-label="需要批准通知停留">
474
+ <option value="auto">自动消失</option>
475
+ <option value="persistent">常驻</option>
476
+ </select></label>
477
+ <label class="stay"><span class="rt"><b>等待选择</b></span><select id="browserNotifyQuestionPersistent" aria-label="等待选择通知停留">
478
+ <option value="auto">自动消失</option>
479
+ <option value="persistent">常驻</option>
480
+ </select></label>
481
+ </div>
482
+ <p class="hint">浏览器通知的静音策略在「静音管理」中设置。</p>
483
+ </section>
484
+
485
+ <section class="section" id="section-browser-templates">
486
+ <div class="section-head"><h2>正文模板</h2><span class="section-state" data-section-state="browser">已保存</span></div>
487
+ <p class="section-sub">通知标题固定为会话标题,正文由模板生成。支持占位符:<code>{status}</code>、<code>{session}</code>、<code>{summary}</code>、<code>{turn}</code>、<code>{tool}</code>、<code>{reason}</code>、<code>{question}</code>、<code>{questionCount}</code>、<code>{description}</code>。</p>
488
+ <div class="row wide"><label for="browserNotifyReplyBody">回复完成</label><textarea id="browserNotifyReplyBody" rows="2"></textarea><p class="hint" id="browserReplyPreview"></p></div>
489
+ <div class="row wide"><label for="browserNotifyApprovalBody">需要批准</label><textarea id="browserNotifyApprovalBody" rows="2"></textarea><p class="hint" id="browserApprovalPreview"></p></div>
490
+ <div class="row wide"><label for="browserNotifyQuestionBody">等待选择</label><textarea id="browserNotifyQuestionBody" rows="2"></textarea><p class="hint" id="browserQuestionPreview"></p></div>
491
+ <div class="row"><label for="browserNotifyMaxBodyLength">正文最大长度</label><input id="browserNotifyMaxBodyLength" type="number" min="32" max="500"></div>
492
+ <div class="actions">
493
+ <button class="primary" id="saveBrowser">保存浏览器设置</button>
494
+ <span id="browserSaveStatus" class="save-status" role="status" aria-live="polite"></span>
495
+ </div>
496
+ </section>
497
+
498
+ </section>
499
+
500
+ <section class="view" id="panel-mute" hidden>
501
+ <section class="section" id="section-mute-policy">
502
+ <div class="section-head"><h2>静音策略</h2><span class="section-state" data-section-state="mute">已保存</span></div>
503
+ <p class="section-sub">浏览器通知默认复用推送通知的工作区与会话静音;关闭复用后使用独立的浏览器静音集合,不会影响 Bark 推送。</p>
504
+ <div class="row" style="margin-top:10px"><label>浏览器通知</label><div class="checks"><label><input id="browserNotifyUsePushMutes" type="checkbox"> 复用推送通知的工作区 / 会话静音</label></div></div>
505
+ <div class="actions">
506
+ <button id="saveMute">保存静音策略</button>
507
+ <span id="muteSaveStatus" class="save-status" role="status" aria-live="polite"></span>
508
+ </div>
509
+ </section>
510
+ <section class="section" id="section-mute">
511
+ <div class="section-head"><h2>静音管理</h2><span class="section-state">即时生效</span></div>
324
512
  <p class="section-sub">工作区静音优先于会话静音;任一层级静音即停止推送,状态持久化。会话列表与 DSH 左侧会话栏采用同一套可见性规则。</p>
325
513
  <div class="lists">
326
514
  <div>
@@ -335,9 +523,29 @@ export function renderUiPage({ version, embedded = false }) {
335
523
  </div>
336
524
  </section>
337
525
 
338
- <footer class="page-foot">dsh-bark-push v${safeVersion} · 只向这里配置的推送渠道发送内容。</footer>
526
+ <section class="section" id="section-browser-mute">
527
+ <div class="section-head"><h2>浏览器通知静音管理</h2><span class="section-state">即时生效</span></div>
528
+ <p class="section-sub" id="browserMuteHint">当前复用推送通知的静音设置。关闭上方「复用推送通知的工作区/会话静音」后,可在这里管理独立的浏览器通知静音。</p>
529
+ <div class="lists" id="browserMuteLists">
530
+ <div>
531
+ <p class="list-title">工作区</p>
532
+ <div class="list" id="browserWorkspaces"><div class="empty">读取中…</div></div>
533
+ </div>
534
+ <div>
535
+ <p class="list-title">会话 <span class="count" id="browserSessionCount">0</span></p>
536
+ <input id="browserSessionSearch" type="text" placeholder="按标题或 ID 过滤" style="margin-bottom:8px">
537
+ <div class="list" id="browserSessions"><div class="empty">读取中…</div></div>
538
+ </div>
539
+ </div>
540
+ </section>
541
+
542
+ </section>
543
+
544
+ <footer class="page-foot">dsh-bark-push v${safeVersion} · 所有通知配置仅保存在本机。</footer>
545
+ </div>
339
546
  </main>
340
547
  <div id="toast" role="status" aria-live="polite"></div>
548
+
341
549
  <script>
342
550
  (() => {
343
551
  'use strict';
@@ -354,6 +562,168 @@ export function renderUiPage({ version, embedded = false }) {
354
562
  let toastTimer = null;
355
563
  let channelTypes = [];
356
564
  let channelDraft = [];
565
+ let savedForm = null;
566
+ let lastSavedAt = '';
567
+ let saveBusy = false;
568
+ let saveError = '';
569
+
570
+ const BROWSER_SAMPLES = {
571
+ reply: { status: '回复完成', session: '示例会话', summary: '已完成会话列表修复', turn: '3', description: '已完成会话列表修复' },
572
+ approval: { status: '需要批准', session: '示例会话', tool: 'Bash', reason: '写入工作区文件', description: 'Bash · 写入工作区文件' },
573
+ question: { status: '等待选择', session: '示例会话', question: '请选择部署环境', questionCount: '2', description: '请选择部署环境' }
574
+ };
575
+
576
+ const VIEW_META = {
577
+ overview: { title: '概览', lead: '先确认通知链路,再进入具体设置。' },
578
+ delivery: { title: '推送渠道', lead: '配置 Bark 与额外渠道,确保通知能送达。' },
579
+ rules: { title: '通知规则', lead: '决定哪些事件需要通知。' },
580
+ browser: { title: '浏览器通知', lead: '控制 DSH 页面打开时的浏览器提醒。' },
581
+ mute: { title: '静音管理', lead: '按工作区或会话停止特定通知。' }
582
+ };
583
+ const VIEW_IDS = {
584
+ overview: 'panel-overview',
585
+ delivery: 'panel-delivery',
586
+ rules: 'panel-rules',
587
+ browser: 'panel-browser',
588
+ mute: 'panel-mute'
589
+ };
590
+
591
+ function setView(name, updateHash) {
592
+ const target = VIEW_META[name] ? name : 'overview';
593
+ for (const [key, id] of Object.entries(VIEW_IDS)) {
594
+ const panel = $(id);
595
+ if (panel) panel.hidden = key !== target;
596
+ }
597
+ document.querySelectorAll('.topnav [data-goto]').forEach((button) => {
598
+ button.setAttribute('aria-current', button.dataset.goto === target ? 'page' : 'false');
599
+ });
600
+ const meta = VIEW_META[target];
601
+ const title = $('stageTitle');
602
+ const lead = $('stageLead');
603
+ if (title) text(title, meta.title);
604
+ if (lead) text(lead, meta.lead);
605
+ if (updateHash) {
606
+ try {
607
+ const url = new URL(window.location.href);
608
+ url.searchParams.set('view', target);
609
+ window.history.replaceState(null, '', url.pathname + url.search + url.hash);
610
+ } catch (_) { /* hash updates are optional */ }
611
+ }
612
+ postHeight();
613
+ }
614
+
615
+ function notificationState() {
616
+ if (typeof Notification === 'undefined' || typeof Notification.requestPermission !== 'function') {
617
+ return { key: 'unsupported', label: '当前浏览器不支持通知', cls: 'bad' };
618
+ }
619
+ const permission = Notification.permission;
620
+ if (permission === 'granted') return { key: 'granted', label: '浏览器通知权限:已授权', cls: 'ok' };
621
+ if (permission === 'denied') return { key: 'denied', label: '浏览器通知权限:已拒绝', cls: 'bad' };
622
+ return { key: 'default', label: '浏览器通知权限:未授权', cls: 'warn' };
623
+ }
624
+
625
+ function renderBrowserPermission() {
626
+ const box = $('browserPermissionStatus');
627
+ if (!box) return;
628
+ const state = notificationState();
629
+ box.replaceChildren();
630
+ const pill = document.createElement('span');
631
+ pill.className = 'pill ' + state.cls;
632
+ text(pill, state.label);
633
+ box.append(pill);
634
+ const button = $('requestNotifyPermission');
635
+ if (button) {
636
+ button.disabled = state.key === 'unsupported' || state.key === 'granted';
637
+ button.textContent = state.key === 'granted' ? '已授权' : '请求通知权限';
638
+ }
639
+ if (state.key === 'denied') {
640
+ const hint = document.createElement('span');
641
+ hint.className = 'hint';
642
+ text(hint, '请在浏览器站点设置中允许通知后重新打开页面。');
643
+ box.append(hint);
644
+ }
645
+ syncOverview(current);
646
+ }
647
+
648
+ function renderTemplatePreview(kind) {
649
+ const input = $('browserNotify' + kind[0].toUpperCase() + kind.slice(1) + 'Body');
650
+ const target = $('browser' + kind[0].toUpperCase() + kind.slice(1) + 'Preview');
651
+ if (!input || !target) return;
652
+ const template = input.value || '';
653
+ const values = BROWSER_SAMPLES[kind] || {};
654
+ let preview = template.replace(/\\{([A-Za-z][A-Za-z0-9]*)\\}/g, (match, name) =>
655
+ Object.prototype.hasOwnProperty.call(values, name) ? String(values[name] ?? '') : match);
656
+ const unknown = [];
657
+ template.replace(/\\{([A-Za-z][A-Za-z0-9]*)\\}/g, (match, name) => {
658
+ if (!Object.prototype.hasOwnProperty.call(values, name)) unknown.push(match);
659
+ return match;
660
+ });
661
+ text(target, '预览:' + (preview.trim() || '(空模板,将使用默认值)') + (unknown.length ? ' 未知占位符:' + unknown.join('、') : ''));
662
+ }
663
+
664
+ function renderTemplatePreviews() {
665
+ renderTemplatePreview('reply');
666
+ renderTemplatePreview('approval');
667
+ renderTemplatePreview('question');
668
+ }
669
+
670
+ function updateBrowserMuteVisibility() {
671
+ const reuse = $('browserNotifyUsePushMutes');
672
+ const lists = $('browserMuteLists');
673
+ const hint = $('browserMuteHint');
674
+ if (!reuse || !lists || !hint) return;
675
+ const independent = !reuse.checked;
676
+ lists.hidden = !independent;
677
+ text(hint, independent
678
+ ? '当前使用独立的浏览器通知静音集合,不影响 Bark 推送。'
679
+ : '当前复用推送通知的静音设置。关闭上方「复用推送通知的工作区/会话静音」后,可在这里管理独立的浏览器通知静音。');
680
+ }
681
+
682
+ async function requestBrowserPermission() {
683
+ const state = notificationState();
684
+ if (state.key === 'unsupported') {
685
+ toast('当前浏览器不支持通知', true);
686
+ return;
687
+ }
688
+ try {
689
+ const permission = await Notification.requestPermission();
690
+ renderBrowserPermission();
691
+ toast(permission === 'granted' ? '浏览器通知权限已授予' : '浏览器通知权限未授予', permission !== 'granted');
692
+ } catch (error) {
693
+ if (window.parent && window.parent !== window) {
694
+ try {
695
+ window.parent.postMessage({ type: 'dsh-bark-push:browser-permission-request' }, window.location.origin);
696
+ toast('已向浏览器请求通知权限');
697
+ return;
698
+ } catch (_) { /* fall through to error */ }
699
+ }
700
+ toast('请求通知权限失败:' + error.message, true);
701
+ }
702
+ }
703
+
704
+ function testBrowserNotification() {
705
+ const state = notificationState();
706
+ if (state.key !== 'granted') {
707
+ toast('请先授予浏览器通知权限', true);
708
+ return;
709
+ }
710
+ if (window.parent && window.parent !== window) {
711
+ try {
712
+ window.parent.postMessage({ type: 'dsh-bark-push:browser-test' }, window.location.origin);
713
+ toast('测试通知已发送');
714
+ return;
715
+ } catch (_) { /* fall through to a local Notification */ }
716
+ }
717
+ try {
718
+ new Notification('DSH 浏览器通知测试', { body: '浏览器通知已开启。' });
719
+ toast('测试通知已发送');
720
+ } catch (error) {
721
+ toast('发送测试通知失败:' + error.message, true);
722
+ }
723
+ }
724
+
725
+ renderBrowserPermission();
726
+ renderTemplatePreviews();
357
727
 
358
728
  function toast(message, bad) {
359
729
  const text = message == null ? '' : String(message);
@@ -392,8 +762,157 @@ export function renderUiPage({ version, embedded = false }) {
392
762
  return pad(d.getHours()) + ':' + pad(d.getMinutes()) + ':' + pad(d.getSeconds());
393
763
  }
394
764
 
765
+ const SECTION_KEYS = {
766
+ default: [
767
+ 'server', 'group', 'icon', 'soundReply', 'soundApproval', 'soundQuestion',
768
+ 'levelReply', 'levelApproval', 'levelQuestion', 'titlePrefix', 'titleMode',
769
+ 'maxTitleLength', 'maxBodyLength', 'timeoutMs', 'maxRetries', 'retryDelayMs',
770
+ 'publicBaseUrl', 'linkToSession', 'trace', '__pendingDeviceKeys',
771
+ ],
772
+ rules: ['enabled', 'notifyOnReply', 'notifyOnApproval', 'notifyOnQuestion', 'includeSubagents'],
773
+ channels: ['channels'],
774
+ browser: [
775
+ 'browserNotifyEnabled', 'browserNotifyOnReply', 'browserNotifyOnApproval',
776
+ 'browserNotifyOnQuestion', 'browserNotifyReplyPersistent', 'browserNotifyApprovalPersistent',
777
+ 'browserNotifyQuestionPersistent', 'browserNotifySkipForeground',
778
+ 'browserNotifyReplyBody', 'browserNotifyApprovalBody', 'browserNotifyQuestionBody',
779
+ 'browserNotifyMaxBodyLength',
780
+ ],
781
+ mute: ['browserNotifyUsePushMutes'],
782
+ };
783
+
784
+ function pendingKeyText() {
785
+ const input = $('newKeys');
786
+ return input ? input.value.trim() : '';
787
+ }
788
+
789
+ function readForm() {
790
+ try {
791
+ const form = collect();
792
+ form.__pendingDeviceKeys = pendingKeyText();
793
+ return form;
794
+ } catch (_) { return null; }
795
+ }
796
+
797
+ function formSignature(form) {
798
+ return JSON.stringify(form ?? null);
799
+ }
800
+
801
+ function isFormDirty() {
802
+ return savedForm !== null && formSignature(readForm()) !== formSignature(savedForm);
803
+ }
804
+
805
+ function hasConfigChanges() {
806
+ if (savedForm === null) return false;
807
+ const current = readForm();
808
+ if (!current) return false;
809
+ const currentConfig = { ...current };
810
+ const savedConfig = { ...savedForm };
811
+ delete currentConfig.__pendingDeviceKeys;
812
+ delete savedConfig.__pendingDeviceKeys;
813
+ return formSignature(currentConfig) !== formSignature(savedConfig);
814
+ }
815
+
816
+ function sectionIsDirty(name) {
817
+ if (savedForm === null) return false;
818
+ const form = readForm();
819
+ const keys = SECTION_KEYS[name];
820
+ if (!form || !keys) return false;
821
+ return keys.some((key) => JSON.stringify(form[key]) !== JSON.stringify(savedForm[key]));
822
+ }
823
+
824
+ function renderSaveState() {
825
+ const bar = $('savebar');
826
+ if (!bar) return;
827
+ const loading = savedForm === null;
828
+ const dirty = !loading && formSignature(readForm()) !== formSignature(savedForm);
829
+ const state = loading ? 'loading' : dirty ? 'dirty' : 'saved';
830
+ bar.dataset.state = state;
831
+
832
+ const pendingKeys = pendingKeyText().length > 0;
833
+ const label = $('saveStateLabel');
834
+ const hint = $('saveStateHint');
835
+ if (label) {
836
+ text(label, saveBusy ? '正在保存…' : saveError ? '保存失败' : loading ? '正在读取配置…' : pendingKeys ? '有未追加的 Device Key' : dirty ? '有未保存的更改' : '全部更改已保存');
837
+ }
838
+ if (hint) {
839
+ text(hint, saveBusy ? '正在写入配置文件…' : saveError ? saveError : loading ? '读取完成后会显示保存状态' : pendingKeys ? '先点击「追加密钥」把密钥加入配置' : dirty ? '点击「保存更改」写入配置' : (lastSavedAt ? '上次保存 ' + lastSavedAt : '当前配置已载入,尚未修改'));
840
+ }
841
+
842
+ const saveAll = $('saveAll');
843
+ const discard = $('discardAll');
844
+ if (saveAll) saveAll.disabled = saveBusy || loading || !dirty || pendingKeys;
845
+ if (discard) discard.disabled = saveBusy || loading || !dirty;
846
+ const sectionButtons = {
847
+ save: 'default',
848
+ saveChannels: 'channels',
849
+ saveRules: 'rules',
850
+ saveBrowser: 'browser',
851
+ saveMute: 'mute'
852
+ };
853
+ for (const [id, section] of Object.entries(sectionButtons)) {
854
+ const button = $(id);
855
+ if (button) button.disabled = saveBusy || loading || !sectionIsDirty(section) || pendingKeys;
856
+ }
857
+
858
+ const sectionStatuses = {
859
+ barkSaveStatus: 'default',
860
+ rulesSaveStatus: 'rules',
861
+ channelsSaveStatus: 'channels',
862
+ browserSaveStatus: 'browser',
863
+ muteSaveStatus: 'mute'
864
+ };
865
+ for (const [id, section] of Object.entries(sectionStatuses)) {
866
+ const node = $(id);
867
+ if (!node) continue;
868
+ const sectionDirty = sectionIsDirty(section);
869
+ const inline = saveBusy ? '保存中…' : saveError ? saveError : loading ? '' : sectionDirty ? '有未保存的更改' : (lastSavedAt ? '已保存 ' + lastSavedAt : '已保存');
870
+ node.textContent = inline;
871
+ node.className = 'save-status ' + (saveBusy || saveError || sectionDirty ? 'warn' : 'ok');
872
+ }
873
+
874
+ document.querySelectorAll('[data-section-state]').forEach((node) => {
875
+ const name = node.getAttribute('data-section-state');
876
+ const sectionDirty = sectionIsDirty(name);
877
+ node.dataset.state = loading ? '' : saveBusy ? 'saving' : sectionDirty ? 'dirty' : 'saved';
878
+ text(node, loading ? '读取中…' : saveBusy ? '保存中…' : sectionDirty ? '未保存' : '已保存');
879
+ });
880
+
881
+ const viewDirty = {
882
+ overview: false,
883
+ delivery: sectionIsDirty('default') || sectionIsDirty('channels'),
884
+ rules: sectionIsDirty('rules'),
885
+ browser: sectionIsDirty('browser'),
886
+ mute: sectionIsDirty('mute')
887
+ };
888
+ document.querySelectorAll('.topnav [data-goto]').forEach((button) => {
889
+ button.dataset.dirty = viewDirty[button.dataset.goto] ? 'true' : 'false';
890
+ });
891
+ }
892
+
893
+ function captureSavedForm(stamp) {
894
+ savedForm = readForm();
895
+ if (stamp) lastSavedAt = stamp;
896
+ saveError = '';
897
+ saveBusy = false;
898
+ renderSaveState();
899
+ }
900
+
901
+ function refreshDirtyState() {
902
+ if (savedForm !== null) {
903
+ saveError = '';
904
+ renderSaveState();
905
+ }
906
+ }
907
+
908
+ function saveFailed(message) {
909
+ saveBusy = false;
910
+ saveError = message || '保存失败';
911
+ renderSaveState();
912
+ }
913
+
395
914
  function markChannelsDirty() {
396
- setSaveStatus('channelsSaveStatus', '有未保存的更改,点“保存全部更改”生效', 'warn');
915
+ refreshDirtyState();
397
916
  }
398
917
 
399
918
  async function requestAllowFail(path, body) {
@@ -615,6 +1134,7 @@ export function renderUiPage({ version, embedded = false }) {
615
1134
  }
616
1135
 
617
1136
  async function testChannel(id, button, info) {
1137
+ if (pendingKeyText()) { toast('请先点击「追加密钥」添加新增密钥', true); return; }
618
1138
  button.disabled = true;
619
1139
  try {
620
1140
  const saved = await request(api.config, collect());
@@ -623,6 +1143,7 @@ export function renderUiPage({ version, embedded = false }) {
623
1143
  fill(saved.config);
624
1144
  status(saved);
625
1145
  renderMutes(saved);
1146
+ captureSavedForm(nowStamp());
626
1147
  const data = await requestAllowFail(api.testChannel, { id });
627
1148
  const detail = (data.result && data.result.results && data.result.results[0]) || {};
628
1149
  renderChannelTestResult(id, data.result || {});
@@ -682,6 +1203,7 @@ export function renderUiPage({ version, embedded = false }) {
682
1203
  }
683
1204
 
684
1205
  function fill(config) {
1206
+ $('newKeys').value = '';
685
1207
  $('server').value = config.server || '';
686
1208
  $('group').value = config.group || '';
687
1209
  $('icon').value = config.icon || '';
@@ -707,6 +1229,23 @@ export function renderUiPage({ version, embedded = false }) {
707
1229
  $('linkToSession').checked = config.linkToSession === true;
708
1230
  $('trace').checked = config.trace === true;
709
1231
 
1232
+ $('browserNotifyEnabled').checked = config.browserNotifyEnabled === true;
1233
+ $('browserNotifyOnReply').checked = config.browserNotifyOnReply !== false;
1234
+ $('browserNotifyOnApproval').checked = config.browserNotifyOnApproval !== false;
1235
+ $('browserNotifyOnQuestion').checked = config.browserNotifyOnQuestion !== false;
1236
+ $('browserNotifyReplyPersistent').value = config.browserNotifyReplyPersistent === true ? 'persistent' : 'auto';
1237
+ $('browserNotifyApprovalPersistent').value = config.browserNotifyApprovalPersistent !== false ? 'persistent' : 'auto';
1238
+ $('browserNotifyQuestionPersistent').value = config.browserNotifyQuestionPersistent !== false ? 'persistent' : 'auto';
1239
+ $('browserNotifySkipForeground').checked = config.browserNotifySkipForeground !== false;
1240
+ $('browserNotifyUsePushMutes').checked = config.browserNotifyUsePushMutes !== false;
1241
+ $('browserNotifyReplyBody').value = config.browserNotifyReplyBody || '{status} · {summary}';
1242
+ $('browserNotifyApprovalBody').value = config.browserNotifyApprovalBody || '{status} · {tool} · {reason}';
1243
+ $('browserNotifyQuestionBody').value = config.browserNotifyQuestionBody || '{status} · {question}';
1244
+ $('browserNotifyMaxBodyLength').value = config.browserNotifyMaxBodyLength || 200;
1245
+ renderBrowserPermission();
1246
+ renderTemplatePreviews();
1247
+ updateBrowserMuteVisibility();
1248
+
710
1249
  const list = $('keylist');
711
1250
  list.replaceChildren();
712
1251
  if (!config.deviceKeyCount) {
@@ -759,6 +1298,36 @@ export function renderUiPage({ version, embedded = false }) {
759
1298
  warnings.hidden = true;
760
1299
  text(warnings, '');
761
1300
  }
1301
+ syncOverview(data);
1302
+ }
1303
+
1304
+ function syncOverview(data) {
1305
+ const cfg = data && data.config ? data.config : (current && current.config) || {};
1306
+ const pushMeta = $('overviewPushMeta');
1307
+ const pushState = $('overviewPushState');
1308
+ const browserMeta = $('overviewBrowserMeta');
1309
+ const browserState = $('overviewBrowserState');
1310
+ const channelCount = Array.isArray(cfg.channels) ? cfg.channels.length : 0;
1311
+ if (pushMeta) text(pushMeta, (cfg.deviceKeyCount || 0) + ' 台设备 · ' + channelCount + ' 个渠道');
1312
+ if (pushState) {
1313
+ pushState.dataset.state = cfg.enabled ? 'ok' : 'warn';
1314
+ text(pushState, cfg.enabled ? '已启用' : '已停用');
1315
+ }
1316
+ const permission = notificationState();
1317
+ if (browserMeta) text(browserMeta, permission.key === 'granted' ? '已授权' : permission.key === 'denied' ? '已拒绝' : '等待授权');
1318
+ if (browserState) {
1319
+ browserState.dataset.state = permission.cls;
1320
+ text(browserState, permission.key === 'granted' ? '可用' : permission.key === 'denied' ? '已拒绝' : '待授权');
1321
+ }
1322
+ const last = $('overviewLast');
1323
+ if (last) {
1324
+ const delivery = data && data.lastDelivery;
1325
+ if (!delivery) text(last, '还没有投递记录');
1326
+ else {
1327
+ const when = delivery.at ? new Date(delivery.at).toLocaleTimeString('zh-CN', { hour: '2-digit', minute: '2-digit' }) : '';
1328
+ text(last, labelOf(delivery.kind) + ' · ' + (delivery.ok ? '已送达' : delivery.skipped ? '已跳过' : '失败') + (when ? ' · ' + when : ''));
1329
+ }
1330
+ }
762
1331
  }
763
1332
 
764
1333
  function labelOf(kind) {
@@ -802,9 +1371,56 @@ export function renderUiPage({ version, embedded = false }) {
802
1371
  ].filter(Boolean);
803
1372
  sessionBox.append(muteRow('session', session.id, session.title || '未命名', subLines, mutedSessions.has(session.id)));
804
1373
  }
1374
+ renderBrowserMutes(data);
805
1375
  }
806
1376
 
807
- function muteRow(kind, id, title, sub, muted) {
1377
+ function renderBrowserMutes(data) {
1378
+ if (!data || !data.mute || !data.catalog) return;
1379
+ const mutedWorkspaces = new Set(data.mute.browserWorkspaces || []);
1380
+ const mutedSessions = new Set(data.mute.browserSessions || []);
1381
+ const workspaceBox = $('browserWorkspaces');
1382
+ if (workspaceBox) {
1383
+ workspaceBox.replaceChildren();
1384
+ if (!data.catalog.workspaces.length) {
1385
+ const empty = document.createElement('div'); empty.className = 'empty'; text(empty, '没有工作区记录');
1386
+ workspaceBox.append(empty);
1387
+ }
1388
+ for (const workspace of data.catalog.workspaces) {
1389
+ workspaceBox.append(muteRow('workspace', workspace.id, workspace.title || workspace.id, workspace.path, mutedWorkspaces.has(workspace.id), 'browser'));
1390
+ }
1391
+ }
1392
+
1393
+ const queryInput = $('browserSessionSearch');
1394
+ const query = queryInput ? (queryInput.value || '').trim().toLowerCase() : '';
1395
+ const sessionBox = $('browserSessions');
1396
+ if (sessionBox) {
1397
+ sessionBox.replaceChildren();
1398
+ const rows = data.catalog.sessions.filter((session) => {
1399
+ if (!query) return true;
1400
+ return String(session.title || '').toLowerCase().includes(query) || String(session.id).toLowerCase().includes(query);
1401
+ });
1402
+ const sessionCount = $('browserSessionCount');
1403
+ if (sessionCount) text(sessionCount, String(rows.length));
1404
+ if (!rows.length) {
1405
+ const empty = document.createElement('div'); empty.className = 'empty'; text(empty, '没有会话记录');
1406
+ sessionBox.append(empty);
1407
+ }
1408
+ for (const session of rows) {
1409
+ const workspaceLabel = session.workspaceTitle || session.workspaceId;
1410
+ const subLines = [
1411
+ session.id,
1412
+ workspaceLabel ? ('工作区 ' + workspaceLabel) : '',
1413
+ session.running ? '运行中' : '',
1414
+ session.archived ? '已归档' : '',
1415
+ session.orphaned && !session.archived ? '仅保留静音记录' : '',
1416
+ ].filter(Boolean);
1417
+ sessionBox.append(muteRow('session', session.id, session.title || '未命名', subLines, mutedSessions.has(session.id), 'browser'));
1418
+ }
1419
+ }
1420
+ updateBrowserMuteVisibility();
1421
+ }
1422
+
1423
+ function muteRow(kind, id, title, sub, muted, channel) {
808
1424
  const item = document.createElement('label');
809
1425
  item.className = 'item';
810
1426
  const box = document.createElement('input');
@@ -813,9 +1429,8 @@ export function renderUiPage({ version, embedded = false }) {
813
1429
  box.addEventListener('change', async () => {
814
1430
  box.disabled = true;
815
1431
  try {
816
- const data = await request(api.mute, { kind, id, muted: box.checked });
1432
+ const data = await request(api.mute, { kind, id, muted: box.checked, channel: channel || 'push' });
817
1433
  current = data;
818
- fill(data.config);
819
1434
  status(data);
820
1435
  renderMutes(data);
821
1436
  toast(box.checked ? '已静音' : '已取消静音');
@@ -854,6 +1469,14 @@ export function renderUiPage({ version, embedded = false }) {
854
1469
  window.parent.postMessage({ type: 'dsh-bark-push:height', height }, window.location.origin);
855
1470
  }
856
1471
 
1472
+ window.addEventListener('message', (event) => {
1473
+ if (event.origin !== window.location.origin) return;
1474
+ const data = event.data;
1475
+ if (!data || data.type !== 'dsh-bark-push:browser-permission-result') return;
1476
+ renderBrowserPermission();
1477
+ toast(data.permission === 'granted' ? '浏览器通知权限已授予' : '浏览器通知权限未授予', data.permission !== 'granted');
1478
+ });
1479
+
857
1480
  if (window.parent !== window) {
858
1481
  window.addEventListener('load', postHeight);
859
1482
  if (typeof ResizeObserver !== 'undefined') new ResizeObserver(postHeight).observe(document.body);
@@ -887,7 +1510,20 @@ export function renderUiPage({ version, embedded = false }) {
887
1510
  notifyOnQuestion: $('notifyOnQuestion').checked,
888
1511
  includeSubagents: $('includeSubagents').checked,
889
1512
  linkToSession: $('linkToSession').checked,
890
- trace: $('trace').checked
1513
+ trace: $('trace').checked,
1514
+ browserNotifyEnabled: $('browserNotifyEnabled').checked,
1515
+ browserNotifyOnReply: $('browserNotifyOnReply').checked,
1516
+ browserNotifyOnApproval: $('browserNotifyOnApproval').checked,
1517
+ browserNotifyOnQuestion: $('browserNotifyOnQuestion').checked,
1518
+ browserNotifyReplyPersistent: $('browserNotifyReplyPersistent').value === 'persistent',
1519
+ browserNotifyApprovalPersistent: $('browserNotifyApprovalPersistent').value === 'persistent',
1520
+ browserNotifyQuestionPersistent: $('browserNotifyQuestionPersistent').value === 'persistent',
1521
+ browserNotifySkipForeground: $('browserNotifySkipForeground').checked,
1522
+ browserNotifyUsePushMutes: $('browserNotifyUsePushMutes').checked,
1523
+ browserNotifyReplyBody: $('browserNotifyReplyBody').value,
1524
+ browserNotifyApprovalBody: $('browserNotifyApprovalBody').value,
1525
+ browserNotifyQuestionBody: $('browserNotifyQuestionBody').value,
1526
+ browserNotifyMaxBodyLength: Number($('browserNotifyMaxBodyLength').value)
891
1527
  };
892
1528
  }
893
1529
 
@@ -899,18 +1535,41 @@ export function renderUiPage({ version, embedded = false }) {
899
1535
  fill(data.config);
900
1536
  status(data);
901
1537
  renderMutes(data);
1538
+ captureSavedForm();
902
1539
  } catch (error) {
1540
+ saveError = '读取失败:' + error.message;
1541
+ renderSaveState();
903
1542
  toast('读取失败:' + error.message, true);
904
1543
  }
905
1544
  }
906
1545
 
907
- const STATUS_BY_BUTTON = { saveChannels: 'channelsSaveStatus', saveRules: 'rulesSaveStatus', save: 'barkSaveStatus' };
1546
+ const STATUS_BY_BUTTON = { saveChannels: 'channelsSaveStatus', saveRules: 'rulesSaveStatus', save: 'barkSaveStatus', saveBrowser: 'browserSaveStatus', saveMute: 'muteSaveStatus' };
908
1547
 
909
1548
  // Single save path shared by every section's "保存全部更改" button. It always
910
1549
  // persists the whole config; only the inline status location differs.
1550
+ function broadcastBrowserConfig(config) {
1551
+ if (window.parent === window || !config) return;
1552
+ try {
1553
+ window.parent.postMessage({
1554
+ type: 'dsh-bark-push:config-updated',
1555
+ config: {
1556
+ browserNotifyEnabled: config.browserNotifyEnabled === true,
1557
+ browserNotifySkipForeground: config.browserNotifySkipForeground !== false,
1558
+ browserNotifyReplyPersistent: config.browserNotifyReplyPersistent === true,
1559
+ browserNotifyApprovalPersistent: config.browserNotifyApprovalPersistent !== false,
1560
+ browserNotifyQuestionPersistent: config.browserNotifyQuestionPersistent !== false,
1561
+ },
1562
+ }, window.location.origin);
1563
+ } catch (_) { /* optional parent bridge */ }
1564
+ }
1565
+
911
1566
  async function persistConfig(button) {
1567
+ if (pendingKeyText()) { toast('请先点击「追加密钥」添加新增密钥', true); return false; }
912
1568
  const statusId = (button && STATUS_BY_BUTTON[button.id]) || 'barkSaveStatus';
913
1569
  if (button) button.disabled = true;
1570
+ saveBusy = true;
1571
+ saveError = '';
1572
+ renderSaveState();
914
1573
  setSaveStatus(statusId, '保存中…', '');
915
1574
  try {
916
1575
  const data = await request(api.config, collect());
@@ -919,15 +1578,17 @@ export function renderUiPage({ version, embedded = false }) {
919
1578
  fill(data.config);
920
1579
  status(data);
921
1580
  renderMutes(data);
922
- setSaveStatus(statusId, '已保存 ' + nowStamp(), 'ok');
1581
+ broadcastBrowserConfig(data.config);
1582
+ captureSavedForm(nowStamp());
923
1583
  toast('配置已保存');
924
1584
  return true;
925
1585
  } catch (error) {
926
- setSaveStatus(statusId, '保存失败:' + (error.message || '未知错误'), 'bad');
1586
+ saveFailed('保存失败:' + (error.message || '未知错误'));
927
1587
  toast('保存失败:' + error.message, true);
928
1588
  return false;
929
1589
  } finally {
930
1590
  if (button) button.disabled = false;
1591
+ renderSaveState();
931
1592
  }
932
1593
  }
933
1594
 
@@ -947,8 +1608,45 @@ export function renderUiPage({ version, embedded = false }) {
947
1608
  $('save').addEventListener('click', () => { void persistConfig($('save')); });
948
1609
  $('saveChannels').addEventListener('click', () => { void persistConfig($('saveChannels')); });
949
1610
  $('saveRules').addEventListener('click', () => { void persistConfig($('saveRules')); });
1611
+ $('saveBrowser').addEventListener('click', () => { void persistConfig($('saveBrowser')); });
1612
+ $('saveAll').addEventListener('click', () => { void persistConfig($('saveAll')); });
1613
+ $('discardAll').addEventListener('click', async () => {
1614
+ if (!isFormDirty()) return;
1615
+ if (!window.confirm('放弃当前未保存的更改,恢复为最近保存的配置?')) return;
1616
+ await load();
1617
+ toast('已恢复为最近保存的配置');
1618
+ });
1619
+ document.addEventListener('input', (event) => {
1620
+ if (event.target && event.target.closest && event.target.closest('main')) refreshDirtyState();
1621
+ });
1622
+ document.addEventListener('change', (event) => {
1623
+ if (event.target && event.target.closest && event.target.closest('main')) refreshDirtyState();
1624
+ });
1625
+ window.addEventListener('keydown', (event) => {
1626
+ if (!(event.metaKey || event.ctrlKey) || String(event.key).toLowerCase() !== 's') return;
1627
+ event.preventDefault();
1628
+ if (!saveBusy && savedForm !== null && isFormDirty()) void persistConfig($('saveAll'));
1629
+ });
1630
+ window.addEventListener('beforeunload', (event) => {
1631
+ if (savedForm === null || !isFormDirty()) return;
1632
+ event.preventDefault();
1633
+ event.returnValue = '';
1634
+ });
1635
+ document.querySelectorAll('[data-goto]').forEach((button) => {
1636
+ button.addEventListener('click', () => setView(button.dataset.goto, true));
1637
+ });
1638
+ $('saveMute').addEventListener('click', () => { void persistConfig($('saveMute')); });
1639
+ $('requestNotifyPermission').addEventListener('click', () => { void requestBrowserPermission(); });
1640
+ $('testBrowserNotify').addEventListener('click', testBrowserNotification);
1641
+ $('browserNotifyUsePushMutes').addEventListener('change', updateBrowserMuteVisibility);
1642
+ $('browserSessionSearch').addEventListener('input', () => { if (current) renderBrowserMutes(current); });
1643
+ for (const kind of ['reply', 'approval', 'question']) {
1644
+ const input = $('browserNotify' + kind[0].toUpperCase() + kind.slice(1) + 'Body');
1645
+ if (input) input.addEventListener('input', () => renderTemplatePreview(kind));
1646
+ }
950
1647
 
951
1648
  $('addKeys').addEventListener('click', async () => {
1649
+ if (hasConfigChanges()) { toast('请先保存当前更改,再追加密钥', true); return; }
952
1650
  const raw = $('newKeys').value.trim();
953
1651
  if (!raw) { toast('请先粘贴至少一个 Device Key', true); return; }
954
1652
  const keys = raw.split(/\\r?\\n|,/).map((part) => part.trim()).filter(Boolean);
@@ -960,7 +1658,7 @@ export function renderUiPage({ version, embedded = false }) {
960
1658
  fill(data.config);
961
1659
  status(data);
962
1660
  renderMutes(data);
963
- setSaveStatus('barkSaveStatus', '已追加 ' + keys.length + ' 个密钥', 'ok');
1661
+ captureSavedForm(nowStamp());
964
1662
  toast('已追加 ' + keys.length + ' 个密钥');
965
1663
  } catch (error) {
966
1664
  toast('保存失败:' + error.message, true);
@@ -970,6 +1668,7 @@ export function renderUiPage({ version, embedded = false }) {
970
1668
  });
971
1669
 
972
1670
  $('clearKeys').addEventListener('click', async () => {
1671
+ if (hasConfigChanges()) { toast('请先保存当前更改,再清空 Device Key', true); return; }
973
1672
  if (!window.confirm('确定清空全部 Device Key?')) return;
974
1673
  try {
975
1674
  const data = await request(api.config, { clearDeviceKeys: true });
@@ -977,7 +1676,7 @@ export function renderUiPage({ version, embedded = false }) {
977
1676
  fill(data.config);
978
1677
  status(data);
979
1678
  renderMutes(data);
980
- setSaveStatus('barkSaveStatus', '已清空 Device Key', 'ok');
1679
+ captureSavedForm(nowStamp());
981
1680
  toast('已清空 Device Key');
982
1681
  } catch (error) {
983
1682
  toast('保存失败:' + error.message, true);
@@ -985,6 +1684,7 @@ export function renderUiPage({ version, embedded = false }) {
985
1684
  });
986
1685
 
987
1686
  $('reset').addEventListener('click', async () => {
1687
+ if (hasConfigChanges()) { toast('请先保存或放弃当前更改,再恢复默认配置', true); return; }
988
1688
  if (!window.confirm('恢复默认配置?静音状态、Device Key 与已配置渠道不会被清除。')) return;
989
1689
  try {
990
1690
  const data = await request(api.config, { reset: true });
@@ -992,7 +1692,7 @@ export function renderUiPage({ version, embedded = false }) {
992
1692
  fill(data.config);
993
1693
  status(data);
994
1694
  renderMutes(data);
995
- setSaveStatus('barkSaveStatus', '已恢复默认', 'ok');
1695
+ captureSavedForm(nowStamp());
996
1696
  toast('已恢复默认配置');
997
1697
  } catch (error) {
998
1698
  toast('恢复失败:' + error.message, true);
@@ -1005,7 +1705,6 @@ export function renderUiPage({ version, embedded = false }) {
1005
1705
  const data = await requestAllowFail(api.test, {});
1006
1706
  if (data.state) {
1007
1707
  current = data.state;
1008
- fill(data.state.config);
1009
1708
  status(data.state);
1010
1709
  renderMutes(data.state);
1011
1710
  }
@@ -1026,6 +1725,10 @@ export function renderUiPage({ version, embedded = false }) {
1026
1725
  });
1027
1726
 
1028
1727
  $('sessionSearch').addEventListener('input', () => { if (current) renderMutes(current); });
1728
+ try {
1729
+ const initialView = new URL(window.location.href).searchParams.get('view');
1730
+ setView(initialView && VIEW_META[initialView] ? initialView : 'overview', false);
1731
+ } catch (_) { setView('overview', false); }
1029
1732
  load();
1030
1733
  })();
1031
1734
  </script>