dsh-bark-push 0.2.2 → 0.3.0

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,325 @@ 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
+ .actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 15px; }
131
+ .save-status { color: var(--muted); font-size: 12px; margin-left: 4px; }
129
132
  .save-status.ok { color: var(--ok); }
130
133
  .save-status.bad { color: var(--bad); }
131
134
  .save-status.warn { color: var(--warn); }
132
-
133
- /* Key list */
134
135
  .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; }
136
+ .keylist code { color: var(--ink); font-variant-numeric: tabular-nums; }
137
+ details.advanced { margin: 16px 0 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 1px 0 6px; }
138
+ 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
139
  details.advanced > summary::-webkit-details-marker { display: none; }
141
140
  details.advanced > summary::before { content: '▸ '; }
142
141
  details.advanced[open] > summary::before { content: '▾ '; }
143
- .advanced-group { margin: 8px 0 2px; }
142
+ .advanced-group { margin: 6px 0 2px; }
144
143
  .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; }
144
+ .lane { border-bottom: 1px solid var(--line); margin: 0; }
145
+ .lane-head { display: flex; align-items: center; gap: 10px; padding: 11px 0; flex-wrap: wrap; }
146
+ .lane .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--ok); }
147
+ .lane[data-enabled="0"] .dot { background: transparent; border: 1.5px solid var(--muted); }
151
148
  .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; }
149
+ .lane-name { font-size: 13.5px; font-weight: 600; }
150
+ .tag { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 5px; padding: 0 6px; }
154
151
  .lane-grow { flex: 1; }
155
152
  .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; }
153
+ .lane-toggle { padding: 5px 9px; min-height: 28px; }
154
+ .lane-head button { padding: 5px 9px; min-height: 28px; }
155
+ .lane-fields { padding: 4px 12px 12px; border-top: 1px dashed var(--line); background: var(--surface-muted); }
156
+ .channel-field { display: grid; grid-template-columns: 175px minmax(0, 1fr); gap: 8px 14px; align-items: center; margin: 0 0 9px; }
157
+ .channel-field > label { color: var(--muted); font-size: 12.5px; }
161
158
  .channel-field .req { color: var(--bad); }
162
159
  .channel-add { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 14px; }
163
- .channel-add select { max-width: 260px; }
160
+ .channel-add select { max-width: 250px; }
164
161
  .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
162
  .test-result { margin-top: 10px; border-top: 1px dashed var(--line); padding-top: 10px; display: flex; flex-direction: column; gap: 5px; }
168
163
  .test-result .tr-title { font-size: 12.5px; font-weight: 600; }
169
164
  .test-result .tr-row { display: flex; align-items: center; gap: 8px; font-size: 12.5px; }
170
165
  .test-result .tr-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
171
166
  .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; }
167
+ .lists { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; margin-top: 10px; }
168
+ .lists > div { min-width: 0; }
169
+ .list-title { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 12.5px; color: var(--muted); margin: 0 0 8px; }
170
+ .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); }
171
+ .item { display: flex; gap: 9px; align-items: flex-start; min-width: 0; max-width: 100%; overflow: hidden; padding: 6px; border-radius: 6px; }
172
+ .item:hover { background: var(--surface); }
173
+ .item > input { flex: none; }
174
+ .item .meta { min-width: 0; flex: 1 1 auto; overflow: hidden; }
175
+ .item .title { max-width: 100%; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
176
+ .item .sub { max-width: 100%; color: var(--muted); font-size: 12px; line-height: 1.45; overflow-wrap: anywhere; word-break: break-word; }
184
177
  .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
-
178
+ .page-foot { color: var(--muted); font-size: 12px; margin-top: 30px; border-top: 1px solid var(--line); padding-top: 14px; }
179
+ code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .95em; }
180
+ .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; }
181
+ .overview-copy h2 { margin: 0; max-width: 14ch; font-size: 28px; line-height: 1.2; font-weight: 650; letter-spacing: -.04em; }
182
+ .overview-copy p { max-width: 43ch; margin: 12px 0 0; color: var(--muted); font-size: 13px; }
183
+ .quick-links { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 20px; }
184
+ .quick-link { background: transparent; border-color: var(--line-strong); color: var(--ink); }
185
+ .quick-link:hover { border-color: var(--accent); color: var(--accent); }
186
+ .route-map { align-self: start; border: 1px solid var(--line); background: var(--surface); }
187
+ .route-source { padding: 17px 16px 15px; border-bottom: 1px solid var(--line); }
188
+ .route-source-label { display: block; color: var(--muted); font-size: 11px; }
189
+ .route-source strong { display: block; margin-top: 5px; font-size: 14px; font-weight: 600; }
190
+ .route-source small { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; }
191
+ .route-paths { display: grid; }
192
+ .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); }
193
+ .route-row:last-child { border-bottom: 0; }
194
+ .route-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
195
+ .route-row:nth-child(2) .route-dot { background: var(--ok); }
196
+ .route-copy strong { display: block; font-size: 13px; font-weight: 600; }
197
+ .route-copy small { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; }
198
+ .route-state { font-size: 12px; color: var(--muted); }
199
+ .route-state[data-state="ok"] { color: var(--ok); }
200
+ .route-state[data-state="warn"] { color: var(--warn); }
201
+ .route-state[data-state="bad"] { color: var(--bad); }
202
+ .overview-summary { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; padding: 24px 0 0; }
203
+ .summary-block h2 { margin: 0 0 10px; font-size: 14px; font-weight: 600; }
204
+ .healthstrip { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; }
205
+ .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; }
206
+ .pill.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 42%, var(--line)); }
207
+ .pill.bad { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 42%, var(--line)); }
208
+ .pill.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 42%, var(--line)); }
209
+ .summary-text { margin: 0; color: var(--muted); font-size: 13px; }
191
210
  #toast {
192
211
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
193
- background: var(--fg); color: var(--bg); padding: 8px 14px; border-radius: 999px;
212
+ background: var(--ink); color: var(--canvas); padding: 8px 14px; border-radius: 999px;
194
213
  font-size: 13px; opacity: 0; pointer-events: none; transition: opacity .18s ease;
195
214
  max-width: 80vw; text-align: center; z-index: 10;
196
215
  }
197
216
  #toast.show { opacity: 1; }
198
217
  #toast.bad { background: var(--bad); color: #fff; }
218
+ @media (max-width: 900px) {
219
+ .shell { padding: 15px 16px 42px; }
220
+ .topbar { display: block; }
221
+ .brand { padding-bottom: 10px; }
222
+ .topnav { width: 100%; border-top: 1px solid var(--line); }
223
+ .topnav .nav-item { padding: 10px 10px 9px; }
224
+ .top-meta { display: none; }
225
+ .overview-hero { grid-template-columns: 1fr; gap: 22px; }
226
+ .overview-copy h2 { max-width: 18ch; font-size: 25px; }
227
+ }
228
+ @media (max-width: 720px) {
229
+ .savebar { align-items: flex-start; flex-direction: column; }
230
+ .savebar-actions { width: 100%; }
231
+ .savebar-actions button { flex: 1 1 auto; }
232
+ .row, .row.wide { grid-template-columns: 1fr; gap: 5px; }
233
+ .row > label { padding-top: 0; }
234
+ .rule-grid, .lists, .overview-summary { grid-template-columns: 1fr; }
235
+ .channel-field { grid-template-columns: 1fr; }
236
+ .stage-head { flex-direction: column; }
237
+ }
238
+ @media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
199
239
  </style>
