dsh-windows-tray 1.0.2 → 1.0.3

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.
@@ -1,116 +1,116 @@
1
- # dsh-update.ps1 —— 托盘自更新执行器 (由托盘菜单「更新到最新版」触发, 独立隐藏进程)
2
- # 流程: npm install -g 最新包 -> 运行新包 install.ps1 (重新部署+改写路径+快捷方式) -> 杀旧托盘 -> 起新托盘
3
- # 失败时旧托盘不受影响 (旧托盘在最后一步才被终止)
4
- param(
5
- [int]$OldPid = 0
6
- )
7
- $ErrorActionPreference = 'Stop'
8
- . (Join-Path $PSScriptRoot 'dsh-lib.ps1')
9
-
10
- $logFile = Join-Path $LOG_DIR 'dsh-tray-actions.log'
11
- function Log([string]$msg) {
12
- Add-Content -Path $logFile -Value ('[{0}] {1}' -f (Get-Date -Format 'yyyy-MM-dd HH:mm:ss'), $msg) -ErrorAction SilentlyContinue
13
- }
14
-
15
- function Find-NpmCmd {
16
- if ($NODE -and (Test-Path $NODE)) {
17
- $p = Join-Path (Split-Path $NODE -Parent) 'npm.cmd'
18
- if (Test-Path $p) { return $p }
19
- }
20
- $c = Get-Command npm.cmd -ErrorAction SilentlyContinue
21
- if ($c) { return $c.Source }
22
- $c2 = Get-Command npm -ErrorAction SilentlyContinue
23
- if ($c2) { return $c2.Source }
24
- return $null
25
- }
26
-
27
- # 隐藏执行 cmd /c (CreateNoWindow: 不弹黑窗), 可选超时
28
- function Run-HiddenCmd([string]$cmdLine, [int]$timeoutMs = 0) {
29
- $psi = New-Object System.Diagnostics.ProcessStartInfo
30
- $psi.FileName = $env:ComSpec
31
- $psi.Arguments = $cmdLine
32
- $psi.UseShellExecute = $false
33
- $psi.CreateNoWindow = $true
34
- $p = [System.Diagnostics.Process]::Start($psi)
35
- if ($timeoutMs -gt 0) {
36
- $p.WaitForExit($timeoutMs) | Out-Null
37
- if (-not $p.HasExited) { $p.Kill(); return -1 }
38
- } else { $p.WaitForExit() }
39
- return $p.ExitCode
40
- }
41
-
42
- # 结果气泡 (临时 NotifyIcon, 更新脚本自身无托盘)
43
- function Show-Balloon([string]$text, [string]$icon = 'Info') {
44
- try {
45
- Add-Type -AssemblyName System.Windows.Forms
46
- Add-Type -AssemblyName System.Drawing
47
- $n = New-Object System.Windows.Forms.NotifyIcon
48
- $n.Icon = [System.Drawing.SystemIcons]::Information
49
- $n.Visible = $true
50
- $n.BalloonTipTitle = 'DSH 系统托盘'
51
- $n.BalloonTipText = $text
52
- $n.BalloonTipIcon = [System.Windows.Forms.ToolTipIcon]::$icon
53
- $n.ShowBalloonTip(5000)
54
- Start-Sleep -Seconds 6
55
- $n.Visible = $false
56
- $n.Dispose()
57
- } catch { }
58
- }
59
-
60
- Log '自更新开始'
61
- $npm = Find-NpmCmd
62
- if (-not $npm) {
63
- Log '自更新失败: npm 未找到'
64
- Show-Balloon '自更新失败:npm 未找到' 'Error'
65
- exit 1
66
- }
67
-
68
- # 1) 安装最新包 (全局)
69
- $code = Run-HiddenCmd ('/c ""' + $npm + '" install -g ' + $TRAY_PKG + ' 2>nul "', 180000)
70
- if ($code -ne 0) {
71
- Log "自更新失败: npm install 退出码 $code"
72
- Show-Balloon '自更新失败:npm install 出错,详见日志' 'Error'
73
- exit 1
74
- }
75
- Log 'npm install -g 完成'
76
-
77
- # 2) 定位新包根目录
78
- $rootTmp = Join-Path $LOG_DIR 'tray-npm-root.txt'
79
- Remove-Item $rootTmp -Force -ErrorAction SilentlyContinue
80
- Run-HiddenCmd ('/c ""' + $npm + '" root -g > "' + $rootTmp + '" 2>nul "') | Out-Null
81
- $globalRoot = ''
82
- if (Test-Path $rootTmp) {
83
- $globalRoot = (Get-Content $rootTmp -Raw).Trim()
84
- Remove-Item $rootTmp -Force -ErrorAction SilentlyContinue
85
- }
86
- $newInstall = Join-Path $globalRoot ($TRAY_PKG + '\install.ps1')
87
- if (-not (Test-Path $newInstall)) {
88
- Log "自更新失败: 未找到新包 $newInstall"
89
- Show-Balloon '自更新失败:未找到新包(npm 全局目录)' 'Error'
90
- exit 1
91
- }
92
-
93
- # 3) 运行新包 install.ps1 (重新部署 + 探测回填 + 快捷方式, 不启动托盘; -Auto=隐藏窗口非交互)
94
- $code = Run-HiddenCmd ('/c ""' + $PWSH + '" -NoProfile -ExecutionPolicy Bypass -File "' + $newInstall + '" -Auto -NoTrayStart 2>nul "', 120000)
95
- if ($code -ne 0) {
96
- Log "自更新失败: install.ps1 退出码 $code"
97
- Show-Balloon '自更新失败:部署出错,详见日志' 'Error'
98
- exit 1
99
- }
100
- Log '新版本部署完成'
101
-
102
- # 4) 杀旧托盘 -> 起新托盘
103
- if ($OldPid -gt 0) {
104
- Stop-Process -Id $OldPid -Force -ErrorAction SilentlyContinue
105
- Log "旧托盘已停止 (PID $OldPid)"
106
- }
107
- Start-Sleep -Milliseconds 500
108
- $newTray = Join-Path $env:USERPROFILE '.dsh\launcher\dsh-tray.ps1'
109
- if (Test-Path $PWSH) {
110
- Start-Process -FilePath $PWSH -ArgumentList @('-NoProfile', '-ExecutionPolicy', 'Bypass', '-WindowStyle', 'Hidden', '-File', $newTray) -WindowStyle Hidden | Out-Null
111
- } else {
112
- Start-Process -FilePath 'powershell.exe' -ArgumentList @('-NoProfile', '-ExecutionPolicy', 'Bypass', '-WindowStyle', 'Hidden', '-File', $newTray) -WindowStyle Hidden | Out-Null
113
- }
114
- Log '新托盘已启动'
115
- Show-Balloon '托盘已更新并自动重启 ✓'
1
+ # dsh-update.ps1 —— 托盘自更新执行器 (由托盘菜单「更新到最新版」触发, 独立隐藏进程)
2
+ # 流程: npm install -g 最新包 -> 运行新包 install.ps1 (重新部署+改写路径+快捷方式) -> 杀旧托盘 -> 起新托盘
3
+ # 失败时旧托盘不受影响 (旧托盘在最后一步才被终止)
4
+ param(
5
+ [int]$OldPid = 0
6
+ )
7
+ $ErrorActionPreference = 'Stop'
8
+ . (Join-Path $PSScriptRoot 'dsh-lib.ps1')
9
+
10
+ $logFile = Join-Path $LOG_DIR 'dsh-tray-actions.log'
11
+ function Log([string]$msg) {
12
+ Add-Content -Path $logFile -Value ('[{0}] {1}' -f (Get-Date -Format 'yyyy-MM-dd HH:mm:ss'), $msg) -ErrorAction SilentlyContinue
13
+ }
14
+
15
+ function Find-NpmCmd {
16
+ if ($NODE -and (Test-Path $NODE)) {
17
+ $p = Join-Path (Split-Path $NODE -Parent) 'npm.cmd'
18
+ if (Test-Path $p) { return $p }
19
+ }
20
+ $c = Get-Command npm.cmd -ErrorAction SilentlyContinue
21
+ if ($c) { return $c.Source }
22
+ $c2 = Get-Command npm -ErrorAction SilentlyContinue
23
+ if ($c2) { return $c2.Source }
24
+ return $null
25
+ }
26
+
27
+ # 隐藏执行 cmd /c (CreateNoWindow: 不弹黑窗), 可选超时
28
+ function Run-HiddenCmd([string]$cmdLine, [int]$timeoutMs = 0) {
29
+ $psi = New-Object System.Diagnostics.ProcessStartInfo
30
+ $psi.FileName = $env:ComSpec
31
+ $psi.Arguments = $cmdLine
32
+ $psi.UseShellExecute = $false
33
+ $psi.CreateNoWindow = $true
34
+ $p = [System.Diagnostics.Process]::Start($psi)
35
+ if ($timeoutMs -gt 0) {
36
+ $p.WaitForExit($timeoutMs) | Out-Null
37
+ if (-not $p.HasExited) { $p.Kill(); return -1 }
38
+ } else { $p.WaitForExit() }
39
+ return $p.ExitCode
40
+ }
41
+
42
+ # 结果气泡 (临时 NotifyIcon, 更新脚本自身无托盘)
43
+ function Show-Balloon([string]$text, [string]$icon = 'Info') {
44
+ try {
45
+ Add-Type -AssemblyName System.Windows.Forms
46
+ Add-Type -AssemblyName System.Drawing
47
+ $n = New-Object System.Windows.Forms.NotifyIcon
48
+ $n.Icon = [System.Drawing.SystemIcons]::Information
49
+ $n.Visible = $true
50
+ $n.BalloonTipTitle = 'DSH 系统托盘'
51
+ $n.BalloonTipText = $text
52
+ $n.BalloonTipIcon = [System.Windows.Forms.ToolTipIcon]::$icon
53
+ $n.ShowBalloonTip(5000)
54
+ Start-Sleep -Seconds 6
55
+ $n.Visible = $false
56
+ $n.Dispose()
57
+ } catch { }
58
+ }
59
+
60
+ Log '自更新开始'
61
+ $npm = Find-NpmCmd
62
+ if (-not $npm) {
63
+ Log '自更新失败: npm 未找到'
64
+ Show-Balloon '自更新失败:npm 未找到' 'Error'
65
+ exit 1
66
+ }
67
+
68
+ # 1) 安装最新包 (全局)
69
+ $code = Run-HiddenCmd ('/c ""' + $npm + '" install -g ' + $TRAY_PKG + ' 2>nul "', 180000)
70
+ if ($code -ne 0) {
71
+ Log "自更新失败: npm install 退出码 $code"
72
+ Show-Balloon '自更新失败:npm install 出错,详见日志' 'Error'
73
+ exit 1
74
+ }
75
+ Log 'npm install -g 完成'
76
+
77
+ # 2) 定位新包根目录
78
+ $rootTmp = Join-Path $LOG_DIR 'tray-npm-root.txt'
79
+ Remove-Item $rootTmp -Force -ErrorAction SilentlyContinue
80
+ Run-HiddenCmd ('/c ""' + $npm + '" root -g > "' + $rootTmp + '" 2>nul "') | Out-Null
81
+ $globalRoot = ''
82
+ if (Test-Path $rootTmp) {
83
+ $globalRoot = (Get-Content $rootTmp -Raw).Trim()
84
+ Remove-Item $rootTmp -Force -ErrorAction SilentlyContinue
85
+ }
86
+ $newInstall = Join-Path $globalRoot ($TRAY_PKG + '\install.ps1')
87
+ if (-not (Test-Path $newInstall)) {
88
+ Log "自更新失败: 未找到新包 $newInstall"
89
+ Show-Balloon '自更新失败:未找到新包(npm 全局目录)' 'Error'
90
+ exit 1
91
+ }
92
+
93
+ # 3) 运行新包 install.ps1 (重新部署 + 探测回填 + 快捷方式, 不启动托盘; -Auto=隐藏窗口非交互)
94
+ $code = Run-HiddenCmd ('/c ""' + $PWSH + '" -NoProfile -ExecutionPolicy Bypass -File "' + $newInstall + '" -Auto -NoTrayStart 2>nul "', 120000)
95
+ if ($code -ne 0) {
96
+ Log "自更新失败: install.ps1 退出码 $code"
97
+ Show-Balloon '自更新失败:部署出错,详见日志' 'Error'
98
+ exit 1
99
+ }
100
+ Log '新版本部署完成'
101
+
102
+ # 4) 杀旧托盘 -> 起新托盘
103
+ if ($OldPid -gt 0) {
104
+ Stop-Process -Id $OldPid -Force -ErrorAction SilentlyContinue
105
+ Log "旧托盘已停止 (PID $OldPid)"
106
+ }
107
+ Start-Sleep -Milliseconds 500
108
+ $newTray = Join-Path $env:USERPROFILE '.dsh\launcher\dsh-tray.ps1'
109
+ if (Test-Path $PWSH) {
110
+ Start-Process -FilePath $PWSH -ArgumentList @('-NoProfile', '-ExecutionPolicy', 'Bypass', '-WindowStyle', 'Hidden', '-File', $newTray) -WindowStyle Hidden | Out-Null
111
+ } else {
112
+ Start-Process -FilePath 'powershell.exe' -ArgumentList @('-NoProfile', '-ExecutionPolicy', 'Bypass', '-WindowStyle', 'Hidden', '-File', $newTray) -WindowStyle Hidden | Out-Null
113
+ }
114
+ Log '新托盘已启动'
115
+ Show-Balloon '托盘已更新并自动重启 ✓'
116
116
  exit 0
