dsh-cloudmusic-player 0.7.22 → 0.7.23

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/CHANGELOG.md CHANGED
@@ -3,6 +3,14 @@
3
3
  All notable changes to this project are documented here.
4
4
  格式按 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/),版本号按 [SemVer](https://semver.org/lang/zh-CN/)。
5
5
 
6
+ ## [0.7.23] - 2026-11-28
7
+
8
+ ### Fixed
9
+
10
+ - 修复「连接客户端时调 APP 音量,界面显示变了、实际音量没变」。根因:helper.ps1 把 Core Audio 的 COM 对象(`IAudioSessionManager2` / `IAudioEndpointVolume`)长期缓存,默认音频设备切换(插拔耳机/蓝牙/虚拟声卡)后缓存仍绑定旧端点,`SetMasterVolume` 静默写到旧设备、回读也读旧设备,于是回显「正确」而真实音量不变。改为:在 `SetProcVol` / `SetProcMute` / `SetSysVol` / `SetSysMute` 四个写操作前强制 `Reset()` 重建 COM 对象,绑定到当前默认端点;读操作保留缓存维持轮询性能。
11
+ - 修复 `detectClientRunning()` 在宿主沙箱里 spawn `tasklist` 的 pipe stdio 被 EPERM 拦掉时静默返回 `undefined`,被 `clientOnline()` 当「离线」缓存 3 秒、client-first 误切 web 通道导致「客户端明明在放歌却有时不识别」。改为:探测失败时回退问常驻 helper 的真实 pids,且只缓存布尔结果、`undefined` 不缓存;`detect` 做成可注入依赖,新增回归测试。
12
+ - 恢复 `lib/helper.ps1` 的 UTF-16 LE BOM(编辑工具曾丢失,导致 PowerShell 5.1 按 ANSI 读中文乱码、内嵌 C# 编译失败);`test/channel.test.mjs` 新增 1 例。全套 214 测试通过。
13
+
6
14
  ## [0.7.22] - 2026-11-27
7
15
 
8
16
  ### Fixed
package/README.md CHANGED
@@ -81,7 +81,7 @@ dsh plugin --profile desktop add dsh-cloudmusic-player
81
81
  node scripts/enable-desktop.mjs # 把包接进桌面 profile(幂等);在 clone 下来的目录里跑
82
82
  ```
83
83
 
84
- > npm 包暂时落后于 GitHub 时,可以指定 GitHub 源装最新版:把上面的包名换成 `github:YOUR_GITHUB_USER/dsh-cloudmusic-player`。
84
+ > npm 包暂时落后于 GitHub 时,可以指定 GitHub 源装最新版:把上面的包名换成 `github:jx70/dsh-cloudmusic-player`。
85
85
 
86
86
  然后重开 DSH。右下角出现小胶囊,点 ⌃ 展开。
87
87
 
@@ -89,7 +89,7 @@ node scripts/enable-desktop.mjs # 把包接进桌面 profile(幂等);
89
89
  <summary><b>从源码装 / 本地开发</b></summary>
90
90
 
91
91
  ```bash
92
- git clone https://github.com/YOUR_GITHUB_USER/dsh-cloudmusic-player.git
92
+ git clone https://github.com/jx70/dsh-cloudmusic-player.git
93
93
  cd dsh-cloudmusic-player
94
94
  npm install
95
95
  dsh plugin --profile web add link:"$PWD" # Windows 上把 $PWD 换成绝对路径 D:/...
package/lib/channel.mjs CHANGED
@@ -63,11 +63,12 @@ export class ChannelRouter {
63
63
  * @param {{ native: any, web: import('./web-backend.mjs').WebBackend,
64
64
  * getConfig: () => any, log?: (msg:string)=>void }} deps
65
65
  */
66
- constructor({ native, web, getConfig, log = () => {} }) {
66
+ constructor({ native, web, getConfig, log = () => {}, detect = detectClientRunning }) {
67
67
  this.native = native
68
68
  this.web = web
69
69
  this.getConfig = getConfig
70
70
  this.log = log
71
+ this.detect = detect
71
72
  this.active = 'native'
72
73
  this._clientCache = { at: 0, value: null }
73
74
  this._webCache = { at: 0, value: null }
@@ -81,11 +82,41 @@ export class ChannelRouter {
81
82
  if (this._clientCache.value !== null && now - this._clientCache.at < CLIENT_CHECK_MS) {
82
83
  return this._clientCache.value
83
84
  }
84
- const value = await detectClientRunning(this.getConfig())
85
- this._clientCache = { at: now, value }
85
+ let value = await this.detect(this.getConfig())
86
+ // 探测整体失败(tasklist 的 pipe spawn 在沙箱里被 EPERM 拦掉)会返回
87
+ // undefined —— 不能把它当「离线」缓存,否则 client-first 会误切 web 通道,
88
+ // 表现就是「客户端明明在放歌却不被识别」。回退去问常驻 helper:它的
89
+ // stdin/stdout 管道是通的,deep/state 都能拿到真实 pid。
90
+ if (value === undefined) {
91
+ value = await this.#clientOnlineViaHelper().catch(() => undefined)
92
+ }
93
+ // 只有布尔结果才缓存;undefined 不缓存,下次重新探。
94
+ if (typeof value === 'boolean') {
95
+ this._clientCache = { at: now, value }
96
+ }
86
97
  return value
87
98
  }
88
99
 
100
+ /** 用 native helper 已上报的 pid 判断客户端是否在线(不 spawn 外部进程) */
101
+ async #clientOnlineViaHelper() {
102
+ const native = this.native
103
+ if (!native) return undefined
104
+ // 先试 deepHealth 的 pids(含全部匹配进程),再试 state 的 pid。
105
+ try {
106
+ const h = await native.deepHealth()
107
+ const pids = Array.isArray(h?.pids) ? h.pids : []
108
+ if (pids.length > 0) return true
109
+ if (h && h.ok === false && /ENOENT|EPERM|spawn/i.test(String(h.detail || ''))) return undefined
110
+ } catch { /* 落到 state 再试 */ }
111
+ try {
112
+ const st = await native.state({ fresh: true })
113
+ if (st?.now?.pid) return true
114
+ // state 能正常返回(哪怕没在播)说明 helper 活着;此时没有 pid 判为无客户端。
115
+ if (st && st.ok !== false) return false
116
+ } catch { /* ignore */ }
117
+ return undefined
118
+ }
119
+
89
120
  async webAvailable() {
90
121
  const now = Date.now()
91
122
  if (this._webCache.value !== null && now - this._webCache.at < CLIENT_CHECK_MS) {
package/lib/helper.ps1 CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-cloudmusic-player",
3
- "version": "0.7.22",
3
+ "version": "0.7.23",
4
4
  "description": "DSH 悬浮播放器:联动本地网易云音乐客户端或网页版,调音量 / 切歌 / 喜欢红心 / 跳进度 / 滚动歌词 / 一键日推",
5
5
  "keywords": [
6
6
  "dsh",
@@ -16,11 +16,11 @@
16
16
  "author": "dsh-cloudmusic-player contributors",
17
17
  "repository": {
18
18
  "type": "git",
19
- "url": "git+https://github.com/YOUR_GITHUB_USER/dsh-cloudmusic-player.git"
19
+ "url": "git+https://github.com/jx70/dsh-cloudmusic-player.git"
20
20
  },
21
- "homepage": "https://github.com/YOUR_GITHUB_USER/dsh-cloudmusic-player#readme",
21
+ "homepage": "https://github.com/jx70/dsh-cloudmusic-player#readme",
22
22
  "bugs": {
23
- "url": "https://github.com/YOUR_GITHUB_USER/dsh-cloudmusic-player/issues"
23
+ "url": "https://github.com/jx70/dsh-cloudmusic-player/issues"
24
24
  },
25
25
  "type": "module",
26
26
  "main": "index.js",
@@ -51,7 +51,7 @@ try {
51
51
  Fail @'
52
52
  这里不是 git 仓库(.git 丢了?)。
53
53
  换机器/换目录后的恢复办法:
54
- git clone https://github.com/YOUR_GITHUB_USER/dsh-cloudmusic-player.git <新目录>
54
+ git clone https://github.com/jx70/dsh-cloudmusic-player.git <新目录>
55
55
  然后把你的改动覆盖进去,再跑一次 npm run sync。
56
56
  (注意:clone 时本地 node_modules 会被跳过,需要时跑一次 npm install。)
57
57
  '@
@@ -87,3 +87,32 @@ test('detectClientRunning 非 win32 返回 false', async () => {
87
87
  assert.equal(await detectClientRunning({}), false)
88
88
  }
89
89
  })
90
+
91
+ test('clientOnline 探测失败(undefined)时不缓存,回退用 helper 的 pids 判定在线', async () => {
92
+ const r = new ChannelRouter({
93
+ native: {
94
+ ...fakeNative(),
95
+ deepHealth: async () => ({ ok: true, pids: [1234, 5678] }),
96
+ },
97
+ web: fakeWeb(true),
98
+ getConfig: () => ({ channelMode: 'client-first', processName: 'cloudmusic' }),
99
+ log: () => {},
100
+ detect: async () => undefined, // 模拟沙箱里 tasklist 的 pipe spawn 被拦
101
+ })
102
+ // 探测失败 → helper 回退拿到 pids → 判为在线,且缓存 true。
103
+ assert.equal(await r.clientOnline(), true)
104
+ assert.equal(r._clientCache.value, true)
105
+ // client-first 下据此锁定 native,不切到 web。
106
+ assert.equal(await r.pick(), 'native')
107
+
108
+ // helper 也拿不到任何证据 → undefined,不应被缓存。
109
+ const r2 = new ChannelRouter({
110
+ native: { ...fakeNative(), deepHealth: async () => ({ ok: false, detail: 'EPERM' }), state: async () => ({ ok: false }) },
111
+ web: fakeWeb(true),
112
+ getConfig: () => ({ channelMode: 'client-first' }),
113
+ log: () => {},
114
+ detect: async () => undefined,
115
+ })
116
+ assert.equal(await r2.clientOnline(), undefined)
117
+ assert.equal(r2._clientCache.value, null)
118
+ })