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

Commit 358a653

Browse files
author
Steven Kirk
committed
Fix logging in.
We need to make sure we're on the main thread to get an instance of `ITwoFactorChallengeHandler`. This is nasty and the whole thing needs to be refactored; see #1398.
1 parent b5be1a1 commit 358a653

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/GitHub.VisualStudio/GitHubPackage.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,19 @@ async Task<object> CreateService(IAsyncServiceContainer container, CancellationT
213213
var serviceProvider = await GetServiceAsync(typeof(IGitHubServiceProvider)) as IGitHubServiceProvider;
214214
var keychain = serviceProvider.GetService<IKeychain>();
215215

216+
// HACK: We need to make sure this is run on the main thread. We really
217+
// shouldn't be injecting a view model concern into LoginManager - this
218+
// needs to be refactored. See #1398.
219+
var lazy2Fa = new Lazy<ITwoFactorChallengeHandler>(() =>
220+
ThreadHelper.JoinableTaskFactory.Run(async () =>
221+
{
222+
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
223+
return serviceProvider.GetService<ITwoFactorChallengeHandler>();
224+
}));
225+
216226
return new LoginManager(
217227
keychain,
218-
new Lazy<ITwoFactorChallengeHandler>(() => serviceProvider.GetService<ITwoFactorChallengeHandler>()),
228+
lazy2Fa,
219229
ApiClientConfiguration.ClientId,
220230
ApiClientConfiguration.ClientSecret,
221231
ApiClientConfiguration.AuthorizationNote,

0 commit comments

Comments
 (0)