dsh-windows-tray 1.0.8 → 1.0.9
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/launcher/dsh-lib.ps1 +50 -3
- package/launcher/dsh-tray.ps1 +2 -2
- package/package.json +1 -1
package/launcher/dsh-lib.ps1
CHANGED
|
@@ -12,7 +12,7 @@ $URL = "http://127.0.0.1:$PORT"
|
|
|
12
12
|
$LOG_DIR = Join-Path (Join-Path $env:USERPROFILE '.dsh\logs') 'dsh-windows-tray' # 本插件专属日志目录 (logs\<插件名>\, 边界规则见 release-standards §3.1)
|
|
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.
|
|
15
|
+
$TRAY_VERSION = '1.0.9' # 托盘版本 (与 npm 包版本同步, 用于日志/排查)
|
|
16
16
|
$TRAY_PKG = 'dsh-windows-tray' # npm 包名 (托盘自更新)
|
|
17
17
|
$TRAY_SCRIPT = Join-Path $PSScriptRoot 'dsh-tray.ps1'
|
|
18
18
|
|
|
@@ -85,7 +85,7 @@ function Start-Dsh {
|
|
|
85
85
|
if ($pids.Count -gt 0) {
|
|
86
86
|
Write-Host "[dsh] 已在运行: $URL (PID $($pids -join ','))" -ForegroundColor Green
|
|
87
87
|
if ($trayStarted) { Write-Host '[tray] 系统托盘已自动启动(右键可控制 DSH)' -ForegroundColor DarkGray }
|
|
88
|
-
if ($OpenBrowser) {
|
|
88
|
+
if ($OpenBrowser) { Open-DshWeb }
|
|
89
89
|
return
|
|
90
90
|
}
|
|
91
91
|
Write-Host "[dsh] 启动中 (端口 $PORT)..."
|
|
@@ -102,7 +102,7 @@ function Start-Dsh {
|
|
|
102
102
|
Write-Host "[dsh] 启动成功: $URL" -ForegroundColor Green
|
|
103
103
|
if ($trayStarted) { Write-Host '[tray] 系统托盘已自动启动(右键可控制 DSH)' -ForegroundColor DarkGray }
|
|
104
104
|
Start-Sleep -Seconds 2
|
|
105
|
-
if ($OpenBrowser) {
|
|
105
|
+
if ($OpenBrowser) { Open-DshWeb }
|
|
106
106
|
} else {
|
|
107
107
|
Write-Host "[dsh] 启动失败: 12 秒内端口 $PORT 未监听" -ForegroundColor Red
|
|
108
108
|
Write-Host "[dsh] 错误日志: $err(末尾 10 行)"
|
|
@@ -207,6 +207,53 @@ function Stop-Tui {
|
|
|
207
207
|
}
|
|
208
208
|
}
|
|
209
209
|
|
|
210
|
+
# ---- 打开 Web UI: 智能复用已有标签页 (UIA), 任何失败降级为新开 (最坏=旧行为) ----
|
|
211
|
+
$WEB_TITLE_PREFIX = 'DeepSeek Harness' # dsh web 页面 <title> 前缀 (标题可能带 Edge 的 睡眠/内存 后缀)
|
|
212
|
+
$BROWSER_PROGID_MAP = @{ 'MSEdgeHTM' = 'msedge'; 'ChromeHTML' = 'chrome' } # Chromium ProgId → 进程名; 查不到=降级新开
|
|
213
|
+
|
|
214
|
+
function Open-DshWeb {
|
|
215
|
+
param([string]$Url = $URL)
|
|
216
|
+
try {
|
|
217
|
+
$progId = (Get-ItemProperty 'HKCU:\SOFTWARE\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice' -ErrorAction Stop).ProgId
|
|
218
|
+
$procName = $BROWSER_PROGID_MAP[$progId]
|
|
219
|
+
if (-not $procName) { throw "非 Chromium 默认浏览器: $progId" }
|
|
220
|
+
Add-Type -AssemblyName UIAutomationClient -ErrorAction SilentlyContinue
|
|
221
|
+
Add-Type -AssemblyName UIAutomationTypes -ErrorAction SilentlyContinue
|
|
222
|
+
if (-not ('DSH.Win32FG' -as [type])) {
|
|
223
|
+
Add-Type -TypeDefinition @'
|
|
224
|
+
namespace DSH {
|
|
225
|
+
using System;
|
|
226
|
+
using System.Runtime.InteropServices;
|
|
227
|
+
public static class Win32FG {
|
|
228
|
+
[DllImport("user32.dll")] public static extern bool SetForegroundWindow(IntPtr hWnd);
|
|
229
|
+
[DllImport("user32.dll")] public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
'@
|
|
233
|
+
}
|
|
234
|
+
$root = [System.Windows.Automation.AutomationElement]::RootElement
|
|
235
|
+
$winCond = New-Object System.Windows.Automation.PropertyCondition([System.Windows.Automation.AutomationElement]::ClassNameProperty, 'Chrome_WidgetWin_1')
|
|
236
|
+
foreach ($win in $root.FindAll('Children', $winCond)) {
|
|
237
|
+
if ((Get-Process -Id $win.Current.ProcessId -ErrorAction SilentlyContinue).ProcessName -ne $procName) { continue }
|
|
238
|
+
$tabCond = New-Object System.Windows.Automation.PropertyCondition([System.Windows.Automation.AutomationElement]::ControlTypeProperty, [System.Windows.Automation.ControlType]::TabItem)
|
|
239
|
+
foreach ($tab in $win.FindAll('Descendants', $tabCond)) {
|
|
240
|
+
if (-not ($tab.Current.Name -like "$WEB_TITLE_PREFIX*")) { continue }
|
|
241
|
+
# 命中已打开的 DSH Web 标签页: 切换过去并激活窗口
|
|
242
|
+
([System.Windows.Automation.SelectionItemPattern]$tab.GetCurrentPattern([System.Windows.Automation.SelectionItemPattern]::Pattern)).Select()
|
|
243
|
+
$hwnd = [IntPtr]$win.Current.NativeWindowHandle
|
|
244
|
+
[DSH.Win32FG]::ShowWindow($hwnd, 9) | Out-Null # SW_RESTORE: 最小化也恢复
|
|
245
|
+
[DSH.Win32FG]::SetForegroundWindow($hwnd) | Out-Null
|
|
246
|
+
Write-Host "[web] 已切换到已打开的 DSH Web 标签页" -ForegroundColor Green
|
|
247
|
+
return
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
Write-Host "[web] 未发现已打开的 Web 标签页, 新开" -ForegroundColor DarkGray
|
|
251
|
+
} catch {
|
|
252
|
+
Write-Host "[web] 切换检测不可用($($_.Exception.Message)), 新开" -ForegroundColor DarkGray
|
|
253
|
+
}
|
|
254
|
+
Start-Process $Url
|
|
255
|
+
}
|
|
256
|
+
|
|
210
257
|
function Show-Status {
|
|
211
258
|
$pids = @(Get-WebPid)
|
|
212
259
|
if ($pids.Count -gt 0) {
|
package/launcher/dsh-tray.ps1
CHANGED
|
@@ -195,7 +195,7 @@ $menu.Items.Add((New-Object System.Windows.Forms.ToolStripSeparator)) | Out-Null
|
|
|
195
195
|
|
|
196
196
|
# ---- Web UI 子菜单 ----
|
|
197
197
|
$itemDsh = New-SubMenu 'Web UI'
|
|
198
|
-
$itemOpen = New-MenuItem '打开 Web UI' { try {
|
|
198
|
+
$itemOpen = New-MenuItem '打开 Web UI' { try { Open-DshWeb } catch { Log "打开 Web 失败: $($_.Exception.Message)" } }
|
|
199
199
|
$itemStart = New-MenuItem '启动 Web UI' { Invoke-DshAction 'start' }
|
|
200
200
|
$itemStop = New-MenuItem '停止 Web UI' {
|
|
201
201
|
$r = [System.Windows.Forms.MessageBox]::Show('确定停止 Web UI 服务?Web 界面与当前会话将关闭。', 'DSH 系统托盘', 'YesNo', 'Question', 'Button2')
|
|
@@ -336,7 +336,7 @@ $notify.Text = "DSH 托盘 · 检测中 (端口 $PORT)"
|
|
|
336
336
|
$notify.ContextMenuStrip = $menu
|
|
337
337
|
$notify.Visible = $true
|
|
338
338
|
$notify.add_DoubleClick({
|
|
339
|
-
if (Test-Port $PORT) {
|
|
339
|
+
if (Test-Port $PORT) { Open-DshWeb } else { Show-Balloon 'DSH' 'Web UI 未运行,右键选择「启动 Web UI」' }
|
|
340
340
|
})
|
|
341
341
|
|
|
342
342
|
function Show-Balloon([string]$title, [string]$text) {
|