package/package.json CHANGED
@@ -1,36 +1,36 @@
1
- {
2
- "name": "dsh-windows-tray",
3
- "version": "1.0.2",
4
- "description": "DSH (DeepSeek Harness) Windows 系统托盘: 蓝/灰鲸鱼状态图标 + Web/TUI 一键启停控制。纯 PowerShell + WinForms, 零依赖。",
5
- "license": "MIT",
6
- "author": "jankin_lv",
7
- "keywords": [
8
- "dsh",
9
- "deepseek",
10
- "harness",
11
- "tray",
12
- "notifyicon",
13
- "windows",
14
- "powershell",
15
- "system-tray"
16
- ],
17
- "os": [
18
- "win32"
19
- ],
20
- "engines": {
21
- "node": ">=18"
22
- },
23
- "files": [
24
- "launcher/",
25
- "build/",
26
- "docs/",
27
- "bin/",
28
- "install.ps1",
29
- "README.md",
30
- "LICENSE"
31
- ],
32
- "bin": {
33
- "dsh-tray": "bin/dsh-tray.js"
34
- },
35
- "private": false
36
- }
1
+ {
2
+ "name": "dsh-windows-tray",
3
+ "version": "1.0.3",
4
+ "description": "DSH (DeepSeek Harness) Windows 系统托盘: 蓝/灰鲸鱼状态图标 + Web/TUI 一键启停控制。纯 PowerShell + WinForms, 零依赖。",
5
+ "license": "MIT",
6
+ "author": "jankin_lv",
7
+ "keywords": [
8
+ "dsh",
9
+ "deepseek",
10
+ "harness",
11
+ "tray",
12
+ "notifyicon",
13
+ "windows",
14
+ "powershell",
15
+ "system-tray"
16
+ ],
17
+ "os": [
18
+ "win32"
19
+ ],
20
+ "engines": {
21
+ "node": ">=18"
22
+ },
23
+ "files": [
24
+ "launcher/",
25
+ "build/",
26
+ "docs/",
27
+ "bin/",
28
+ "install.ps1",
29
+ "README.md",
30
+ "LICENSE"
31
+ ],
32
+ "bin": {
33
+ "dsh-tray": "bin/dsh-tray.js"
34
+ },
35
+ "private": false
36
+ }