From f8335327bb397d8e686a990ef2ef149c60e1b8b2 Mon Sep 17 00:00:00 2001 From: jliddev Date: Wed, 30 Sep 2020 14:33:14 -0500 Subject: [PATCH 1/2] My addon view model can now update the list items during install #76 --- WowUp.WPF/Models/Events/AddonStateEventArgs.cs | 12 ++++++++++++ WowUp.WPF/Services/AddonService.cs | 18 ++++++++++++++++++ WowUp.WPF/Services/Contracts/IAddonService.cs | 2 ++ WowUp.WPF/ViewModels/AddonListItemViewModel.cs | 10 +++++----- WowUp.WPF/ViewModels/AddonsViewViewModel.cs | 9 +++++++++ WowUp.WPF/WowUp.WPF.csproj | 2 +- 6 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 WowUp.WPF/Models/Events/AddonStateEventArgs.cs diff --git a/WowUp.WPF/Models/Events/AddonStateEventArgs.cs b/WowUp.WPF/Models/Events/AddonStateEventArgs.cs new file mode 100644 index 00000000..44b14e7f --- /dev/null +++ b/WowUp.WPF/Models/Events/AddonStateEventArgs.cs @@ -0,0 +1,12 @@ +using WowUp.Common.Enums; +using WowUp.WPF.Entities; + +namespace WowUp.WPF.Models.Events +{ + public class AddonStateEventArgs + { + public Addon Addon { get; set; } + public AddonInstallState AddonInstallState { get; set; } + public decimal Progress { get; set; } + } +} diff --git a/WowUp.WPF/Services/AddonService.cs b/WowUp.WPF/Services/AddonService.cs index 164616e4..730ce49e 100644 --- a/WowUp.WPF/Services/AddonService.cs +++ b/WowUp.WPF/Services/AddonService.cs @@ -45,6 +45,7 @@ namespace WowUp.WPF.Services public event AddonEventHandler AddonUninstalled; public event AddonEventHandler AddonInstalled; public event AddonEventHandler AddonUpdated; + public event AddonStateEventHandler AddonStateChanged; public string BackupPath => Path.Combine(FileUtilities.AppDataPath, BackupFolder); @@ -383,6 +384,19 @@ namespace WowUp.WPF.Services await InstallAddon(addon.Id, onUpdate); } + private void SendAddonStateChange( + Addon addon, + AddonInstallState addonInstallState, + decimal progress) + { + AddonStateChanged?.Invoke(this, new AddonStateEventArgs + { + Addon = addon, + AddonInstallState = addonInstallState, + Progress = progress + }); + } + public async Task InstallAddon(int addonId, Action updateAction = null) { var addon = GetAddon(addonId); @@ -392,6 +406,7 @@ namespace WowUp.WPF.Services } updateAction?.Invoke(AddonInstallState.Downloading, 25m); + SendAddonStateChange(addon, AddonInstallState.Downloading, 25m); string downloadedFilePath = string.Empty; string unzippedDirectory = string.Empty; @@ -405,11 +420,13 @@ namespace WowUp.WPF.Services if (!string.IsNullOrEmpty(addon.InstalledVersion)) { updateAction?.Invoke(AddonInstallState.BackingUp, 0.50m); + SendAddonStateChange(addon, AddonInstallState.BackingUp, 75m); var backupZipFilePath = Path.Combine(BackupPath, $"{addon.Name}-{addon.InstalledVersion}.zip"); //await _downloadService.ZipFile(downloadedFilePath, backupZipFilePath); } updateAction?.Invoke(AddonInstallState.Installing, 75m); + SendAddonStateChange(addon, AddonInstallState.Installing, 75m); unzippedDirectory = await _downloadService.UnzipFile(downloadedFilePath); @@ -449,6 +466,7 @@ namespace WowUp.WPF.Services } updateAction?.Invoke(AddonInstallState.Complete, 100m); + SendAddonStateChange(addon, AddonInstallState.Complete, 100m); } private async Task CacheThumbnail(Addon addon) diff --git a/WowUp.WPF/Services/Contracts/IAddonService.cs b/WowUp.WPF/Services/Contracts/IAddonService.cs index a2f66328..1a41a369 100644 --- a/WowUp.WPF/Services/Contracts/IAddonService.cs +++ b/WowUp.WPF/Services/Contracts/IAddonService.cs @@ -9,12 +9,14 @@ using WowUp.WPF.Models.Events; namespace WowUp.WPF.Services.Contracts { public delegate void AddonEventHandler(object sender, AddonEventArgs e); + public delegate void AddonStateEventHandler(object sender, AddonStateEventArgs e); public interface IAddonService { event AddonEventHandler AddonUninstalled; event AddonEventHandler AddonInstalled; event AddonEventHandler AddonUpdated; + event AddonStateEventHandler AddonStateChanged; string BackupPath { get; } diff --git a/WowUp.WPF/ViewModels/AddonListItemViewModel.cs b/WowUp.WPF/ViewModels/AddonListItemViewModel.cs index cdcdcf0b..7e02aaf1 100644 --- a/WowUp.WPF/ViewModels/AddonListItemViewModel.cs +++ b/WowUp.WPF/ViewModels/AddonListItemViewModel.cs @@ -327,12 +327,9 @@ namespace WowUp.WPF.ViewModels public async Task UpdateAddon() { - ShowStatusText = false; - ShowUpdateButton = false; - try { - await _addonService.InstallAddon(_addon.Id, OnInstallUpdate); + await _addonService.InstallAddon(_addon.Id); } catch (Exception ex) { @@ -423,8 +420,11 @@ namespace WowUp.WPF.ViewModels _analyticsService.TrackUserAction("Addons", "Channel", channelType.ToString()); } - private void OnInstallUpdate(AddonInstallState installState, decimal percent) + public void OnInstallUpdate(AddonInstallState installState, decimal percent) { + ShowStatusText = false; + ShowUpdateButton = false; + try { ProgressText = GetInstallStateText(installState); diff --git a/WowUp.WPF/ViewModels/AddonsViewViewModel.cs b/WowUp.WPF/ViewModels/AddonsViewViewModel.cs index 49069ae0..59a8a469 100644 --- a/WowUp.WPF/ViewModels/AddonsViewViewModel.cs +++ b/WowUp.WPF/ViewModels/AddonsViewViewModel.cs @@ -212,6 +212,15 @@ namespace WowUp.WPF.ViewModels AddonUpdated(args.Addon); }; + _addonService.AddonStateChanged += (sender, args) => + { + var addon = DisplayAddons.FirstOrDefault(listItem => listItem.Addon.Id == args.Addon.Id); + if(addon != null) + { + addon.OnInstallUpdate(args.AddonInstallState, args.Progress); + } + }; + _warcraftService.ProductChanged += (sender, args) => { SetClientNames(); diff --git a/WowUp.WPF/WowUp.WPF.csproj b/WowUp.WPF/WowUp.WPF.csproj index 21f9e3e0..984780ff 100644 --- a/WowUp.WPF/WowUp.WPF.csproj +++ b/WowUp.WPF/WowUp.WPF.csproj @@ -10,7 +10,7 @@ WowUp Jliddev WowUp - 1.17.0 + 1.17.1 wowup_logo_512np_RRT_icon.ico jliddev https://wowup.io From b883ea2fad46d7b2d9714c1880ec69cc902efe27 Mon Sep 17 00:00:00 2001 From: jliddev Date: Wed, 30 Sep 2020 14:54:30 -0500 Subject: [PATCH 2/2] Update changelog.json --- WowUp.WPF/Assets/changelog.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/WowUp.WPF/Assets/changelog.json b/WowUp.WPF/Assets/changelog.json index 67d97deb..7e514000 100644 --- a/WowUp.WPF/Assets/changelog.json +++ b/WowUp.WPF/Assets/changelog.json @@ -1,5 +1,9 @@ { "ChangeLogs": [ + { + "Version": "1.17.1", + "Description": "Fix a visual bug where auto updated addons were not shown up to date on the My Addons page." + }, { "Version": "1.17.0", "Description": "Auto updates should function more like you would expect.\nSystem Notifications should appear when addons are auto updated.\nRe-Scan is now less desctructive, should preserve channels and auto update state.\nAdd the ability to update multiple clients at once by right clicking update-all.\nBug fixes.\nUI Updates."