From ac54bde383410929fc6caf318b7ff28a98c269e8 Mon Sep 17 00:00:00 2001 From: Jeffrey <9938813+Raphire@users.noreply.github.com> Date: Mon, 22 Jun 2026 02:07:26 +0200 Subject: [PATCH] Replace FocusHelper C# compilation with WPF Activate() to fix temp DLL access-denied errors (#661) --- Scripts/GUI/Show-ApplyModal.ps1 | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/Scripts/GUI/Show-ApplyModal.ps1 b/Scripts/GUI/Show-ApplyModal.ps1 index 9b112d1..8d67aef 100644 --- a/Scripts/GUI/Show-ApplyModal.ps1 +++ b/Scripts/GUI/Show-ApplyModal.ps1 @@ -7,26 +7,6 @@ function Show-ApplyModal { ) Add-Type -AssemblyName PresentationFramework,PresentationCore,WindowsBase | Out-Null - - # P/Invoke helpers for forcing focus back after Explorer restart - if (-not ([System.Management.Automation.PSTypeName]'Win11Debloat.FocusHelper').Type) { - Add-Type -Namespace Win11Debloat -Name FocusHelper -MemberDefinition @' - [DllImport("user32.dll")] public static extern bool SetForegroundWindow(IntPtr hWnd); - [DllImport("user32.dll")] public static extern IntPtr GetForegroundWindow(); - [DllImport("user32.dll")] public static extern uint GetWindowThreadProcessId(IntPtr hWnd, IntPtr lpdwProcessId); - [DllImport("user32.dll")] public static extern bool AttachThreadInput(uint idAttach, uint idAttachTo, bool fAttach); - [DllImport("kernel32.dll")] public static extern uint GetCurrentThreadId(); - - public static void ForceActivate(IntPtr hwnd) { - IntPtr fg = GetForegroundWindow(); - uint fgThread = GetWindowThreadProcessId(fg, IntPtr.Zero); - uint myThread = GetCurrentThreadId(); - if (fgThread != myThread) AttachThreadInput(myThread, fgThread, true); - SetForegroundWindow(hwnd); - if (fgThread != myThread) AttachThreadInput(myThread, fgThread, false); - } -'@ - } $usesDarkMode = GetSystemUsesDarkMode @@ -133,8 +113,7 @@ function Show-ApplyModal { # Wait for Explorer to finish relaunching, then reclaim focus. Start-Sleep -Milliseconds 800 $applyWindow.Dispatcher.Invoke([action]{ - $hwnd = (New-Object System.Windows.Interop.WindowInteropHelper($applyWindow)).Handle - [Win11Debloat.FocusHelper]::ForceActivate($hwnd) + $applyWindow.Activate() }) }