From 4f2b6c4e1cf35e0030d74f49d0ea3a4216184f04 Mon Sep 17 00:00:00 2001 From: Dade Lamkins Date: Thu, 23 Sep 2021 19:36:38 -0400 Subject: [PATCH] Updated to Gw2Sharp 1.3 and fixed a bug that could occur if you revoked your token (which would then prevent you from deleting it in the UI). --- Blish HUD/Blish HUD.csproj | 2 +- .../Gw2WebApi/UI/Presenters/ApiTokenPresenter.cs | 10 ++++++++++ .../GameServices/Gw2WebApi/UI/Views/ApiTokenView.cs | 13 +++++++++---- Blish HUD/GameServices/Gw2WebApiService.cs | 2 +- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/Blish HUD/Blish HUD.csproj b/Blish HUD/Blish HUD.csproj index e1d5c56af..cce510623 100644 --- a/Blish HUD/Blish HUD.csproj +++ b/Blish HUD/Blish HUD.csproj @@ -221,7 +221,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/Blish HUD/GameServices/Gw2WebApi/UI/Presenters/ApiTokenPresenter.cs b/Blish HUD/GameServices/Gw2WebApi/UI/Presenters/ApiTokenPresenter.cs index b497d5cda..c35048ca7 100644 --- a/Blish HUD/GameServices/Gw2WebApi/UI/Presenters/ApiTokenPresenter.cs +++ b/Blish HUD/GameServices/Gw2WebApi/UI/Presenters/ApiTokenPresenter.cs @@ -20,6 +20,8 @@ public class ApiTokenPresenter : Presenter { public ApiTokenPresenter(ApiTokenView view, string apiKey) : base(view, apiKey) { _loadCancel = new CancellationTokenSource(); + + this.View.DeleteClicked += TokenDeleteClicked; } protected override async Task Load(IProgress progress) { @@ -54,6 +56,12 @@ protected override async Task Load(IProgress progress) { return true; } + private void TokenDeleteClicked(object sender, EventArgs e) { + GameService.Gw2WebApi.UnregisterKey(this.Model); + + this.View.RemoveTokenView(); + } + private bool UpdateFromRequestTaskResult(Task infoTask, ref T field) { if (infoTask.IsCanceled) return false; @@ -88,6 +96,8 @@ protected override void UpdateView() { protected override void Unload() { _loadCancel.Cancel(); + this.View.DeleteClicked -= TokenDeleteClicked; + base.Unload(); } diff --git a/Blish HUD/GameServices/Gw2WebApi/UI/Views/ApiTokenView.cs b/Blish HUD/GameServices/Gw2WebApi/UI/Views/ApiTokenView.cs index 1e443b284..6ce89e2fa 100644 --- a/Blish HUD/GameServices/Gw2WebApi/UI/Views/ApiTokenView.cs +++ b/Blish HUD/GameServices/Gw2WebApi/UI/Views/ApiTokenView.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Blish_HUD.Controls; using Blish_HUD.Graphics.UI; using Blish_HUD.Input; @@ -19,6 +20,8 @@ public class ApiTokenView : View { {"23", ("Spain", GameService.Content.GetTexture(@"common/784344"))} }; + public event EventHandler DeleteClicked; + private Label _accountNameLbl; private Label _tokenKeyLbl; private Label _tokenNameLbl; @@ -184,11 +187,13 @@ protected override void Build(Container buildPanel) { _deleteBttn.Click += DeleteRegisteredToken; } - private void DeleteRegisteredToken(object sender, MouseEventArgs e) { - GameService.Gw2WebApi.UnregisterKey(_tokenInfo.Id); - + public void RemoveTokenView() { this.ViewTarget.Dispose(); } + private void DeleteRegisteredToken(object sender, MouseEventArgs e) { + this.DeleteClicked?.Invoke(this, EventArgs.Empty); + } + } } diff --git a/Blish HUD/GameServices/Gw2WebApiService.cs b/Blish HUD/GameServices/Gw2WebApiService.cs index be4a86acb..0d4924e97 100644 --- a/Blish HUD/GameServices/Gw2WebApiService.cs +++ b/Blish HUD/GameServices/Gw2WebApiService.cs @@ -143,7 +143,7 @@ internal string[] GetKeys() { private void UpdateCharacterList(SettingEntry definedKey) { GetCharacters(GetConnection(definedKey.Value)).ContinueWith((charactersResponse) => { - if (charactersResponse.Result != null) { + if (charactersResponse.Exception == null && charactersResponse.Result != null) { foreach (string characterId in charactersResponse.Result) { _characterRepository.AddOrUpdate(characterId, definedKey.Value, (k, o) => definedKey.Value); }