Skip to content

Commit

Permalink
Modified PathPrecedence config to broadcast the WM_SETTINGCHANGE mess…
Browse files Browse the repository at this point in the history
…age, ensuring that the system recognize the changes without requiring a restart.
  • Loading branch information
gerardog committed May 30, 2024
1 parent d368e6e commit 25d89fc
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/gsudo/AppSettings/PathPrecedenceSetting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;

namespace gsudo.AppSettings
{
Expand Down Expand Up @@ -53,16 +54,14 @@ public override void Save(string newValue, bool global)
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 _);
SendNotifyMessage(HWND_BROADCAST, WM_SETTINGCHANGE, UIntPtr.Zero, "Environment");
}

[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);
[DllImport("user32.dll", CharSet = CharSet.Auto)]

Check warning on line 60 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)

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

View workflow job for this annotation

GitHub Actions / build / Test

Specify marshaling for P/Invoke string arguments (https://docs.microsoft.com/visualstudio/code-quality/ca2101-specify-marshaling-for-p-invoke-string-arguments)
private static extern bool SendNotifyMessage(
IntPtr hWnd, uint Msg, UIntPtr wParam, string lParam);

private static readonly IntPtr HWND_BROADCAST = new IntPtr(0xFFFF);
private const uint WM_SETTINGCHANGE = 0x001A;
private const uint SMTO_NORMAL = 0x0000;
private static readonly IntPtr HWND_BROADCAST = new IntPtr(0xFFFF);
}
}

0 comments on commit 25d89fc

Please sign in to comment.