This repository was archived by the owner on Jun 21, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +21
-1
lines changed
src/GitHub.VisualStudio.UI/Views/Dialog Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change 11using System ;
22using System . ComponentModel . Composition ;
3+ using System . Diagnostics ;
34using System . Reactive . Disposables ;
45using System . Reactive . Linq ;
6+ using System . Runtime . InteropServices ;
57using System . Windows ;
68using System . Windows . Input ;
79using GitHub . Controls ;
@@ -46,7 +48,7 @@ public LoginCredentialsView()
4648 this . WhenAnyObservable (
4749 x => x . ViewModel . GitHubLogin . LoginViaOAuth ,
4850 x => x . ViewModel . EnterpriseLogin . LoginViaOAuth )
49- . Subscribe ( _ => Application . Current . MainWindow ? . Activate ( ) ) ;
51+ . Subscribe ( _ => SetForegroundWindow ( ) ) ;
5052
5153 hostTabControl . SelectionChanged += ( s , e ) =>
5254 {
@@ -122,5 +124,23 @@ void SetupSelectedTabBindings(Action<IDisposable> d)
122124 . Where ( x => x == true )
123125 . BindTo ( this , v => v . enterpriseTab . IsSelected ) ) ;
124126 }
127+
128+ static bool SetForegroundWindow ( )
129+ {
130+ var hWnd = Process . GetCurrentProcess ( ) . MainWindowHandle ;
131+ if ( hWnd != IntPtr . Zero )
132+ {
133+ return NativeMethods . SetForegroundWindow ( hWnd ) ;
134+ }
135+
136+ return false ;
137+ }
138+
139+ class NativeMethods
140+ {
141+ [ DllImport ( "user32.dll" ) ]
142+ [ return : MarshalAs ( UnmanagedType . Bool ) ]
143+ internal static extern bool SetForegroundWindow ( IntPtr hWnd ) ;
144+ }
125145 }
126146}
You can’t perform that action at this time.
0 commit comments