pennyrouter 0.2.8 → 0.2.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/package.json +1 -1
- package/src/launch.js +23 -3
package/package.json
CHANGED
package/src/launch.js
CHANGED
|
@@ -152,9 +152,29 @@ function writeWindowsUserPath(value) {
|
|
|
152
152
|
"add", "HKCU\\Environment", "/v", "Path", "/t", "REG_EXPAND_SZ", "/d", value, "/f",
|
|
153
153
|
], { stdio: "ignore", windowsHide: true });
|
|
154
154
|
if (result.status !== 0) throw new Error("Could not add PennyRouter to the Windows user PATH.");
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
155
|
+
broadcastEnvironmentChange();
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// user32.dll,UpdatePerUserSystemParameters refreshes desktop/profile parameters (wallpaper,
|
|
159
|
+
// etc.) — it is NOT the env var broadcast and does nothing for PATH. The actual mechanism
|
|
160
|
+
// (what setx.exe and the System Properties dialog use) is a WM_SETTINGCHANGE broadcast with
|
|
161
|
+
// lParam "Environment", which only Win32 SendMessageTimeout can send. Shell out to a tiny
|
|
162
|
+
// inline PowerShell snippet to make that call. New processes started by an already-running
|
|
163
|
+
// shell host (Explorer, Windows Terminal) still won't see the change until that host itself
|
|
164
|
+
// receives and acts on the broadcast, but this is what makes a freshly-opened terminal work.
|
|
165
|
+
function broadcastEnvironmentChange() {
|
|
166
|
+
const script = [
|
|
167
|
+
"$sig = '[DllImport(\"user32.dll\", SetLastError = true, CharSet = CharSet.Auto)]",
|
|
168
|
+
"public static extern IntPtr SendMessageTimeout(IntPtr hWnd, uint Msg, UIntPtr wParam,",
|
|
169
|
+
"string lParam, uint fuFlags, uint uTimeout, out UIntPtr lpdwResult);'",
|
|
170
|
+
"$type = Add-Type -MemberDefinition $sig -Name NativeMethods -Namespace Win32 -PassThru",
|
|
171
|
+
"$result = [UIntPtr]::Zero",
|
|
172
|
+
"$HWND_BROADCAST = [IntPtr]0xffff",
|
|
173
|
+
"$WM_SETTINGCHANGE = 0x1a",
|
|
174
|
+
"$SMTO_ABORTIFHUNG = 0x2",
|
|
175
|
+
"$type::SendMessageTimeout($HWND_BROADCAST, $WM_SETTINGCHANGE, [UIntPtr]::Zero, 'Environment', $SMTO_ABORTIFHUNG, 5000, [ref]$result) | Out-Null",
|
|
176
|
+
].join("\n");
|
|
177
|
+
spawnSync("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", script], {
|
|
158
178
|
stdio: "ignore", windowsHide: true,
|
|
159
179
|
});
|
|
160
180
|
}
|