dsh-notify-tray 0.1.11 → 0.1.13

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.
@@ -0,0 +1,92 @@
1
+ import { createHash, randomUUID } from 'node:crypto'
2
+ import { mkdirSync, readFileSync, readdirSync, renameSync, statSync, unlinkSync, writeFileSync } from 'node:fs'
3
+ import { join, resolve } from 'node:path'
4
+ import { fileURLToPath } from 'node:url'
5
+
6
+ export const WINDOWS_SENDER = 'DSH.NotifyTray.Whale'
7
+ const WEEK = 7 * 24 * 3600_000
8
+ const quote = text => "'" + text.replace(/'/g, "''") + "'"
9
+ export const activationRoot = () => join(process.env.LOCALAPPDATA, 'dsh-notify-tray', 'notifications')
10
+ const scope = dir => createHash('sha256').update(resolve(dir).toLowerCase()).digest('hex').slice(0, 32)
11
+ let registration
12
+
13
+ // The registry references stable per-user assets, independent of the package version.
14
+ // Hash the executable name so an update can install while a previous activation is running.
15
+ export async function registerWindowsSender(run, powershell) {
16
+ if (!registration) registration = install(run, powershell).catch(error => { registration = undefined; throw error })
17
+ return registration
18
+ }
19
+
20
+ async function install(run, powershell) {
21
+ const root = activationRoot()
22
+ mkdirSync(root, { recursive: true })
23
+ const source = fileURLToPath(new URL('./ToastActivator.cs', import.meta.url))
24
+ const icon = readFileSync(new URL('../assets/notify-icon.png', import.meta.url))
25
+ const digest = data => createHash('sha256').update(data).digest('hex').slice(0, 16)
26
+ const exe = join(root, 'activate-' + digest(readFileSync(source)) + '.exe')
27
+ const iconPath = join(root, 'whale-' + digest(icon) + '.png')
28
+ try { writeFileSync(iconPath, icon, { flag: 'wx' }) } catch (e) { if (e.code !== 'EEXIST') throw e }
29
+ const compiler = join(process.env.SystemRoot, 'Microsoft.NET', 'Framework', 'v4.0.30319', 'csc.exe')
30
+ try { statSync(exe) } catch (e) {
31
+ if (e.code !== 'ENOENT') throw e
32
+ const temp = join(root, randomUUID() + '.exe')
33
+ if (!await run(compiler, ['/nologo', '/target:winexe', '/optimize+', '/out:' + temp, source])) throw Error('Cannot build notification activator')
34
+ try { renameSync(temp, exe) } catch (error) {
35
+ try { statSync(exe) } catch { throw error }
36
+ unlinkSync(temp)
37
+ }
38
+ }
39
+ const script = [
40
+ "$ErrorActionPreference='Stop'",
41
+ "$classes=[Microsoft.Win32.Registry]::CurrentUser.CreateSubKey('Software\\Classes')",
42
+ "$sender=$classes.CreateSubKey('AppUserModelId\\" + WINDOWS_SENDER + "')",
43
+ "$sender.SetValue('DisplayName'," + quote('小鲸鱼通知站') + ")",
44
+ "$sender.SetValue('IconUri'," + quote(iconPath) + ",[Microsoft.Win32.RegistryValueKind]::ExpandString)",
45
+
46
+ "$scheme=$classes.CreateSubKey('dsh-notify-tray')",
47
+ "$scheme.SetValue('','URL:Whale Notify Station')",
48
+ "$scheme.SetValue('URL Protocol','')",
49
+ "$command=$scheme.CreateSubKey('shell\\open\\command')",
50
+ "$command.SetValue(''," + quote('"' + exe + '" "%1"') + ")",
51
+ '$command.Close();$scheme.Close();$sender.Close();$classes.Close()',
52
+ ].join(';')
53
+ const ok = await run(powershell, ['-NoProfile', '-NonInteractive', '-EncodedCommand', Buffer.from(script, 'utf16le').toString('base64')])
54
+ if (!ok) throw Error('Cannot register Whale Notify Station with Windows')
55
+ }
56
+
57
+ export function issueWindowsClick(dir, id, target, root = activationRoot()) {
58
+ if (!target || !id) return undefined
59
+ const profile = scope(dir)
60
+ const folder = join(root, profile)
61
+ mkdirSync(folder, { recursive: true })
62
+ const nonce = randomUUID().replaceAll('-', '')
63
+ const path = join(folder, nonce + '.pending')
64
+ const launchTarget = target === 'dsh://open' ? target : new URL(target).href
65
+ if (launchTarget !== 'dsh://open' && !/^https?:\/\//.test(launchTarget)) return undefined
66
+ writeFileSync(path, launchTarget + '\n' + JSON.stringify(id), { flag: 'wx' })
67
+ return profile + '/' + nonce
68
+ }
69
+
70
+ // Only .clicked files were activated by the Windows shell. Pending notices
71
+ // must never be opened on focus, ordinary polling, or application startup.
72
+ export function readWindowsClicks(dir, { root = activationRoot(), prune = false } = {}) {
73
+ const folder = join(root, scope(dir))
74
+ let files
75
+ try { files = readdirSync(folder) } catch (e) { if (e.code === 'ENOENT') return []; throw e }
76
+ const clicks = []
77
+ for (const name of files) {
78
+ if (!/^[0-9a-f]{32}\.(pending|clicked)$/.test(name)) continue
79
+ const path = join(folder, name)
80
+ try {
81
+ if (prune) {
82
+ if (Date.now() - statSync(path).mtimeMs > WEEK) unlinkSync(path)
83
+ } else if (name.endsWith('.clicked')) {
84
+ const contents = readFileSync(path, 'utf8')
85
+ const id = JSON.parse(contents.slice(contents.indexOf('\n') + 1))
86
+ unlinkSync(path)
87
+ if (typeof id === 'string') clicks.push(id)
88
+ }
89
+ } catch (e) { if (e.code !== 'ENOENT') throw e }
90
+ }
91
+ return clicks
92
+ }
package/locale/en.json CHANGED
@@ -1,7 +1,7 @@
1
- {
2
- "meta": {
3
- "title": "Whale Notify Station",
4
- "description": "Notifications when tasks finish, fail, or need your attention, with daily spend and plan quota. Open Whale Notify Station in the left sidebar to configure it; this page contains the user guide. The status-bar whale is available on macOS / Linux; Windows supports notifications only.",
5
- "detail": "README.md"
6
- }
7
- }
1
+ {
2
+ "meta": {
3
+ "title": "Whale Notify Station",
4
+ "description": "Notifications when tasks finish, fail, or need your attention, with daily spend and plan quota. Open Whale Notify Station in the left sidebar to configure it; this page contains the user guide. The status-bar whale is available on macOS / Linux; Windows supports notifications only.",
5
+ "detail": "README.md"
6
+ }
7
+ }
package/locale/zh.json CHANGED
@@ -1,7 +1,7 @@
1
- {
2
- "meta": {
3
- "title": "小鲸鱼通知站",
4
- "description": "任务完成、失败或需要你处理时弹通知,查看今日花费与套餐额度。点击左侧栏「小鲸鱼通知站」进行设置;此页为使用说明。macOS / Linux 支持状态栏小鲸鱼,Windows 仅提供通知。",
5
- "detail": "README.md"
6
- }
7
- }
1
+ {
2
+ "meta": {
3
+ "title": "小鲸鱼通知站",
4
+ "description": "任务完成、失败或需要你处理时弹通知,查看今日花费与套餐额度。点击左侧栏「小鲸鱼通知站」进行设置;此页为使用说明。macOS / Linux 支持状态栏小鲸鱼,Windows 仅提供通知。",
5
+ "detail": "README.md"
6
+ }
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-notify-tray",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "description": "DeepSeek Harness 通知 + 状态栏插件:任务完成、需要输入、需要选择时弹系统通知(macOS / Windows / Linux);macOS 与 Linux(含 UOS、Deepin、麒麟)状态栏常驻小图标,显示任务进度与花费。Windows 没有状态栏,只弹通知。",
5
5
  "keywords": [
6
6
  "deepseek",
@@ -24,6 +24,7 @@
24
24
  },
25
25
  "files": [
26
26
  "lib",
27
+ "assets/notify-icon.png",
27
28
  "assets/mascot-peeking.png",
28
29
  "assets/mascot-peeking.prompt.txt",
29
30
  "assets/preview.svg",