Skip to content

Commit

Permalink
Modified PathPrecedence config to call to broadcast the WM_SETTINGC…
Browse files Browse the repository at this point in the history
…HANGE message, ensuring that the system recognize the changes without requiring a restart.
  • Loading branch information
gerardog committed May 30, 2024
1 parent 5e380bd commit d368e6e
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/gsudo/AppSettings/PathPrecedenceSetting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Check warning on line 61 in src/gsudo/AppSettings/PathPrecedenceSetting.cs

View workflow job for this annotation

GitHub Actions / Test

Specify marshaling for P/Invoke string arguments (https://docs.microsoft.com/visualstudio/code-quality/ca2101-specify-marshaling-for-p-invoke-string-arguments)
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;
}
}

0 comments on commit d368e6e

Please sign in to comment.