Skip to content

Commit 309a710

Browse files
authored
Merge pull request #3466 from onesounds/250415-FixDialogOwner
Fix Content Dialog owner & Fix Win32Exception
2 parents f3ff865 + 28c7538 commit 309a710

File tree

3 files changed

+11
-19
lines changed

3 files changed

+11
-19
lines changed

Flow.Launcher.Infrastructure/Win32Helper.cs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -365,21 +365,10 @@ public static unsafe void SwitchToEnglishKeyboardLayout(bool backupPrevious)
365365
// No installed English layout found
366366
if (enHKL == HKL.Null) return;
367367

368-
// When application is exiting, the Application.Current will be null
369-
if (Application.Current == null) return;
370-
371-
// Get the FL main window
372-
var hwnd = GetWindowHandle(Application.Current.MainWindow, true);
368+
// Get the foreground window
369+
var hwnd = PInvoke.GetForegroundWindow();
373370
if (hwnd == HWND.Null) return;
374371

375-
// Check if the FL main window is the current foreground window
376-
if (!IsForegroundWindow(hwnd))
377-
{
378-
var result = PInvoke.SetForegroundWindow(hwnd);
379-
// If we cannot set the foreground window, we can use the foreground window and switch the layout
380-
if (!result) hwnd = PInvoke.GetForegroundWindow();
381-
}
382-
383372
// Get the current foreground window thread ID
384373
var threadId = PInvoke.GetWindowThreadProcessId(hwnd);
385374
if (threadId == 0) throw new Win32Exception(Marshal.GetLastWin32Error());

Flow.Launcher/HotkeyControl.xaml.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
#nullable enable
2-
3-
using System.Collections.ObjectModel;
1+
using System.Collections.ObjectModel;
42
using System.Threading.Tasks;
53
using System.Windows;
64
using System.Windows.Input;
@@ -9,6 +7,8 @@
97
using Flow.Launcher.Infrastructure.Hotkey;
108
using Flow.Launcher.Infrastructure.UserSettings;
119

10+
#nullable enable
11+
1212
namespace Flow.Launcher
1313
{
1414
public partial class HotkeyControl
@@ -242,7 +242,11 @@ private async Task OpenHotkeyDialogAsync()
242242
HotKeyMapper.RemoveHotkey(Hotkey);
243243
}
244244

245-
var dialog = new HotkeyControlDialog(Hotkey, DefaultHotkey, WindowTitle);
245+
var dialog = new HotkeyControlDialog(Hotkey, DefaultHotkey, WindowTitle)
246+
{
247+
Owner = Window.GetWindow(this)
248+
};
249+
246250
await dialog.ShowAsync();
247251
switch (dialog.ResultType)
248252
{

Flow.Launcher/SettingPages/ViewModels/SettingsPanePluginsViewModel.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Windows;
66
using CommunityToolkit.Mvvm.Input;
77
using Flow.Launcher.Core.Plugin;
8-
using Flow.Launcher.Infrastructure;
98
using Flow.Launcher.Infrastructure.UserSettings;
109
using Flow.Launcher.Plugin;
1110
using Flow.Launcher.ViewModel;
@@ -116,6 +115,7 @@ private async Task OpenHelperAsync()
116115
{
117116
var helpDialog = new ContentDialog()
118117
{
118+
Owner = Application.Current.MainWindow,
119119
Content = new StackPanel
120120
{
121121
Children =
@@ -146,7 +146,6 @@ private async Task OpenHelperAsync()
146146
}
147147
}
148148
},
149-
150149
PrimaryButtonText = (string)Application.Current.Resources["commonOK"],
151150
CornerRadius = new CornerRadius(8),
152151
Style = (Style)Application.Current.Resources["ContentDialog"]

0 commit comments

Comments
 (0)