mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Implemented Artemis.Web.Update client
This commit is contained in:
1 parent
a5d2249593
commit
0cd65a2ebf
36 files changed
+1022
-359
No files matched your search
@@ -137,7 +137,7 @@
|
||||
</Border>
|
||||
|
||||
<!-- Update settings -->
|
||||
<StackPanel IsVisible="{CompiledBinding IsUpdatingSupported}">
|
||||
<StackPanel>
|
||||
<TextBlock Classes="h4" Margin="0 15">
|
||||
Updating
|
||||
</TextBlock>
|
||||
|
||||
@@ -12,6 +12,7 @@ using Artemis.Core.Providers;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Screens.StartupWizard;
|
||||
using Artemis.UI.Services.Interfaces;
|
||||
using Artemis.UI.Services.Updating;
|
||||
using Artemis.UI.Shared;
|
||||
using Artemis.UI.Shared.Providers;
|
||||
using Artemis.UI.Shared.Services;
|
||||
@@ -30,6 +31,7 @@ public class GeneralTabViewModel : ActivatableViewModelBase
|
||||
private readonly PluginSetting<LayerBrushReference> _defaultLayerBrushDescriptor;
|
||||
private readonly ISettingsService _settingsService;
|
||||
private readonly IUpdateService _updateService;
|
||||
private readonly INotificationService _notificationService;
|
||||
private readonly IWindowService _windowService;
|
||||
private bool _startupWizardOpen;
|
||||
|
||||
@@ -38,13 +40,15 @@ public class GeneralTabViewModel : ActivatableViewModelBase
|
||||
IPluginManagementService pluginManagementService,
|
||||
IDebugService debugService,
|
||||
IWindowService windowService,
|
||||
IUpdateService updateService)
|
||||
IUpdateService updateService,
|
||||
INotificationService notificationService)
|
||||
{
|
||||
DisplayName = "General";
|
||||
_settingsService = settingsService;
|
||||
_debugService = debugService;
|
||||
_windowService = windowService;
|
||||
_updateService = updateService;
|
||||
_notificationService = notificationService;
|
||||
_autoRunProvider = container.Resolve<IAutoRunProvider>(IfUnresolved.ReturnDefault);
|
||||
|
||||
List<LayerBrushProvider> layerBrushProviders = pluginManagementService.GetFeaturesOfType<LayerBrushProvider>();
|
||||
@@ -88,7 +92,6 @@ public class GeneralTabViewModel : ActivatableViewModelBase
|
||||
public ReactiveCommand<Unit, Unit> ShowDataFolder { get; }
|
||||
|
||||
public bool IsAutoRunSupported => _autoRunProvider != null;
|
||||
public bool IsUpdatingSupported => _updateService.UpdatingSupported;
|
||||
|
||||
public ObservableCollection<LayerBrushDescriptor> LayerBrushDescriptors { get; }
|
||||
public ObservableCollection<string> GraphicsContexts { get; }
|
||||
@@ -142,8 +145,8 @@ public class GeneralTabViewModel : ActivatableViewModelBase
|
||||
public PluginSetting<bool> UIAutoRun => _settingsService.GetSetting("UI.AutoRun", false);
|
||||
public PluginSetting<int> UIAutoRunDelay => _settingsService.GetSetting("UI.AutoRunDelay", 15);
|
||||
public PluginSetting<bool> UIShowOnStartup => _settingsService.GetSetting("UI.ShowOnStartup", true);
|
||||
public PluginSetting<bool> UICheckForUpdates => _settingsService.GetSetting("UI.CheckForUpdates", true);
|
||||
public PluginSetting<bool> UIAutoUpdate => _settingsService.GetSetting("UI.AutoUpdate", false);
|
||||
public PluginSetting<bool> UICheckForUpdates => _settingsService.GetSetting("UI.Updating.AutoCheck", true);
|
||||
public PluginSetting<bool> UIAutoUpdate => _settingsService.GetSetting("UI.Updating.AutoInstall", false);
|
||||
public PluginSetting<bool> ProfileEditorShowDataModelValues => _settingsService.GetSetting("ProfileEditor.ShowDataModelValues", false);
|
||||
public PluginSetting<LogEventLevel> CoreLoggingLevel => _settingsService.GetSetting("Core.LoggingLevel", LogEventLevel.Information);
|
||||
public PluginSetting<string> CorePreferredGraphicsContext => _settingsService.GetSetting("Core.PreferredGraphicsContext", "Software");
|
||||
@@ -159,7 +162,14 @@ public class GeneralTabViewModel : ActivatableViewModelBase
|
||||
|
||||
private async Task ExecuteCheckForUpdate(CancellationToken cancellationToken)
|
||||
{
|
||||
await _updateService.ManualUpdate();
|
||||
// If an update was available a popup was shown, no need to continue
|
||||
if (await _updateService.CheckForUpdate())
|
||||
return;
|
||||
|
||||
_notificationService.CreateNotification()
|
||||
.WithTitle("No update available")
|
||||
.WithMessage("You are running the latest version in your current channel")
|
||||
.Show();
|
||||
}
|
||||
|
||||
private async Task ExecuteShowSetupWizard()
|
||||
|
||||
@@ -0,0 +1,216 @@
|
||||
<controls:CoreWindow xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:controls="clr-namespace:FluentAvalonia.UI.Controls;assembly=FluentAvalonia"
|
||||
xmlns:updating="clr-namespace:Artemis.UI.Screens.Settings.Updating"
|
||||
xmlns:avalonia="clr-namespace:Markdown.Avalonia;assembly=Markdown.Avalonia"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
xmlns:mdc="clr-namespace:Markdown.Avalonia.Controls;assembly=Markdown.Avalonia"
|
||||
xmlns:mde="clr-namespace:Markdown.Avalonia.Extensions;assembly=Markdown.Avalonia"
|
||||
xmlns:ctxt="clr-namespace:ColorTextBlock.Avalonia;assembly=ColorTextBlock.Avalonia"
|
||||
x:Class="Artemis.UI.Screens.Settings.Updating.ReleaseAvailableView"
|
||||
x:DataType="updating:ReleaseAvailableViewModel"
|
||||
Title="Artemis | Update available"
|
||||
Width="750"
|
||||
Height="750"
|
||||
WindowStartupLocation="CenterOwner">
|
||||
<Grid Margin="15" RowDefinitions="Auto,*,Auto">
|
||||
|
||||
<TextBlock Grid.Row="0" Classes="h4">
|
||||
A new Artemis update is available! 🥳
|
||||
</TextBlock>
|
||||
|
||||
<StackPanel Grid.Row="1" IsVisible="{CompiledBinding Release, Converter={x:Static ObjectConverters.IsNull}}" VerticalAlignment="Center" HorizontalAlignment="Center">
|
||||
<TextBlock>Retrieving release...</TextBlock>
|
||||
<ProgressBar IsIndeterminate="True"></ProgressBar>
|
||||
</StackPanel>
|
||||
|
||||
<Border Grid.Row="1" Classes="card" IsVisible="{CompiledBinding Release, Converter={x:Static ObjectConverters.IsNotNull}}">
|
||||
<Grid RowDefinitions="Auto,*">
|
||||
<StackPanel Grid.Row="0">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Text="You are currently running version " />
|
||||
<TextBlock Text="{CompiledBinding CurrentVersion, Mode=OneWay}"></TextBlock>
|
||||
<TextBlock Text=" while the latest build is " />
|
||||
<TextBlock Text="{CompiledBinding Release.Version, Mode=OneWay, FallbackValue='Unknown'}"></TextBlock>
|
||||
<TextBlock Text="." />
|
||||
</StackPanel>
|
||||
|
||||
<TextBlock Text="Updating Artemis will give you the latest bug(fixes), features and improvements." />
|
||||
<Separator Classes="card-separator" />
|
||||
</StackPanel>
|
||||
|
||||
<avalonia:MarkdownScrollViewer Grid.Row="1"
|
||||
VerticalAlignment="Top"
|
||||
Markdown="{CompiledBinding Release.Changelog}">
|
||||
<avalonia:MarkdownScrollViewer.Styles>
|
||||
<Style Selector="ctxt|CTextBlock">
|
||||
<Style.Setters>
|
||||
<Setter Property="FontSize" Value="{mde:Multiply ControlContentThemeFontSize, 1}" />
|
||||
<Setter Property="Margin" Value="0,5" />
|
||||
</Style.Setters>
|
||||
</Style>
|
||||
<Style Selector="TextBlock">
|
||||
<Style.Setters>
|
||||
<Setter Property="FontSize" Value="{mde:Multiply ControlContentThemeFontSize, 1}" />
|
||||
</Style.Setters>
|
||||
</Style>
|
||||
|
||||
<Style Selector="ctxt|CTextBlock.Heading1">
|
||||
<Style.Setters>
|
||||
<Setter Property="FontSize" Value="{mde:Multiply ControlContentThemeFontSize, 3.2}" />
|
||||
<Setter Property="Foreground" Value="{mde:Alpha TextFillColorPrimaryBrush}" />
|
||||
<Setter Property="FontWeight" Value="Light" />
|
||||
</Style.Setters>
|
||||
</Style>
|
||||
|
||||
<Style Selector="ctxt|CTextBlock.Heading2">
|
||||
<Style.Setters>
|
||||
<Setter Property="FontSize" Value="{mde:Multiply ControlContentThemeFontSize, 1.6}" />
|
||||
<Setter Property="Foreground" Value="{mde:Alpha TextFillColorPrimaryBrush}" />
|
||||
<Setter Property="FontWeight" Value="Light" />
|
||||
</Style.Setters>
|
||||
</Style>
|
||||
|
||||
<Style Selector="ctxt|CTextBlock.Heading3">
|
||||
<Style.Setters>
|
||||
<Setter Property="FontSize" Value="{mde:Multiply ControlContentThemeFontSize, 1.6}" />
|
||||
<Setter Property="Foreground" Value="{mde:Alpha TextFillColorPrimaryBrush, 0.7}" />
|
||||
<Setter Property="FontWeight" Value="Light" />
|
||||
</Style.Setters>
|
||||
</Style>
|
||||
|
||||
<Style Selector="ctxt|CTextBlock.Heading4">
|
||||
<Style.Setters>
|
||||
<Setter Property="FontSize" Value="{mde:Multiply ControlContentThemeFontSize, 1.2}" />
|
||||
<Setter Property="Foreground" Value="{mde:Alpha TextFillColorPrimaryBrush, 0.7}" />
|
||||
<Setter Property="FontWeight" Value="Light" />
|
||||
</Style.Setters>
|
||||
</Style>
|
||||
|
||||
<Style Selector="ctxt|CHyperlink">
|
||||
<Style.Setters>
|
||||
<Setter Property="IsUnderline" Value="true" />
|
||||
<Setter Property="Foreground" Value="{StaticResource SystemAccentColor}" />
|
||||
</Style.Setters>
|
||||
</Style>
|
||||
<Style Selector="ctxt|CHyperlink:pointerover">
|
||||
<Setter Property="Foreground" Value="{mde:Complementary SystemAccentColor}" />
|
||||
</Style>
|
||||
|
||||
<Style Selector="Border.Table">
|
||||
<Style.Setters>
|
||||
<Setter Property="Margin" Value="5" />
|
||||
<Setter Property="BorderThickness" Value="0,0,1,1" />
|
||||
<Setter Property="BorderBrush" Value="{mde:Alpha TextFillColorPrimaryBrush, 0.7}" />
|
||||
</Style.Setters>
|
||||
</Style>
|
||||
|
||||
<Style Selector="Grid.Table > Border">
|
||||
<Style.Setters>
|
||||
<Setter Property="Margin" Value="0" />
|
||||
<Setter Property="BorderThickness" Value="1,1,0,0" />
|
||||
<Setter Property="BorderBrush" Value="{mde:Alpha TextFillColorPrimaryBrush, 0.7}" />
|
||||
<Setter Property="Padding" Value="2" />
|
||||
</Style.Setters>
|
||||
</Style>
|
||||
|
||||
<Style Selector="Border.TableHeader">
|
||||
<Style.Setters>
|
||||
<Setter Property="Background" Value="{mde:Alpha TextFillColorPrimaryBrush, 0.3}" />
|
||||
</Style.Setters>
|
||||
</Style>
|
||||
<Style Selector="Border.TableHeader ctxt|CTextBlock">
|
||||
<Style.Setters>
|
||||
<Setter Property="FontWeight" Value="DemiBold" />
|
||||
</Style.Setters>
|
||||
</Style>
|
||||
|
||||
<Style Selector="Border.EvenTableRow">
|
||||
<Style.Setters>
|
||||
<Setter Property="Background" Value="{mde:Alpha ControlFillColorDefaultBrush, 0.9}" />
|
||||
</Style.Setters>
|
||||
</Style>
|
||||
|
||||
<Style Selector="Border.CodeBlock">
|
||||
<Style.Setters>
|
||||
<Setter Property="BorderBrush" Value="{mde:Alpha TextFillColorPrimaryBrush, 0.2}" />
|
||||
<Setter Property="BorderThickness" Value="0,5,0,5" />
|
||||
<Setter Property="Margin" Value="5,0,5,0" />
|
||||
<Setter Property="Background" Value="{mde:Alpha ControlFillColorDefaultBrush, 0.9}" />
|
||||
</Style.Setters>
|
||||
</Style>
|
||||
<Style Selector="TextBlock.CodeBlock">
|
||||
<Style.Setters>
|
||||
<Setter Property="FontFamily" Value="menlo,monaco,consolas,droid sans mono,inconsolata,courier new,monospace,dejavu sans mono" />
|
||||
<Setter Property="Foreground" Value="{mde:DivideColor Blue, TextFillColorPrimary, 0.4}" />
|
||||
</Style.Setters>
|
||||
</Style>
|
||||
<Style Selector="Border.NoContainer">
|
||||
<Style.Setters>
|
||||
<Setter Property="BorderBrush" Value="Red" />
|
||||
</Style.Setters>
|
||||
</Style>
|
||||
|
||||
<Style Selector="ctxt|CCode">
|
||||
<Style.Setters>
|
||||
<Setter Property="Foreground" Value="{mde:DivideColor Blue, TextFillColorPrimary, 0.4}" />
|
||||
<Setter Property="Background" Value="{mde:Alpha ControlFillColorDefaultBrush, 0.9}" />
|
||||
</Style.Setters>
|
||||
</Style>
|
||||
|
||||
<Style Selector="Border.Note">
|
||||
<Style.Setters>
|
||||
<Setter Property="Margin" Value="5,0,5,0" />
|
||||
<Setter Property="BorderBrush" Value="{mde:Alpha TextFillColorPrimaryBrush, 0.2}" />
|
||||
<Setter Property="BorderThickness" Value="3,3,3,3" />
|
||||
<Setter Property="Background" Value="{mde:Alpha ControlFillColorDefaultBrush, 0.9}" />
|
||||
</Style.Setters>
|
||||
</Style>
|
||||
<Style Selector="ctxt|CTextBlock.Note">
|
||||
<Style.Setters>
|
||||
<Setter Property="Margin" Value="10, 5" />
|
||||
</Style.Setters>
|
||||
</Style>
|
||||
|
||||
<Style Selector="Grid.List">
|
||||
<Style.Setters>
|
||||
<Setter Property="Margin" Value="15,0,0,0" />
|
||||
</Style.Setters>
|
||||
</Style>
|
||||
<Style Selector="ctxt|CTextBlock.ListMarker">
|
||||
<Style.Setters>
|
||||
<Setter Property="Margin" Value="0,5,5,5" />
|
||||
</Style.Setters>
|
||||
</Style>
|
||||
|
||||
<Style Selector="Border.Blockquote">
|
||||
<Style.Setters>
|
||||
<Setter Property="BorderBrush" Value="{mde:Alpha TextFillColorPrimaryBrush, 0.2}" />
|
||||
<Setter Property="BorderThickness" Value="5,0,0,0" />
|
||||
</Style.Setters>
|
||||
</Style>
|
||||
|
||||
<Style Selector="StackPanel.Blockquote">
|
||||
<Style.Setters>
|
||||
<Setter Property="Margin" Value="10, 5" />
|
||||
</Style.Setters>
|
||||
</Style>
|
||||
|
||||
<Style Selector="mdc|Rule">
|
||||
<Style.Setters>
|
||||
<Setter Property="Margin" Value="0,3" />
|
||||
</Style.Setters>
|
||||
</Style>
|
||||
</avalonia:MarkdownScrollViewer.Styles>
|
||||
</avalonia:MarkdownScrollViewer>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<StackPanel HorizontalAlignment="Right" Orientation="Horizontal" Spacing="5" Grid.Row="2" Margin="0 15 0 0">
|
||||
<Button Classes="accent" Command="{CompiledBinding Install}" Click="Button_OnClick">Install update</Button>
|
||||
<Button Click="Button_OnClick">Ask later</Button>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</controls:CoreWindow>
|
||||
@@ -0,0 +1,29 @@
|
||||
using Artemis.UI.Shared;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Settings.Updating;
|
||||
|
||||
public partial class ReleaseAvailableView : ReactiveCoreWindow<ReleaseAvailableViewModel>
|
||||
{
|
||||
public ReleaseAvailableView()
|
||||
{
|
||||
InitializeComponent();
|
||||
#if DEBUG
|
||||
this.AttachDevTools();
|
||||
#endif
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
|
||||
private void Button_OnClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
using System.Reactive;
|
||||
using System.Reactive.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Core;
|
||||
using Artemis.UI.Extensions;
|
||||
using Artemis.UI.Services.Updating;
|
||||
using Artemis.UI.Shared;
|
||||
using Artemis.UI.Shared.Services;
|
||||
using Artemis.WebClient.Updating;
|
||||
using ReactiveUI;
|
||||
using Serilog;
|
||||
using StrawberryShake;
|
||||
|
||||
namespace Artemis.UI.Screens.Settings.Updating;
|
||||
|
||||
public class ReleaseAvailableViewModel : ActivatableViewModelBase
|
||||
{
|
||||
private readonly string _nextReleaseId;
|
||||
private readonly ILogger _logger;
|
||||
private readonly IUpdateService _updateService;
|
||||
private readonly IUpdatingClient _updatingClient;
|
||||
private readonly INotificationService _notificationService;
|
||||
private IGetReleaseById_Release? _release;
|
||||
|
||||
public ReleaseAvailableViewModel(string nextReleaseId, ILogger logger, IUpdateService updateService, IUpdatingClient updatingClient, INotificationService notificationService)
|
||||
{
|
||||
_nextReleaseId = nextReleaseId;
|
||||
_logger = logger;
|
||||
_updateService = updateService;
|
||||
_updatingClient = updatingClient;
|
||||
_notificationService = notificationService;
|
||||
|
||||
CurrentVersion = _updateService.CurrentVersion ?? "Development build";
|
||||
Install = ReactiveCommand.Create(ExecuteInstall, this.WhenAnyValue(vm => vm.Release).Select(r => r != null));
|
||||
|
||||
this.WhenActivated(async d => await RetrieveRelease(d.AsCancellationToken()));
|
||||
}
|
||||
|
||||
private void ExecuteInstall()
|
||||
{
|
||||
_updateService.InstallRelease(_nextReleaseId);
|
||||
}
|
||||
|
||||
private async Task RetrieveRelease(CancellationToken cancellationToken)
|
||||
{
|
||||
IOperationResult<IGetReleaseByIdResult> result = await _updatingClient.GetReleaseById.ExecuteAsync(_nextReleaseId, cancellationToken);
|
||||
// Borrow GraphQLClientException for messaging, how lazy of me..
|
||||
if (result.Errors.Count > 0)
|
||||
{
|
||||
GraphQLClientException exception = new(result.Errors);
|
||||
_logger.Error(exception, "Failed to retrieve release details");
|
||||
_notificationService.CreateNotification().WithTitle("Failed to retrieve release details").WithMessage(exception.Message).Show();
|
||||
return;
|
||||
}
|
||||
|
||||
if (result.Data?.Release == null)
|
||||
{
|
||||
_notificationService.CreateNotification().WithTitle("Failed to retrieve release details").WithMessage("Release not found").Show();
|
||||
return;
|
||||
}
|
||||
|
||||
Release = result.Data.Release;
|
||||
}
|
||||
|
||||
public string CurrentVersion { get; }
|
||||
|
||||
public IGetReleaseById_Release? Release
|
||||
{
|
||||
get => _release;
|
||||
set => RaiseAndSetIfChanged(ref _release, value);
|
||||
}
|
||||
|
||||
public ReactiveCommand<Unit, Unit> Install { get; }
|
||||
public ReactiveCommand<Unit, Unit> AskLater { get; }
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<controls:CoreWindow xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:controls="clr-namespace:FluentAvalonia.UI.Controls;assembly=FluentAvalonia"
|
||||
xmlns:updating="clr-namespace:Artemis.UI.Screens.Settings.Updating"
|
||||
mc:Ignorable="d"
|
||||
x:Class="Artemis.UI.Screens.Settings.Updating.ReleaseInstallerView"
|
||||
x:DataType="updating:ReleaseInstallerViewModel"
|
||||
Title="Artemis | Updating"
|
||||
ShowAsDialog="True"
|
||||
Width="465" Height="260"
|
||||
Padding="15"
|
||||
CanResize="False"
|
||||
|
||||
WindowStartupLocation="CenterOwner">
|
||||
<Grid RowDefinitions="Auto,Auto,*,Auto" Width="450" Height="200">
|
||||
<TextBlock Grid.Row="0" Classes="h4" TextWrapping="Wrap">
|
||||
Downloading & installing update...
|
||||
</TextBlock>
|
||||
|
||||
<TextBlock Grid.Row="1" Classes="subtitle" TextWrapping="Wrap">
|
||||
This should not take long, when finished Artemis must restart.
|
||||
</TextBlock>
|
||||
|
||||
<StackPanel Grid.Row="2" VerticalAlignment="Center" HorizontalAlignment="Stretch" IsVisible="{CompiledBinding !Ready}">
|
||||
<ProgressBar Value="{CompiledBinding OverallProgress}" ></ProgressBar>
|
||||
<ProgressBar Margin="0 15 0 0" Value="{CompiledBinding StepProgress}"></ProgressBar>
|
||||
</StackPanel>
|
||||
|
||||
<TextBlock Grid.Row="2" IsVisible="{CompiledBinding Ready}" VerticalAlignment="Top" Margin="0 15 0 0">Done, click restart to apply the update 🫡</TextBlock>
|
||||
|
||||
<StackPanel HorizontalAlignment="Right" Orientation="Horizontal" Spacing="15" Grid.Row="3" Margin="0 15 0 0" Height="30">
|
||||
<CheckBox IsVisible="{CompiledBinding !Ready}" IsChecked="{CompiledBinding RestartWhenFinished}">Restart when finished</CheckBox>
|
||||
<Button IsVisible="{CompiledBinding Ready}" Command="{CompiledBinding Restart}" Classes="accent">Restart</Button>
|
||||
<Button Click="Cancel_OnClick">Cancel</Button>
|
||||
</StackPanel>
|
||||
|
||||
</Grid>
|
||||
</controls:CoreWindow>
|
||||
@@ -0,0 +1,28 @@
|
||||
using Artemis.UI.Shared;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Markup.Xaml;
|
||||
|
||||
namespace Artemis.UI.Screens.Settings.Updating;
|
||||
|
||||
public partial class ReleaseInstallerView : ReactiveCoreWindow<ReleaseInstallerViewModel>
|
||||
{
|
||||
public ReleaseInstallerView()
|
||||
{
|
||||
InitializeComponent();
|
||||
#if DEBUG
|
||||
this.AttachDevTools();
|
||||
#endif
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
|
||||
private void Cancel_OnClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
using System;
|
||||
using System.Reactive;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Reactive.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Core;
|
||||
using Artemis.UI.Extensions;
|
||||
using Artemis.UI.Services.Updating;
|
||||
using Artemis.UI.Shared;
|
||||
using Artemis.UI.Shared.Services;
|
||||
using ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Screens.Settings.Updating;
|
||||
|
||||
public class ReleaseInstallerViewModel : ActivatableViewModelBase
|
||||
{
|
||||
private readonly ReleaseInstaller _releaseInstaller;
|
||||
private readonly IWindowService _windowService;
|
||||
private ObservableAsPropertyHelper<float>? _overallProgress;
|
||||
private ObservableAsPropertyHelper<float>? _stepProgress;
|
||||
private bool _ready;
|
||||
private bool _restartWhenFinished;
|
||||
|
||||
public ReleaseInstallerViewModel(ReleaseInstaller releaseInstaller, IWindowService windowService)
|
||||
{
|
||||
_releaseInstaller = releaseInstaller;
|
||||
_windowService = windowService;
|
||||
|
||||
Restart = ReactiveCommand.Create(() => Utilities.ApplyUpdate(false));
|
||||
this.WhenActivated(d =>
|
||||
{
|
||||
_overallProgress = Observable.FromEventPattern<float>(x => _releaseInstaller.OverallProgress.ProgressChanged += x, x => _releaseInstaller.OverallProgress.ProgressChanged -= x)
|
||||
.Select(e => e.EventArgs)
|
||||
.ToProperty(this, vm => vm.OverallProgress)
|
||||
.DisposeWith(d);
|
||||
_stepProgress = Observable.FromEventPattern<float>(x => _releaseInstaller.StepProgress.ProgressChanged += x, x => _releaseInstaller.StepProgress.ProgressChanged -= x)
|
||||
.Select(e => e.EventArgs)
|
||||
.ToProperty(this, vm => vm.StepProgress)
|
||||
.DisposeWith(d);
|
||||
|
||||
Task.Run(() => InstallUpdate(d.AsCancellationToken()));
|
||||
});
|
||||
}
|
||||
|
||||
public ReactiveCommand<Unit, Unit> Restart { get; }
|
||||
|
||||
public float OverallProgress => _overallProgress?.Value ?? 0;
|
||||
public float StepProgress => _stepProgress?.Value ?? 0;
|
||||
|
||||
public bool Ready
|
||||
{
|
||||
get => _ready;
|
||||
set => RaiseAndSetIfChanged(ref _ready, value);
|
||||
}
|
||||
|
||||
public bool RestartWhenFinished
|
||||
{
|
||||
get => _restartWhenFinished;
|
||||
set => RaiseAndSetIfChanged(ref _restartWhenFinished, value);
|
||||
}
|
||||
|
||||
private async Task InstallUpdate(CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _releaseInstaller.InstallAsync(cancellationToken);
|
||||
Ready = true;
|
||||
if (RestartWhenFinished)
|
||||
Utilities.ApplyUpdate(false);
|
||||
}
|
||||
catch (TaskCanceledException)
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_windowService.ShowExceptionDialog("Something went wrong while installing the update", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
using Artemis.Core;
|
||||
using Artemis.UI.Shared;
|
||||
|
||||
namespace Artemis.UI.Screens.Settings.Updating;
|
||||
|
||||
public class UpdateInstallationViewModel : DialogViewModelBase<bool>
|
||||
{
|
||||
private readonly string _nextReleaseId;
|
||||
|
||||
public UpdateInstallationViewModel(string nextReleaseId)
|
||||
{
|
||||
_nextReleaseId = nextReleaseId;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user