dsh-notify-tray 0.1.4 → 0.1.6
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/README.md +13 -9
- package/README.zh-CN.md +13 -9
- package/lib/catalog.js +15 -0
- package/lib/client.js +417 -316
- package/lib/format.js +59 -65
- package/lib/index.js +80 -12
- package/lib/ledger.js +15 -5
- package/lib/pricing.js +90 -11
- package/lib/system.js +58 -2
- package/package.json +3 -2
package/lib/system.js
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
* when no DSH window is listening) and bringing the DSH window forward.
|
|
4
4
|
*/
|
|
5
5
|
import { spawn } from 'node:child_process'
|
|
6
|
+
import { existsSync, mkdirSync, readdirSync, unlinkSync } from 'node:fs'
|
|
7
|
+
import { delimiter, join, posix } from 'node:path'
|
|
6
8
|
|
|
7
9
|
function run(file, args, options = {}) {
|
|
8
10
|
return new Promise(resolve => {
|
|
@@ -75,13 +77,67 @@ function windowsToast(xml) {
|
|
|
75
77
|
return run(powershell(), ['-NoProfile', '-NonInteractive', '-WindowStyle', 'Hidden', '-EncodedCommand', encoded])
|
|
76
78
|
}
|
|
77
79
|
|
|
80
|
+
/** POSIX shell single-quoted literal. */
|
|
81
|
+
const sh = text => `'${String(text).replace(/'/gu, "'\\''")}'`
|
|
82
|
+
|
|
83
|
+
let notifierPath
|
|
84
|
+
/**
|
|
85
|
+
* `terminal-notifier` (Homebrew), when installed. Unlike `display notification`
|
|
86
|
+
* (attributed to Script Editor, whose click only opens Script Editor), it runs
|
|
87
|
+
* a command when its notification is clicked, which is how a click reaches the
|
|
88
|
+
* session it is about.
|
|
89
|
+
*/
|
|
90
|
+
export function terminalNotifier(env = process.env, exists = existsSync) {
|
|
91
|
+
if (notifierPath !== undefined && env === process.env) return notifierPath || undefined
|
|
92
|
+
const dirs = [...String(env.PATH ?? '').split(delimiter), '/opt/homebrew/bin', '/usr/local/bin']
|
|
93
|
+
const found = dirs.filter(Boolean).map(dir => join(dir, 'terminal-notifier')).find(file => {
|
|
94
|
+
try { return exists(file) } catch { return false }
|
|
95
|
+
})
|
|
96
|
+
if (env === process.env) notifierPath = found ?? ''
|
|
97
|
+
return found
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** A session id as a file name: anything outside [A-Za-z0-9._-] is dropped. */
|
|
101
|
+
const clickName = id => String(id).replace(/[^\w.-]/gu, '')
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* The shell command a clicked macOS notification runs: it drops a file named
|
|
105
|
+
* after the session into `clickDir`, which the host picks up (consumeClicks).
|
|
106
|
+
*/
|
|
107
|
+
export function clickCommand(clickDir, sessionId) {
|
|
108
|
+
// A macOS shell command: always '/'-joined, whatever OS builds it (tests run everywhere).
|
|
109
|
+
return `/usr/bin/touch ${sh(posix.join(clickDir, clickName(sessionId)))}`
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Session ids whose notification was clicked since the last call; each file is removed as it is read. */
|
|
113
|
+
export function consumeClicks(clickDir) {
|
|
114
|
+
let names
|
|
115
|
+
try { names = readdirSync(clickDir) } catch { return [] }
|
|
116
|
+
const ids = []
|
|
117
|
+
for (const name of names) {
|
|
118
|
+
try {
|
|
119
|
+
unlinkSync(join(clickDir, name))
|
|
120
|
+
ids.push(name)
|
|
121
|
+
} catch {}
|
|
122
|
+
}
|
|
123
|
+
return ids
|
|
124
|
+
}
|
|
125
|
+
|
|
78
126
|
/**
|
|
79
127
|
* Show one native notification.
|
|
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)
|
|
128
|
+
* @param {{title: string, body: string, sound?: boolean, onClick?: () => void, webOrigin?: () => string | undefined, state?: string, iconDir?: string, sessionId?: string, clickDir?: string}} n
|
|
129
|
+
* `state` picks the whale's colour and `iconDir` where its PNG is cached (Linux);
|
|
130
|
+
* `sessionId` + `clickDir` make a macOS notification clickable when terminal-notifier is installed.
|
|
82
131
|
*/
|
|
83
132
|
export async function systemNotify(n) {
|
|
84
133
|
if (process.platform === 'darwin') {
|
|
134
|
+
const notifier = n.clickDir && n.sessionId ? terminalNotifier() : undefined
|
|
135
|
+
if (notifier) {
|
|
136
|
+
try { mkdirSync(n.clickDir, { recursive: true }) } catch {}
|
|
137
|
+
const args = ['-title', n.title, '-message', n.body, '-execute', clickCommand(n.clickDir, n.sessionId)]
|
|
138
|
+
if (n.sound) args.push('-sound', 'Glass')
|
|
139
|
+
if (await run(notifier, args)) return true
|
|
140
|
+
}
|
|
85
141
|
const sound = n.sound ? ' sound name "Glass"' : ''
|
|
86
142
|
return run('/usr/bin/osascript', ['-e', `display notification ${as(n.body)} with title ${as(n.title)}${sound}`])
|
|
87
143
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-notify-tray",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "DeepSeek Harness 通知 + 状态栏插件:任务完成、需要输入、需要选择时弹系统通知(macOS / Windows / Linux);macOS 与 Linux(含 UOS、Deepin、麒麟)状态栏常驻小图标,显示任务进度与花费。Windows 没有状态栏,只弹通知。",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"deepseek",
|
|
@@ -49,7 +49,8 @@
|
|
|
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
|
+
"version": "node scripts/sync-readme-version.mjs && git add README.md README.zh-CN.md"
|
|
53
54
|
},
|
|
54
55
|
"dsh": {
|
|
55
56
|
"bundle": {
|