Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions src/TwitchStreamingTools/ViewModels/Pages/AccountViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public override async void OnLoaded() {
base.OnLoaded();

try {
await LoadProfileImage();
await LoadProfileImage().ConfigureAwait(false);
}
catch (Exception ex) {
_logger.Error("Failed to load profile image", ex);
Expand All @@ -162,7 +162,7 @@ private async Task LoadProfileImage() {
}

// If we couldn't find the file, download it.
profileImagePath = await DownloadUserImage();
profileImagePath = await DownloadUserImage().ConfigureAwait(false);
if (null == profileImagePath) {
return;
}
Expand All @@ -177,10 +177,11 @@ private async Task LoadProfileImage() {
private async void OnCredentialsChanged(TwitchAccessToken? token) {
try {
if (string.IsNullOrWhiteSpace(token?.AccessToken)) {
ProfileImage = null;
return;
}

await LoadProfileImage();
await LoadProfileImage().ConfigureAwait(false);
}
catch (Exception ex) {
_logger.Error("Failed to download user profile image", ex);
Expand Down Expand Up @@ -219,8 +220,8 @@ private async void PerformLogin() {

// Create a web socket connection to the api which will provide us with the credentials from twitch.
ClientWebSocket webSocket = new();
await webSocket.ConnectAsync(new Uri($"ws://{Constants.DOMAIN}/api/v1/user/twitch-login/twitch-streaming-tools/ws"), token);
await webSocket.SendTextAsync(guid.ToString(), token);
await webSocket.ConnectAsync(new Uri($"ws://{Constants.DOMAIN}/api/v1/user/twitch-login/twitch-streaming-tools/ws"), token).ConfigureAwait(false);
await webSocket.SendTextAsync(guid.ToString(), token).ConfigureAwait(false);

// Launch the web browser to twitch to ask for account permissions. Twitch will be instructed to callback to our
// api (redirect_uri) which will give us the credentials on the web socket above.
Expand All @@ -233,10 +234,10 @@ private async void PerformLogin() {

// Wait for the user to finish giving us permission on the website. Once they provide us access we will receive
// a response on the web socket containing a JSON with our OAuth information.
string json = await webSocket.ReceiveTextAsync(token);
string json = await webSocket.ReceiveTextAsync(token).ConfigureAwait(false);

// Close the connection, both sides will be waiting to do this so we do it immediately.
await webSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, "Completed Successfully!", token);
await webSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, "Completed Successfully!", token).ConfigureAwait(false);

// Update the oauth token in the twitch account service.
var oauthResp = JsonConvert.DeserializeObject<TwitchAccessToken>(json);
Expand All @@ -245,7 +246,7 @@ private async void PerformLogin() {
return;
}

await _twitchAccountService.UpdateCredentials(oauthResp.AccessToken, oauthResp.RefreshToken, oauthResp.ExpiresUtc.Value);
await _twitchAccountService.UpdateCredentials(oauthResp.AccessToken, oauthResp.RefreshToken, oauthResp.ExpiresUtc.Value).ConfigureAwait(false);
}
catch (Exception ex) {
_logger.Error("Failed to launch browser to login", ex);
Expand All @@ -270,14 +271,14 @@ private void ClearCredentials() {
return null;
}

User? user = await api.GetUser();
User? user = await api.GetUser().ConfigureAwait(false);
if (string.IsNullOrWhiteSpace(user?.ProfileImageUrl)) {
return null;
}

// Download the image via http.
using var http = new HttpClient();
byte[] imageBytes = await http.GetByteArrayAsync(user.ProfileImageUrl);
byte[] imageBytes = await http.GetByteArrayAsync(user.ProfileImageUrl).ConfigureAwait(false);

// If the directory doesn't exist, create it.
if (!Directory.Exists(PROFILE_IMAGE_FOLDER)) {
Expand All @@ -289,7 +290,7 @@ private void ClearCredentials() {
string imagePath = Path.Combine(PROFILE_IMAGE_FOLDER, filename);

// Save to disk
await File.WriteAllBytesAsync(imagePath, imageBytes);
await File.WriteAllBytesAsync(imagePath, imageBytes).ConfigureAwait(false);

// Return path to file, even though everyone already knows it.
return imagePath;
Expand Down