File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,30 +11,6 @@ public static T Open<T>(params object[] args) where T : Window
1111 var window = Application . Current . Windows . OfType < Window > ( ) . FirstOrDefault ( x => x . GetType ( ) == typeof ( T ) )
1212 ?? ( T ) Activator . CreateInstance ( typeof ( T ) , args ) ;
1313
14- // Fix UI bug
15- // Add `window.WindowState = WindowState.Normal`
16- // If only use `window.Show()`, Settings-window doesn't show when minimized in taskbar
17- // Not sure why this works tho
18- // Probably because, when `.Show()` fails, `window.WindowState == Minimized` (not `Normal`)
19- // https://stackoverflow.com/a/59719760/4230390
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-
36- window . Focus ( ) ;
37-
38- return ( T ) window ;
14+ return WindowVisibilityHelper . ShowOrActivate ( ( T ) window ) ;
3915 }
4016}
Original file line number Diff line number Diff line change 1+ using System . Windows ;
2+
3+ namespace Flow . Launcher . Helper ;
4+
5+ public static class WindowVisibilityHelper
6+ {
7+ public static T ShowOrActivate < T > ( T window ) where T : Window
8+ {
9+ // Fix UI bug
10+ // Add `window.WindowState = WindowState.Normal`
11+ // If only use `window.Show()`, Settings-window doesn't show when minimized in taskbar
12+ // Not sure why this works tho
13+ // Probably because, when `.Show()` fails, `window.WindowState == Minimized` (not `Normal`)
14+ // https://stackoverflow.com/a/59719760/4230390
15+ // Ensure the window is not minimized before showing it
16+ if ( window . WindowState == WindowState . Minimized )
17+ {
18+ window . WindowState = WindowState . Normal ;
19+ }
20+
21+ // Ensure the window is visible
22+ if ( ! window . IsVisible )
23+ {
24+ window . Show ( ) ;
25+ }
26+ else
27+ {
28+ window . Activate ( ) ; // Bring the window to the foreground if already open
29+ }
30+
31+ window . Focus ( ) ;
32+
33+ return ( T ) window ;
34+ }
35+ }
Original file line number Diff line number Diff line change @@ -160,21 +160,7 @@ public bool OpenPluginSettingsWindow(string pluginId)
160160 . FirstOrDefault ( existing => existing . PluginId == pluginId )
161161 ?? new PluginSettingsWindow ( pluginId ) ;
162162
163- if ( window . WindowState == WindowState . Minimized )
164- {
165- window . WindowState = WindowState . Normal ;
166- }
167-
168- if ( ! window . IsVisible )
169- {
170- window . Show ( ) ;
171- }
172- else
173- {
174- window . Activate ( ) ;
175- }
176-
177- window . Focus ( ) ;
163+ WindowVisibilityHelper . ShowOrActivate ( window ) ;
178164 return true ;
179165 }
180166 catch ( Exception e )
You can’t perform that action at this time.
0 commit comments