From d368e6e627fa45a921e765b7fc695a69120abb12 Mon Sep 17 00:00:00 2001 From: Gerardo Grignoli Date: Wed, 29 May 2024 23:28:07 -0300 Subject: [PATCH] Modified `PathPrecedence` config to call to broadcast the WM_SETTINGCHANGE message, ensuring that the system recognize the changes without requiring a restart. --- src/gsudo/AppSettings/PathPrecedenceSetting.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/gsudo/AppSettings/PathPrecedenceSetting.cs b/src/gsudo/AppSettings/PathPrecedenceSetting.cs index 95bbe21..d4b1deb 100644 --- a/src/gsudo/AppSettings/PathPrecedenceSetting.cs +++ b/src/gsudo/AppSettings/PathPrecedenceSetting.cs @@ -51,6 +51,18 @@ public override void Save(string newValue, bool global) Logger.Instance.Log($"\"{system32Path}\" path is now prioritized in the PATH environment variable.", LogLevel.Info); Logger.Instance.Log("Please restart all your consoles to ensure the change makes effect.", LogLevel.Warning); + + // Notify the system of the change + SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, IntPtr.Zero, "Environment", SMTO_NORMAL, 100, out var _); } + + [System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true, CharSet = System.Runtime.InteropServices.CharSet.Auto)] + public static extern IntPtr SendMessageTimeout(IntPtr hWnd, uint Msg, IntPtr wParam, + [System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPTStr)] string lParam, + uint fuFlags, uint uTimeout, out IntPtr lpdwResult); + + private static readonly IntPtr HWND_BROADCAST = new IntPtr(0xFFFF); + private const uint WM_SETTINGCHANGE = 0x001A; + private const uint SMTO_NORMAL = 0x0000; } }