Skip to content

Commit 94728e0

Browse files
authored
Merge pull request #3204 from Jack251970/settings_window_freeze
Fix setting window freeze issue & Improve singleton window opener
2 parents 64441a2 + 1c7e290 commit 94728e0

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

Flow.Launcher/Helper/SingletonWindowOpener.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,29 @@ public static T Open<T>(params object[] args) where T : Window
1010
{
1111
var window = Application.Current.Windows.OfType<Window>().FirstOrDefault(x => x.GetType() == typeof(T))
1212
?? (T)Activator.CreateInstance(typeof(T), args);
13-
13+
1414
// Fix UI bug
1515
// Add `window.WindowState = WindowState.Normal`
1616
// If only use `window.Show()`, Settings-window doesn't show when minimized in taskbar
1717
// Not sure why this works tho
1818
// Probably because, when `.Show()` fails, `window.WindowState == Minimized` (not `Normal`)
1919
// https://stackoverflow.com/a/59719760/4230390
20-
window.WindowState = WindowState.Normal;
21-
window.Show();
22-
20+
// Ensure the window is not minimized before showing it
21+
if (window.WindowState == WindowState.Minimized)
22+
{
23+
window.WindowState = WindowState.Normal;
24+
}
25+
26+
// Ensure the window is visible
27+
if (!window.IsVisible)
28+
{
29+
window.Show();
30+
}
31+
else
32+
{
33+
window.Activate(); // Bring the window to the foreground if already open
34+
}
35+
2336
window.Focus();
2437

2538
return (T)window;

Flow.Launcher/SettingWindow.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ public SettingWindow(IPublicAPI api, SettingWindowViewModel viewModel)
3434
private void OnLoaded(object sender, RoutedEventArgs e)
3535
{
3636
RefreshMaximizeRestoreButton();
37-
// Fix (workaround) for the window freezes after lock screen (Win+L)
37+
// Fix (workaround) for the window freezes after lock screen (Win+L) or sleep
3838
// https://stackoverflow.com/questions/4951058/software-rendering-mode-wpf
3939
HwndSource hwndSource = PresentationSource.FromVisual(this) as HwndSource;
4040
HwndTarget hwndTarget = hwndSource.CompositionTarget;
41-
hwndTarget.RenderMode = RenderMode.Default;
41+
hwndTarget.RenderMode = RenderMode.SoftwareOnly; // Must use software only render mode here
4242

4343
InitializePosition();
4444
}

0 commit comments

Comments
 (0)