Skip to content

Commit 70c8ea1

Browse files
Jack251970jjw24
authored andcommitted
Fix setting window freeze issue & Improve singleton window opener
1 parent aa8f472 commit 70c8ea1

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
@@ -35,11 +35,11 @@ public SettingWindow(IPublicAPI api, SettingWindowViewModel viewModel)
3535
private void OnLoaded(object sender, RoutedEventArgs e)
3636
{
3737
RefreshMaximizeRestoreButton();
38-
// Fix (workaround) for the window freezes after lock screen (Win+L)
38+
// Fix (workaround) for the window freezes after lock screen (Win+L) or sleep
3939
// https://stackoverflow.com/questions/4951058/software-rendering-mode-wpf
4040
HwndSource hwndSource = PresentationSource.FromVisual(this) as HwndSource;
4141
HwndTarget hwndTarget = hwndSource.CompositionTarget;
42-
hwndTarget.RenderMode = RenderMode.Default;
42+
hwndTarget.RenderMode = RenderMode.SoftwareOnly; // Must use software only render mode here
4343

4444
InitializePosition();
4545
}

0 commit comments

Comments
 (0)