200
240
  </head>
201
241
  <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>
242
+ <main class="shell">
243
+ <header class="topbar">
244
+ <div class="brand">
245
+ <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>
246
+ <div><strong>Bark Push</strong><small>通知设置</small></div>
247
+ </div>
248
+ <nav class="topnav" aria-label="通知设置">
249
+ <button class="nav-item" type="button" data-goto="overview" aria-current="page"><span>概览</span><span class="nav-dot" aria-hidden="true"></span></button>
250
+ <button class="nav-item" type="button" data-goto="delivery"><span>推送渠道</span><span class="nav-dot" aria-hidden="true"></span></button>
251
+ <button class="nav-item" type="button" data-goto="rules"><span>通知规则</span><span class="nav-dot" aria-hidden="true"></span></button>
252
+ <button class="nav-item" type="button" data-goto="browser"><span>浏览器通知</span><span class="nav-dot" aria-hidden="true"></span></button>
253
+ <button class="nav-item" type="button" data-goto="mute"><span>静音管理</span><span class="nav-dot" aria-hidden="true"></span></button>
254
+ </nav>
255
+ <span class="top-meta">仅保存在本机</span>
208
256
  </header>
209
257
 
210
- <section class="section" id="section-default">
211
- <div class="section-head"><h2>默认渠道 · Bark</h2></div>
258
+ <div class="stage">
259
+ <header class="stage-head">
260
+ <div class="stage-copy">
261
+ <h1 id="stageTitle">概览</h1>
262
+ <p class="lead" id="stageLead">先确认通知链路,再进入具体设置。</p>
263
+ </div>
264
+ </header>
265
+
266
+ <div class="savebar" id="savebar" data-state="loading" role="status" aria-live="polite">
267
+ <div class="savebar-main">
268
+ <span class="savebar-dot" aria-hidden="true"></span>
269
+ <div class="savebar-copy">
270
+ <strong id="saveStateLabel">正在读取配置…</strong>
271
+ <small id="saveStateHint">读取完成后会显示保存状态</small>
272
+ </div>
273
+ </div>
274
+ <div class="savebar-actions">
275
+ <button class="primary" id="saveAll" type="button" disabled>保存更改</button>
276
+ <button id="discardAll" type="button" disabled>放弃</button>
277
+ </div>
278
+ </div>
279
+
280
+ <section class="view" id="panel-overview">
281
+ <div class="overview-hero">
282
+ <div class="overview-copy">
283
+ <h2>让每条重要通知,都有明确的去处。</h2>
284
+ <p>DSH 的回复、审批和选择请求,可以同时送达 Bark 与浏览器。两个通道独立开关,互不影响;配置是否有未保存的修改,始终写在页面上方。</p>
285
+ <div class="quick-links">
286
+ <button class="quick-link" type="button" data-goto="delivery">配置推送渠道</button>
287
+ <button class="quick-link" type="button" data-goto="rules">选择通知事件</button>
288
+ <button class="quick-link" type="button" data-goto="browser">设置浏览器通知</button>
289
+ </div>
290
+ </div>
291
+ <div class="route-map" aria-label="通知链路">
292
+ <div class="route-source">
293
+ <span class="route-source-label">事件来源</span>
294
+ <strong>DSH 会话</strong>
295
+ <small>回复、批准、选择</small>
296
+ </div>
297
+ <div class="route-paths">
298
+ <div class="route-row">
299
+ <span class="route-dot" aria-hidden="true"></span>
300
+ <div class="route-copy"><strong>Bark 推送</strong><small id="overviewPushMeta">正在读取…</small></div>
301
+ <span class="route-state" id="overviewPushState">…</span>
302
+ </div>
303
+ <div class="route-row">
304
+ <span class="route-dot" aria-hidden="true"></span>
305
+ <div class="route-copy"><strong>浏览器通知</strong><small id="overviewBrowserMeta">等待授权</small></div>
306
+ <span class="route-state" id="overviewBrowserState">…</span>
307
+ </div>
308
+ </div>
309
+ </div>
310
+ </div>
311
+ <div class="overview-summary">
312
+ <section class="summary-block">
313
+ <h2>当前状态</h2>
314
+ <div class="healthstrip" id="status"><span class="pill">读取中…</span></div>
315
+ <p class="hint" id="warnings" hidden></p>
316
+ </section>
317
+ <section class="summary-block">
318
+ <h2>最近动态</h2>
319
+ <p class="summary-text" id="overviewLast">还没有投递记录</p>
320
+ </section>
321
+ </div>
322
+ </section>
323
+
324
+ <section class="view" id="panel-delivery" hidden>
325
+ <section class="section" id="section-default">
326
+ <div class="section-head"><h2>默认渠道 · Bark</h2><span class="section-state" data-section-state="default">已保存</span></div>
212
327
  <p class="section-sub">Bark 是内置的第一渠道。填入服务器与 Device Key 即可使用;其余按需展开「高级选项」。</p>
213
328
  <div class="row"><label for="server">Bark Server</label><input id="server" type="text" placeholder="https://api.day.app"></div>
214
329
  <div class="row"><label>已配置 Device Key</label><div><div class="keylist" id="keylist"></div><p class="hint">页面只显示掩码;新增密钥逐行粘贴,保存后不再显示完整值。</p></div></div>
