Skip to content

Commit ea34808

Browse files
committed
broadcast environment var change on windows
1 parent 716007e commit ea34808

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/sdk.rs

+21
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,27 @@ fn set_sdk_env(path: &Path) -> bool {
163163
env_success = false;
164164
} else {
165165
env_success = true;
166+
167+
use std::ffi::c_void;
168+
169+
#[link(name = "user32")]
170+
extern "system" {
171+
fn SendMessageTimeoutW(hwnd: *const c_void, msg: u32, wparam: *const c_void, lparam: *const c_void, flags: u32, timeout: u32, result: *mut c_void) -> i32;
172+
}
173+
unsafe {
174+
const HWND_BROADCAST: *const c_void = 0xffff as *const c_void;
175+
const WM_SETTINGCHANGE: u32 = 0x1a;
176+
const SMTO_ABORTIFHUNG: u32 = 0x2;
177+
178+
let param = ['E', 'n', 'v', 'i', 'r', 'o', 'n', 'm', 'e', 'n', 't', '\0'].map(|x| x as i8);
179+
let param_wide = param.map(|x| x as i16);
180+
181+
// This should properly update the enviroment variable change to new cmd instances for example,
182+
// existing terminals will still have to reload though
183+
// Do it for both narrow and wide because i saw it on stackoverflow idk
184+
SendMessageTimeoutW(HWND_BROADCAST, WM_SETTINGCHANGE, std::ptr::null(), param.as_ptr() as *const c_void, SMTO_ABORTIFHUNG, 1000, std::ptr::null_mut());
185+
SendMessageTimeoutW(HWND_BROADCAST, WM_SETTINGCHANGE, std::ptr::null(), param_wide.as_ptr() as *const c_void, SMTO_ABORTIFHUNG, 1000, std::ptr::null_mut());
186+
}
166187
}
167188
}
168189

0 commit comments

Comments
 (0)