Workshop - Auto-updating WIP

This commit is contained in:
Robert committed 2024-07-14 22:14:17 +02:00
1 parent 99d11e1921
commit 3b2d799bfc
18 files changed
+379 -108

No files matched your search

@@ -101,14 +101,27 @@ public partial class EntryReleaseInfoViewModel : ActivatableViewModelBase
return;
}
// If not the latest version, warn and offer to disable auto-updates
bool disableAutoUpdates = false;
if (Release.Id != Release.Entry.LatestReleaseId)
{
disableAutoUpdates = await _windowService.ShowConfirmContentDialog(
"You are installing an older version of this entry",
"Would you like to disable auto-updates for this entry?",
"Yes",
"No"
);
}
_cts = new CancellationTokenSource();
InstallProgress = 0;
InstallationInProgress = true;
try
{
EntryInstallResult result = await _workshopService.InstallEntry(Release.Entry, Release, _progress, _cts.Token);
if (result.IsSuccess)
if (result.IsSuccess && result.Entry != null)
{
_workshopService.SetAutoUpdate(result.Entry, !disableAutoUpdates);
_notificationService.CreateNotification().WithTitle("Installation succeeded").WithSeverity(NotificationSeverity.Success).Show();
InstallationInProgress = false;
await Manage();
@@ -156,7 +169,7 @@ public partial class EntryReleaseInfoViewModel : ActivatableViewModelBase
await UninstallPluginPrerequisites(installedEntry);
await _workshopService.UninstallEntry(installedEntry, CancellationToken.None);
_notificationService.CreateNotification().WithTitle("Entry uninstalled").WithSeverity(NotificationSeverity.Success).Show();
}
finally
@@ -66,11 +66,9 @@
<!-- Info -->
<StackPanel Grid.Column="2" Grid.Row="0" Margin="0 0 4 0" HorizontalAlignment="Right">
<TextBlock TextAlignment="Right" Text="{CompiledBinding Entry.CreatedAt, FallbackValue=01-01-1337, Converter={StaticResource DateTimeConverter}}" />
<TextBlock TextAlignment="Right">
<avalonia:MaterialIcon Kind="Downloads" />
<Run Classes="h5" Text="{CompiledBinding Entry.Downloads, FallbackValue=0}" />
<Run>downloads</Run>
<avalonia:MaterialIcon Kind="Harddisk" />
<Run Text="{CompiledBinding Entry.ReleaseVersion}" />
</TextBlock>
</StackPanel>
@@ -89,7 +87,7 @@
<Button Command="{CompiledBinding ViewLocal}" HorizontalAlignment="Stretch" >Open</Button>
<Button Command="{CompiledBinding Uninstall}" HorizontalAlignment="Stretch">Uninstall</Button>
</StackPanel>
<CheckBox MinHeight="26" Margin="0 4 0 0" IsEnabled="False">Auto-update</CheckBox>
<CheckBox MinHeight="26" Margin="0 4 0 0" IsChecked="{CompiledBinding AutoUpdate}">Auto-update</CheckBox>
</StackPanel>
</Border>
</Grid>
@@ -1,7 +1,4 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using Avalonia.ReactiveUI;
using Avalonia.ReactiveUI;
namespace Artemis.UI.Screens.Workshop.Library.Tabs;
@@ -2,6 +2,7 @@ using System;
using System.Linq;
using System.Reactive;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Threading;
using System.Threading.Tasks;
using Artemis.Core;
@@ -9,6 +10,7 @@ using Artemis.Core.Services;
using Artemis.UI.DryIoc.Factories;
using Artemis.UI.Extensions;
using Artemis.UI.Screens.Plugins;
using Artemis.UI.Services.Interfaces;
using Artemis.UI.Shared;
using Artemis.UI.Shared.Routing;
using Artemis.UI.Shared.Services;
@@ -25,16 +27,19 @@ public partial class InstalledTabItemViewModel : ActivatableViewModelBase
{
private readonly IWorkshopClient _client;
private readonly IWorkshopService _workshopService;
private readonly IWorkshopUpdateService _workshopUpdateService;
private readonly IRouter _router;
private readonly IWindowService _windowService;
private readonly IPluginManagementService _pluginManagementService;
private readonly ISettingsVmFactory _settingsVmFactory;
[Notify] private bool _updateAvailable;
[Notify] private bool _autoUpdate;
public InstalledTabItemViewModel(InstalledEntry entry,
IWorkshopClient client,
IWorkshopService workshopService,
IWorkshopUpdateService workshopUpdateService,
IRouter router,
IWindowService windowService,
IPluginManagementService pluginManagementService,
@@ -42,10 +47,13 @@ public partial class InstalledTabItemViewModel : ActivatableViewModelBase
{
_client = client;
_workshopService = workshopService;
_workshopUpdateService = workshopUpdateService;
_router = router;
_windowService = windowService;
_pluginManagementService = pluginManagementService;
_settingsVmFactory = settingsVmFactory;
_autoUpdate = entry.AutoUpdate;
Entry = entry;
this.WhenActivatedAsync(async _ =>
@@ -65,6 +73,8 @@ public partial class InstalledTabItemViewModel : ActivatableViewModelBase
UpdateAvailable = Entry.ReleaseId != Entry.LatestReleaseId;
}
});
this.WhenAnyValue(vm => vm.AutoUpdate).Skip(1).Subscribe(_ => AutoUpdateToggled());
}
public InstalledEntry Entry { get; }
@@ -108,4 +118,18 @@ public partial class InstalledTabItemViewModel : ActivatableViewModelBase
PluginViewModel pluginViewModel = _settingsVmFactory.PluginViewModel(plugin, ReactiveCommand.Create(() => { }));
await pluginViewModel.ExecuteRemovePrerequisites(true);
}
private void AutoUpdateToggled()
{
_workshopService.SetAutoUpdate(Entry, AutoUpdate);
if (!AutoUpdate)
return;
Task.Run(async () =>
{
await _workshopUpdateService.AutoUpdateEntry(Entry);
UpdateAvailable = Entry.ReleaseId != Entry.LatestReleaseId;
});
}
}