dsh-restart-refresh 0.6.0 → 0.6.1
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 +9 -0
- package/index.js +21 -0
- package/package.json +1 -1
- package/test/host-smoke.mjs +3 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.6.1
|
|
4
|
+
|
|
5
|
+
- **Safety fix.** The helper now looks the shell up by PID before doing anything (`Win32_Process`): if that PID turns out to run a different executable — Windows recycles PIDs — it aborts instead of closing somebody else's windows, and it also refuses when the Host is not a child of that process.
|
|
6
|
+
- Package renamed from `dsh-refresh` to `dsh-restart-refresh`; routes, module id, log and settings file names follow the new name.
|
|
7
|
+
|
|
8
|
+
## 0.6.0
|
|
9
|
+
|
|
10
|
+
- Package renamed to `dsh-restart-refresh` (the npm name `dsh-refresh` was already taken).
|
|
11
|
+
|
|
3
12
|
## 0.5.0
|
|
4
13
|
|
|
5
14
|
- Portability: the generated PowerShell script is now written as UTF-8 **with BOM** and the VBS launcher as UTF-16LE with BOM, so non-ASCII paths work on other machines.
|
package/index.js
CHANGED
|
@@ -98,6 +98,27 @@ Remove-Item Env:\ELECTRON_NO_ATTACH_CONSOLE -ErrorAction SilentlyContinue
|
|
|
98
98
|
Start-Sleep -Milliseconds 250
|
|
99
99
|
if (-not (Test-Path -LiteralPath $Exe)) { Write-Log 'abort: executable is missing'; exit 1 }
|
|
100
100
|
$name = [System.IO.Path]::GetFileNameWithoutExtension($Exe)
|
|
101
|
+
# PIDs are recycled by Windows. Before this script touches anything, prove that
|
|
102
|
+
# $MainPid really is the shell we are about to replace — otherwise a stale pid
|
|
103
|
+
# would make us close (and kill) whatever app inherited the number. $HostPid is
|
|
104
|
+
# the Host the caller was running in, so it must be a child of $MainPid.
|
|
105
|
+
$mainInfo = $null
|
|
106
|
+
try { $mainInfo = Get-CimInstance Win32_Process -Filter ("ProcessId={0}" -f $MainPid) -ErrorAction Stop } catch { }
|
|
107
|
+
if (-not $mainInfo) { Write-Log ("abort: main process {0} is gone" -f $MainPid); exit 1 }
|
|
108
|
+
$mainPath = $null
|
|
109
|
+
try { $mainPath = [string]$mainInfo.ExecutablePath } catch { }
|
|
110
|
+
if (-not $mainPath) { Write-Log ("abort: cannot read the image path of {0}" -f $MainPid); exit 1 }
|
|
111
|
+
$same = [string]::Equals([System.IO.Path]::GetFullPath($mainPath), [System.IO.Path]::GetFullPath($Exe), [System.StringComparison]::OrdinalIgnoreCase)
|
|
112
|
+
if (-not $same) {
|
|
113
|
+
Write-Log ("abort: pid {0} runs {1}, not {2}" -f $MainPid, $mainPath, $Exe)
|
|
114
|
+
exit 1
|
|
115
|
+
}
|
|
116
|
+
$hostInfo = $null
|
|
117
|
+
try { $hostInfo = Get-CimInstance Win32_Process -Filter ("ProcessId={0}" -f $HostPid) -ErrorAction Stop } catch { }
|
|
118
|
+
if ($hostInfo -and ([int]$hostInfo.ParentProcessId -ne $MainPid)) {
|
|
119
|
+
Write-Log ("abort: host {0} is not a child of {1}" -f $HostPid, $MainPid)
|
|
120
|
+
exit 1
|
|
121
|
+
}
|
|
101
122
|
# Quit and restart both try the graceful road first: let the shell run its own
|
|
102
123
|
# shutdown (stop the Host, save state, dispose the tray). A bare close does not
|
|
103
124
|
# work — the shell turns it into "hide to tray" — but once the window has seen
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-restart-refresh",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Restart, quit and hot-reload the DSH desktop app from the sidebar: two icon buttons next to the logo plus a reload button in the conversation header.",
|
|
6
6
|
"license": "MIT",
|
package/test/host-smoke.mjs
CHANGED
|
@@ -185,6 +185,9 @@ const ok = (condition, message) => {
|
|
|
185
185
|
ok(ps1Text.includes('WM_ENDSESSION'), 'the session-end message makes the shell allow the close')
|
|
186
186
|
ok(ps1Text.includes('WM_CLOSE'), 'the script then closes the window so the shell can quit')
|
|
187
187
|
ok(ps1Text.includes('DshGraceful'), 'the graceful helper is compiled on demand')
|
|
188
|
+
ok(ps1Text.includes('Win32_Process'), 'the script looks the main pid up before touching it')
|
|
189
|
+
ok(ps1Text.includes('runs {1}, not {2}'), 'a recycled pid is refused instead of being closed')
|
|
190
|
+
ok(ps1Text.includes('is not a child of'), 'the host must be a child of the shell it came from')
|
|
188
191
|
ok(ps1Text.includes('graceful shutdown timed out; falling back to a force stop'), 'the force stop stays as the fallback')
|
|
189
192
|
ok(!ps1Text.includes("if ($Mode -eq 'quit') {\n $graceful"), 'both modes take the graceful road')
|
|
190
193
|
ok(ps1Text.includes('Start-Process -FilePath $Exe'), 'the script relaunches the app')
|