From ef4e5b4c3b20ae97a03399466d96dc33230c778e Mon Sep 17 00:00:00 2001 From: Robert Date: Sat, 18 Sep 2021 20:40:57 +0200 Subject: [PATCH] UI - Moved color scheme code away from tray VM UI - Cleaned up settings page code Core - Changed default framerate to 30 --- .../Plugins/Settings/PluginSetting.cs | 79 ++++-- .../Plugins/Settings/PluginSettings.cs | 22 +- src/Artemis.Core/Services/RgbService.cs | 2 +- src/Artemis.Core/Services/SettingsService.cs | 11 + .../NormalizedPercentageConverter.cs | 30 ++ .../Events/WindowsThemeEventArgs.cs | 5 +- .../Providers/ToastNotificationProvider.cs | 14 +- .../LayerPropertiesViewModel.cs | 4 +- .../Tabs/General/GeneralSettingsTabView.xaml | 175 +++++++----- .../General/GeneralSettingsTabViewModel.cs | 264 ++++++------------ src/Artemis.UI/Screens/TrayViewModel.cs | 66 +---- .../Services/RegistrationService.cs | 7 +- src/Artemis.UI/Services/ThemeService.cs | 176 ++++++++++++ src/Artemis.UI/Utilities/ThemeWatcher.cs | 112 -------- 14 files changed, 504 insertions(+), 463 deletions(-) create mode 100644 src/Artemis.UI/Converters/NormalizedPercentageConverter.cs create mode 100644 src/Artemis.UI/Services/ThemeService.cs delete mode 100644 src/Artemis.UI/Utilities/ThemeWatcher.cs diff --git a/src/Artemis.Core/Plugins/Settings/PluginSetting.cs b/src/Artemis.Core/Plugins/Settings/PluginSetting.cs index eb8ec0433..0756412f8 100644 --- a/src/Artemis.Core/Plugins/Settings/PluginSetting.cs +++ b/src/Artemis.Core/Plugins/Settings/PluginSetting.cs @@ -11,18 +11,14 @@ namespace Artemis.Core /// Represents a setting tied to a plugin of type /// /// The value type of the setting - public class PluginSetting : CorePropertyChanged + public class PluginSetting : CorePropertyChanged, IPluginSetting { - // TODO: Why? Should have included that... - // ReSharper disable once NotAccessedField.Local - private readonly Plugin _plugin; private readonly IPluginRepository _pluginRepository; private readonly PluginSettingEntity _pluginSettingEntity; private T _value; - internal PluginSetting(Plugin plugin, IPluginRepository pluginRepository, PluginSettingEntity pluginSettingEntity) + internal PluginSetting(IPluginRepository pluginRepository, PluginSettingEntity pluginSettingEntity) { - _plugin = plugin; _pluginRepository = pluginRepository; _pluginSettingEntity = pluginSettingEntity; @@ -37,9 +33,7 @@ namespace Artemis.Core } } - /// - /// The name of the setting, unique to this plugin - /// + /// public string Name { get; } /// @@ -63,28 +57,19 @@ namespace Artemis.Core } } - /// - /// Determines whether the setting has been changed - /// + /// public bool HasChanged => CoreJson.SerializeObject(Value) != _pluginSettingEntity.Value; - /// - /// Gets or sets whether changes must automatically be saved - /// Note: When set to true is always false - /// + /// public bool AutoSave { get; set; } - /// - /// Resets the setting to the last saved value - /// + /// public void RejectChanges() { Value = CoreJson.DeserializeObject(_pluginSettingEntity.Value); } - /// - /// Saves the setting - /// + /// public void Save() { if (!HasChanged) @@ -95,14 +80,10 @@ namespace Artemis.Core OnSettingSaved(); } - /// - /// Occurs when the value of the setting has been changed - /// + /// public event EventHandler? SettingChanged; - /// - /// Occurs when the value of the setting has been saved - /// + /// public event EventHandler? SettingSaved; /// @@ -127,4 +108,46 @@ namespace Artemis.Core SettingSaved?.Invoke(this, EventArgs.Empty); } } + + /// + /// Represents a setting tied to a plugin + /// + public interface IPluginSetting + { + /// + /// The name of the setting, unique to this plugin + /// + string Name { get; } + + /// + /// Determines whether the setting has been changed + /// + bool HasChanged { get; } + + /// + /// Gets or sets whether changes must automatically be saved + /// Note: When set to true is always false + /// + bool AutoSave { get; set; } + + /// + /// Resets the setting to the last saved value + /// + void RejectChanges(); + + /// + /// Saves the setting + /// + void Save(); + + /// + /// Occurs when the value of the setting has been changed + /// + event EventHandler? SettingChanged; + + /// + /// Occurs when the value of the setting has been saved + /// + event EventHandler? SettingSaved; + } } \ No newline at end of file diff --git a/src/Artemis.Core/Plugins/Settings/PluginSettings.cs b/src/Artemis.Core/Plugins/Settings/PluginSettings.cs index 2c22ae42d..5b7a7409b 100644 --- a/src/Artemis.Core/Plugins/Settings/PluginSettings.cs +++ b/src/Artemis.Core/Plugins/Settings/PluginSettings.cs @@ -1,7 +1,6 @@ using System.Collections.Generic; using Artemis.Storage.Entities.Plugins; using Artemis.Storage.Repositories.Interfaces; -using Newtonsoft.Json; namespace Artemis.Core { @@ -12,15 +11,15 @@ namespace Artemis.Core public class PluginSettings { private readonly IPluginRepository _pluginRepository; - private readonly Dictionary _settingEntities; + private readonly Dictionary _settingEntities; internal PluginSettings(Plugin plugin, IPluginRepository pluginRepository) { Plugin = plugin; Plugin.Settings = this; - + _pluginRepository = pluginRepository; - _settingEntities = new Dictionary(); + _settingEntities = new Dictionary(); } /// @@ -49,14 +48,14 @@ namespace Artemis.Core { settingEntity = new PluginSettingEntity { - Name = name, - PluginGuid = Plugin.Guid, + Name = name, + PluginGuid = Plugin.Guid, Value = CoreJson.SerializeObject(defaultValue) }; _pluginRepository.AddSetting(settingEntity); } - PluginSetting pluginSetting = new(Plugin, _pluginRepository, settingEntity); + PluginSetting pluginSetting = new(_pluginRepository, settingEntity); // This overrides null with the default value, I'm not sure if that's desirable because you // might expect something to go null and you might not @@ -68,6 +67,15 @@ namespace Artemis.Core } } + /// + /// Saves all currently loaded settings + /// + public void SaveAllSettings() + { + foreach (var (_, pluginSetting) in _settingEntities) + pluginSetting.Save(); + } + internal void ClearSettings() { _settingEntities.Clear(); diff --git a/src/Artemis.Core/Services/RgbService.cs b/src/Artemis.Core/Services/RgbService.cs index 40f2c42bd..9dbbea60f 100644 --- a/src/Artemis.Core/Services/RgbService.cs +++ b/src/Artemis.Core/Services/RgbService.cs @@ -35,7 +35,7 @@ namespace Artemis.Core.Services _logger = logger; _pluginManagementService = pluginManagementService; _deviceRepository = deviceRepository; - _targetFrameRateSetting = settingsService.GetSetting("Core.TargetFrameRate", 25); + _targetFrameRateSetting = settingsService.GetSetting("Core.TargetFrameRate", 30); _renderScaleSetting = settingsService.GetSetting("Core.RenderScale", 0.25); Surface = new RGBSurface(); diff --git a/src/Artemis.Core/Services/SettingsService.cs b/src/Artemis.Core/Services/SettingsService.cs index 6dd54a47a..e2c9fb08e 100644 --- a/src/Artemis.Core/Services/SettingsService.cs +++ b/src/Artemis.Core/Services/SettingsService.cs @@ -16,6 +16,12 @@ namespace Artemis.Core.Services { return _pluginSettings.GetSetting(name, defaultValue); } + + /// + public void SaveAllSettings() + { + _pluginSettings.SaveAllSettings(); + } } /// @@ -32,5 +38,10 @@ namespace Artemis.Core.Services /// The default value to use if the setting does not exist yet /// PluginSetting GetSetting(string name, T? defaultValue = default); + + /// + /// Saves all settings, obviously + /// + void SaveAllSettings(); } } \ No newline at end of file diff --git a/src/Artemis.UI/Converters/NormalizedPercentageConverter.cs b/src/Artemis.UI/Converters/NormalizedPercentageConverter.cs new file mode 100644 index 000000000..06cc0853c --- /dev/null +++ b/src/Artemis.UI/Converters/NormalizedPercentageConverter.cs @@ -0,0 +1,30 @@ +using System; +using System.Globalization; +using System.Windows.Data; + +namespace Artemis.UI.Converters +{ + [ValueConversion(typeof(double), typeof(double))] + public class NormalizedPercentageConverter : IValueConverter + { + #region IValueConverter Members + + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is double number) + return number * 100.0; + + return value; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is double number) + return number / 100.0; + + return value; + } + + #endregion + } +} \ No newline at end of file diff --git a/src/Artemis.UI/Events/WindowsThemeEventArgs.cs b/src/Artemis.UI/Events/WindowsThemeEventArgs.cs index 54310f545..03fd30e14 100644 --- a/src/Artemis.UI/Events/WindowsThemeEventArgs.cs +++ b/src/Artemis.UI/Events/WindowsThemeEventArgs.cs @@ -1,15 +1,16 @@ using System; +using Artemis.UI.Services; using Artemis.UI.Utilities; namespace Artemis.UI.Events { public class WindowsThemeEventArgs : EventArgs { - public WindowsThemeEventArgs(ThemeWatcher.WindowsTheme theme) + public WindowsThemeEventArgs(IThemeService.WindowsTheme theme) { Theme = theme; } - public ThemeWatcher.WindowsTheme Theme { get; set; } + public IThemeService.WindowsTheme Theme { get; set; } } } \ No newline at end of file diff --git a/src/Artemis.UI/Providers/ToastNotificationProvider.cs b/src/Artemis.UI/Providers/ToastNotificationProvider.cs index 53e8d5d25..a5b27ac85 100644 --- a/src/Artemis.UI/Providers/ToastNotificationProvider.cs +++ b/src/Artemis.UI/Providers/ToastNotificationProvider.cs @@ -4,8 +4,8 @@ using System.IO; using System.Windows.Media; using System.Windows.Media.Imaging; using Windows.UI.Notifications; +using Artemis.UI.Services; using Artemis.UI.Shared.Services; -using Artemis.UI.Utilities; using MaterialDesignThemes.Wpf; using Microsoft.Toolkit.Uwp.Notifications; using Stylet; @@ -14,11 +14,11 @@ namespace Artemis.UI.Providers { public class ToastNotificationProvider : INotificationProvider { - private ThemeWatcher _themeWatcher; + private readonly IThemeService _themeService; - public ToastNotificationProvider() + public ToastNotificationProvider(IThemeService themeService) { - _themeWatcher = new ThemeWatcher(); + _themeService = themeService; } public static PngBitmapEncoder GetEncoderForIcon(PackIconKind icon, Color color) @@ -71,7 +71,7 @@ namespace Artemis.UI.Providers Execute.OnUIThreadSync(() => { using FileStream stream = File.OpenWrite(imagePath); - GetEncoderForIcon(icon, _themeWatcher.GetSystemTheme() == ThemeWatcher.WindowsTheme.Dark ? Colors.White : Colors.Black).Save(stream); + GetEncoderForIcon(icon, _themeService.GetSystemTheme() == IThemeService.WindowsTheme.Dark ? Colors.White : Colors.Black).Save(stream); }); new ToastContentBuilder() @@ -88,14 +88,10 @@ namespace Artemis.UI.Providers #endregion - #region IDisposable - /// public void Dispose() { ToastNotificationManagerCompat.Uninstall(); } - - #endregion } } \ No newline at end of file diff --git a/src/Artemis.UI/Screens/ProfileEditor/LayerProperties/LayerPropertiesViewModel.cs b/src/Artemis.UI/Screens/ProfileEditor/LayerProperties/LayerPropertiesViewModel.cs index 95af67ace..4c506471b 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/LayerProperties/LayerPropertiesViewModel.cs +++ b/src/Artemis.UI/Screens/ProfileEditor/LayerProperties/LayerPropertiesViewModel.cs @@ -512,7 +512,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties if (SelectedProfileElement == null) return; - double frameTime = 1000.0 / SettingsService.GetSetting("Core.TargetFrameRate", 25).Value; + double frameTime = 1000.0 / SettingsService.GetSetting("Core.TargetFrameRate", 30).Value; double newTime = Math.Max(0, Math.Round((ProfileEditorService.CurrentTime.TotalMilliseconds - frameTime) / frameTime) * frameTime); ProfileEditorService.CurrentTime = TimeSpan.FromMilliseconds(newTime); } @@ -522,7 +522,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties if (SelectedProfileElement == null) return; - double frameTime = 1000.0 / SettingsService.GetSetting("Core.TargetFrameRate", 25).Value; + double frameTime = 1000.0 / SettingsService.GetSetting("Core.TargetFrameRate", 30).Value; double newTime = Math.Round((ProfileEditorService.CurrentTime.TotalMilliseconds + frameTime) / frameTime) * frameTime; newTime = Math.Min(newTime, SelectedProfileElement.Timeline.EndSegmentEndPosition.TotalMilliseconds); ProfileEditorService.CurrentTime = TimeSpan.FromMilliseconds(newTime); diff --git a/src/Artemis.UI/Screens/Settings/Tabs/General/GeneralSettingsTabView.xaml b/src/Artemis.UI/Screens/Settings/Tabs/General/GeneralSettingsTabView.xaml index 95be11f8b..28afdf8ec 100644 --- a/src/Artemis.UI/Screens/Settings/Tabs/General/GeneralSettingsTabView.xaml +++ b/src/Artemis.UI/Screens/Settings/Tabs/General/GeneralSettingsTabView.xaml @@ -1,27 +1,32 @@ - + + + - General + + + @@ -37,7 +42,7 @@ Start up with Windows - + @@ -55,7 +60,9 @@ Start up with Windows minimized - + @@ -72,14 +79,14 @@ Startup delay - Set the amount of seconds to wait before running Artemis with Windows. - If some devices don't work because Artemis starts before the manufacturer's software, try increasing this value. + + @@ -105,7 +112,7 @@ - Log level + + Log level + Sets the logging level, a higher logging level will result in more log files. @@ -132,7 +141,7 @@ - Logs + + Logs + Opens the directory where logs are stored. - + + + + +