dsh-bark-push 0.1.6 → 0.2.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/client.js CHANGED
@@ -5,6 +5,14 @@ window.__ModuleLoader__.load({
5
5
  var exports = module.exports;
6
6
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
7
7
  var React = require("react");
8
+ // Host-shipped menu primitive; absent in minimal/test hosts, so fall back
9
+ // to a locally styled button.
10
+ var UI_PRIMITIVES = null;
11
+ try {
12
+ UI_PRIMITIVES = require("@deepseek-ai/dsh-client-ui-primitives") || null;
13
+ } catch (_) {
14
+ UI_PRIMITIVES = null;
15
+ }
8
16
 
9
17
  /**
10
18
  * Browser half of dsh-bark-push.
@@ -28,24 +36,26 @@ window.__ModuleLoader__.load({
28
36
 
29
37
  const COPY = {
30
38
  zh: {
31
- nav: "Bark 推送",
32
- mute: "静音 Bark 通知",
33
- unmute: "取消静音 Bark 通知",
34
- muted: "Bark 通知已静音",
35
- unmuted: "Bark 通知已取消静音",
36
- settingsTitle: "Bark 推送",
37
- settingsIntro: "在下方配置 Bark Server、Device Key、通知类型与静音状态。",
39
+ nav: "推送通知",
40
+ mute: "静音推送通知",
41
+ unmute: "取消静音推送通知",
42
+ muted: "推送通知已静音",
43
+ mutedWorkspace: "工作区推送通知已静音",
44
+ unmuted: "推送通知已取消静音",
45
+ settingsTitle: "推送通知",
46
+ settingsIntro: "在下方管理推送渠道、通知规则与静音状态。",
38
47
  unavailable: "管理接口不可用;请确认 Web 运行时与 client-connection 已加载。",
39
48
  failed: "操作失败",
40
49
  },
41
50
  en: {
42
- nav: "Bark push",
43
- mute: "Mute Bark notifications",
44
- unmute: "Unmute Bark notifications",
45
- muted: "Bark notifications muted",
46
- unmuted: "Bark notifications unmuted",
47
- settingsTitle: "Bark push",
48
- settingsIntro: "Configure the Bark server, device keys, notification types, and mute state below.",
51
+ nav: "Push notifications",
52
+ mute: "Mute push notifications",
53
+ unmute: "Unmute push notifications",
54
+ muted: "Push notifications muted",
55
+ mutedWorkspace: "Workspace push notifications muted",
56
+ unmuted: "Push notifications unmuted",
57
+ settingsTitle: "Push notifications",
58
+ settingsIntro: "Manage push channels, notification rules, and mute state below.",
49
59
  unavailable: "Management API unavailable; check that the Web runtime and client-connection are mounted.",
50
60
  failed: "Action failed",
51
61
  },
@@ -71,9 +81,51 @@ window.__ModuleLoader__.load({
71
81
  loaded: false,
72
82
  workspaces: new Set(),
73
83
  sessions: new Set(),
84
+ /** Session id -> workspace id, so a row can reflect workspace-level mute. */
85
+ sessionWorkspace: new Map(),
86
+ /** Workspace id -> root path, used to infer a workspace from a Session cwd. */
87
+ workspacePaths: new Map(),
74
88
  listeners: new Set(),
75
89
  };
76
90
 
91
+ /**
92
+ * Transient notices raised by the iframe management page. The iframe cannot
93
+ * anchor a fixed toast (the host grows it to full content height), so it
94
+ * posts here and this top-document store feeds a `shell.overlay` entry.
95
+ */
96
+ const toastStore = (() => {
97
+ let current = null;
98
+ let seq = 0;
99
+ const listeners = new Set();
100
+ const emit = () => {
101
+ for (const listener of listeners) {
102
+ try {
103
+ listener();
104
+ } catch (_) {
105
+ // A broken subscriber must not stop the others.
106
+ }
107
+ }
108
+ };
109
+ return {
110
+ get: () => current,
111
+ subscribe(listener) {
112
+ listeners.add(listener);
113
+ return () => listeners.delete(listener);
114
+ },
115
+ show(message, kind) {
116
+ if (!message) return;
117
+ seq += 1;
118
+ current = { id: seq, message: String(message), kind: kind === 'bad' ? 'bad' : 'ok' };
119
+ emit();
120
+ },
121
+ dismiss() {
122
+ if (current === null) return;
123
+ current = null;
124
+ emit();
125
+ },
126
+ };
127
+ })();
128
+
77
129
  function emit() {
78
130
  for (const listener of store.listeners) {
79
131
  try {
@@ -84,10 +136,58 @@ window.__ModuleLoader__.load({
84
136
  }
85
137
  }
86
138
 
139
+ /** Longest workspace root containing a Session cwd. */
140
+ function workspaceIdForPath(paths, cwd) {
141
+ const target = String(cwd || "").replace(/[\\/]+$/, "");
142
+ if (target.length === 0) return undefined;
143
+ let best;
144
+ let bestLength = -1;
145
+ for (const [id, path] of paths) {
146
+ const root = String(path || "").replace(/[\\/]+$/, "");
147
+ if (root.length === 0) continue;
148
+ if (target === root || target.startsWith(root + "/") || target.startsWith(root + "\\")) {
149
+ if (root.length > bestLength) {
150
+ best = id;
151
+ bestLength = root.length;
152
+ }
153
+ }
154
+ }
155
+ return best;
156
+ }
157
+
87
158
  function adopt(payload) {
88
159
  if (!payload || !payload.mute) return;
89
160
  store.workspaces = new Set(Array.isArray(payload.mute.workspaces) ? payload.mute.workspaces : []);
90
161
  store.sessions = new Set(Array.isArray(payload.mute.sessions) ? payload.mute.sessions : []);
162
+ if (payload.catalog && typeof payload.catalog === "object") {
163
+ const catalog = payload.catalog;
164
+ const paths = new Map();
165
+ for (const row of Array.isArray(catalog.workspaces) ? catalog.workspaces : []) {
166
+ if (row && typeof row.id === "string" && typeof row.path === "string" && row.path.length > 0) {
167
+ paths.set(row.id, row.path);
168
+ }
169
+ }
170
+ store.workspacePaths = paths;
171
+
172
+ const map = new Map();
173
+ if (catalog.sessionWorkspace && typeof catalog.sessionWorkspace === "object") {
174
+ for (const [sessionId, workspaceId] of Object.entries(catalog.sessionWorkspace)) {
175
+ if (typeof sessionId === "string" && typeof workspaceId === "string" && workspaceId.length > 0) {
176
+ map.set(sessionId, workspaceId);
177
+ }
178
+ }
179
+ }
180
+ for (const row of Array.isArray(catalog.sessions) ? catalog.sessions : []) {
181
+ if (!row || typeof row.id !== "string") continue;
182
+ if (typeof row.workspaceId === "string" && row.workspaceId.length > 0) {
183
+ map.set(row.id, row.workspaceId);
184
+ } else if (typeof row.cwd === "string" && row.cwd.length > 0) {
185
+ const inferred = workspaceIdForPath(paths, row.cwd);
186
+ if (inferred !== undefined) map.set(row.id, inferred);
187
+ }
188
+ }
189
+ store.sessionWorkspace = map;
190
+ }
91
191
  store.loaded = true;
92
192
  emit();
93
193
  }
@@ -143,6 +243,20 @@ window.__ModuleLoader__.load({
143
243
  return set.has(id);
144
244
  }
145
245
 
246
+ /** Effective mute for a Session row: its own mute, or its workspace's mute. */
247
+ function useSessionMuteState(sessionId) {
248
+ const [, force] = React.useReducer((value) => value + 1, 0);
249
+ React.useEffect(() => {
250
+ const listener = () => force();
251
+ store.listeners.add(listener);
252
+ return () => store.listeners.delete(listener);
253
+ }, []);
254
+ const session = store.sessions.has(sessionId);
255
+ const workspaceId = store.sessionWorkspace.get(sessionId);
256
+ const workspace = typeof workspaceId === "string" && store.workspaces.has(workspaceId);
257
+ return { session, workspace };
258
+ }
259
+
146
260
  // Bell / bell-off glyphs mirror lib/assets/bell.svg and bell-off.svg.
147
261
  // They are inlined so `currentColor` follows the host theme and no
148
262
  // authenticated image request is needed for a 24x24 icon.
@@ -181,10 +295,136 @@ window.__ModuleLoader__.load({
181
295
  );
182
296
  }
183
297
 
184
- function SessionMuteAction(props) {
298
+ /**
299
+ * Frame-wide toast rendered into the host's `shell.overlay` seat. It lives
300
+ * in the top document (outside the Settings iframe), so it stays visible
301
+ * regardless of how far the Settings content is scrolled.
302
+ */
303
+ function BarkToast(props) {
304
+ const notify = props.store;
305
+ const [state, setState] = React.useState(notify.get());
306
+ React.useEffect(() => notify.subscribe(() => setState(notify.get())), [notify]);
307
+ React.useEffect(() => {
308
+ if (state === null) return undefined;
309
+ const timer = setTimeout(() => notify.dismiss(), 3200);
310
+ return () => clearTimeout(timer);
311
+ }, [state, notify]);
312
+ if (state === null) return null;
313
+ const tone = state.kind === 'bad'
314
+ ? { background: '#c0392b', color: '#ffffff' }
315
+ : { background: '#1c1d21', color: '#ffffff' };
316
+ return React.createElement(
317
+ 'div',
318
+ {
319
+ role: 'status',
320
+ 'aria-live': 'polite',
321
+ 'data-bark-toast': state.kind,
322
+ style: {
323
+ position: 'absolute',
324
+ left: '50%',
325
+ bottom: '24px',
326
+ transform: 'translateX(-50%)',
327
+ maxWidth: '80vw',
328
+ padding: '9px 16px',
329
+ borderRadius: '999px',
330
+ fontSize: '13px',
331
+ lineHeight: '1.5',
332
+ textAlign: 'center',
333
+ boxShadow: '0 6px 24px rgba(0, 0, 0, .18)',
334
+ pointerEvents: 'auto',
335
+ ...tone,
336
+ },
337
+ },
338
+ state.message,
339
+ );
340
+ }
341
+
342
+ function sessionCopy(props) {
343
+ return typeof props.t === "function" ? props.t : (key) => COPY.zh[key] || key;
344
+ }
345
+
346
+ /** Inject the menu-row styles once; mirrors the host's own menu item look. */
347
+ function ensureMenuStyles() {
348
+ try {
349
+ if (typeof document === "undefined" || !document.head) return;
350
+ if (document.getElementById("dsh-bark-push-menu-style")) return;
351
+ const style = document.createElement("style");
352
+ style.id = "dsh-bark-push-menu-style";
353
+ style.textContent =
354
+ ".bark-menuItem{display:flex;align-items:center;gap:8px;width:100%;box-sizing:border-box;" +
355
+ "padding:6px 10px;border:0;border-radius:6px;background:none;" +
356
+ "color:var(--dsw-alias-label-primary,rgba(20,20,20,.9));font-family:inherit;" +
357
+ "font-size:13px;line-height:20px;text-align:left;cursor:pointer}" +
358
+ ".bark-menuItem:hover{background:var(--dsw-alias-bg-layer-2,rgba(128,128,128,.14))}" +
359
+ ".bark-menuIcon{display:inline-flex;align-items:center;justify-content:center;width:16px;height:16px;flex:none}" +
360
+ ".bark-menuLabel{flex:1;min-width:0;text-align:left}";
361
+ document.head.append(style);
362
+ } catch (_) {
363
+ // Styling is cosmetic; the menu entry still works without it.
364
+ }
365
+ }
366
+
367
+ /** Session-row "..." / right-click menu entry that toggles this mute. */
368
+ function SessionMuteMenuItem(props) {
369
+ const translate = sessionCopy(props);
370
+ const muted = useMuted("session", props.sessionId);
371
+ const label = muted ? translate("unmute") : translate("mute");
372
+ const menu = typeof props.useMenuOpenState === "function" ? props.useMenuOpenState() : [false, () => {}];
373
+ const setMenuOpen = menu[1];
374
+ const select = (event) => {
375
+ if (event && typeof event.preventDefault === "function") event.preventDefault();
376
+ setMenuOpen(false);
377
+ toggle("session", props.sessionId).catch(() => {});
378
+ };
379
+ const icon = React.createElement(BellGlyph, { off: muted, size: 16 });
380
+ const MenuItemButton = UI_PRIMITIVES && typeof UI_PRIMITIVES.MenuItemButton === "function"
381
+ ? UI_PRIMITIVES.MenuItemButton
382
+ : null;
383
+ if (MenuItemButton) {
384
+ return React.createElement(
385
+ MenuItemButton,
386
+ { icon, onSelect: select, "data-bark-muted": muted ? "1" : "0" },
387
+ label,
388
+ );
389
+ }
390
+ return React.createElement(
391
+ "button",
392
+ {
393
+ type: "button",
394
+ role: "menuitem",
395
+ className: "bark-menuItem",
396
+ "data-bark-muted": muted ? "1" : "0",
397
+ onClick: select,
398
+ },
399
+ React.createElement("span", { className: "bark-menuIcon" }, icon),
400
+ React.createElement("span", { className: "bark-menuLabel" }, label),
401
+ );
402
+ }
403
+
404
+ /** Non-interactive muted mark in the Session row, only while muted. */
405
+ function SessionMutedMark(props) {
406
+ const translate = sessionCopy(props);
407
+ const state = useSessionMuteState(props.sessionId);
408
+ if (!state.session && !state.workspace) return null;
409
+ const label = state.workspace ? translate("mutedWorkspace") : translate("muted");
410
+ return React.createElement(
411
+ "span",
412
+ {
413
+ role: "img",
414
+ title: label,
415
+ "aria-label": label,
416
+ "data-bark-muted-mark": state.workspace ? "workspace" : "session",
417
+ style: { display: "inline-flex", alignItems: "center", opacity: 0.72 },
418
+ },
419
+ React.createElement(BellGlyph, { off: true, size: 12 }),
420
+ );
421
+ }
422
+
423
+ /** Current Session's header bell toggle (quick access, one icon only). */
424
+ function SessionHeaderMute(props) {
425
+ const translate = sessionCopy(props);
185
426
  const muted = useMuted("session", props.sessionId);
186
427
  const [busy, setBusy] = React.useState(false);
187
- const translate = typeof props.t === "function" ? props.t : (key) => COPY.zh[key] || key;
188
428
  const label = muted ? translate("unmute") : translate("mute");
189
429
  return React.createElement(
190
430
  "button",
@@ -197,22 +437,20 @@ window.__ModuleLoader__.load({
197
437
  style: {
198
438
  background: "transparent",
199
439
  border: 0,
200
- padding: "0 2px",
440
+ padding: "0 6px",
201
441
  cursor: "pointer",
202
- fontSize: "12px",
203
- lineHeight: "1",
204
- opacity: muted ? 0.95 : 0.5,
442
+ display: "inline-flex",
443
+ alignItems: "center",
444
+ opacity: muted ? 0.95 : 0.6,
205
445
  },
206
- onClick: (event) => {
207
- event.preventDefault();
208
- event.stopPropagation();
446
+ onClick: () => {
209
447
  setBusy(true);
210
448
  toggle("session", props.sessionId)
211
449
  .catch(() => {})
212
450
  .finally(() => setBusy(false));
213
451
  },
214
452
  },
215
- React.createElement(BellGlyph, { off: muted, size: 14 }),
453
+ React.createElement(BellGlyph, { off: muted, size: 16 }),
216
454
  );
217
455
  }
218
456
 
@@ -318,6 +556,7 @@ window.__ModuleLoader__.load({
318
556
  function apply(ctx) {
319
557
  propsContext = ctx;
320
558
  const t = bindCopy(ctx);
559
+ ensureMenuStyles();
321
560
 
322
561
  let disposeLocale;
323
562
  try {
@@ -328,6 +567,19 @@ window.__ModuleLoader__.load({
328
567
  }
329
568
 
330
569
  refresh();
570
+ // The first state fetch can race the connection/route mount. Retry soon
571
+ // until one succeeds, so mute state and the session->workspace map do not
572
+ // stay empty for a whole 60s polling period.
573
+ try {
574
+ const bootTimers = [];
575
+ const retry = () => { if (!store.loaded) refresh(); };
576
+ for (const delay of [600, 1500, 3000, 6000, 12000]) bootTimers.push(window.setTimeout(retry, delay));
577
+ ctx.effect(() => () => {
578
+ for (const id of bootTimers) window.clearTimeout(id);
579
+ }, "bark-push: initial refresh retry");
580
+ } catch (_) {
581
+ // No timers in a non-DOM harness: the normal refresh still runs later.
582
+ }
331
583
  try {
332
584
  ctx.effect(() => {
333
585
  const timer = window.setInterval(refresh, 60_000);
@@ -344,8 +596,38 @@ window.__ModuleLoader__.load({
344
596
  // Non-DOM test harnesses skip the refresh timer.
345
597
  }
346
598
 
599
+ // Bridge: the management iframe posts toast notices here for the
600
+ // frame-wide overlay, because a toast inside the auto-height iframe would
601
+ // be anchored to the whole (tall) document rather than the viewport.
602
+ try {
603
+ if (typeof window !== "undefined" && typeof window.addEventListener === "function") {
604
+ const onToast = (event) => {
605
+ if (event.origin !== window.location.origin) return;
606
+ const data = event.data;
607
+ if (!data || data.type !== "dsh-bark-push:toast") return;
608
+ toastStore.show(data.message, data.kind);
609
+ };
610
+ window.addEventListener("message", onToast);
611
+ ctx.effect(() => () => window.removeEventListener("message", onToast), "bark-push: toast bridge");
612
+ }
613
+ } catch (_) {
614
+ // No window (non-web composition): notices stay local to the iframe.
615
+ }
616
+
347
617
  if (!ctx.slots) return;
348
618
 
619
+ // Frame-wide overlay entry hosted by the layout shell (top document,
620
+ // above every column and outside their scroll containers).
621
+ try {
622
+ ctx.slots.inject("shell.overlay", () => ctx.slots.register({
623
+ name: "shell.overlay",
624
+ id: "dsh-bark-push.toast",
625
+ inject: () => ({ store: toastStore }),
626
+ }, BarkToast));
627
+ } catch (_) {
628
+ // Hosts without the overlay seat simply do not show host toasts.
629
+ }
630
+
349
631
  // Settings section: an authenticated iframe keeps the rich form out of
350
632
  // the client bundle and works in every web shell that declares the slot.
351
633
  try {
@@ -385,22 +667,45 @@ window.__ModuleLoader__.load({
385
667
  // Older Settings shells render their fallback nav glyph.
386
668
  }
387
669
 
388
- // Session-row bell, shown only when the host declares the list slot.
670
+ // Per-Session mute is contributed through the existing contextMenus
671
+ // session entry, which the host renders in both the right-click menu and
672
+ // the row's "..." menu. The crowded row hover strip is no longer used.
673
+ // A small non-interactive mark keeps the muted state glanceable without
674
+ // adding another clickable icon to the row.
389
675
  try {
390
- ctx.slots.inject("sidebar.workspaces.session.row.action", () =>
676
+ ctx.slots.inject("sidebar.session.row.trailing", () =>
391
677
  ctx.slots.register(
392
678
  {
393
- name: "sidebar.workspaces.session.row.action",
394
- id: "bark-push-mute",
395
- order: 30,
679
+ name: "sidebar.session.row.trailing",
680
+ id: "bark-push.muted-mark",
681
+ order: 500,
396
682
  locale: NS,
397
683
  inject: () => ({ t }),
398
684
  },
399
- SessionMuteAction,
685
+ SessionMutedMark,
400
686
  ),
401
687
  );
402
688
  } catch (_) {
403
- // Older hosts may not declare the row action slot.
689
+ // Older hosts may not declare the row trailing slot.
690
+ }
691
+
692
+ // Quick toggle for the Session that is currently open, in the header's
693
+ // right-aligned utilities. Session-scoped inject supplies the id.
694
+ try {
695
+ ctx.slots.inject("conversation.session.header.utilities", () =>
696
+ ctx.slots.register(
697
+ {
698
+ name: "conversation.session.header.utilities",
699
+ id: "bark-push.mute",
700
+ order: 10,
701
+ locale: NS,
702
+ inject: (sessionId) => ({ sessionId, t }),
703
+ },
704
+ SessionHeaderMute,
705
+ ),
706
+ );
707
+ } catch (_) {
708
+ // Older hosts may not declare the header utilities slot.
404
709
  }
405
710
 
406
711
  // Context-menu icons use the keyed contextMenu.icon slot. Register both
@@ -424,41 +729,39 @@ window.__ModuleLoader__.load({
424
729
  // Hosts without the keyed icon slot render text-only menu rows.
425
730
  }
426
731
 
427
- // Native context-menu entries for Session and workspace mute. The
428
- // service may activate after this plugin, so wait for it through
429
- // ctx.inject() instead of reading ctx.contextMenus at apply time.
732
+ // Session mute is a React menu row in the legacy slot the host renders
733
+ // in BOTH the row "..." menu and the right-click menu, together before
734
+ // the built-in Archive row. Using this slot instead of contextMenus
735
+ // keeps the position deterministic.
736
+ try {
737
+ ctx.slots.inject("sidebar.workspaces.session.menu.item", () =>
738
+ ctx.slots.register(
739
+ {
740
+ name: "sidebar.workspaces.session.menu.item",
741
+ id: "bark-push.mute",
742
+ order: 510,
743
+ locale: NS,
744
+ inject: () => ({ t }),
745
+ },
746
+ SessionMuteMenuItem,
747
+ ),
748
+ );
749
+ } catch (_) {
750
+ // Older hosts may not declare the row menu slot.
751
+ }
752
+
753
+ // Workspace mute stays in the context menu. The host renders the
754
+ // reveal/copy/open/archive workspace actions as one provider group at
755
+ // order 200, so "above archive" means sitting just before that group;
756
+ // order 199 is the closest slot available without a workspace menu slot.
430
757
  try {
431
758
  ctx.inject(["contextMenus"], (scope) => {
432
- scope.effect(
433
- () =>
434
- scope.contextMenus.register({
435
- id: "bark-push.session",
436
- target: "session",
437
- order: 900,
438
- resolve: (target) => {
439
- const id = target && target.sessionId;
440
- if (!id) return [];
441
- const muted = store.sessions.has(id);
442
- return [
443
- {
444
- id: "bark-mute",
445
- label: muted ? t("unmute") : t("mute"),
446
- icon: { key: muted ? "bark-push.bell-off" : "bark-push.bell" },
447
- run: () => {
448
- toggle("session", id).catch(() => {});
449
- },
450
- },
451
- ];
452
- },
453
- }),
454
- "bark-push: session mute menu",
455
- );
456
759
  scope.effect(
457
760
  () =>
458
761
  scope.contextMenus.register({
459
762
  id: "bark-push.workspace",
460
763
  target: "workspace",
461
- order: 900,
764
+ order: 199,
462
765
  resolve: (target) => {
463
766
  const id = target && target.workspaceId;
464
767
  if (!id) return [];
@@ -487,7 +790,7 @@ window.__ModuleLoader__.load({
487
790
 
488
791
  exports.apply = apply;
489
792
  exports.inject = inject;
490
- exports.__internals = { store, request, toggle, adopt, useMuted, COPY, NS, BELL_PATHS };
793
+ exports.__internals = { store, toastStore, request, toggle, adopt, useMuted, COPY, NS, BELL_PATHS };
491
794
  return module.exports;
492
795
  },
493
796
  });