From 26d8322b154666f91fee4c4b1d8a89ec6c3014fe Mon Sep 17 00:00:00 2001 From: Robert Date: Sun, 19 Sep 2021 18:40:46 +0200 Subject: [PATCH 1/3] UI - Fixed a possible startup freeze on Windows 11 --- .../Services/Interfaces/IThemeService.cs | 19 ++++++++ src/Artemis.UI/Services/ThemeService.cs | 48 +++++++++++-------- 2 files changed, 48 insertions(+), 19 deletions(-) create mode 100644 src/Artemis.UI/Services/Interfaces/IThemeService.cs diff --git a/src/Artemis.UI/Services/Interfaces/IThemeService.cs b/src/Artemis.UI/Services/Interfaces/IThemeService.cs new file mode 100644 index 000000000..8e7e56137 --- /dev/null +++ b/src/Artemis.UI/Services/Interfaces/IThemeService.cs @@ -0,0 +1,19 @@ +using System; +using Artemis.UI.Events; + +namespace Artemis.UI.Services +{ + public interface IThemeService : IArtemisUIService + { + WindowsTheme GetAppsTheme(); + WindowsTheme GetSystemTheme(); + event EventHandler AppsThemeChanged; + event EventHandler SystemThemeChanged; + + enum WindowsTheme + { + Light, + Dark + } + } +} \ No newline at end of file diff --git a/src/Artemis.UI/Services/ThemeService.cs b/src/Artemis.UI/Services/ThemeService.cs index e07c70eb7..ae4060eb7 100644 --- a/src/Artemis.UI/Services/ThemeService.cs +++ b/src/Artemis.UI/Services/ThemeService.cs @@ -2,32 +2,56 @@ using System.Globalization; using System.Management; using System.Security.Principal; +using System.Threading.Tasks; using Artemis.Core; using Artemis.Core.Services; using Artemis.UI.Events; using Artemis.UI.Screens.Settings.Tabs.General; using MaterialDesignThemes.Wpf; using Microsoft.Win32; +using Serilog; namespace Artemis.UI.Services { public class ThemeService : IThemeService { + private readonly ILogger _logger; private readonly PluginSetting _colorScheme; private const string RegistryKeyPath = @"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize"; private const string AppsThemeRegistryValueName = "AppsUseLightTheme"; private const string SystemThemeRegistryValueName = "SystemUsesLightTheme"; - public ThemeService(ISettingsService settingsService) + public ThemeService(ISettingsService settingsService, ILogger logger) { - WatchTheme(); - + _logger = logger; _colorScheme = settingsService.GetSetting("UI.ColorScheme", ApplicationColorScheme.Automatic); _colorScheme.SettingChanged += ColorSchemeOnSettingChanged; - ApplyColorSchemeSetting(); AppsThemeChanged += OnAppsThemeChanged; + + Task.Run(Initialize); + } + + private void Initialize() + { + try + { + WatchTheme(); + } + catch (Exception e) + { + _logger.Warning(e, "WatchTheme failed"); + } + + try + { + ApplyColorSchemeSetting(); + } + catch (Exception e) + { + _logger.Warning(e, "ApplyColorSchemeSetting failed"); + } } public IThemeService.WindowsTheme GetAppsTheme() @@ -123,7 +147,7 @@ namespace Artemis.UI.Services object registryValueObject = key?.GetValue(themeKeyName); if (registryValueObject == null) return IThemeService.WindowsTheme.Light; - int registryValue = (int) registryValueObject; + int registryValue = (int)registryValueObject; return registryValue > 0 ? IThemeService.WindowsTheme.Light : IThemeService.WindowsTheme.Dark; } @@ -159,18 +183,4 @@ namespace Artemis.UI.Services #endregion } - - public interface IThemeService : IArtemisUIService - { - WindowsTheme GetAppsTheme(); - WindowsTheme GetSystemTheme(); - event EventHandler AppsThemeChanged; - event EventHandler SystemThemeChanged; - - enum WindowsTheme - { - Light, - Dark - } - } } \ No newline at end of file From daac4e44ee08857b09a84b70f96a625c92f3588a Mon Sep 17 00:00:00 2001 From: Robert Date: Wed, 22 Sep 2021 21:42:42 +0200 Subject: [PATCH 2/3] Plugins - Remove related device settings when clearing plugin settings --- src/Artemis.Core/Models/Surface/ArtemisDevice.cs | 1 + src/Artemis.Core/Services/PluginManagementService.cs | 9 ++++++++- src/Artemis.Storage/Entities/Surface/DeviceEntity.cs | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Artemis.Core/Models/Surface/ArtemisDevice.cs b/src/Artemis.Core/Models/Surface/ArtemisDevice.cs index b8034ca26..1fa950b3c 100644 --- a/src/Artemis.Core/Models/Surface/ArtemisDevice.cs +++ b/src/Artemis.Core/Models/Surface/ArtemisDevice.cs @@ -457,6 +457,7 @@ namespace Artemis.Core { // Other properties are computed DeviceEntity.Id = Identifier; + DeviceEntity.DeviceProvider = DeviceProvider.Plugin.Guid.ToString(); DeviceEntity.InputIdentifiers.Clear(); foreach (ArtemisDeviceInputIdentifier identifier in InputIdentifiers) diff --git a/src/Artemis.Core/Services/PluginManagementService.cs b/src/Artemis.Core/Services/PluginManagementService.cs index 6c528bcfe..d03c22e3e 100644 --- a/src/Artemis.Core/Services/PluginManagementService.cs +++ b/src/Artemis.Core/Services/PluginManagementService.cs @@ -10,6 +10,7 @@ using Artemis.Core.DeviceProviders; using Artemis.Core.Ninject; using Artemis.Storage.Entities.General; using Artemis.Storage.Entities.Plugins; +using Artemis.Storage.Entities.Surface; using Artemis.Storage.Repositories.Interfaces; using McMaster.NETCore.Plugins; using Ninject; @@ -28,15 +29,17 @@ namespace Artemis.Core.Services private readonly IKernel _kernel; private readonly ILogger _logger; private readonly IPluginRepository _pluginRepository; + private readonly IDeviceRepository _deviceRepository; private readonly IQueuedActionRepository _queuedActionRepository; private readonly List _plugins; private bool _isElevated; - public PluginManagementService(IKernel kernel, ILogger logger, IPluginRepository pluginRepository, IQueuedActionRepository queuedActionRepository) + public PluginManagementService(IKernel kernel, ILogger logger, IPluginRepository pluginRepository, IDeviceRepository deviceRepository, IQueuedActionRepository queuedActionRepository) { _kernel = kernel; _logger = logger; _pluginRepository = pluginRepository; + _deviceRepository = deviceRepository; _queuedActionRepository = queuedActionRepository; _plugins = new List(); @@ -572,7 +575,11 @@ namespace Artemis.Core.Services { if (plugin.IsEnabled) throw new ArtemisCoreException("Cannot remove the settings of an enabled plugin"); + _pluginRepository.RemoveSettings(plugin.Guid); + foreach (DeviceEntity deviceEntity in _deviceRepository.GetAll().Where(e => e.DeviceProvider == plugin.Guid.ToString())) + _deviceRepository.Remove(deviceEntity); + plugin.Settings?.ClearSettings(); } diff --git a/src/Artemis.Storage/Entities/Surface/DeviceEntity.cs b/src/Artemis.Storage/Entities/Surface/DeviceEntity.cs index 6cce72dcc..a1c6784ba 100644 --- a/src/Artemis.Storage/Entities/Surface/DeviceEntity.cs +++ b/src/Artemis.Storage/Entities/Surface/DeviceEntity.cs @@ -12,6 +12,7 @@ namespace Artemis.Storage.Entities.Surface } public string Id { get; set; } + public string DeviceProvider { get; set; } public float X { get; set; } public float Y { get; set; } public float Rotation { get; set; } From c45f1d91309c786813fde2df6270f564e8089122 Mon Sep 17 00:00:00 2001 From: Diogo Trindade Date: Tue, 28 Sep 2021 19:00:08 +0100 Subject: [PATCH 3/3] Core - Fixed module name using plugin name incorrectly --- src/Artemis.Core/Plugins/Modules/Module.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Artemis.Core/Plugins/Modules/Module.cs b/src/Artemis.Core/Plugins/Modules/Module.cs index 8f2c56a60..c42e378a4 100644 --- a/src/Artemis.Core/Plugins/Modules/Module.cs +++ b/src/Artemis.Core/Plugins/Modules/Module.cs @@ -237,7 +237,7 @@ namespace Artemis.Core.Modules /// public virtual DataModelPropertyAttribute GetDataModelDescription() { - return new() {Name = Plugin.Info.Name, Description = Plugin.Info.Description}; + return new() {Name = Info.Name, Description = Info.Description}; } ///