dsh-dev-modes 1.1.2 → 1.1.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.
@@ -29,6 +29,7 @@ param(
29
29
 
30
30
  [string]$Title,
31
31
  [int]$ProcessId = 0,
32
+ [int]$WaitSeconds = 10,
32
33
  [int]$X = 20000,
33
34
  [int]$Y = 20000
34
35
  )
@@ -138,33 +139,68 @@ switch ($Action) {
138
139
  }
139
140
 
140
141
  'hide' {
141
- $matched = $all
142
- if ($ProcessId -gt 0) { $matched = $matched | Where-Object { $_.pid -eq $ProcessId } }
143
- if ($Title) { $matched = $matched | Where-Object { $_.title -like "*$Title*" } }
144
- if (-not $matched) {
145
- "未匹配到窗口(Title='$Title' ProcessId=$ProcessId)" | Write-Error
142
+ # 打包应用(如 Win11 记事本、部分商店应用)里,Start-Process 拿到的 PID
143
+ # 常常不是真正拥有窗口的那个进程,所以这里把子进程也纳入匹配,
144
+ # 并且轮询等待窗口出现(GUI 启动需要时间)。
145
+ $candidatePids = New-Object System.Collections.Generic.HashSet[int]
146
+ if ($ProcessId -gt 0) {
147
+ [void]$candidatePids.Add($ProcessId)
148
+ try {
149
+ $children = Get-CimInstance Win32_Process -Filter "ParentProcessId = $ProcessId" -ErrorAction SilentlyContinue |
150
+ Select-Object -ExpandProperty ProcessId
151
+ foreach ($childPid in @($children)) { [void]$candidatePids.Add([int]$childPid) }
152
+ } catch {
153
+ # 拿不到进程树就只按原 PID 匹配
154
+ }
155
+ }
156
+
157
+ $matched = @()
158
+ $deadline = (Get-Date).AddSeconds([Math]::Max(0, $WaitSeconds))
159
+ while ($true) {
160
+ $snapshot = [DshWin]::List() | ForEach-Object {
161
+ $p = $_ -split '\|', 7
162
+ [pscustomobject]@{
163
+ handle = [int64]$p[0]; pid = [int]$p[1]
164
+ left = [int]$p[2]; top = [int]$p[3]; width = [int]$p[4]; height = [int]$p[5]
165
+ title = $p[6]
166
+ }
167
+ }
168
+ $matched = @($snapshot)
169
+ if ($candidatePids.Count -gt 0) { $matched = @($matched | Where-Object { $candidatePids.Contains([int]$_.pid) }) }
170
+ if ($Title) { $matched = @($matched | Where-Object { $_.title -like "*$Title*" }) }
171
+ if ($matched.Count -gt 0) { break }
172
+ if ((Get-Date) -ge $deadline) { break }
173
+ Start-Sleep -Milliseconds 250
174
+ }
175
+
176
+ if ($matched.Count -eq 0) {
177
+ "未匹配到窗口(Title='$Title' ProcessId=$ProcessId,已等待 $WaitSeconds 秒)" | Write-Error
146
178
  exit 1
147
179
  }
148
180
 
149
181
  $state = @(Read-State)
150
182
  foreach ($w in $matched) {
183
+ # 已经在屏幕外的不要重复记,避免 -Action show 时坐标被覆盖成 20000
184
+ $alreadyOut = ($w.left -ge 10000) -or ($w.top -ge 10000)
151
185
  $ok = [DshWin]::Move([IntPtr]$w.handle, $X, $Y, $w.width, $w.height)
152
186
  if (-not $ok) {
153
187
  "移动失败(可能是全屏独占窗口):$($w.title)"
154
188
  continue
155
189
  }
156
- $state += [pscustomobject]@{
157
- handle = $w.handle; pid = $w.pid; title = $w.title
158
- left = $w.left; top = $w.top; width = $w.width; height = $w.height
190
+ if (-not $alreadyOut) {
191
+ $state += [pscustomobject]@{
192
+ handle = $w.handle; pid = $w.pid; title = $w.title
193
+ left = $w.left; top = $w.top; width = $w.width; height = $w.height
194
+ }
159
195
  }
160
- "已移出可视区:$($w.title) → ($X,$Y)"
196
+ "已移出可视区:$($w.title) [PID $($w.pid)] → ($X,$Y)"
161
197
  }
162
198
  Write-State $state
163
199
  break
164
200
  }
165
201
 
166
202
  'show' {
167
- $state = Read-State
203
+ $state = @(Read-State)
168
204
  if (-not $state -or $state.Count -eq 0) {
169
205
  '没有记录到需要还原的窗口'
170
206
  break
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-dev-modes",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "type": "module",
5
5
  "description": "Three DeepSeek Harness Agent presets in one bundle — plus the per-session isolation and quiet-run switches: software development, game development, and read-only discussion, with the matching delivery and engine workflows bundled as skills.",
6
6
  "author": "qingfengshangnanzhi",