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

@@ -9,6 +9,7 @@ using System.Windows.Media;
using Artemis.Core;
using Artemis.Core.LayerEffects;
using Artemis.Core.Services;
using Artemis.UI.Extensions;
using Artemis.UI.Ninject.Factories;
using Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings;
using Artemis.UI.Screens.ProfileEditor.LayerProperties.LayerEffects;
@@ -220,7 +221,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
private void SelectedProfileEditorServiceOnSelectedProfileElementChanged(object sender, RenderProfileElementEventArgs e)
{
PopulateProperties(e.RenderProfileElement);
Execute.PostToUIThread(() => PopulateProperties(e.RenderProfileElement));
}
private void ProfileEditorServiceOnCurrentTimeChanged(object sender, EventArgs e)
@@ -347,7 +348,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
.ToList();
// Order the effects
List<LayerPropertyGroupViewModel> effectProperties = Items
.Where(l => l.TreeGroupViewModel.GroupType == LayerEffectRoot)
.Where(l => l.TreeGroupViewModel.GroupType == LayerEffectRoot && l.LayerPropertyGroup.LayerEffect != null)
.OrderBy(l => l.LayerPropertyGroup.LayerEffect.Order)
.ToList();
@@ -355,14 +356,16 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
for (int index = 0; index < nonEffectProperties.Count; index++)
{
LayerPropertyGroupViewModel layerPropertyGroupViewModel = nonEffectProperties[index];
((BindableCollection<LayerPropertyGroupViewModel>) Items).Move(Items.IndexOf(layerPropertyGroupViewModel), index);
if (Items.IndexOf(layerPropertyGroupViewModel) != index)
((BindableCollection<LayerPropertyGroupViewModel>) Items).Move(Items.IndexOf(layerPropertyGroupViewModel), index);
}
// Put the effect properties after, sorted by their order
for (int index = 0; index < effectProperties.Count; index++)
{
LayerPropertyGroupViewModel layerPropertyGroupViewModel = effectProperties[index];
((BindableCollection<LayerPropertyGroupViewModel>) Items).Move(Items.IndexOf(layerPropertyGroupViewModel), index + nonEffectProperties.Count);
if (Items.IndexOf(layerPropertyGroupViewModel) != index + nonEffectProperties.Count)
((BindableCollection<LayerPropertyGroupViewModel>) Items).Move(Items.IndexOf(layerPropertyGroupViewModel), index + nonEffectProperties.Count);
}
}
@@ -527,7 +530,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
Repeating = false;
}
}
private TimeSpan GetCurrentSegmentStart()
{
TimeSpan current = ProfileEditorService.CurrentTime;
@@ -637,7 +640,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties
public void TimelineJump(object sender, MouseButtonEventArgs e)
{
// Get the parent grid, need that for our position
IInputElement parent = (IInputElement)VisualTreeHelper.GetParent((DependencyObject)sender);
IInputElement parent = (IInputElement) VisualTreeHelper.GetParent((DependencyObject) sender);
double x = Math.Max(0, e.GetPosition(parent).X);
TimeSpan newTime = TimeSpan.FromSeconds(x / ProfileEditorService.PixelsPerSecond);
@@ -15,6 +15,15 @@
d:DataContext="{d:DesignInstance {x:Type profileTree1:ProfileTreeViewModel}}">
<materialDesign:DialogHost IsTabStop="False" Focusable="False" Identifier="ProfileTreeDialog" DialogTheme="Inherit">
<Grid>
<Grid.Resources>
<DataTemplate x:Key="ElementDragTemplate" DataType="{x:Type treeItem:TreeItemViewModel}">
<Border Background="{DynamicResource MaterialDesignTextFieldBoxHoverBackground}"
Padding="10"
CornerRadius="4">
<TextBlock Text="{Binding ProfileElement.Name}" VerticalAlignment="Center" Foreground="{DynamicResource MaterialDesignBody}" />
</Border>
</DataTemplate>
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
@@ -33,7 +42,10 @@
dd:DragDrop.IsDragSource="True"
dd:DragDrop.IsDropTarget="True"
dd:DragDrop.DropHandler="{Binding}"
ContextMenuOpening="{s:Action ContextMenuOpening}">
dd:DragDrop.DragAdornerTemplate="{StaticResource ElementDragTemplate}"
ContextMenuOpening="{s:Action ContextMenuOpening}"
PreviewMouseDown="{s:Action TreeViewPreviewMouseDown}"
PreviewMouseUp="{s:Action TreeViewPreviewMouseUp}">
<TreeView.InputBindings>
<KeyBinding Key="F2" Command="{s:Action RenameElement}" s:View.ActionTarget="{Binding SelectedTreeItem}" />
<KeyBinding Key="Delete" Command="{s:Action DeleteElement}" s:View.ActionTarget="{Binding SelectedTreeItem}" />
@@ -83,7 +95,7 @@
</ContextMenu>
</TreeView.ContextMenu>
<b:Interaction.Behaviors>
<behaviors:TreeViewSelectionBehavior SelectedItem="{Binding SelectedTreeItem}" />
<behaviors:TreeViewSelectionBehavior SelectedItem="{Binding SelectedTreeItem, IsAsync=True}" />
</b:Interaction.Behaviors>
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type treeItem:FolderViewModel}" ItemsSource="{Binding Items}">
@@ -1,6 +1,7 @@
using System;
using System.Linq;
using System.Windows;
using System.Windows.Input;
using Artemis.Core;
using Artemis.UI.Ninject.Factories;
using Artemis.UI.Screens.ProfileEditor.ProfileTree.TreeItem;
@@ -15,6 +16,7 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree
{
private readonly IProfileEditorService _profileEditorService;
private readonly IProfileTreeVmFactory _profileTreeVmFactory;
private bool _draggingTreeView;
private TreeItemViewModel _selectedTreeItem;
private bool _updatingTree;
@@ -33,16 +35,25 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree
{
if (_updatingTree) return;
if (!SetAndNotify(ref _selectedTreeItem, value)) return;
if (_draggingTreeView) return;
if (value != null && value.ProfileElement is RenderProfileElement renderElement)
_profileEditorService.ChangeSelectedProfileElement(renderElement);
else
_profileEditorService.ChangeSelectedProfileElement(null);
ApplySelectedTreeItem();
}
}
public bool CanPasteElement => _profileEditorService.GetCanPasteProfileElement();
public void TreeViewPreviewMouseDown(object sender, MouseButtonEventArgs e)
{
_draggingTreeView = true;
}
public void TreeViewPreviewMouseUp(object sender, MouseButtonEventArgs e)
{
_draggingTreeView = false;
ApplySelectedTreeItem();
}
protected override void OnInitialActivate()
{
Subscribe();
@@ -55,6 +66,14 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree
base.OnClose();
}
private void ApplySelectedTreeItem()
{
if (_selectedTreeItem != null && _selectedTreeItem.ProfileElement is RenderProfileElement renderElement)
_profileEditorService.ChangeSelectedProfileElement(renderElement);
else
_profileEditorService.ChangeSelectedProfileElement(null);
}
private void CreateRootFolderViewModel()
{
_updatingTree = true;
@@ -64,7 +83,7 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree
ActivateItem(null);
return;
}
ActiveItem = _profileTreeVmFactory.FolderViewModel(folder);
_updatingTree = false;
}
@@ -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));
}
}
@@ -91,14 +91,10 @@
<StackPanel>
<StackPanel.Resources>
<DataTemplate x:Key="CategoryDragTemplate" DataType="{x:Type sidebar:SidebarCategoryViewModel}">
<DataTemplate.Resources>
<shared:NullToVisibilityConverter x:Key="NullToVisibilityConverter" />
</DataTemplate.Resources>
<Border Background="{DynamicResource MaterialDesignTextFieldBoxHoverBackground}"
Padding="10"
CornerRadius="4"
Visibility="{Binding Path=ProfileCategory, FallbackValue=null, Converter={StaticResource NullToVisibilityConverter}}">
<TextBlock Text="{Binding ProfileCategory.Name,TargetNullValue='Oops, I am missing'}" VerticalAlignment="Center" Foreground="{DynamicResource MaterialDesignBody}" />
<Border Background="{DynamicResource MaterialDesignTextFieldBoxHoverBackground}"
Padding="10"
CornerRadius="4">
<TextBlock Text="{Binding ProfileCategory.Name}" VerticalAlignment="Center" Foreground="{DynamicResource MaterialDesignBody}" />
</Border>
</DataTemplate>
</StackPanel.Resources>
@@ -69,7 +69,7 @@ namespace Artemis.UI.Screens.Sidebar
private void UpdateHeaderDevice()
{
HeaderDevice = _rgbService.Devices.FirstOrDefault(d => d.DeviceType == RGBDeviceType.Keyboard && d.Layout.IsValid);
HeaderDevice = _rgbService.Devices.FirstOrDefault(d => d.DeviceType == RGBDeviceType.Keyboard && d.Layout is {IsValid: true});
}
public ArtemisDevice HeaderDevice