Skip to content

Commit 8902bb7

Browse files
Merge pull request #103 from nullinside-development-group/bug/logout
bug: fix remove photo on logout
2 parents d099716 + ffebd4c commit 8902bb7

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

src/TwitchStreamingTools/ViewModels/Pages/AccountViewModel.cs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public override async void OnLoaded() {
143143
base.OnLoaded();
144144

145145
try {
146-
await LoadProfileImage();
146+
await LoadProfileImage().ConfigureAwait(false);
147147
}
148148
catch (Exception ex) {
149149
_logger.Error("Failed to load profile image", ex);
@@ -162,7 +162,7 @@ private async Task LoadProfileImage() {
162162
}
163163

164164
// If we couldn't find the file, download it.
165-
profileImagePath = await DownloadUserImage();
165+
profileImagePath = await DownloadUserImage().ConfigureAwait(false);
166166
if (null == profileImagePath) {
167167
return;
168168
}
@@ -177,10 +177,11 @@ private async Task LoadProfileImage() {
177177
private async void OnCredentialsChanged(TwitchAccessToken? token) {
178178
try {
179179
if (string.IsNullOrWhiteSpace(token?.AccessToken)) {
180+
ProfileImage = null;
180181
return;
181182
}
182-
183-
await LoadProfileImage();
183+
184+
await LoadProfileImage().ConfigureAwait(false);
184185
}
185186
catch (Exception ex) {
186187
_logger.Error("Failed to download user profile image", ex);
@@ -219,8 +220,8 @@ private async void PerformLogin() {
219220

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

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

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

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

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

248-
await _twitchAccountService.UpdateCredentials(oauthResp.AccessToken, oauthResp.RefreshToken, oauthResp.ExpiresUtc.Value);
249+
await _twitchAccountService.UpdateCredentials(oauthResp.AccessToken, oauthResp.RefreshToken, oauthResp.ExpiresUtc.Value).ConfigureAwait(false);
249250
}
250251
catch (Exception ex) {
251252
_logger.Error("Failed to launch browser to login", ex);
@@ -270,14 +271,14 @@ private void ClearCredentials() {
270271
return null;
271272
}
272273

273-
User? user = await api.GetUser();
274+
User? user = await api.GetUser().ConfigureAwait(false);
274275
if (string.IsNullOrWhiteSpace(user?.ProfileImageUrl)) {
275276
return null;
276277
}
277278

278279
// Download the image via http.
279280
using var http = new HttpClient();
280-
byte[] imageBytes = await http.GetByteArrayAsync(user.ProfileImageUrl);
281+
byte[] imageBytes = await http.GetByteArrayAsync(user.ProfileImageUrl).ConfigureAwait(false);
281282

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

291292
// Save to disk
292-
await File.WriteAllBytesAsync(imagePath, imageBytes);
293+
await File.WriteAllBytesAsync(imagePath, imageBytes).ConfigureAwait(false);
293294

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

0 commit comments

Comments
 (0)