Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 20b01fa

Browse files
author
Meaghan Lewis
committed
Merge branch 'master' into releases/2.10.3-vsinstaller
2 parents 52e8ee6 + ee98673 commit 20b01fa

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/GitHub.VisualStudio.UI/Views/Dialog/LoginCredentialsView.xaml.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using System;
22
using System.ComponentModel.Composition;
3+
using System.Diagnostics;
34
using System.Reactive.Disposables;
45
using System.Reactive.Linq;
6+
using System.Runtime.InteropServices;
57
using System.Windows;
68
using System.Windows.Input;
79
using 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
}

0 commit comments

Comments
 (0)