mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
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:
1 parent
38c04913e2
commit
fe933f60e8
17 files changed
+195
-135
No files matched your search
@@ -25,9 +25,11 @@ namespace Artemis.UI.Screens.Settings.Device
|
||||
private readonly ICoreService _coreService;
|
||||
private readonly IDeviceService _deviceService;
|
||||
private readonly IDialogService _dialogService;
|
||||
private readonly IDeviceDebugVmFactory _factory;
|
||||
private readonly IRgbService _rgbService;
|
||||
private SnackbarMessageQueue _deviceMessageQueue;
|
||||
private BindableCollection<ArtemisLed> _selectedLeds;
|
||||
private ArtemisDevice _device;
|
||||
|
||||
public DeviceDialogViewModel(ArtemisDevice device,
|
||||
ICoreService coreService,
|
||||
@@ -40,22 +42,46 @@ namespace Artemis.UI.Screens.Settings.Device
|
||||
_deviceService = deviceService;
|
||||
_rgbService = rgbService;
|
||||
_dialogService = dialogService;
|
||||
_factory = factory;
|
||||
|
||||
Device = device;
|
||||
PanZoomViewModel = new PanZoomViewModel();
|
||||
SelectedLeds = new BindableCollection<ArtemisLed>();
|
||||
|
||||
Items.Add(factory.DevicePropertiesTabViewModel(device));
|
||||
if (device.DeviceType == RGBDeviceType.Keyboard)
|
||||
Items.Add(factory.InputMappingsTabViewModel(device));
|
||||
Items.Add(factory.DeviceInfoTabViewModel(device));
|
||||
Items.Add(factory.DeviceLedsTabViewModel(device));
|
||||
|
||||
ActiveItem = Items.First();
|
||||
DisplayName = $"{device.RgbDevice.DeviceInfo.Model} | Artemis";
|
||||
Initialize(device);
|
||||
}
|
||||
|
||||
private void Initialize(ArtemisDevice device)
|
||||
{
|
||||
if (SelectedLeds.Any())
|
||||
SelectedLeds.Clear();
|
||||
|
||||
if (Device != null)
|
||||
Device.DeviceUpdated -= DeviceOnDeviceUpdated;
|
||||
Device = device;
|
||||
Device.DeviceUpdated += DeviceOnDeviceUpdated;
|
||||
|
||||
int activeTabIndex = 0;
|
||||
if (Items.Any())
|
||||
{
|
||||
activeTabIndex = Items.IndexOf(ActiveItem);
|
||||
Items.Clear();
|
||||
}
|
||||
Items.Add(_factory.DevicePropertiesTabViewModel(Device));
|
||||
if (Device.DeviceType == RGBDeviceType.Keyboard)
|
||||
Items.Add(_factory.InputMappingsTabViewModel(Device));
|
||||
Items.Add(_factory.DeviceInfoTabViewModel(Device));
|
||||
Items.Add(_factory.DeviceLedsTabViewModel(Device));
|
||||
|
||||
ActiveItem = Items[activeTabIndex];
|
||||
DisplayName = $"{Device.RgbDevice.DeviceInfo.Model} | Artemis";
|
||||
}
|
||||
|
||||
public ArtemisDevice Device
|
||||
{
|
||||
get => _device;
|
||||
set => SetAndNotify(ref _device, value);
|
||||
}
|
||||
|
||||
public ArtemisDevice Device { get; }
|
||||
public PanZoomViewModel PanZoomViewModel { get; }
|
||||
|
||||
public SnackbarMessageQueue DeviceMessageQueue
|
||||
@@ -84,14 +110,21 @@ namespace Artemis.UI.Screens.Settings.Device
|
||||
protected override void OnInitialActivate()
|
||||
{
|
||||
_coreService.FrameRendering += CoreServiceOnFrameRendering;
|
||||
_rgbService.DeviceAdded += RgbServiceOnDeviceAdded;
|
||||
DeviceMessageQueue = new SnackbarMessageQueue(TimeSpan.FromSeconds(5));
|
||||
Device.DeviceUpdated += DeviceOnDeviceUpdated;
|
||||
base.OnInitialActivate();
|
||||
}
|
||||
|
||||
private void RgbServiceOnDeviceAdded(object sender, DeviceEventArgs e)
|
||||
{
|
||||
if (e.Device != Device && e.Device.Identifier == Device.Identifier)
|
||||
Execute.OnUIThread(() => Initialize(e.Device));
|
||||
}
|
||||
|
||||
protected override void OnClose()
|
||||
{
|
||||
_coreService.FrameRendering -= CoreServiceOnFrameRendering;
|
||||
_rgbService.DeviceAdded -= RgbServiceOnDeviceAdded;
|
||||
Device.DeviceUpdated -= DeviceOnDeviceUpdated;
|
||||
base.OnClose();
|
||||
}
|
||||
|
||||
@@ -202,12 +202,12 @@
|
||||
The device layout is used to determine the position of LEDs and to create the visual representation of the device you see on the left side of this window.
|
||||
</TextBlock>
|
||||
|
||||
<CheckBox Margin="0 0 0 5" Style="{StaticResource MaterialDesignCheckBox}" IsChecked="{Binding UseDefaultLayout}">
|
||||
<CheckBox Margin="0 0 0 5" Style="{StaticResource MaterialDesignCheckBox}" IsChecked="{Binding Device.DisableDefaultLayout, Delay=300}">
|
||||
<CheckBox.Content>
|
||||
<TextBlock Margin="0 -5 0 0">
|
||||
Use default layout if needed
|
||||
Don't load default layout
|
||||
<materialDesign:PackIcon Kind="HelpCircle"
|
||||
ToolTip="If there is no built-in layout and no custom layout, with this enabled Artemis will fall back to the default layout of this device type." />
|
||||
ToolTip="With this enabled Artemis will not load a layout for this device unless you specifically provide one." />
|
||||
</TextBlock>
|
||||
</CheckBox.Content>
|
||||
</CheckBox>
|
||||
|
||||
@@ -101,7 +101,7 @@ namespace Artemis.UI.Screens.Settings.Device.Tabs
|
||||
get => _displayOnDevices;
|
||||
set => SetAndNotify(ref _displayOnDevices, value);
|
||||
}
|
||||
|
||||
|
||||
// This solution won't scale well but I don't expect there to be many more categories.
|
||||
// If for some reason there will be, dynamically creating a view model per category may be more appropriate
|
||||
public bool HasDeskCategory
|
||||
@@ -134,16 +134,6 @@ namespace Artemis.UI.Screens.Settings.Device.Tabs
|
||||
set => SetCategory(DeviceCategory.Peripherals, value);
|
||||
}
|
||||
|
||||
public bool UseDefaultLayout
|
||||
{
|
||||
get => !Device.DisableDefaultLayout;
|
||||
set
|
||||
{
|
||||
Device.DisableDefaultLayout = !value;
|
||||
NotifyOfPropertyChange(nameof(UseDefaultLayout));
|
||||
}
|
||||
}
|
||||
|
||||
public void ApplyScaling()
|
||||
{
|
||||
Device.RedScale = RedScale / 100f;
|
||||
@@ -266,7 +256,9 @@ namespace Artemis.UI.Screens.Settings.Device.Tabs
|
||||
private void DeviceOnPropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == nameof(Device.CustomLayoutPath) || e.PropertyName == nameof(Device.DisableDefaultLayout))
|
||||
_rgbService.ApplyBestDeviceLayout(Device);
|
||||
{
|
||||
Task.Run(() => _rgbService.ApplyBestDeviceLayout(Device));
|
||||
}
|
||||
}
|
||||
|
||||
private void OnFrameRendering(object sender, FrameRenderingEventArgs e)
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user