1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Startup wizard - Implemented auto-run and update settings

This commit is contained in:
Robert 2022-08-20 17:45:30 +02:00
parent bfa1d60dec
commit 090d5b76e8
5 changed files with 176 additions and 61 deletions

View File

@ -32,6 +32,7 @@ namespace Artemis.UI.Screens.Settings
private readonly IWindowService _windowService; private readonly IWindowService _windowService;
private readonly IUpdateService _updateService; private readonly IUpdateService _updateService;
private readonly IAutoRunProvider? _autoRunProvider; private readonly IAutoRunProvider? _autoRunProvider;
private bool _startupWizardOpen;
public GeneralTabViewModel(IKernel kernel, public GeneralTabViewModel(IKernel kernel,
ISettingsService settingsService, ISettingsService settingsService,
@ -156,7 +157,6 @@ namespace Artemis.UI.Screens.Settings
Utilities.OpenFolder(Constants.LogsFolder); Utilities.OpenFolder(Constants.LogsFolder);
} }
private async Task ExecuteCheckForUpdate(CancellationToken cancellationToken) private async Task ExecuteCheckForUpdate(CancellationToken cancellationToken)
{ {
await _updateService.ManualUpdate(); await _updateService.ManualUpdate();
@ -164,7 +164,9 @@ namespace Artemis.UI.Screens.Settings
private async Task ExecuteShowSetupWizard() private async Task ExecuteShowSetupWizard()
{ {
_startupWizardOpen = true;
await _windowService.ShowDialogAsync<StartupWizardViewModel, bool>(); await _windowService.ShowDialogAsync<StartupWizardViewModel, bool>();
_startupWizardOpen = false;
} }
private void ExecuteShowDebugger() private void ExecuteShowDebugger()
@ -179,7 +181,7 @@ namespace Artemis.UI.Screens.Settings
private async Task ApplyAutoRun() private async Task ApplyAutoRun()
{ {
if (_autoRunProvider == null) if (_autoRunProvider == null || _startupWizardOpen)
return; return;
try try
@ -202,7 +204,7 @@ namespace Artemis.UI.Screens.Settings
private async void UIAutoRunDelayOnSettingChanged(object? sender, EventArgs e) private async void UIAutoRunDelayOnSettingChanged(object? sender, EventArgs e)
{ {
if (_autoRunProvider == null || !UIAutoRun.Value) if (_autoRunProvider == null || !UIAutoRun.Value || _startupWizardOpen)
return; return;
try try

View File

@ -17,8 +17,8 @@
<Button Grid.Row="1" Grid.Column="0" Command="{CompiledBinding SkipOrFinishWizard}" IsVisible="{CompiledBinding !ShowFinish}">Skip &amp; close</Button> <Button Grid.Row="1" Grid.Column="0" Command="{CompiledBinding SkipOrFinishWizard}" IsVisible="{CompiledBinding !ShowFinish}">Skip &amp; close</Button>
<StackPanel Grid.Row="1" Grid.Column="1" HorizontalAlignment="Right" Orientation="Horizontal" Spacing="5" Margin="0 15 0 0"> <StackPanel Grid.Row="1" Grid.Column="1" HorizontalAlignment="Right" Orientation="Horizontal" Spacing="5" Margin="0 15 0 0">
<Button Command="{CompiledBinding GoBack}" IsVisible="{CompiledBinding ShowGoBack}">Back</Button> <Button Command="{CompiledBinding GoBack}" IsEnabled="{CompiledBinding ShowGoBack}">Back</Button>
<Button Command="{CompiledBinding Continue}" IsVisible="{CompiledBinding ShowContinue}" Width="80">Continue</Button> <Button Command="{CompiledBinding Continue}" IsVisible="{CompiledBinding !ShowFinish}" IsEnabled="{CompiledBinding ShowContinue}" Width="80">Continue</Button>
<Button Command="{CompiledBinding SkipOrFinishWizard}" IsVisible="{CompiledBinding ShowFinish}" Width="80">Finish</Button> <Button Command="{CompiledBinding SkipOrFinishWizard}" IsVisible="{CompiledBinding ShowFinish}" Width="80">Finish</Button>
</StackPanel> </StackPanel>
</Grid> </Grid>

View File

@ -1,31 +1,44 @@
using System.Collections.Generic; using System;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using System.Reactive; using System.Reactive;
using System.Reactive.Disposables;
using System.Reflection; using System.Reflection;
using System.Threading.Tasks;
using Artemis.Core; using Artemis.Core;
using Artemis.Core.DeviceProviders; using Artemis.Core.DeviceProviders;
using Artemis.Core.Services; using Artemis.Core.Services;
using Artemis.UI.Ninject.Factories; using Artemis.UI.Ninject.Factories;
using Artemis.UI.Screens.Plugins; using Artemis.UI.Screens.Plugins;
using Artemis.UI.Services.Interfaces;
using Artemis.UI.Shared; using Artemis.UI.Shared;
using Artemis.UI.Shared.Providers;
using Artemis.UI.Shared.Services;
using Ninject;
using ReactiveUI; using ReactiveUI;
namespace Artemis.UI.Screens.StartupWizard; namespace Artemis.UI.Screens.StartupWizard;
public class StartupWizardViewModel : DialogViewModelBase<bool> public class StartupWizardViewModel : DialogViewModelBase<bool>
{ {
private readonly IAutoRunProvider? _autoRunProvider;
private readonly IRgbService _rgbService; private readonly IRgbService _rgbService;
private readonly ISettingsService _settingsService; private readonly ISettingsService _settingsService;
private readonly IUpdateService _updateService;
private readonly IWindowService _windowService;
private int _currentStep; private int _currentStep;
private bool _showContinue; private bool _showContinue;
private bool _showGoBack;
private bool _showFinish; private bool _showFinish;
private bool _showGoBack;
public StartupWizardViewModel(ISettingsService settingsService, IRgbService rgbService, IPluginManagementService pluginManagementService, ISettingsVmFactory settingsVmFactory) public StartupWizardViewModel(IKernel kernel, ISettingsService settingsService, IRgbService rgbService, IPluginManagementService pluginManagementService, IWindowService windowService,
IUpdateService updateService, ISettingsVmFactory settingsVmFactory)
{ {
_settingsService = settingsService; _settingsService = settingsService;
_rgbService = rgbService; _rgbService = rgbService;
_windowService = windowService;
_updateService = updateService;
_autoRunProvider = kernel.TryGet<IAutoRunProvider>();
Continue = ReactiveCommand.Create(ExecuteContinue); Continue = ReactiveCommand.Create(ExecuteContinue);
GoBack = ReactiveCommand.Create(ExecuteGoBack); GoBack = ReactiveCommand.Create(ExecuteGoBack);
@ -43,8 +56,21 @@ public class StartupWizardViewModel : DialogViewModelBase<bool>
CurrentStep = 1; CurrentStep = 1;
SetupButtons(); SetupButtons();
}
this.WhenActivated(d =>
{
UIAutoRun.SettingChanged += UIAutoRunOnSettingChanged;
UIAutoRunDelay.SettingChanged += UIAutoRunDelayOnSettingChanged;
Disposable.Create(() =>
{
UIAutoRun.SettingChanged -= UIAutoRunOnSettingChanged;
UIAutoRunDelay.SettingChanged -= UIAutoRunDelayOnSettingChanged;
_settingsService.SaveAllSettings();
}).DisposeWith(d);
});
}
public ReactiveCommand<Unit, Unit> Continue { get; } public ReactiveCommand<Unit, Unit> Continue { get; }
public ReactiveCommand<Unit, Unit> GoBack { get; } public ReactiveCommand<Unit, Unit> GoBack { get; }
@ -54,10 +80,14 @@ public class StartupWizardViewModel : DialogViewModelBase<bool>
public string Version { get; } public string Version { get; }
public ObservableCollection<PluginViewModel> DeviceProviders { get; } public ObservableCollection<PluginViewModel> DeviceProviders { get; }
public bool IsAutoRunSupported => _autoRunProvider != null;
public bool IsUpdatingSupported => _updateService.UpdatingSupported;
public PluginSetting<bool> UIAutoRun => _settingsService.GetSetting("UI.AutoRun", false); public PluginSetting<bool> UIAutoRun => _settingsService.GetSetting("UI.AutoRun", false);
public PluginSetting<int> UIAutoRunDelay => _settingsService.GetSetting("UI.AutoRunDelay", 15); public PluginSetting<int> UIAutoRunDelay => _settingsService.GetSetting("UI.AutoRunDelay", 15);
public PluginSetting<bool> UIShowOnStartup => _settingsService.GetSetting("UI.ShowOnStartup", true); public PluginSetting<bool> UIShowOnStartup => _settingsService.GetSetting("UI.ShowOnStartup", true);
public PluginSetting<bool> UICheckForUpdates => _settingsService.GetSetting("UI.CheckForUpdates", true); public PluginSetting<bool> UICheckForUpdates => _settingsService.GetSetting("UI.CheckForUpdates", true);
public PluginSetting<bool> UIAutoUpdate => _settingsService.GetSetting("UI.AutoUpdate", false);
public int CurrentStep public int CurrentStep
{ {
@ -88,6 +118,10 @@ public class StartupWizardViewModel : DialogViewModelBase<bool>
if (CurrentStep > 1) if (CurrentStep > 1)
CurrentStep--; CurrentStep--;
// Skip the settings step if none of it's contents are supported
if (CurrentStep == 4 && !IsAutoRunSupported && !IsUpdatingSupported)
CurrentStep--;
SetupButtons(); SetupButtons();
} }
@ -96,6 +130,10 @@ public class StartupWizardViewModel : DialogViewModelBase<bool>
if (CurrentStep < 5) if (CurrentStep < 5)
CurrentStep++; CurrentStep++;
// Skip the settings step if none of it's contents are supported
if (CurrentStep == 4 && !IsAutoRunSupported && !IsUpdatingSupported)
CurrentStep++;
SetupButtons(); SetupButtons();
} }
@ -123,4 +161,42 @@ public class StartupWizardViewModel : DialogViewModelBase<bool>
ExecuteContinue(); ExecuteContinue();
} }
private async Task ApplyAutoRun()
{
if (_autoRunProvider == null)
return;
try
{
if (UIAutoRun.Value)
await _autoRunProvider.EnableAutoRun(false, UIAutoRunDelay.Value);
else
await _autoRunProvider.DisableAutoRun();
}
catch (Exception exception)
{
_windowService.ShowExceptionDialog("Failed to apply auto-run", exception);
}
}
private async void UIAutoRunOnSettingChanged(object? sender, EventArgs e)
{
await ApplyAutoRun();
}
private async void UIAutoRunDelayOnSettingChanged(object? sender, EventArgs e)
{
if (_autoRunProvider == null || !UIAutoRun.Value)
return;
try
{
await _autoRunProvider.EnableAutoRun(true, UIAutoRunDelay.Value);
}
catch (Exception exception)
{
_windowService.ShowExceptionDialog("Failed to apply auto-run", exception);
}
}
} }

View File

@ -3,6 +3,9 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:startupWizard="clr-namespace:Artemis.UI.Screens.StartupWizard" xmlns:startupWizard="clr-namespace:Artemis.UI.Screens.StartupWizard"
xmlns:controls="clr-namespace:FluentAvalonia.UI.Controls;assembly=FluentAvalonia"
xmlns:behaviors="clr-namespace:Artemis.UI.Shared.Behaviors;assembly=Artemis.UI.Shared"
xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Artemis.UI.Screens.StartupWizard.Steps.SettingsStep" x:Class="Artemis.UI.Screens.StartupWizard.Steps.SettingsStep"
x:DataType="startupWizard:StartupWizardViewModel"> x:DataType="startupWizard:StartupWizardViewModel">
@ -15,8 +18,14 @@
Below you can find a few relevant settings, many more can be changed later on the settings page. Below you can find a few relevant settings, many more can be changed later on the settings page.
</TextBlock> </TextBlock>
<Border Classes="card" Margin="0 15 0 0"> <!-- Auto-run settings -->
<StackPanel IsVisible="{CompiledBinding IsAutoRunSupported}">
<TextBlock Classes="h4" Margin="0 15">
Auto-run
</TextBlock>
<Border Classes="card" VerticalAlignment="Stretch" Margin="0,0,5,0">
<StackPanel> <StackPanel>
<StackPanel IsVisible="{CompiledBinding IsAutoRunSupported}">
<Grid RowDefinitions="*,*" ColumnDefinitions="*,Auto"> <Grid RowDefinitions="*,*" ColumnDefinitions="*,Auto">
<StackPanel Grid.Column="0"> <StackPanel Grid.Column="0">
<TextBlock>Auto-run on startup</TextBlock> <TextBlock>Auto-run on startup</TextBlock>
@ -46,12 +55,26 @@
</TextBlock> </TextBlock>
</StackPanel> </StackPanel>
<StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center" Orientation="Horizontal"> <StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center" Orientation="Horizontal">
<TextBox Text="{CompiledBinding UIAutoRunDelay.Value}" IsEnabled="{CompiledBinding UIAutoRun.Value}" Width="120" /> <controls:NumberBox IsEnabled="{CompiledBinding UIAutoRun.Value}" Width="120">
<Interaction.Behaviors>
<behaviors:LostFocusNumberBoxBindingBehavior Value="{CompiledBinding UIAutoRunDelay.Value}" />
</Interaction.Behaviors>
</controls:NumberBox>
<TextBlock VerticalAlignment="Center" TextAlignment="Right" Width="30">sec</TextBlock> <TextBlock VerticalAlignment="Center" TextAlignment="Right" Width="30">sec</TextBlock>
</StackPanel> </StackPanel>
</Grid> </Grid>
<Separator Classes="card-separator" /> </StackPanel>
</StackPanel>
</Border>
</StackPanel>
<!-- Update settings -->
<StackPanel IsVisible="{CompiledBinding IsUpdatingSupported}">
<TextBlock Classes="h4" Margin="0 15">
Updating
</TextBlock>
<Border Classes="card" VerticalAlignment="Stretch" Margin="0,0,5,0">
<StackPanel>
<Grid RowDefinitions="*,*" ColumnDefinitions="*,Auto"> <Grid RowDefinitions="*,*" ColumnDefinitions="*,Auto">
<StackPanel Grid.Column="0"> <StackPanel Grid.Column="0">
<TextBlock> <TextBlock>
@ -65,10 +88,24 @@
<ToggleSwitch IsChecked="{CompiledBinding UICheckForUpdates.Value}" MinWidth="0" /> <ToggleSwitch IsChecked="{CompiledBinding UICheckForUpdates.Value}" MinWidth="0" />
</StackPanel> </StackPanel>
</Grid> </Grid>
<Separator Classes="card-separator" />
<Grid RowDefinitions="*,*" ColumnDefinitions="*,Auto">
<StackPanel Grid.Column="0">
<TextBlock>
Auto-install updates
</TextBlock>
<TextBlock Classes="subtitle" TextWrapping="Wrap">
If enabled, new updates will automatically be installed.
</TextBlock>
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center">
<ToggleSwitch IsEnabled="{CompiledBinding UICheckForUpdates.Value}" IsChecked="{CompiledBinding UIAutoUpdate.Value}" MinWidth="0" />
</StackPanel>
</Grid>
</StackPanel> </StackPanel>
</Border> </Border>
</StackPanel> </StackPanel>
</StackPanel>
</Border> </Border>
</UserControl> </UserControl>