@@ -281,7 +396,7 @@ export function renderUiPage({ version, embedded = false }) {
281
396
  </details>
282
397
 
283
398
  <div class="actions">
284
- <button class="primary" id="save">保存全部更改</button>
399
+ <button class="primary" id="save">保存默认渠道</button>
285
400
  <button id="test">测试默认渠道</button>
286
401
  <button id="reset" class="danger">恢复默认</button>
287
402
  <button id="addKeys">追加密钥</button>
@@ -291,8 +406,23 @@ export function renderUiPage({ version, embedded = false }) {
291
406
  <div class="test-result" id="barkTestResult" hidden></div>
292
407
  </section>
293
408
 
294
- <section class="section" id="section-rules">
295
- <div class="section-head"><h2>通知规则</h2></div>
409
+ <section class="section" id="section-channels">
410
+ <div class="section-head"><h2>渠道</h2><span class="count" id="channelCount">0</span><span class="section-state" data-section-state="channels">已保存</span></div>
411
+ <p class="section-sub">Bark 之外可同时启用多个渠道,互不影响;点「参数」展开填写,点「测试」会先保存当前配置,再单独验证该渠道。</p>
412
+ <div id="channelList"></div>
413
+ <div class="channel-add">
414
+ <select id="channelTypeSelect" aria-label="渠道类型"></select>
415
+ <button id="addChannel">添加渠道</button>
416
+ <button id="saveChannels">保存渠道</button>
417
+ <span id="channelsSaveStatus" class="save-status" role="status" aria-live="polite"></span>
418
+ </div>
419
+ </section>
420
+
421
+ </section>
422
+
423
+ <section class="view" id="panel-rules" hidden>
424
+ <section class="section" id="section-rules">
425
+ <div class="section-head"><h2>通知规则</h2><span class="section-state" data-section-state="rules">已保存</span></div>
296
426
  <p class="section-sub">选择哪些事件需要推送。总开关关闭后不发送任何通知。</p>
297
427
  <div class="rule-grid">
298
428
  <label class="rule"><input id="enabled" type="checkbox"><span class="rt"><b>总开关</b><small>关闭后暂停全部推送</small></span></label>
@@ -302,25 +432,59 @@ export function renderUiPage({ version, embedded = false }) {
302
432
  <label class="rule"><input id="includeSubagents" type="checkbox"><span class="rt"><b>包含子代理</b><small>子代理会话也推送</small></span></label>
303
433
  </div>
304
434
  <div class="actions">
305
- <button id="saveRules">保存全部更改</button>
435
+ <button id="saveRules">保存规则</button>
306
436
  <span id="rulesSaveStatus" class="save-status" role="status" aria-live="polite"></span>
307
437
  </div>
308
438
  </section>
309
439
 
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>
440
+ </section>
321
441
 
322
- <section class="section" id="section-mute">
323
- <div class="section-head"><h2>静音管理</h2></div>
442
+ <section class="view" id="panel-browser" hidden>
443
+ <section class="section" id="section-browser">
444
+ <div class="section-head"><h2>浏览器通知</h2><span class="section-state" data-section-state="browser">已保存</span></div>
445
+ <p class="section-sub">通过浏览器系统通知提醒回复、审批和选择请求;不依赖 Bark 或任何推送渠道。浏览器通知只在 DSH 页面打开时生效。</p>
446
+ <div class="healthstrip" id="browserPermissionStatus"><span class="pill">检查中…</span></div>
447
+ <div class="actions">
448
+ <button id="requestNotifyPermission">请求通知权限</button>
449
+ <button id="testBrowserNotify">发送测试通知</button>
450
+ </div>
451
+ <div class="rule-grid" style="margin-top:14px">
452
+ <label class="rule"><input id="browserNotifyEnabled" type="checkbox"><span class="rt"><b>启用浏览器通知</b><small>与推送通知总开关独立</small></span></label>
453
+ <label class="rule"><input id="browserNotifyOnReply" type="checkbox"><span class="rt"><b>回复完成</b><small>一轮结束时提醒</small></span></label>
454
+ <label class="rule"><input id="browserNotifyOnApproval" type="checkbox"><span class="rt"><b>需要批准</b><small>工具请求授权时提醒</small></span></label>
455
+ <label class="rule"><input id="browserNotifyOnQuestion" type="checkbox"><span class="rt"><b>等待选择</b><small>等待你回答时提醒</small></span></label>
456
+ <label class="rule"><input id="browserNotifySkipForeground" type="checkbox"><span class="rt"><b>前台免打扰</b><small>当前会话且页面在前台时不提醒</small></span></label>
457
+ </div>
458
+ <p class="hint">浏览器通知的静音策略在「静音管理」中设置。</p>
459
+ </section>
460
+
461
+ <section class="section" id="section-browser-templates">
462
+ <div class="section-head"><h2>正文模板</h2><span class="section-state" data-section-state="browser">已保存</span></div>
463
+ <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>
464
+ <div class="row wide"><label for="browserNotifyReplyBody">回复完成</label><textarea id="browserNotifyReplyBody" rows="2"></textarea><p class="hint" id="browserReplyPreview"></p></div>
465
+ <div class="row wide"><label for="browserNotifyApprovalBody">需要批准</label><textarea id="browserNotifyApprovalBody" rows="2"></textarea><p class="hint" id="browserApprovalPreview"></p></div>
466
+ <div class="row wide"><label for="browserNotifyQuestionBody">等待选择</label><textarea id="browserNotifyQuestionBody" rows="2"></textarea><p class="hint" id="browserQuestionPreview"></p></div>
467
+ <div class="row"><label for="browserNotifyMaxBodyLength">正文最大长度</label><input id="browserNotifyMaxBodyLength" type="number" min="32" max="500"></div>
468
+ <div class="actions">
469
+ <button class="primary" id="saveBrowser">保存浏览器设置</button>
470
+ <span id="browserSaveStatus" class="save-status" role="status" aria-live="polite"></span>
471
+ </div>
472
+ </section>
473
+
474
+ </section>
475
+
476
+ <section class="view" id="panel-mute" hidden>
477
+ <section class="section" id="section-mute-policy">
478
+ <div class="section-head"><h2>静音策略</h2><span class="section-state" data-section-state="mute">已保存</span></div>
479
+ <p class="section-sub">浏览器通知默认复用推送通知的工作区与会话静音;关闭复用后使用独立的浏览器静音集合,不会影响 Bark 推送。</p>
480
+ <div class="row" style="margin-top:10px"><label>浏览器通知</label><div class="checks"><label><input id="browserNotifyUsePushMutes" type="checkbox"> 复用推送通知的工作区 / 会话静音</label></div></div>
481
+ <div class="actions">
482
+ <button id="saveMute">保存静音策略</button>
483
+ <span id="muteSaveStatus" class="save-status" role="status" aria-live="polite"></span>
484
+ </div>
485
+ </section>
486
+ <section class="section" id="section-mute">
487
+ <div class="section-head"><h2>静音管理</h2><span class="section-state">即时生效</span></div>
324
488
  <p class="section-sub">工作区静音优先于会话静音;任一层级静音即停止推送,状态持久化。会话列表与 DSH 左侧会话栏采用同一套可见性规则。</p>
325
489
  <div class="lists">
326
490
  <div>
@@ -335,9 +499,29 @@ export function renderUiPage({ version, embedded = false }) {
335
499
  </div>
336
500
  </section>
337
501
 
338
- <footer class="page-foot">dsh-bark-push v${safeVersion} · 只向这里配置的推送渠道发送内容。</footer>
502
+ <section class="section" id="section-browser-mute">
503
+ <div class="section-head"><h2>浏览器通知静音管理</h2><span class="section-state">即时生效</span></div>
504
+ <p class="section-sub" id="browserMuteHint">当前复用推送通知的静音设置。关闭上方「复用推送通知的工作区/会话静音」后,可在这里管理独立的浏览器通知静音。</p>
505
+ <div class="lists" id="browserMuteLists">
506
+ <div>
507
+ <p class="list-title">工作区</p>
508
+ <div class="list" id="browserWorkspaces"><div class="empty">读取中…</div></div>
509
+ </div>
510
+ <div>
511
+ <p class="list-title">会话 <span class="count" id="browserSessionCount">0</span></p>
512
+ <input id="browserSessionSearch" type="text" placeholder="按标题或 ID 过滤" style="margin-bottom:8px">
513
+ <div class="list" id="browserSessions"><div class="empty">读取中…</div></div>
514
+ </div>
515
+ </div>
516
+ </section>
517
+
518
+ </section>
519
+
520
+ <footer class="page-foot">dsh-bark-push v${safeVersion} · 所有通知配置仅保存在本机。</footer>
521
+ </div>
339
522
  </main>
340
523
  <div id="toast" role="status" aria-live="polite"></div>
524
+
341
525
  <script>
342
526
  (() => {
343
527
  'use strict';
@@ -354,6 +538,168 @@ export function renderUiPage({ version, embedded = false }) {
354
538
  let toastTimer = null;
355
539
  let channelTypes = [];
356
540
  let channelDraft = [];
541
+ let savedForm = null;
542
+ let lastSavedAt = '';
543
+ let saveBusy = false;
544
+ let saveError = '';
545
+
546
+ const BROWSER_SAMPLES = {
547
+ reply: { status: '回复完成', session: '示例会话', summary: '已完成会话列表修复', turn: '3', description: '已完成会话列表修复' },
548
+ approval: { status: '需要批准', session: '示例会话', tool: 'Bash', reason: '写入工作区文件', description: 'Bash · 写入工作区文件' },
549
+ question: { status: '等待选择', session: '示例会话', question: '请选择部署环境', questionCount: '2', description: '请选择部署环境' }
550
+ };
551
+
552
+ const VIEW_META = {
553
+ overview: { title: '概览', lead: '先确认通知链路,再进入具体设置。' },
554
+ delivery: { title: '推送渠道', lead: '配置 Bark 与额外渠道,确保通知能送达。' },
555
+ rules: { title: '通知规则', lead: '决定哪些事件需要通知。' },
556
+ browser: { title: '浏览器通知', lead: '控制 DSH 页面打开时的浏览器提醒。' },
557
+ mute: { title: '静音管理', lead: '按工作区或会话停止特定通知。' }
558
+ };
559
+ const VIEW_IDS = {
560
+ overview: 'panel-overview',
561
+ delivery: 'panel-delivery',
562
+ rules: 'panel-rules',
563
+ browser: 'panel-browser',
564
+ mute: 'panel-mute'
565
+ };
566
+
567
+ function setView(name, updateHash) {
568
+ const target = VIEW_META[name] ? name : 'overview';
569
+ for (const [key, id] of Object.entries(VIEW_IDS)) {
570
+ const panel = $(id);
571
+ if (panel) panel.hidden = key !== target;
572
+ }
573
+ document.querySelectorAll('.topnav [data-goto]').forEach((button) => {
574
+ button.setAttribute('aria-current', button.dataset.goto === target ? 'page' : 'false');
575
+ });
576
+ const meta = VIEW_META[target];
577
+ const title = $('stageTitle');
578
+ const lead = $('stageLead');
579
+ if (title) text(title, meta.title);
580
+ if (lead) text(lead, meta.lead);
581
+ if (updateHash) {
582
+ try {
583
+ const url = new URL(window.location.href);
584
+ url.searchParams.set('view', target);
585
+ window.history.replaceState(null, '', url.pathname + url.search + url.hash);
586
+ } catch (_) { /* hash updates are optional */ }
587
+ }
588
+ postHeight();
589
+ }
590
+
591
+ function notificationState() {
592
+ if (typeof Notification === 'undefined' || typeof Notification.requestPermission !== 'function') {
593
+ return { key: 'unsupported', label: '当前浏览器不支持通知', cls: 'bad' };
594
+ }
595
+ const permission = Notification.permission;
596
+ if (permission === 'granted') return { key: 'granted', label: '浏览器通知权限:已授权', cls: 'ok' };
597
+ if (permission === 'denied') return { key: 'denied', label: '浏览器通知权限:已拒绝', cls: 'bad' };
598
+ return { key: 'default', label: '浏览器通知权限:未授权', cls: 'warn' };
599
+ }
600
+
601
+ function renderBrowserPermission() {
602
+ const box = $('browserPermissionStatus');
603
+ if (!box) return;
604
+ const state = notificationState();
605
+ box.replaceChildren();
606
+ const pill = document.createElement('span');
607
+ pill.className = 'pill ' + state.cls;
608
+ text(pill, state.label);
609
+ box.append(pill);
610
+ const button = $('requestNotifyPermission');
611
+ if (button) {
612
+ button.disabled = state.key === 'unsupported' || state.key === 'granted';
613
+ button.textContent = state.key === 'granted' ? '已授权' : '请求通知权限';
614
+ }
615
+ if (state.key === 'denied') {
616
+ const hint = document.createElement('span');
617
+ hint.className = 'hint';
618
+ text(hint, '请在浏览器站点设置中允许通知后重新打开页面。');
619
+ box.append(hint);
620
+ }
621
+ syncOverview(current);
622
+ }
623
+
624
+ function renderTemplatePreview(kind) {
625
+ const input = $('browserNotify' + kind[0].toUpperCase() + kind.slice(1) + 'Body');
626
+ const target = $('browser' + kind[0].toUpperCase() + kind.slice(1) + 'Preview');
627
+ if (!input || !target) return;
628
+ const template = input.value || '';
629
+ const values = BROWSER_SAMPLES[kind] || {};
630
+ let preview = template.replace(/\\{([A-Za-z][A-Za-z0-9]*)\\}/g, (match, name) =>
631
+ Object.prototype.hasOwnProperty.call(values, name) ? String(values[name] ?? '') : match);
632
+ const unknown = [];
633
+ template.replace(/\\{([A-Za-z][A-Za-z0-9]*)\\}/g, (match, name) => {
634
+ if (!Object.prototype.hasOwnProperty.call(values, name)) unknown.push(match);
635
+ return match;
636
+ });
637
+ text(target, '预览:' + (preview.trim() || '(空模板,将使用默认值)') + (unknown.length ? ' 未知占位符:' + unknown.join('、') : ''));
638
+ }
639
+
640
+ function renderTemplatePreviews() {
641
+ renderTemplatePreview('reply');
642
+ renderTemplatePreview('approval');
643
+ renderTemplatePreview('question');
644
+ }
645
+
646
+ function updateBrowserMuteVisibility() {
647
+ const reuse = $('browserNotifyUsePushMutes');
648
+ const lists = $('browserMuteLists');
649
+ const hint = $('browserMuteHint');
650
+ if (!reuse || !lists || !hint) return;
651
+ const independent = !reuse.checked;
652
+ lists.hidden = !independent;
653
+ text(hint, independent
654
+ ? '当前使用独立的浏览器通知静音集合,不影响 Bark 推送。'
655
+ : '当前复用推送通知的静音设置。关闭上方「复用推送通知的工作区/会话静音」后,可在这里管理独立的浏览器通知静音。');
656
+ }
657
+
658
+ async function requestBrowserPermission() {
659
+ const state = notificationState();
660
+ if (state.key === 'unsupported') {
661
+ toast('当前浏览器不支持通知', true);
662
+ return;
663
+ }
664
+ try {
665
+ const permission = await Notification.requestPermission();
666
+ renderBrowserPermission();
667
+ toast(permission === 'granted' ? '浏览器通知权限已授予' : '浏览器通知权限未授予', permission !== 'granted');
668
+ } catch (error) {
669
+ if (window.parent && window.parent !== window) {
670
+ try {
671
+ window.parent.postMessage({ type: 'dsh-bark-push:browser-permission-request' }, window.location.origin);
672
+ toast('已向浏览器请求通知权限');
673
+ return;
674
+ } catch (_) { /* fall through to error */ }
675
+ }
676
+ toast('请求通知权限失败:' + error.message, true);
677
+ }
678
+ }
679
+
680
+ function testBrowserNotification() {
681
+ const state = notificationState();
682
+ if (state.key !== 'granted') {
683
+ toast('请先授予浏览器通知权限', true);
684
+ return;
685
+ }
686
+ if (window.parent && window.parent !== window) {
687
+ try {
688
+ window.parent.postMessage({ type: 'dsh-bark-push:browser-test' }, window.location.origin);
689
+ toast('测试通知已发送');
690
+ return;
691
+ } catch (_) { /* fall through to a local Notification */ }
692
+ }
693
+ try {
694
+ new Notification('DSH 浏览器通知测试', { body: '浏览器通知已开启。' });
695
+ toast('测试通知已发送');
696
+ } catch (error) {
697
+ toast('发送测试通知失败:' + error.message, true);
698
+ }
699
+ }
700
+
701
+ renderBrowserPermission();
702
+ renderTemplatePreviews();
357
703
 
358
704
  function toast(message, bad) {
359
705
  const text = message == null ? '' : String(message);
@@ -392,8 +738,156 @@ export function renderUiPage({ version, embedded = false }) {
392
738
  return pad(d.getHours()) + ':' + pad(d.getMinutes()) + ':' + pad(d.getSeconds());
393
739
  }
394
740
 
741
+ const SECTION_KEYS = {
742
+ default: [
743
+ 'server', 'group', 'icon', 'soundReply', 'soundApproval', 'soundQuestion',
744
+ 'levelReply', 'levelApproval', 'levelQuestion', 'titlePrefix', 'titleMode',
745
+ 'maxTitleLength', 'maxBodyLength', 'timeoutMs', 'maxRetries', 'retryDelayMs',
746
+ 'publicBaseUrl', 'linkToSession', 'trace', '__pendingDeviceKeys',
747
+ ],
748
+ rules: ['enabled', 'notifyOnReply', 'notifyOnApproval', 'notifyOnQuestion', 'includeSubagents'],
749
+ channels: ['channels'],
750
+ browser: [
751
+ 'browserNotifyEnabled', 'browserNotifyOnReply', 'browserNotifyOnApproval',
752
+ 'browserNotifyOnQuestion', 'browserNotifySkipForeground',
753
+ 'browserNotifyReplyBody', 'browserNotifyApprovalBody', 'browserNotifyQuestionBody',
754
+ 'browserNotifyMaxBodyLength',
755
+ ],
756
+ mute: ['browserNotifyUsePushMutes'],
757
+ };
758
+
759
+ function pendingKeyText() {
760
+ const input = $('newKeys');
761
+ return input ? input.value.trim() : '';
762
+ }
763
+
764
+ function readForm() {
765
+ try {
766
+ const form = collect();
767
+ form.__pendingDeviceKeys = pendingKeyText();
768
+ return form;
769
+ } catch (_) { return null; }
770
+ }
771
+
772
+ function formSignature(form) {
773
+ return JSON.stringify(form ?? null);
774
+ }
775
+
776
+ function isFormDirty() {
777
+ return savedForm !== null && formSignature(readForm()) !== formSignature(savedForm);
778
+ }
779
+
780
+ function hasConfigChanges() {
781
+ if (savedForm === null) return false;
782
+ const current = readForm();
783
+ if (!current) return false;
784
+ const currentConfig = { ...current };
785
+ const savedConfig = { ...savedForm };
786
+ delete currentConfig.__pendingDeviceKeys;
787
+ delete savedConfig.__pendingDeviceKeys;
788
+ return formSignature(currentConfig) !== formSignature(savedConfig);
789
+ }
790
+
791
+ function sectionIsDirty(name) {
792
+ if (savedForm === null) return false;
793
+ const form = readForm();
794
+ const keys = SECTION_KEYS[name];
795
+ if (!form || !keys) return false;
796
+ return keys.some((key) => JSON.stringify(form[key]) !== JSON.stringify(savedForm[key]));
797
+ }
798
+
799
+ function renderSaveState() {
800
+ const bar = $('savebar');
801
+ if (!bar) return;
802
+ const loading = savedForm === null;
803
+ const dirty = !loading && formSignature(readForm()) !== formSignature(savedForm);
804
+ const state = loading ? 'loading' : dirty ? 'dirty' : 'saved';
805
+ bar.dataset.state = state;
806
+
807
+ const pendingKeys = pendingKeyText().length > 0;
808
+ const label = $('saveStateLabel');
809
+ const hint = $('saveStateHint');
810
+ if (label) {
811
+ text(label, saveBusy ? '正在保存…' : saveError ? '保存失败' : loading ? '正在读取配置…' : pendingKeys ? '有未追加的 Device Key' : dirty ? '有未保存的更改' : '全部更改已保存');
812
+ }
813
+ if (hint) {
814
+ text(hint, saveBusy ? '正在写入配置文件…' : saveError ? saveError : loading ? '读取完成后会显示保存状态' : pendingKeys ? '先点击「追加密钥」把密钥加入配置' : dirty ? '点击「保存更改」写入配置' : (lastSavedAt ? '上次保存 ' + lastSavedAt : '当前配置已载入,尚未修改'));
815
+ }
816
+
817
+ const saveAll = $('saveAll');
818
+ const discard = $('discardAll');
819
+ if (saveAll) saveAll.disabled = saveBusy || loading || !dirty || pendingKeys;
820
+ if (discard) discard.disabled = saveBusy || loading || !dirty;
821
+ const sectionButtons = {
822
+ save: 'default',
823
+ saveChannels: 'channels',
824
+ saveRules: 'rules',
825
+ saveBrowser: 'browser',
826
+ saveMute: 'mute'
827
+ };
828
+ for (const [id, section] of Object.entries(sectionButtons)) {
829
+ const button = $(id);
830
+ if (button) button.disabled = saveBusy || loading || !sectionIsDirty(section) || pendingKeys;
831
+ }
832
+
833
+ const sectionStatuses = {
834
+ barkSaveStatus: 'default',
835
+ rulesSaveStatus: 'rules',
836
+ channelsSaveStatus: 'channels',
837
+ browserSaveStatus: 'browser',
838
+ muteSaveStatus: 'mute'
839
+ };
840
+ for (const [id, section] of Object.entries(sectionStatuses)) {
841
+ const node = $(id);
842
+ if (!node) continue;
843
+ const sectionDirty = sectionIsDirty(section);
844
+ const inline = saveBusy ? '保存中…' : saveError ? saveError : loading ? '' : sectionDirty ? '有未保存的更改' : (lastSavedAt ? '已保存 ' + lastSavedAt : '已保存');
845
+ node.textContent = inline;
846
+ node.className = 'save-status ' + (saveBusy || saveError || sectionDirty ? 'warn' : 'ok');
847
+ }
848
+
849
+ document.querySelectorAll('[data-section-state]').forEach((node) => {
850
+ const name = node.getAttribute('data-section-state');
851
+ const sectionDirty = sectionIsDirty(name);
852
+ node.dataset.state = loading ? '' : saveBusy ? 'saving' : sectionDirty ? 'dirty' : 'saved';
853
+ text(node, loading ? '读取中…' : saveBusy ? '保存中…' : sectionDirty ? '未保存' : '已保存');
854
+ });
855
+
856
+ const viewDirty = {
857
+ overview: false,
858
+ delivery: sectionIsDirty('default') || sectionIsDirty('channels'),
859
+ rules: sectionIsDirty('rules'),
860
+ browser: sectionIsDirty('browser'),
861
+ mute: sectionIsDirty('mute')
862
+ };
863
+ document.querySelectorAll('.topnav [data-goto]').forEach((button) => {
864
+ button.dataset.dirty = viewDirty[button.dataset.goto] ? 'true' : 'false';
865
+ });
866
+ }
867
+
868
+ function captureSavedForm(stamp) {
869
+ savedForm = readForm();
870
+ if (stamp) lastSavedAt = stamp;
871
+ saveError = '';
872
+ saveBusy = false;
873
+ renderSaveState();
874
+ }
875
+
876
+ function refreshDirtyState() {
877
+ if (savedForm !== null) {
878
+ saveError = '';
879
+ renderSaveState();
880
+ }
881
+ }
882
+
883
+ function saveFailed(message) {
884
+ saveBusy = false;
885
+ saveError = message || '保存失败';
886
+ renderSaveState();
887
+ }
888
+
395
889
  function markChannelsDirty() {
396
- setSaveStatus('channelsSaveStatus', '有未保存的更改,点“保存全部更改”生效', 'warn');
890
+ refreshDirtyState();
397
891
  }
398
892
 
399
893
  async function requestAllowFail(path, body) {
@@ -615,6 +1109,7 @@ export function renderUiPage({ version, embedded = false }) {
615
1109
  }
616
1110
 
617
1111
  async function testChannel(id, button, info) {
1112
+ if (pendingKeyText()) { toast('请先点击「追加密钥」添加新增密钥', true); return; }
618
1113
  button.disabled = true;
619
1114
  try {
620
1115
  const saved = await request(api.config, collect());
@@ -623,6 +1118,7 @@ export function renderUiPage({ version, embedded = false }) {
623
1118
  fill(saved.config);
624
1119
  status(saved);
625
1120
  renderMutes(saved);
1121
+ captureSavedForm(nowStamp());
626
1122
  const data = await requestAllowFail(api.testChannel, { id });
627
1123
  const detail = (data.result && data.result.results && data.result.results[0]) || {};
628
1124
  renderChannelTestResult(id, data.result || {});
@@ -682,6 +1178,7 @@ export function renderUiPage({ version, embedded = false }) {
682
1178
  }
683
1179
 
684
1180
  function fill(config) {
1181
+ $('newKeys').value = '';
685
1182
  $('server').value = config.server || '';
686
1183
  $('group').value = config.group || '';
687
1184
  $('icon').value = config.icon || '';
@@ -707,6 +1204,20 @@ export function renderUiPage({ version, embedded = false }) {
707
1204
  $('linkToSession').checked = config.linkToSession === true;
708
1205
  $('trace').checked = config.trace === true;
709
1206
 
1207
+ $('browserNotifyEnabled').checked = config.browserNotifyEnabled === true;
1208
+ $('browserNotifyOnReply').checked = config.browserNotifyOnReply !== false;
1209
+ $('browserNotifyOnApproval').checked = config.browserNotifyOnApproval !== false;
1210
+ $('browserNotifyOnQuestion').checked = config.browserNotifyOnQuestion !== false;
1211
+ $('browserNotifySkipForeground').checked = config.browserNotifySkipForeground !== false;
1212
+ $('browserNotifyUsePushMutes').checked = config.browserNotifyUsePushMutes !== false;
1213
+ $('browserNotifyReplyBody').value = config.browserNotifyReplyBody || '{status} · {summary}';
1214
+ $('browserNotifyApprovalBody').value = config.browserNotifyApprovalBody || '{status} · {tool} · {reason}';
1215
+ $('browserNotifyQuestionBody').value = config.browserNotifyQuestionBody || '{status} · {question}';
1216
+ $('browserNotifyMaxBodyLength').value = config.browserNotifyMaxBodyLength || 200;
1217
+ renderBrowserPermission();
1218
+ renderTemplatePreviews();
1219
+ updateBrowserMuteVisibility();
1220
+
710
1221
  const list = $('keylist');
711
1222
  list.replaceChildren();
712
1223
  if (!config.deviceKeyCount) {
@@ -759,6 +1270,36 @@ export function renderUiPage({ version, embedded = false }) {
759
1270
  warnings.hidden = true;
760
1271
  text(warnings, '');
761
1272
  }
1273
+ syncOverview(data);
1274
+ }
1275
+
1276
+ function syncOverview(data) {
1277
+ const cfg = data && data.config ? data.config : (current && current.config) || {};
1278
+ const pushMeta = $('overviewPushMeta');
1279
+ const pushState = $('overviewPushState');
1280
+ const browserMeta = $('overviewBrowserMeta');
1281
+ const browserState = $('overviewBrowserState');
1282
+ const channelCount = Array.isArray(cfg.channels) ? cfg.channels.length : 0;
1283
+ if (pushMeta) text(pushMeta, (cfg.deviceKeyCount || 0) + ' 台设备 · ' + channelCount + ' 个渠道');
1284
+ if (pushState) {
1285
+ pushState.dataset.state = cfg.enabled ? 'ok' : 'warn';
1286
+ text(pushState, cfg.enabled ? '已启用' : '已停用');
1287
+ }
1288
+ const permission = notificationState();
1289
+ if (browserMeta) text(browserMeta, permission.key === 'granted' ? '已授权' : permission.key === 'denied' ? '已拒绝' : '等待授权');
1290
+ if (browserState) {
1291
+ browserState.dataset.state = permission.cls;
1292
+ text(browserState, permission.key === 'granted' ? '可用' : permission.key === 'denied' ? '已拒绝' : '待授权');
1293
+ }
1294
+ const last = $('overviewLast');
1295
+ if (last) {
1296
+ const delivery = data && data.lastDelivery;
1297
+ if (!delivery) text(last, '还没有投递记录');
1298
+ else {
1299
+ const when = delivery.at ? new Date(delivery.at).toLocaleTimeString('zh-CN', { hour: '2-digit', minute: '2-digit' }) : '';
1300
+ text(last, labelOf(delivery.kind) + ' · ' + (delivery.ok ? '已送达' : delivery.skipped ? '已跳过' : '失败') + (when ? ' · ' + when : ''));
1301
+ }
1302
+ }
762
1303
  }
763
1304
 
764
1305
  function labelOf(kind) {
@@ -802,9 +1343,56 @@ export function renderUiPage({ version, embedded = false }) {
802
1343
  ].filter(Boolean);
803
1344
  sessionBox.append(muteRow('session', session.id, session.title || '未命名', subLines, mutedSessions.has(session.id)));
804
1345
  }
1346
+ renderBrowserMutes(data);
805
1347
  }
806
1348
 
807
- function muteRow(kind, id, title, sub, muted) {
1349
+ function renderBrowserMutes(data) {
1350
+ if (!data || !data.mute || !data.catalog) return;
1351
+ const mutedWorkspaces = new Set(data.mute.browserWorkspaces || []);
1352
+ const mutedSessions = new Set(data.mute.browserSessions || []);
1353
+ const workspaceBox = $('browserWorkspaces');
1354
+ if (workspaceBox) {
1355
+ workspaceBox.replaceChildren();
1356
+ if (!data.catalog.workspaces.length) {
1357
+ const empty = document.createElement('div'); empty.className = 'empty'; text(empty, '没有工作区记录');
1358
+ workspaceBox.append(empty);
1359
+ }
1360
+ for (const workspace of data.catalog.workspaces) {
1361
+ workspaceBox.append(muteRow('workspace', workspace.id, workspace.title || workspace.id, workspace.path, mutedWorkspaces.has(workspace.id), 'browser'));
1362
+ }
1363
+ }
1364
+
1365
+ const queryInput = $('browserSessionSearch');
1366
+ const query = queryInput ? (queryInput.value || '').trim().toLowerCase() : '';
1367
+ const sessionBox = $('browserSessions');
1368
+ if (sessionBox) {
1369
+ sessionBox.replaceChildren();
1370
+ const rows = data.catalog.sessions.filter((session) => {
1371
+ if (!query) return true;
1372
+ return String(session.title || '').toLowerCase().includes(query) || String(session.id).toLowerCase().includes(query);
1373
+ });
1374
+ const sessionCount = $('browserSessionCount');
1375
+ if (sessionCount) text(sessionCount, String(rows.length));
1376
+ if (!rows.length) {
1377
+ const empty = document.createElement('div'); empty.className = 'empty'; text(empty, '没有会话记录');
1378
+ sessionBox.append(empty);
1379
+ }
1380
+ for (const session of rows) {
1381
+ const workspaceLabel = session.workspaceTitle || session.workspaceId;
1382
+ const subLines = [
1383
+ session.id,
1384
+ workspaceLabel ? ('工作区 ' + workspaceLabel) : '',
1385
+ session.running ? '运行中' : '',
1386
+ session.archived ? '已归档' : '',
1387
+ session.orphaned && !session.archived ? '仅保留静音记录' : '',
1388
+ ].filter(Boolean);
1389
+ sessionBox.append(muteRow('session', session.id, session.title || '未命名', subLines, mutedSessions.has(session.id), 'browser'));
1390
+ }
1391
+ }
1392
+ updateBrowserMuteVisibility();
1393
+ }
1394
+
1395
+ function muteRow(kind, id, title, sub, muted, channel) {
808
1396
  const item = document.createElement('label');
809
1397
  item.className = 'item';
810
1398
  const box = document.createElement('input');
@@ -813,9 +1401,8 @@ export function renderUiPage({ version, embedded = false }) {
813
1401
  box.addEventListener('change', async () => {
814
1402
  box.disabled = true;
815
1403
  try {
816
- const data = await request(api.mute, { kind, id, muted: box.checked });
1404
+ const data = await request(api.mute, { kind, id, muted: box.checked, channel: channel || 'push' });
817
1405
  current = data;
818
- fill(data.config);
819
1406
  status(data);
820
1407
  renderMutes(data);
821
1408
  toast(box.checked ? '已静音' : '已取消静音');
@@ -854,6 +1441,14 @@ export function renderUiPage({ version, embedded = false }) {
854
1441
  window.parent.postMessage({ type: 'dsh-bark-push:height', height }, window.location.origin);
855
1442
  }
856
1443
 
1444
+ window.addEventListener('message', (event) => {
1445
+ if (event.origin !== window.location.origin) return;
1446
+ const data = event.data;
1447
+ if (!data || data.type !== 'dsh-bark-push:browser-permission-result') return;
1448
+ renderBrowserPermission();
1449
+ toast(data.permission === 'granted' ? '浏览器通知权限已授予' : '浏览器通知权限未授予', data.permission !== 'granted');
1450
+ });
1451
+
857
1452
  if (window.parent !== window) {
858
1453
  window.addEventListener('load', postHeight);
859
1454
  if (typeof ResizeObserver !== 'undefined') new ResizeObserver(postHeight).observe(document.body);
@@ -887,7 +1482,17 @@ export function renderUiPage({ version, embedded = false }) {
887
1482
  notifyOnQuestion: $('notifyOnQuestion').checked,
888
1483
  includeSubagents: $('includeSubagents').checked,
889
1484
  linkToSession: $('linkToSession').checked,
890
- trace: $('trace').checked
1485
+ trace: $('trace').checked,
1486
+ browserNotifyEnabled: $('browserNotifyEnabled').checked,
1487
+ browserNotifyOnReply: $('browserNotifyOnReply').checked,
1488
+ browserNotifyOnApproval: $('browserNotifyOnApproval').checked,
1489
+ browserNotifyOnQuestion: $('browserNotifyOnQuestion').checked,
1490
+ browserNotifySkipForeground: $('browserNotifySkipForeground').checked,
1491
+ browserNotifyUsePushMutes: $('browserNotifyUsePushMutes').checked,
1492
+ browserNotifyReplyBody: $('browserNotifyReplyBody').value,
1493
+ browserNotifyApprovalBody: $('browserNotifyApprovalBody').value,
1494
+ browserNotifyQuestionBody: $('browserNotifyQuestionBody').value,
1495
+ browserNotifyMaxBodyLength: Number($('browserNotifyMaxBodyLength').value)
891
1496
  };
892
1497
  }
893
1498
 
@@ -899,18 +1504,38 @@ export function renderUiPage({ version, embedded = false }) {
899
1504
  fill(data.config);
900
1505
  status(data);
901
1506
  renderMutes(data);
1507
+ captureSavedForm();
902
1508
  } catch (error) {
1509
+ saveError = '读取失败:' + error.message;
1510
+ renderSaveState();
903
1511
  toast('读取失败:' + error.message, true);
904
1512
  }
905
1513
  }
906
1514
 
907
- const STATUS_BY_BUTTON = { saveChannels: 'channelsSaveStatus', saveRules: 'rulesSaveStatus', save: 'barkSaveStatus' };
1515
+ const STATUS_BY_BUTTON = { saveChannels: 'channelsSaveStatus', saveRules: 'rulesSaveStatus', save: 'barkSaveStatus', saveBrowser: 'browserSaveStatus', saveMute: 'muteSaveStatus' };
908
1516
 
909
1517
  // Single save path shared by every section's "保存全部更改" button. It always
910
1518
  // persists the whole config; only the inline status location differs.
1519
+ function broadcastBrowserConfig(config) {
1520
+ if (window.parent === window || !config) return;
1521
+ try {
1522
+ window.parent.postMessage({
1523
+ type: 'dsh-bark-push:config-updated',
1524
+ config: {
1525
+ browserNotifyEnabled: config.browserNotifyEnabled === true,
1526
+ browserNotifySkipForeground: config.browserNotifySkipForeground !== false,
1527
+ },
1528
+ }, window.location.origin);
1529
+ } catch (_) { /* optional parent bridge */ }
1530
+ }
1531
+
911
1532
  async function persistConfig(button) {
1533
+ if (pendingKeyText()) { toast('请先点击「追加密钥」添加新增密钥', true); return false; }
912
1534
  const statusId = (button && STATUS_BY_BUTTON[button.id]) || 'barkSaveStatus';
913
1535
  if (button) button.disabled = true;
1536
+ saveBusy = true;
1537
+ saveError = '';
1538
+ renderSaveState();
914
1539
  setSaveStatus(statusId, '保存中…', '');
915
1540
  try {
916
1541
  const data = await request(api.config, collect());
@@ -919,15 +1544,17 @@ export function renderUiPage({ version, embedded = false }) {
919
1544
  fill(data.config);
920
1545
  status(data);
921
1546
  renderMutes(data);
922
- setSaveStatus(statusId, '已保存 ' + nowStamp(), 'ok');
1547
+ broadcastBrowserConfig(data.config);
1548
+ captureSavedForm(nowStamp());
923
1549
  toast('配置已保存');
924
1550
  return true;
925
1551
  } catch (error) {
926
- setSaveStatus(statusId, '保存失败:' + (error.message || '未知错误'), 'bad');
1552
+ saveFailed('保存失败:' + (error.message || '未知错误'));
927
1553
  toast('保存失败:' + error.message, true);
928
1554
  return false;
929
1555
  } finally {
930
1556
  if (button) button.disabled = false;
1557
+ renderSaveState();
931
1558
  }
932
1559
  }
933
1560
 
@@ -947,8 +1574,45 @@ export function renderUiPage({ version, embedded = false }) {
947
1574
  $('save').addEventListener('click', () => { void persistConfig($('save')); });
948
1575
  $('saveChannels').addEventListener('click', () => { void persistConfig($('saveChannels')); });
949
1576
  $('saveRules').addEventListener('click', () => { void persistConfig($('saveRules')); });
1577
+ $('saveBrowser').addEventListener('click', () => { void persistConfig($('saveBrowser')); });
1578
+ $('saveAll').addEventListener('click', () => { void persistConfig($('saveAll')); });
1579
+ $('discardAll').addEventListener('click', async () => {
1580
+ if (!isFormDirty()) return;
1581
+ if (!window.confirm('放弃当前未保存的更改,恢复为最近保存的配置?')) return;
1582
+ await load();
1583
+ toast('已恢复为最近保存的配置');
1584
+ });
1585
+ document.addEventListener('input', (event) => {
1586
+ if (event.target && event.target.closest && event.target.closest('main')) refreshDirtyState();
1587
+ });
1588
+ document.addEventListener('change', (event) => {
1589
+ if (event.target && event.target.closest && event.target.closest('main')) refreshDirtyState();
1590
+ });
1591
+ window.addEventListener('keydown', (event) => {
1592
+ if (!(event.metaKey || event.ctrlKey) || String(event.key).toLowerCase() !== 's') return;
1593
+ event.preventDefault();
1594
+ if (!saveBusy && savedForm !== null && isFormDirty()) void persistConfig($('saveAll'));
1595
+ });
1596
+ window.addEventListener('beforeunload', (event) => {
1597
+ if (savedForm === null || !isFormDirty()) return;
1598
+ event.preventDefault();
1599
+ event.returnValue = '';
1600
+ });
1601
+ document.querySelectorAll('[data-goto]').forEach((button) => {
1602
+ button.addEventListener('click', () => setView(button.dataset.goto, true));
1603
+ });
1604
+ $('saveMute').addEventListener('click', () => { void persistConfig($('saveMute')); });
1605
+ $('requestNotifyPermission').addEventListener('click', () => { void requestBrowserPermission(); });
1606
+ $('testBrowserNotify').addEventListener('click', testBrowserNotification);
1607
+ $('browserNotifyUsePushMutes').addEventListener('change', updateBrowserMuteVisibility);
1608
+ $('browserSessionSearch').addEventListener('input', () => { if (current) renderBrowserMutes(current); });
1609
+ for (const kind of ['reply', 'approval', 'question']) {
1610
+ const input = $('browserNotify' + kind[0].toUpperCase() + kind.slice(1) + 'Body');
1611
+ if (input) input.addEventListener('input', () => renderTemplatePreview(kind));
1612
+ }
950
1613
 
951
1614
  $('addKeys').addEventListener('click', async () => {
1615
+ if (hasConfigChanges()) { toast('请先保存当前更改,再追加密钥', true); return; }
952
1616
  const raw = $('newKeys').value.trim();
953
1617
  if (!raw) { toast('请先粘贴至少一个 Device Key', true); return; }
954
1618
  const keys = raw.split(/\\r?\\n|,/).map((part) => part.trim()).filter(Boolean);
@@ -960,7 +1624,7 @@ export function renderUiPage({ version, embedded = false }) {
960
1624
  fill(data.config);
961
1625
  status(data);
962
1626
  renderMutes(data);
963
- setSaveStatus('barkSaveStatus', '已追加 ' + keys.length + ' 个密钥', 'ok');
1627
+ captureSavedForm(nowStamp());
964
1628
  toast('已追加 ' + keys.length + ' 个密钥');
965
1629
  } catch (error) {
966
1630
  toast('保存失败:' + error.message, true);
@@ -970,6 +1634,7 @@ export function renderUiPage({ version, embedded = false }) {
970
1634
  });
971
1635
 
972
1636
  $('clearKeys').addEventListener('click', async () => {
1637
+ if (hasConfigChanges()) { toast('请先保存当前更改,再清空 Device Key', true); return; }
973
1638
  if (!window.confirm('确定清空全部 Device Key?')) return;
974
1639
  try {
975
1640
  const data = await request(api.config, { clearDeviceKeys: true });
@@ -977,7 +1642,7 @@ export function renderUiPage({ version, embedded = false }) {
977
1642
  fill(data.config);
978
1643
  status(data);
979
1644
  renderMutes(data);
980
- setSaveStatus('barkSaveStatus', '已清空 Device Key', 'ok');
1645
+ captureSavedForm(nowStamp());
981
1646
  toast('已清空 Device Key');
982
1647
  } catch (error) {
983
1648
  toast('保存失败:' + error.message, true);
@@ -985,6 +1650,7 @@ export function renderUiPage({ version, embedded = false }) {
985
1650
  });
986
1651
 
987
1652
  $('reset').addEventListener('click', async () => {
1653
+ if (hasConfigChanges()) { toast('请先保存或放弃当前更改,再恢复默认配置', true); return; }
988
1654
  if (!window.confirm('恢复默认配置?静音状态、Device Key 与已配置渠道不会被清除。')) return;
989
1655
  try {
990
1656
  const data = await request(api.config, { reset: true });
@@ -992,7 +1658,7 @@ export function renderUiPage({ version, embedded = false }) {
992
1658
  fill(data.config);
993
1659
  status(data);
994
1660
  renderMutes(data);
995
- setSaveStatus('barkSaveStatus', '已恢复默认', 'ok');
1661
+ captureSavedForm(nowStamp());
996
1662
  toast('已恢复默认配置');
997
1663
  } catch (error) {
998
1664
  toast('恢复失败:' + error.message, true);
@@ -1005,7 +1671,6 @@ export function renderUiPage({ version, embedded = false }) {
1005
1671
  const data = await requestAllowFail(api.test, {});
1006
1672
  if (data.state) {
1007
1673
  current = data.state;
1008
- fill(data.state.config);
1009
1674
  status(data.state);
1010
1675
  renderMutes(data.state);
1011
1676
  }
@@ -1026,6 +1691,10 @@ export function renderUiPage({ version, embedded = false }) {
1026
1691
  });
1027
1692
 
1028
1693
  $('sessionSearch').addEventListener('input', () => { if (current) renderMutes(current); });
1694
+ try {
1695
+ const initialView = new URL(window.location.href).searchParams.get('view');
1696
+ setView(initialView && VIEW_META[initialView] ? initialView : 'overview', false);
1697
+ } catch (_) { setView('overview', false); }
1029
1698
  load();
1030
1699
  })();
1031
1700
  </script>