dsh-notify-tray 0.1.3 → 0.1.5

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/system.js CHANGED
@@ -77,7 +77,8 @@ function windowsToast(xml) {
77
77
 
78
78
  /**
79
79
  * Show one native notification.
80
- * @param {{title: string, body: string, sound?: boolean, onClick?: () => void, webOrigin?: () => string | undefined}} n
80
+ * @param {{title: string, body: string, sound?: boolean, onClick?: () => void, webOrigin?: () => string | undefined, state?: string, iconDir?: string}} n
81
+ * `state` picks the whale's colour and `iconDir` where its PNG is cached (Linux).
81
82
  */
82
83
  export async function systemNotify(n) {
83
84
  if (process.platform === 'darwin') {
@@ -94,10 +95,15 @@ export async function systemNotify(n) {
94
95
  // Linux / BSD: D-Bus first (clickable), notify-send as a fallback.
95
96
  try {
96
97
  const { linuxNotify } = await import('./tray/linux.js')
97
- await linuxNotify({ title: n.title, body: n.body, sound: n.sound !== false, onClick: n.onClick })
98
+ await linuxNotify({ title: n.title, body: n.body, sound: n.sound !== false, onClick: n.onClick, state: n.state, iconDir: n.iconDir })
98
99
  return true
99
100
  } catch {
100
- return run('notify-send', ['-a', 'DeepSeek Harness', n.title, n.body])
101
+ let icon = ''
102
+ try {
103
+ const { notifyIcon } = await import('./tray/linux.js')
104
+ icon = notifyIcon(n.state, n.iconDir).path
105
+ } catch {}
106
+ return run('notify-send', ['-a', 'DeepSeek Harness', ...(icon ? ['-i', icon] : []), n.title, n.body])
101
107
  }
102
108
  }
103
109
 
package/lib/tray/linux.js CHANGED
@@ -8,10 +8,10 @@
8
8
  * AppIndicator extension, XFCE and LXQt.
9
9
  * Notifications: org.freedesktop.Notifications, with click-to-open actions.
10
10
  */
11
- import { existsSync } from 'node:fs'
11
+ import { existsSync, mkdirSync, writeFileSync } from 'node:fs'
12
12
  import { createRequire } from 'node:module'
13
13
  import { join } from 'node:path'
14
- import { renderIcon } from '../icon.js'
14
+ import { pngIcon, renderIcon, rgbaIcon } from '../icon.js'
15
15
  import { iconSpec } from '../whale.js'
16
16
 
17
17
  const require = createRequire(import.meta.url)
@@ -304,9 +304,37 @@ export async function startLinuxTray({ onAction, logger }) {
304
304
  }
305
305
 
306
306
  const notifyActions = new Map()
307
+ /** Edge of the whale drawn into notifications. */
308
+ const NOTIFY_ICON_SIZE = 64
309
+
310
+ const notifyIcons = new Map()
311
+ /**
312
+ * The whale for a notification: inline pixels for the `image-data` hint (spec
313
+ * 1.2; older servers read `image_data` / `icon_data`) and, when `iconDir` is
314
+ * writable, a PNG path for `app_icon`, which servers that ignore image hints
315
+ * (and history panes) show instead of a generic icon.
316
+ */
317
+ export function notifyIcon(state = 'idle', iconDir) {
318
+ const key = `${state}|${iconDir ?? ''}`
319
+ let icon = notifyIcons.get(key)
320
+ if (icon === undefined) {
321
+ const size = NOTIFY_ICON_SIZE
322
+ icon = { size, rgba: rgbaIcon(size, state), path: '' }
323
+ if (iconDir) {
324
+ try {
325
+ mkdirSync(iconDir, { recursive: true })
326
+ const file = join(iconDir, `whale-${state}.png`)
327
+ writeFileSync(file, pngIcon(size, state))
328
+ icon.path = file
329
+ } catch {}
330
+ }
331
+ notifyIcons.set(key, icon)
332
+ }
333
+ return icon
334
+ }
307
335
 
308
336
  /** Show one freedesktop notification; `onClick` runs when its default action is invoked. */
309
- export async function linuxNotify({ title, body, sound = true, onClick }) {
337
+ export async function linuxNotify({ title, body, sound = true, onClick, state = 'idle', iconDir }) {
310
338
  const link = await connect()
311
339
  const { dbus, bus } = link
312
340
  if (!link.notifications) {
@@ -320,11 +348,19 @@ export async function linuxNotify({ title, body, sound = true, onClick }) {
320
348
  link.notifications = iface
321
349
  }
322
350
  const iface = link.notifications
323
- const hints = { urgency: new dbus.Variant('y', 1), 'desktop-entry': new dbus.Variant('s', 'deepseek-harness') }
351
+ const icon = notifyIcon(state, iconDir)
352
+ const image = new dbus.Variant('(iiibiiay)', [icon.size, icon.size, icon.size * 4, true, 8, 4, icon.rgba])
353
+ const hints = {
354
+ urgency: new dbus.Variant('y', 1),
355
+ 'desktop-entry': new dbus.Variant('s', 'deepseek-harness'),
356
+ 'image-data': image,
357
+ image_data: image,
358
+ icon_data: image,
359
+ }
324
360
  // freedesktop sound-naming spec; servers that play sounds honour these hints.
325
361
  if (sound) hints['sound-name'] = new dbus.Variant('s', 'message-new-instant')
326
362
  else hints['suppress-sound'] = new dbus.Variant('b', true)
327
- const id = await iface.Notify('DeepSeek Harness', 0, 'dialog-information', title, body, ['default', '打开'], hints, -1)
363
+ const id = await iface.Notify('DeepSeek Harness', 0, icon.path, title, body, ['default', '打开'], hints, -1)
328
364
  if (onClick) notifyActions.set(id, onClick)
329
365
  return id
330
366
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-notify-tray",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "DeepSeek Harness 通知 + 状态栏插件:任务完成、需要输入、需要选择时弹系统通知(macOS / Windows / Linux);macOS 与 Linux(含 UOS、Deepin、麒麟)状态栏常驻小图标,显示任务进度与花费。Windows 没有状态栏,只弹通知。",
5
5
  "keywords": [
6
6
  "deepseek",
@@ -49,7 +49,7 @@
49
49
  "node": ">=20"
50
50
  },
51
51
  "scripts": {
52
- "test": "node --test --test-force-exit test/"
52
+ "test": "node --test --test-force-exit test/*.test.js"
53
53
  },
54
54
  "dsh": {
55
55
  "bundle": {