dsh-windows-tray 1.0.4 → 1.0.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/install.ps1 CHANGED
@@ -56,6 +56,22 @@ if (-not $DshRoot) {
56
56
  (Join-Path $env:USERPROFILE 'dsh'),
57
57
  (Join-Path $env:LOCALAPPDATA 'dsh')
58
58
  )
59
+ # v1.0.5: 从运行中 node 进程命令行提取 bin.js 参数路径, 截断到 \node_modules\ 之前
60
+ # (自定义安装位置的机器: "<根>\node_modules\...\bin.js"; 候选一律经 Test-Path dsh.cmd 验证)
61
+ Get-CimInstance Win32_Process -Filter "Name='node.exe'" -ErrorAction SilentlyContinue |
62
+ ForEach-Object {
63
+ $binJs = $null
64
+ if ($_.CommandLine -match '"([^"]+bin\.js)"') { $binJs = $Matches[1] }
65
+ elseif ($_.CommandLine -match '(\S+bin\.js)') { $binJs = $Matches[1] }
66
+ if ($binJs) {
67
+ $idx = $binJs.IndexOf('\node_modules\')
68
+ if ($idx -lt 0) { $idx = $binJs.IndexOf('/node_modules/') }
69
+ if ($idx -gt 0) { $candidates += $binJs.Substring(0, $idx) }
70
+ }
71
+ }
72
+ # v1.0.5: dsh.cmd 在 PATH 上 (Get-Command 返回的是文件全路径, 取其目录)
73
+ $onPath = Get-Command dsh.cmd -ErrorAction SilentlyContinue
74
+ if ($onPath) { $candidates += Split-Path $onPath.Source -Parent }
59
75
  foreach ($c in $candidates) {
60
76
  $c = [System.IO.Path]::GetFullPath($c)
61
77
  if (Test-Path (Join-Path $c 'dsh.cmd')) { $DshRoot = $c; break }
@@ -12,7 +12,7 @@ $URL = "http://127.0.0.1:$PORT"
12
12
  $LOG_DIR = "$env:USERPROFILE\.dsh\logs"
13
13
  $WT = "$env:LOCALAPPDATA\Microsoft\WindowsApps\wt.exe"
14
14
  $PWSH = 'D:\Program Files (x86)\PowerShell-7.6.4\pwsh.exe'
15
- $TRAY_VERSION = '1.0.4' # 托盘版本 (与 npm 包版本同步, 用于日志/排查)
15
+ $TRAY_VERSION = '1.0.6' # 托盘版本 (与 npm 包版本同步, 用于日志/排查)
16
16
  $TRAY_PKG = 'dsh-windows-tray' # npm 包名 (托盘自更新)
17
17
  $TRAY_SCRIPT = Join-Path $PSScriptRoot 'dsh-tray.ps1'
18
18
 
@@ -1,6 +1,9 @@
1
1
  # dsh-update.ps1 —— 托盘自更新执行器 (由托盘菜单「更新到最新版」触发, 独立隐藏进程)
2
2
  # 流程: npm install -g 最新包 -> 运行新包 install.ps1 (重新部署+改写路径+快捷方式) -> 杀旧托盘 -> 起新托盘
3
3
  # 失败时旧托盘不受影响 (旧托盘在最后一步才被终止)
4
+ # v1.0.5: 步骤输出落盘 (dsh-update-npm.log / dsh-update-deploy.log, 失败时尾部进 actions log —
5
+ # 旧版 2>nul 吞报错, 日志只剩退出码无从排查); install.ps1 显式传本机适配值
6
+ # (-DshRoot/-Port/-NodePath/-PwshPath 取自点源的 dsh-lib, 自定义安装位置不再依赖探测)
4
7
  param(
5
8
  [int]$OldPid = 0
6
9
  )
@@ -25,6 +28,8 @@ function Find-NpmCmd {
25
28
  }
26
29
 
27
30
  # 隐藏执行 cmd /c (CreateNoWindow: 不弹黑窗), 可选超时
31
+ # ⚠️ 调用必须空格分隔传参 (Run-HiddenCmd $cmd $timeout)——写成 ('cmd', timeout) 会把
32
+ # 两者绑成数组并入命令行, 超时值被当成包名/脚本参数 (1.0.5 及以前自更新因此从未成功过)
28
33
  function Run-HiddenCmd([string]$cmdLine, [int]$timeoutMs = 0) {
29
34
  $psi = New-Object System.Diagnostics.ProcessStartInfo
30
35
  $psi.FileName = $env:ComSpec
@@ -65,10 +70,14 @@ if (-not $npm) {
65
70
  exit 1
66
71
  }
67
72
 
68
- # 1) 安装最新包 (全局)
69
- $code = Run-HiddenCmd ('/c ""' + $npm + '" install -g ' + $TRAY_PKG + ' 2>nul "', 180000)
73
+ # 1) 安装最新包 (全局; 输出落盘, 失败可查因 — 旧版 2>nul 黑洞)
74
+ $npmLog = Join-Path $LOG_DIR 'dsh-update-npm.log'
75
+ Remove-Item $npmLog -Force -ErrorAction SilentlyContinue
76
+ $installCmd = '/c ""' + $npm + '" install -g ' + $TRAY_PKG + ' >> "' + $npmLog + '" 2>&1 "'
77
+ $code = Run-HiddenCmd $installCmd 180000
70
78
  if ($code -ne 0) {
71
- Log "自更新失败: npm install 退出码 $code"
79
+ Log "自更新失败: npm install 退出码 $code (输出: $npmLog)"
80
+ Get-Content $npmLog -Tail 5 -ErrorAction SilentlyContinue | ForEach-Object { Log " npm> $_" }
72
81
  Show-Balloon '自更新失败:npm install 出错,详见日志' 'Error'
73
82
  exit 1
74
83
  }
@@ -77,7 +86,8 @@ Log 'npm install -g 完成'
77
86
  # 2) 定位新包根目录
78
87
  $rootTmp = Join-Path $LOG_DIR 'tray-npm-root.txt'
79
88
  Remove-Item $rootTmp -Force -ErrorAction SilentlyContinue
80
- Run-HiddenCmd ('/c ""' + $npm + '" root -g > "' + $rootTmp + '" 2>nul "') | Out-Null
89
+ $rootCmd = '/c ""' + $npm + '" root -g > "' + $rootTmp + '" 2>nul "'
90
+ Run-HiddenCmd $rootCmd | Out-Null
81
91
  $globalRoot = ''
82
92
  if (Test-Path $rootTmp) {
83
93
  $globalRoot = (Get-Content $rootTmp -Raw).Trim()
@@ -90,10 +100,21 @@ if (-not (Test-Path $newInstall)) {
90
100
  exit 1
91
101
  }
92
102
 
93
- # 3) 运行新包 install.ps1 (重新部署 + 探测回填 + 快捷方式, 不启动托盘; -Auto=隐藏窗口非交互)
94
- $code = Run-HiddenCmd ('/c ""' + $PWSH + '" -NoProfile -ExecutionPolicy Bypass -File "' + $newInstall + '" -Auto -NoTrayStart 2>nul "', 120000)
103
+ # 3) 运行新包 install.ps1 (重新部署 + 快捷方式, 不启动托盘; -Auto=隐藏窗口非交互)
104
+ # v1.0.5: 显式传本机适配值 (取自点源的 dsh-lib, install 不必重新探测; 自定义安装位置必需)
105
+ $dshRoot = Split-Path $DSH_CMD -Parent
106
+ $deployLog = Join-Path $LOG_DIR 'dsh-update-deploy.log'
107
+ Remove-Item $deployLog -Force -ErrorAction SilentlyContinue
108
+ $deployCmd = '/c ""' + $PWSH + '" -NoProfile -ExecutionPolicy Bypass -File "' + $newInstall + '" -Auto -NoTrayStart' +
109
+ ' -DshRoot "' + $dshRoot + '"' +
110
+ ' -Port ' + $PORT +
111
+ ' -NodePath "' + $NODE + '"' +
112
+ ' -PwshPath "' + $PWSH + '"' +
113
+ ' >> "' + $deployLog + '" 2>&1 "'
114
+ $code = Run-HiddenCmd $deployCmd 120000
95
115
  if ($code -ne 0) {
96
- Log "自更新失败: install.ps1 退出码 $code"
116
+ Log "自更新失败: install.ps1 退出码 $code (输出: $deployLog)"
117
+ Get-Content $deployLog -Tail 5 -ErrorAction SilentlyContinue | ForEach-Object { Log " deploy> $_" }
97
118
  Show-Balloon '自更新失败:部署出错,详见日志' 'Error'
98
119
  exit 1
99
120
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-windows-tray",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "DSH (DeepSeek Harness) Windows 系统托盘: 蓝/灰鲸鱼状态图标 + Web/TUI 一键启停控制。纯 PowerShell + WinForms, 零依赖。",
5
5
  "license": "MIT",
6
6
  "author": "jankin_lv",