From f8396892940ca99bb1e2c471408b1b4f18277969 Mon Sep 17 00:00:00 2001 From: DB p Date: Tue, 15 Apr 2025 05:54:46 +0900 Subject: [PATCH 1/3] Add Content Dialog owner --- Flow.Launcher/HotkeyControl.xaml.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Flow.Launcher/HotkeyControl.xaml.cs b/Flow.Launcher/HotkeyControl.xaml.cs index 8762a934bbb..9af3b71aafa 100644 --- a/Flow.Launcher/HotkeyControl.xaml.cs +++ b/Flow.Launcher/HotkeyControl.xaml.cs @@ -243,6 +243,9 @@ private async Task OpenHotkeyDialogAsync() } var dialog = new HotkeyControlDialog(Hotkey, DefaultHotkey, WindowTitle); + + dialog.Owner = Window.GetWindow(this); + await dialog.ShowAsync(); switch (dialog.ResultType) { From 9035aa6fab026722ef5ca71ebc3d55b0cfcfea69 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Tue, 15 Apr 2025 08:41:20 +0800 Subject: [PATCH 2/3] Fix dialog owner for all content dialog --- Flow.Launcher/HotkeyControl.xaml.cs | 13 +++++++------ .../ViewModels/SettingsPanePluginsViewModel.cs | 3 +-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Flow.Launcher/HotkeyControl.xaml.cs b/Flow.Launcher/HotkeyControl.xaml.cs index 9af3b71aafa..26272712757 100644 --- a/Flow.Launcher/HotkeyControl.xaml.cs +++ b/Flow.Launcher/HotkeyControl.xaml.cs @@ -1,6 +1,4 @@ -#nullable enable - -using System.Collections.ObjectModel; +using System.Collections.ObjectModel; using System.Threading.Tasks; using System.Windows; using System.Windows.Input; @@ -9,6 +7,8 @@ using Flow.Launcher.Infrastructure.Hotkey; using Flow.Launcher.Infrastructure.UserSettings; +#nullable enable + namespace Flow.Launcher { public partial class HotkeyControl @@ -242,9 +242,10 @@ private async Task OpenHotkeyDialogAsync() HotKeyMapper.RemoveHotkey(Hotkey); } - var dialog = new HotkeyControlDialog(Hotkey, DefaultHotkey, WindowTitle); - - dialog.Owner = Window.GetWindow(this); + var dialog = new HotkeyControlDialog(Hotkey, DefaultHotkey, WindowTitle) + { + Owner = Window.GetWindow(this) + }; await dialog.ShowAsync(); switch (dialog.ResultType) diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPanePluginsViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPanePluginsViewModel.cs index b89e970e99b..916fd1ecee8 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPanePluginsViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPanePluginsViewModel.cs @@ -5,7 +5,6 @@ using System.Windows; using CommunityToolkit.Mvvm.Input; using Flow.Launcher.Core.Plugin; -using Flow.Launcher.Infrastructure; using Flow.Launcher.Infrastructure.UserSettings; using Flow.Launcher.Plugin; using Flow.Launcher.ViewModel; @@ -116,6 +115,7 @@ private async Task OpenHelperAsync() { var helpDialog = new ContentDialog() { + Owner = Application.Current.MainWindow, Content = new StackPanel { Children = @@ -146,7 +146,6 @@ private async Task OpenHelperAsync() } } }, - PrimaryButtonText = (string)Application.Current.Resources["commonOK"], CornerRadius = new CornerRadius(8), Style = (Style)Application.Current.Resources["ContentDialog"] From 28c7538fc3b00bc88a62336bba79d04a0b841fc3 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Tue, 15 Apr 2025 09:06:31 +0800 Subject: [PATCH 3/3] Fix possible Win32Exception --- Flow.Launcher.Infrastructure/Win32Helper.cs | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/Flow.Launcher.Infrastructure/Win32Helper.cs b/Flow.Launcher.Infrastructure/Win32Helper.cs index 6be0243899a..798501ae3fd 100644 --- a/Flow.Launcher.Infrastructure/Win32Helper.cs +++ b/Flow.Launcher.Infrastructure/Win32Helper.cs @@ -365,21 +365,10 @@ public static unsafe void SwitchToEnglishKeyboardLayout(bool backupPrevious) // No installed English layout found if (enHKL == HKL.Null) return; - // When application is exiting, the Application.Current will be null - if (Application.Current == null) return; - - // Get the FL main window - var hwnd = GetWindowHandle(Application.Current.MainWindow, true); + // Get the foreground window + var hwnd = PInvoke.GetForegroundWindow(); if (hwnd == HWND.Null) return; - // Check if the FL main window is the current foreground window - if (!IsForegroundWindow(hwnd)) - { - var result = PInvoke.SetForegroundWindow(hwnd); - // If we cannot set the foreground window, we can use the foreground window and switch the layout - if (!result) hwnd = PInvoke.GetForegroundWindow(); - } - // Get the current foreground window thread ID var threadId = PInvoke.GetWindowThreadProcessId(hwnd); if (threadId == 0) throw new Win32Exception(Marshal.GetLastWin32Error());