Update service - Removed option to install updates without asking

Modules - Decrease CPU usage for activation requirements check by using a centralized service
Devices - Reload provider when unloading a layout
This commit is contained in:
Robert committed 2021-06-10 17:41:54 +02:00
1 parent 38c04913e2
commit fe933f60e8
17 files changed
+195 -135

No files matched your search

@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Artemis.Core;
using Artemis.Core.Services;
using Artemis.UI.Ninject.Factories;
using Artemis.UI.Shared.Services;
@@ -10,9 +11,9 @@ namespace Artemis.UI.Screens.Settings.Tabs.Devices
{
public class DeviceSettingsTabViewModel : Conductor<DeviceSettingsViewModel>.Collection.AllActive
{
private readonly ISettingsVmFactory _settingsVmFactory;
private readonly IRgbService _rgbService;
private readonly IDialogService _dialogService;
private readonly IRgbService _rgbService;
private readonly ISettingsVmFactory _settingsVmFactory;
private bool _confirmedDisable;
public DeviceSettingsTabViewModel(IRgbService rgbService, IDialogService dialogService, ISettingsVmFactory settingsVmFactory)
@@ -24,28 +25,6 @@ namespace Artemis.UI.Screens.Settings.Tabs.Devices
_settingsVmFactory = settingsVmFactory;
}
#region Overrides of AllActive
/// <inheritdoc />
protected override void OnActivate()
{
// Take it off the UI thread to avoid freezing on tab change
Task.Run(async () =>
{
if (Items.Any())
Items.Clear();
await Task.Delay(200);
List<DeviceSettingsViewModel> instances = _rgbService.Devices.Select(d => _settingsVmFactory.CreateDeviceSettingsViewModel(d)).ToList();
foreach (DeviceSettingsViewModel deviceSettingsViewModel in instances)
Items.Add(deviceSettingsViewModel);
});
base.OnActivate();
}
#endregion
public async Task<bool> ShowDeviceDisableDialog()
{
if (_confirmedDisable)
@@ -61,5 +40,49 @@ namespace Artemis.UI.Screens.Settings.Tabs.Devices
return confirmed;
}
private void RgbServiceOnDeviceRemoved(object sender, DeviceEventArgs e)
{
DeviceSettingsViewModel viewModel = Items.FirstOrDefault(i => i.Device == e.Device);
if (viewModel != null)
Items.Remove(viewModel);
}
private void RgbServiceOnDeviceAdded(object sender, DeviceEventArgs e)
{
Items.Add(_settingsVmFactory.CreateDeviceSettingsViewModel(e.Device));
}
#region Overrides of AllActive
/// <inheritdoc />
protected override void OnActivate()
{
_rgbService.DeviceAdded += RgbServiceOnDeviceAdded;
_rgbService.DeviceRemoved += RgbServiceOnDeviceRemoved;
// Take it off the UI thread to avoid freezing on tab change
Task.Run(async () =>
{
if (Items.Any())
Items.Clear();
await Task.Delay(200);
List<DeviceSettingsViewModel> instances = _rgbService.Devices.Select(d => _settingsVmFactory.CreateDeviceSettingsViewModel(d)).ToList();
foreach (DeviceSettingsViewModel deviceSettingsViewModel in instances)
Items.Add(deviceSettingsViewModel);
});
base.OnActivate();
}
/// <inheritdoc />
protected override void OnClose()
{
_rgbService.DeviceAdded -= RgbServiceOnDeviceAdded;
_rgbService.DeviceRemoved -= RgbServiceOnDeviceRemoved;
base.OnClose();
}
#endregion
}
}
@@ -218,27 +218,6 @@
</Grid>
<Separator Style="{StaticResource MaterialDesignSeparator}" Margin="-15 5" />
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0">
<TextBlock Style="{StaticResource MaterialDesignTextBlock}">Automatically install updates</TextBlock>
<TextBlock Style="{StaticResource MaterialDesignTextBlock}" Foreground="{DynamicResource MaterialDesignNavigationItemSubheader}" TextWrapping="Wrap">
If enabled updates are installed automatically without asking first.
</TextBlock>
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center">
<ToggleButton Style="{StaticResource MaterialDesignSwitchToggleButton}" IsChecked="{Binding AutoInstallUpdates}" IsEnabled="{Binding CheckForUpdates}" />
</StackPanel>
</Grid>
<Separator Style="{StaticResource MaterialDesignSeparator}" Margin="-15 5" />
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
@@ -158,20 +158,6 @@ namespace Artemis.UI.Screens.Settings.Tabs.General
_settingsService.GetSetting("UI.CheckForUpdates", true).Value = value;
_settingsService.GetSetting("UI.CheckForUpdates", true).Save();
NotifyOfPropertyChange(nameof(CheckForUpdates));
if (!value)
AutoInstallUpdates = false;
}
}
public bool AutoInstallUpdates
{
get => _settingsService.GetSetting("UI.AutoInstallUpdates", false).Value;
set
{
_settingsService.GetSetting("UI.AutoInstallUpdates", false).Value = value;
_settingsService.GetSetting("UI.AutoInstallUpdates", false).Save();
NotifyOfPropertyChange(nameof(AutoInstallUpdates));
}
}