From 520f145eb0252c27758e3c5db2179df7c7250e84 Mon Sep 17 00:00:00 2001 From: Stone-Red-Code <56473591+Stone-Red-Code@users.noreply.github.com> Date: Sun, 24 Oct 2021 19:38:45 +0200 Subject: [PATCH] - Improve code structure - Improve log output format --- src/DesktopMagic/App.xaml.cs | 8 +-- .../CalendarWindow.xaml | 0 .../CalendarWindow.xaml.cs | 28 ++++------- .../CpuUsageWindow.xaml | 0 .../CpuUsageWindow.xaml.cs | 12 ++--- .../DateWindow.xaml | 0 .../DateWindow.xaml.cs | 11 ++-- .../MusicVisualizerWindow.xaml | 0 .../MusicVisualizerWindow.xaml.cs | 20 ++++---- .../TimeWindow.xaml | 0 .../TimeWindow.xaml.cs | 11 ++-- src/DesktopMagic/GlobalSuppressions.cs | 3 +- .../{ => Helpers}/CalendarManagment.cs | 0 .../{ => Helpers}/SampleAggregator.cs | 0 .../{ => Helpers}/Win32Wrapper.cs | 0 src/DesktopMagic/{ => Helpers}/WindowPos.cs | 0 src/DesktopMagic/InputDialog.xaml.cs | 11 ++-- src/DesktopMagic/MainWindow.xaml.cs | 38 ++++++-------- .../{Plugin => Plugins}/PluginData.cs | 19 ++++--- .../{Plugin => Plugins}/PluginWindow.xaml | 0 .../{Plugin => Plugins}/PluginWindow.xaml.cs | 14 +++--- .../{Plugin => Plugins}/SettingElement.cs | 7 +-- src/DesktopMagic/Plugins/Theme.cs | 18 +++++++ src/DesktopMagic/credentials.json | 14 ------ src/DesktopMagicPlugin.Test/PluginScript.cs | 9 +++- .../DesktopMagicPluginAPI.md | 50 +++++++++++++++++-- .../DesktopMagicPluginAPI.xml | 31 ++++++++++-- src/DesktopMagicPluginAPI/IPluginData.cs | 14 ++++-- src/DesktopMagicPluginAPI/ITheme.cs | 25 ++++++++++ src/DesktopMagicPluginAPI/Plugin.cs | 2 +- 30 files changed, 216 insertions(+), 129 deletions(-) rename src/DesktopMagic/{ => BuiltInWindowElements}/CalendarWindow.xaml (100%) rename src/DesktopMagic/{ => BuiltInWindowElements}/CalendarWindow.xaml.cs (82%) rename src/DesktopMagic/{ => BuiltInWindowElements}/CpuUsageWindow.xaml (100%) rename src/DesktopMagic/{ => BuiltInWindowElements}/CpuUsageWindow.xaml.cs (92%) rename src/DesktopMagic/{ => BuiltInWindowElements}/DateWindow.xaml (100%) rename src/DesktopMagic/{ => BuiltInWindowElements}/DateWindow.xaml.cs (90%) rename src/DesktopMagic/{ => BuiltInWindowElements}/MusicVisualizerWindow.xaml (100%) rename src/DesktopMagic/{ => BuiltInWindowElements}/MusicVisualizerWindow.xaml.cs (94%) rename src/DesktopMagic/{ => BuiltInWindowElements}/TimeWindow.xaml (100%) rename src/DesktopMagic/{ => BuiltInWindowElements}/TimeWindow.xaml.cs (91%) rename src/DesktopMagic/{ => Helpers}/CalendarManagment.cs (100%) rename src/DesktopMagic/{ => Helpers}/SampleAggregator.cs (100%) rename src/DesktopMagic/{ => Helpers}/Win32Wrapper.cs (100%) rename src/DesktopMagic/{ => Helpers}/WindowPos.cs (100%) rename src/DesktopMagic/{Plugin => Plugins}/PluginData.cs (56%) rename src/DesktopMagic/{Plugin => Plugins}/PluginWindow.xaml (100%) rename src/DesktopMagic/{Plugin => Plugins}/PluginWindow.xaml.cs (98%) rename src/DesktopMagic/{Plugin => Plugins}/SettingElement.cs (73%) create mode 100644 src/DesktopMagic/Plugins/Theme.cs delete mode 100644 src/DesktopMagic/credentials.json create mode 100644 src/DesktopMagicPluginAPI/ITheme.cs diff --git a/src/DesktopMagic/App.xaml.cs b/src/DesktopMagic/App.xaml.cs index e86d738..3bfd725 100644 --- a/src/DesktopMagic/App.xaml.cs +++ b/src/DesktopMagic/App.xaml.cs @@ -33,11 +33,11 @@ namespace DesktopMagic // Try to grab mutex _mutex = new Mutex(true, $"Stone_Red{AppName}", out bool createdNew); - //check if creating new was succesfull + //check if creating new was successful if (!createdNew) { Logger.Log("Shutting down because other instance already running.", "Setup"); - //Shutdown Aplication + //Shutdown Application Current.Shutdown(); } else @@ -59,7 +59,7 @@ namespace DesktopMagic private void Updater_NoUpdateAvailible() { - Logger.Log("No update avalible.", "Updater"); + Logger.Log("No update available.", "Updater"); } private void Updater_OnException(Exception exception) @@ -114,7 +114,7 @@ namespace DesktopMagic }, FormatConfig = new FormatConfig() { - DebugConsoleFormat = $"> {{{LogFormatType.DateTime}:hh:mm:ss}} | {{{LogFormatType.LogSeverity},-5}} | {{{LogFormatType.Message}}}\n> at {{{LogFormatType.LineNumber},3}} | {{{LogFormatType.FilePath}}}" + DebugConsoleFormat = $"> {{{LogFormatType.DateTime}:hh:mm:ss}} | {{{LogFormatType.LogSeverity},-5}} | {{{LogFormatType.Message}}}\nat {{{LogFormatType.LineNumber}}} | {{{LogFormatType.FilePath}}}" } }; Logger.ClearLogFile(LogSeverity.Info); diff --git a/src/DesktopMagic/CalendarWindow.xaml b/src/DesktopMagic/BuiltInWindowElements/CalendarWindow.xaml similarity index 100% rename from src/DesktopMagic/CalendarWindow.xaml rename to src/DesktopMagic/BuiltInWindowElements/CalendarWindow.xaml diff --git a/src/DesktopMagic/CalendarWindow.xaml.cs b/src/DesktopMagic/BuiltInWindowElements/CalendarWindow.xaml.cs similarity index 82% rename from src/DesktopMagic/CalendarWindow.xaml.cs rename to src/DesktopMagic/BuiltInWindowElements/CalendarWindow.xaml.cs index 9854c41..6448ba9 100644 --- a/src/DesktopMagic/CalendarWindow.xaml.cs +++ b/src/DesktopMagic/BuiltInWindowElements/CalendarWindow.xaml.cs @@ -10,9 +10,6 @@ using System.Windows.Media; namespace DesktopMagic { - /// - /// Interaktionslogik für TimeWindow.xaml - /// [Obsolete("Disabled due to lack of support (too much work)")] public partial class CalendarWindow : Window { @@ -40,7 +37,7 @@ namespace DesktopMagic Timer t = new Timer(); t.Interval = 100; - t.Elapsed += T_Elapsed; + t.Elapsed += UpdateTimer_Elapsed; t.Start(); Timer valueTimer = new Timer(); @@ -88,7 +85,7 @@ namespace DesktopMagic }); } - private void T_Elapsed(object sender, ElapsedEventArgs e) + private void UpdateTimer_Elapsed(object sender, ElapsedEventArgs e) { Dispatcher.Invoke(() => { @@ -102,10 +99,10 @@ namespace DesktopMagic panel.Visibility = Visibility.Collapsed; WindowPos.SetIsLocked(this, true); } - if (MainWindow.GlobalFont != oldFont || MainWindow.GlobalColor != oldColor) + if (MainWindow.Theme.Font != oldFont || MainWindow.Theme.PrimaryBrush != oldColor) { - oldColor = MainWindow.GlobalColor; - oldFont = MainWindow.GlobalFont; + oldColor = MainWindow.Theme.PrimaryBrush; + oldFont = MainWindow.Theme.Font; LoadEvents(); } listBox.SelectedIndex = -1; @@ -117,22 +114,19 @@ namespace DesktopMagic listBox.Items.Clear(); CalendarItems calendarItem = new CalendarItems(); calendarItem.eventname = "Termine: "; - calendarItem.font = MainWindow.GlobalFont; - calendarItem.color = MainWindow.GlobalColor.ToString(); + calendarItem.font = MainWindow.Theme.Font; + calendarItem.color = MainWindow.Theme.PrimaryColor.ToString(); listBox.Items.Add(calendarItem); for (int i = 0; i < upcomingEventNames.Count; i++) { - DateTime dateTime = DateTime.Now; - DateTime.TryParse(upcomingEventTimes[i], out dateTime); - calendarItem = new CalendarItems(); calendarItem.eventname = upcomingEventNames[i]; - calendarItem.dateTime = dateTime.ToString("dd-MM-yyyy"); - calendarItem.font = MainWindow.GlobalFont; - calendarItem.color = MainWindow.GlobalColor.ToString(); + calendarItem.dateTime = DateTime.Now.ToString("dd-MM-yyyy"); + calendarItem.font = MainWindow.Theme.Font; + calendarItem.color = MainWindow.Theme.PrimaryBrush.ToString(); - if (dateTime < DateTime.Today.AddMonths(12) || upcomingEventTimes[i] == "-") + if (DateTime.Now < DateTime.Today.AddMonths(12) || upcomingEventTimes[i] == "-") { listBox.Items.Add(calendarItem); } diff --git a/src/DesktopMagic/CpuUsageWindow.xaml b/src/DesktopMagic/BuiltInWindowElements/CpuUsageWindow.xaml similarity index 100% rename from src/DesktopMagic/CpuUsageWindow.xaml rename to src/DesktopMagic/BuiltInWindowElements/CpuUsageWindow.xaml diff --git a/src/DesktopMagic/CpuUsageWindow.xaml.cs b/src/DesktopMagic/BuiltInWindowElements/CpuUsageWindow.xaml.cs similarity index 92% rename from src/DesktopMagic/CpuUsageWindow.xaml.cs rename to src/DesktopMagic/BuiltInWindowElements/CpuUsageWindow.xaml.cs index d5afd15..aafc13b 100644 --- a/src/DesktopMagic/CpuUsageWindow.xaml.cs +++ b/src/DesktopMagic/BuiltInWindowElements/CpuUsageWindow.xaml.cs @@ -6,12 +6,10 @@ using System.Timers; using System.Windows; using System.Windows.Interop; using System.Windows.Media; +using System.Windows.Threading; namespace DesktopMagic { - /// - /// Interaktionslogik für TimeWindow.xaml - /// public partial class CpuUsageWindow : Window { private RegistryKey key; @@ -41,7 +39,7 @@ namespace DesktopMagic Timer t = new Timer(); t.Interval = 100; - t.Elapsed += T_Elapsed; + t.Elapsed += UpdateTimer_Elapsed; t.Start(); Timer valueTimer = new Timer(); @@ -68,7 +66,7 @@ namespace DesktopMagic WindowPos.GetWindowLong(helper.Handle, WindowPos.GWL_EXSTYLE) | WindowPos.WS_EX_NOACTIVATE); } - private void T_Elapsed(object sender, ElapsedEventArgs e) + private void UpdateTimer_Elapsed(object sender, ElapsedEventArgs e) { Dispatcher.Invoke(() => { @@ -83,8 +81,8 @@ namespace DesktopMagic WindowPos.SetIsLocked(this, true); } - textBlock.FontFamily = new FontFamily(MainWindow.GlobalFont); - textBlock.Foreground = MainWindow.GlobalColor; + textBlock.FontFamily = new FontFamily(MainWindow.Theme.Font); + textBlock.Foreground = MainWindow.Theme.PrimaryBrush; }); } diff --git a/src/DesktopMagic/DateWindow.xaml b/src/DesktopMagic/BuiltInWindowElements/DateWindow.xaml similarity index 100% rename from src/DesktopMagic/DateWindow.xaml rename to src/DesktopMagic/BuiltInWindowElements/DateWindow.xaml diff --git a/src/DesktopMagic/DateWindow.xaml.cs b/src/DesktopMagic/BuiltInWindowElements/DateWindow.xaml.cs similarity index 90% rename from src/DesktopMagic/DateWindow.xaml.cs rename to src/DesktopMagic/BuiltInWindowElements/DateWindow.xaml.cs index ad58d75..c60264e 100644 --- a/src/DesktopMagic/DateWindow.xaml.cs +++ b/src/DesktopMagic/BuiltInWindowElements/DateWindow.xaml.cs @@ -8,9 +8,6 @@ using System.Windows.Media; namespace DesktopMagic { - /// - /// Interaktionslogik für TimeWindow.xaml - /// public partial class DateWindow : Window { private RegistryKey key; @@ -33,7 +30,7 @@ namespace DesktopMagic Timer t = new Timer(); t.Interval = 100; - t.Elapsed += T_Elapsed; + t.Elapsed += UpdateTimer_Elapsed; t.Start(); key = Registry.CurrentUser.CreateSubKey(@"Software\" + App.AppName); @@ -54,7 +51,7 @@ namespace DesktopMagic WindowPos.GetWindowLong(helper.Handle, WindowPos.GWL_EXSTYLE) | WindowPos.WS_EX_NOACTIVATE); } - private void T_Elapsed(object sender, ElapsedEventArgs e) + private void UpdateTimer_Elapsed(object sender, ElapsedEventArgs e) { Dispatcher.Invoke(() => { @@ -68,8 +65,8 @@ namespace DesktopMagic panel.Visibility = Visibility.Collapsed; WindowPos.SetIsLocked(this, true); } - textBlock.FontFamily = new FontFamily(MainWindow.GlobalFont); - textBlock.Foreground = MainWindow.GlobalColor; + textBlock.FontFamily = new FontFamily(MainWindow.Theme.Font); + textBlock.Foreground = MainWindow.Theme.PrimaryBrush; textBlock.Text = DateTime.Now.ToString("D"); }); } diff --git a/src/DesktopMagic/MusicVisualizerWindow.xaml b/src/DesktopMagic/BuiltInWindowElements/MusicVisualizerWindow.xaml similarity index 100% rename from src/DesktopMagic/MusicVisualizerWindow.xaml rename to src/DesktopMagic/BuiltInWindowElements/MusicVisualizerWindow.xaml diff --git a/src/DesktopMagic/MusicVisualizerWindow.xaml.cs b/src/DesktopMagic/BuiltInWindowElements/MusicVisualizerWindow.xaml.cs similarity index 94% rename from src/DesktopMagic/MusicVisualizerWindow.xaml.cs rename to src/DesktopMagic/BuiltInWindowElements/MusicVisualizerWindow.xaml.cs index 8bb8ab9..b7e7cfb 100644 --- a/src/DesktopMagic/MusicVisualizerWindow.xaml.cs +++ b/src/DesktopMagic/BuiltInWindowElements/MusicVisualizerWindow.xaml.cs @@ -57,7 +57,7 @@ namespace DesktopMagic Timer t = new Timer(); t.Interval = 100; - t.Elapsed += T_Elapsed; + t.Elapsed += UpdateTimer_Elapsed; t.Start(); key = Registry.CurrentUser.CreateSubKey(@"Software\" + App.AppName); @@ -83,7 +83,7 @@ namespace DesktopMagic WindowPos.GetWindowLong(helper.Handle, WindowPos.GWL_EXSTYLE) | WindowPos.WS_EX_NOACTIVATE); } - private void T_Elapsed(object sender, ElapsedEventArgs e) + private void UpdateTimer_Elapsed(object sender, ElapsedEventArgs e) { Dispatcher.Invoke(() => { @@ -299,13 +299,13 @@ namespace DesktopMagic SetPoints(points, bm.Width, bm.Height, offset); Brush brush; - if (MainWindow.MusicVisualzerColor == null) + if (MainWindow.MusicVisualzerColor.HasValue) { - brush = MainWindow.GlobalSystemColor; + brush = new SolidBrush(MainWindow.MusicVisualzerColor.Value); } else { - brush = MainWindow.MusicVisualzerColor; + brush = new SolidBrush(MainWindow.Theme.PrimaryColor); } if (MainWindow.LineMode) @@ -340,7 +340,7 @@ namespace DesktopMagic { case 1: points[0] = new PointF(width, height / 2); - points[points.Length - 1] = new PointF(0, height / 2); + points[^1] = new PointF(0, height / 2); points[points.Length / 2] = new PointF(width, height / 2); points[points.Length / 2 - 1] = new PointF(0, height / 2); @@ -348,12 +348,12 @@ namespace DesktopMagic case 2: points[0] = new PointF(0, 0 - offset); - points[points.Length - 1] = new PointF(points[points.Length - 2].X, 0 - offset); + points[^1] = new PointF(points[^2].X, 0 - offset); break; default: points[0] = new PointF(0, height); - points[points.Length - 1] = new PointF(points[points.Length - 2].X, height); + points[^1] = new PointF(points[^2].X, height); break; } } @@ -376,8 +376,8 @@ namespace DesktopMagic private void Window_LocationChanged(object sender, EventArgs e) { - key.SetValue("MusicVisualizerWindowTop", this.Top); - key.SetValue("MusicVisualizerWindowLeft", this.Left); + key.SetValue("MusicVisualizerWindowTop", Top); + key.SetValue("MusicVisualizerWindowLeft", Left); } private void Window_SizeChanged(object sender, SizeChangedEventArgs e) diff --git a/src/DesktopMagic/TimeWindow.xaml b/src/DesktopMagic/BuiltInWindowElements/TimeWindow.xaml similarity index 100% rename from src/DesktopMagic/TimeWindow.xaml rename to src/DesktopMagic/BuiltInWindowElements/TimeWindow.xaml diff --git a/src/DesktopMagic/TimeWindow.xaml.cs b/src/DesktopMagic/BuiltInWindowElements/TimeWindow.xaml.cs similarity index 91% rename from src/DesktopMagic/TimeWindow.xaml.cs rename to src/DesktopMagic/BuiltInWindowElements/TimeWindow.xaml.cs index 4713c08..2558e10 100644 --- a/src/DesktopMagic/TimeWindow.xaml.cs +++ b/src/DesktopMagic/BuiltInWindowElements/TimeWindow.xaml.cs @@ -8,9 +8,6 @@ using System.Windows.Media; namespace DesktopMagic { - /// - /// Interaktionslogik für TimeWindow.xaml - /// public partial class TimeWindow : Window { private RegistryKey key; @@ -33,7 +30,7 @@ namespace DesktopMagic Timer t = new Timer(); t.Interval = 100; - t.Elapsed += T_Elapsed; + t.Elapsed += UpdateTimer_Elapsed; t.Start(); key = Registry.CurrentUser.CreateSubKey(@"Software\" + App.AppName); @@ -54,7 +51,7 @@ namespace DesktopMagic WindowPos.GetWindowLong(helper.Handle, WindowPos.GWL_EXSTYLE) | WindowPos.WS_EX_NOACTIVATE); } - private void T_Elapsed(object sender, ElapsedEventArgs e) + private void UpdateTimer_Elapsed(object sender, ElapsedEventArgs e) { Dispatcher.Invoke(() => { @@ -69,8 +66,8 @@ namespace DesktopMagic WindowPos.SetIsLocked(this, true); } - textBlock.FontFamily = new FontFamily(MainWindow.GlobalFont); - textBlock.Foreground = MainWindow.GlobalColor; + textBlock.FontFamily = new FontFamily(MainWindow.Theme.Font); + textBlock.Foreground = MainWindow.Theme.PrimaryBrush; //textBlock.Text = DateTime.Now.ToString("hh:mm:ss tt"); textBlock.Text = DateTime.Now.ToString("HH:mm:ss"); }); diff --git a/src/DesktopMagic/GlobalSuppressions.cs b/src/DesktopMagic/GlobalSuppressions.cs index ba7f009..acc3b05 100644 --- a/src/DesktopMagic/GlobalSuppressions.cs +++ b/src/DesktopMagic/GlobalSuppressions.cs @@ -5,5 +5,4 @@ using System.Diagnostics.CodeAnalysis; -[assembly: SuppressMessage("Performance", "CA1822:Member als statisch markieren", Justification = "", Scope = "member", Target = "~M:DesktopMagic.PluginWindow.LoadOptions(System.Object)")] -[assembly: SuppressMessage("Style", "IDE0090:Use 'new(...)'", Justification = "", Scope = "member", Target = "~M:DesktopMagic.MainWindow.GithubButton_Click(System.Object,System.Windows.RoutedEventArgs)")] \ No newline at end of file +[assembly: SuppressMessage("Interoperability", "CA1416:Validate platform compatibility", Justification = "Windows only application")] \ No newline at end of file diff --git a/src/DesktopMagic/CalendarManagment.cs b/src/DesktopMagic/Helpers/CalendarManagment.cs similarity index 100% rename from src/DesktopMagic/CalendarManagment.cs rename to src/DesktopMagic/Helpers/CalendarManagment.cs diff --git a/src/DesktopMagic/SampleAggregator.cs b/src/DesktopMagic/Helpers/SampleAggregator.cs similarity index 100% rename from src/DesktopMagic/SampleAggregator.cs rename to src/DesktopMagic/Helpers/SampleAggregator.cs diff --git a/src/DesktopMagic/Win32Wrapper.cs b/src/DesktopMagic/Helpers/Win32Wrapper.cs similarity index 100% rename from src/DesktopMagic/Win32Wrapper.cs rename to src/DesktopMagic/Helpers/Win32Wrapper.cs diff --git a/src/DesktopMagic/WindowPos.cs b/src/DesktopMagic/Helpers/WindowPos.cs similarity index 100% rename from src/DesktopMagic/WindowPos.cs rename to src/DesktopMagic/Helpers/WindowPos.cs diff --git a/src/DesktopMagic/InputDialog.xaml.cs b/src/DesktopMagic/InputDialog.xaml.cs index 8559ef7..812dc57 100644 --- a/src/DesktopMagic/InputDialog.xaml.cs +++ b/src/DesktopMagic/InputDialog.xaml.cs @@ -4,23 +4,20 @@ using System.Windows; namespace DesktopMagic { - /// - /// Interaktionslogik für InputDialog.xaml - /// public partial class InputDialog : Window { public InputDialog(string content, string title = "InputDialog") { InitializeComponent(); label.Content = content; - this.Title = title; + Title = title; SetLanguageDictionary(); } public string ResponseText { - get { return textBox.Text; } - set { textBox.Text = value; } + get => textBox.Text; + set => textBox.Text = value; } private void OkButton_Click(object sender, RoutedEventArgs e) @@ -46,7 +43,7 @@ namespace DesktopMagic { dict.Source = new Uri("..\\Resources\\StringResources.en.xaml", UriKind.Relative); } - this.Resources.MergedDictionaries.Add(dict); + Resources.MergedDictionaries.Add(dict); } } } \ No newline at end of file diff --git a/src/DesktopMagic/MainWindow.xaml.cs b/src/DesktopMagic/MainWindow.xaml.cs index 5843e48..af4dcf9 100644 --- a/src/DesktopMagic/MainWindow.xaml.cs +++ b/src/DesktopMagic/MainWindow.xaml.cs @@ -1,4 +1,6 @@ -using Microsoft.Win32; +using DesktopMagic.Plugins; + +using Microsoft.Win32; using System; using System.Collections.Generic; @@ -14,17 +16,11 @@ using System.Windows.Media; namespace DesktopMagic { - /// - /// Interaktionslogik für MainWindow.xaml - /// - public partial class MainWindow : Window { #region Global settings - public static string GlobalFont { get; protected set; } = "Segoe UI"; - public static Brush GlobalColor { get; protected set; } = Brushes.White; - public static System.Drawing.Brush GlobalSystemColor { get; protected set; } = System.Drawing.Brushes.White; + internal static Theme Theme = new Theme(); public static bool EditMode { get; protected set; } = false; #endregion Global settings @@ -35,7 +31,7 @@ namespace DesktopMagic public static int AmplifierLevel { get; protected set; } = 0; public static bool MirrorMode { get; protected set; } = false; public static bool LineMode { get; protected set; } = false; - public static System.Drawing.Brush MusicVisualzerColor { get; protected set; } + public static System.Drawing.Color? MusicVisualzerColor { get; protected set; } #endregion Music Visualizer Settings @@ -160,17 +156,17 @@ namespace DesktopMagic checkBox.Style = (Style)FindResource("MaterialDesignDarkCheckBox"); checkBox.Click += CheckBox_Click; - bool exsists = false; + bool exists = false; foreach (UIElement item in stackPanel.Children) { if (((CheckBox)item).Name == "_PluginCb_" + clearPluginName) { - exsists = true; + exists = true; break; } } - if (!exsists) + if (!exists) { _ = stackPanel.Children.Add(checkBox); } @@ -396,9 +392,8 @@ namespace DesktopMagic hex = hex.Replace("#", ""); System.Drawing.Color systemColor = System.Drawing.Color.FromArgb((byte)int.Parse(hex.Substring(0, 2), System.Globalization.NumberStyles.HexNumber), (byte)int.Parse(hex.Substring(2, 2), System.Globalization.NumberStyles.HexNumber), (byte)int.Parse(hex.Substring(4, 2), System.Globalization.NumberStyles.HexNumber)); - System.Drawing.Brush systemBrush = new System.Drawing.SolidBrush(systemColor); - MusicVisualzerColor = systemBrush; + MusicVisualzerColor = systemColor; musicVisualizerColorTextBox.Foreground = Brushes.Black; key.SetValue("MusicVisualizerColor", musicVisualizerColorTextBox.Text); @@ -419,8 +414,8 @@ namespace DesktopMagic private void FontComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { - GlobalFont = fontComboBox.SelectedValue.ToString().Replace("System.Windows.Controls.ComboBoxItem: ", ""); - key.SetValue("Font", GlobalFont); + Theme.Font = fontComboBox.SelectedValue.ToString().Replace("System.Windows.Controls.ComboBoxItem: ", ""); + key.SetValue("Font", Theme.Font); SaveLayout(); } @@ -679,7 +674,7 @@ namespace DesktopMagic }; _ = fontComboBox.Items.Add(comboBoxItem); - if (ff.ToString() == GlobalFont) + if (ff.ToString() == Theme.Font) { fontComboBox.SelectedIndex = index; } @@ -738,10 +733,9 @@ namespace DesktopMagic blueSlider.Value = color.B; Brush brush = new SolidColorBrush(color); - System.Drawing.Brush systemBrush = new System.Drawing.SolidBrush(systemColor); - GlobalColor = brush; - GlobalSystemColor = systemBrush; + Theme.PrimaryBrush = brush; + Theme.PrimaryColor = systemColor; colorRechtangle.Fill = brush; colorHexTextBox.Foreground = Brushes.Black; @@ -784,7 +778,7 @@ namespace DesktopMagic for (int i = 0; i < fontComboBox.Items.Count; i++) { ComboBoxItem comboBoxItem = (ComboBoxItem)fontComboBox.Items[i]; - if (comboBoxItem.FontFamily.ToString() == GlobalFont) + if (comboBoxItem.FontFamily.ToString() == Theme.Font) { fontComboBox.SelectedIndex = i; } @@ -867,7 +861,7 @@ namespace DesktopMagic private void LoadLayout(bool minimize = true) { - GlobalFont = key.GetValue("Font", "Segoe UI").ToString(); + Theme.Font = key.GetValue("Font", "Segoe UI").ToString(); spectrumModeComboBox.SelectedIndex = int.Parse(key.GetValue("SpectrumMode", "0").ToString()); amplifierLevelSlider.Value = int.Parse(key.GetValue("AmplifierLevel", "0").ToString()); mirrorModeCheckBox.IsChecked = bool.Parse(key.GetValue("MirrorMode", "false").ToString()); diff --git a/src/DesktopMagic/Plugin/PluginData.cs b/src/DesktopMagic/Plugins/PluginData.cs similarity index 56% rename from src/DesktopMagic/Plugin/PluginData.cs rename to src/DesktopMagic/Plugins/PluginData.cs index d812d8f..3772ad7 100644 --- a/src/DesktopMagic/Plugin/PluginData.cs +++ b/src/DesktopMagic/Plugins/PluginData.cs @@ -1,20 +1,24 @@ using DesktopMagicPluginAPI; + using System.Drawing; -namespace DesktopMagic +namespace DesktopMagic.Plugins { internal class PluginData : IPluginData { private readonly PluginWindow window; - public PluginData(PluginWindow win) + public PluginData(PluginWindow window) { - window = win; + this.window = window; + Theme = MainWindow.Theme; } - public string Font => MainWindow.GlobalFont; + public string Font => Theme.Font; - public Color Color => (MainWindow.GlobalSystemColor as SolidBrush).Color; + public Color Color => Theme.PrimaryColor; + + public ITheme Theme { get; } public Point WindowSize => new Point((int)window.ActualWidth, (int)window.ActualHeight); @@ -24,6 +28,9 @@ namespace DesktopMagic public string PluginPath => window.PluginFolderPath; - public void UpdateWindow() => window.UpdatePluginWindow(); + public void UpdateWindow() + { + window.UpdatePluginWindow(); + } } } \ No newline at end of file diff --git a/src/DesktopMagic/Plugin/PluginWindow.xaml b/src/DesktopMagic/Plugins/PluginWindow.xaml similarity index 100% rename from src/DesktopMagic/Plugin/PluginWindow.xaml rename to src/DesktopMagic/Plugins/PluginWindow.xaml diff --git a/src/DesktopMagic/Plugin/PluginWindow.xaml.cs b/src/DesktopMagic/Plugins/PluginWindow.xaml.cs similarity index 98% rename from src/DesktopMagic/Plugin/PluginWindow.xaml.cs rename to src/DesktopMagic/Plugins/PluginWindow.xaml.cs index c86dbd0..c89b745 100644 --- a/src/DesktopMagic/Plugin/PluginWindow.xaml.cs +++ b/src/DesktopMagic/Plugins/PluginWindow.xaml.cs @@ -1,4 +1,6 @@ -using DesktopMagicPluginAPI; +using DesktopMagic.Plugins; + +using DesktopMagicPluginAPI; using DesktopMagicPluginAPI.Drawing; using DesktopMagicPluginAPI.Inputs; @@ -20,20 +22,16 @@ using System.Windows.Media.Imaging; namespace DesktopMagic { - /// - /// Interaktionslogik für PluginWindow.xaml - /// - /// public partial class PluginWindow : Window { private readonly RegistryKey key; private Thread pluginThread; private System.Timers.Timer valueTimer; + private bool stop = false; private Plugin pluginClassInstance; public string PluginName { get; private set; } public string PluginFolderPath { get; private set; } - private bool stop = false; public event Action PluginLoaded; @@ -59,7 +57,7 @@ namespace DesktopMagic System.Timers.Timer t = new System.Timers.Timer(); t.Interval = 100; - t.Elapsed += Elapsed; + t.Elapsed += UpdateTimer_Elapsed; t.Start(); PluginName = pluginName; @@ -95,7 +93,7 @@ namespace DesktopMagic ValueTimer_Elapsed(valueTimer, null); } - private void Elapsed(object sender, ElapsedEventArgs e) + private void UpdateTimer_Elapsed(object sender, ElapsedEventArgs e) { Dispatcher.Invoke(() => { diff --git a/src/DesktopMagic/Plugin/SettingElement.cs b/src/DesktopMagic/Plugins/SettingElement.cs similarity index 73% rename from src/DesktopMagic/Plugin/SettingElement.cs rename to src/DesktopMagic/Plugins/SettingElement.cs index 315c659..37c9898 100644 --- a/src/DesktopMagic/Plugin/SettingElement.cs +++ b/src/DesktopMagic/Plugins/SettingElement.cs @@ -1,11 +1,6 @@ using DesktopMagicPluginAPI.Inputs; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -namespace DesktopMagic +namespace DesktopMagic.Plugins { internal class SettingElement { diff --git a/src/DesktopMagic/Plugins/Theme.cs b/src/DesktopMagic/Plugins/Theme.cs new file mode 100644 index 0000000..08c60cb --- /dev/null +++ b/src/DesktopMagic/Plugins/Theme.cs @@ -0,0 +1,18 @@ +using DesktopMagicPluginAPI; + +using System.Drawing; + +namespace DesktopMagic.Plugins +{ + internal class Theme : ITheme + { + public Color PrimaryColor { get; internal set; } = Color.White; + + public Color SecondaryColor { get; internal set; } = Color.White; + + public string Font { get; internal set; } = "Segoe UI"; + + public System.Windows.Media.Brush PrimaryBrush { get; set; } = System.Windows.Media.Brushes.White; + public System.Windows.Media.Brush SecondaryBrush { get; set; } = System.Windows.Media.Brushes.White; + } +} \ No newline at end of file diff --git a/src/DesktopMagic/credentials.json b/src/DesktopMagic/credentials.json deleted file mode 100644 index c74bd58..0000000 --- a/src/DesktopMagic/credentials.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "installed": { - "client_id": "347834359081-0cgj2l2f6a11m25dckg9beuvsclfsd8b.apps.googleusercontent.com", - "project_id": "helfer-1600602266879", - "auth_uri": "https://accounts.google.com/o/oauth2/auth", - "token_uri": "https://oauth2.googleapis.com/token", - "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", - "client_secret": "IlzL9Hh_AycZ5qOTFDIGmF6w", - "redirect_uris": [ - "urn:ietf:wg:oauth:2.0:oob", - "http://localhost" - ] - } -} \ No newline at end of file diff --git a/src/DesktopMagicPlugin.Test/PluginScript.cs b/src/DesktopMagicPlugin.Test/PluginScript.cs index 9bec824..5dccb5e 100644 --- a/src/DesktopMagicPlugin.Test/PluginScript.cs +++ b/src/DesktopMagicPlugin.Test/PluginScript.cs @@ -1,11 +1,12 @@ using DesktopMagicPluginAPI; using DesktopMagicPluginAPI.Inputs; + +using System; +using System.Collections.Generic; using System.Drawing; using System.Drawing.Imaging; using System.IO; -using System.Collections.Generic; using System.Threading.Tasks; -using System; namespace DesktopMagicPlugin.Test { @@ -71,12 +72,16 @@ namespace DesktopMagicPlugin.Test public override Bitmap Main() { if (bitmaps.Count == 0) + { return new Bitmap(1, 1); + } frameCount++; if (frameCount >= bitmaps.Count) + { frameCount = 0; + } return bitmaps[frameCount]; } diff --git a/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.md b/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.md index 18e28ce..83e995d 100644 --- a/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.md +++ b/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.md @@ -28,9 +28,14 @@ - [Font](#P-DesktopMagicPluginAPI-IPluginData-Font 'DesktopMagicPluginAPI.IPluginData.Font') - [PluginName](#P-DesktopMagicPluginAPI-IPluginData-PluginName 'DesktopMagicPluginAPI.IPluginData.PluginName') - [PluginPath](#P-DesktopMagicPluginAPI-IPluginData-PluginPath 'DesktopMagicPluginAPI.IPluginData.PluginPath') + - [Theme](#P-DesktopMagicPluginAPI-IPluginData-Theme 'DesktopMagicPluginAPI.IPluginData.Theme') - [WindowPosition](#P-DesktopMagicPluginAPI-IPluginData-WindowPosition 'DesktopMagicPluginAPI.IPluginData.WindowPosition') - [WindowSize](#P-DesktopMagicPluginAPI-IPluginData-WindowSize 'DesktopMagicPluginAPI.IPluginData.WindowSize') - [UpdateWindow()](#M-DesktopMagicPluginAPI-IPluginData-UpdateWindow 'DesktopMagicPluginAPI.IPluginData.UpdateWindow') +- [ITheme](#T-DesktopMagicPluginAPI-ITheme 'DesktopMagicPluginAPI.ITheme') + - [Font](#P-DesktopMagicPluginAPI-ITheme-Font 'DesktopMagicPluginAPI.ITheme.Font') + - [PrimaryColor](#P-DesktopMagicPluginAPI-ITheme-PrimaryColor 'DesktopMagicPluginAPI.ITheme.PrimaryColor') + - [SecondaryColor](#P-DesktopMagicPluginAPI-ITheme-SecondaryColor 'DesktopMagicPluginAPI.ITheme.SecondaryColor') - [IntegerUpDown](#T-DesktopMagicPluginAPI-Inputs-IntegerUpDown 'DesktopMagicPluginAPI.Inputs.IntegerUpDown') - [#ctor(min,max,value)](#M-DesktopMagicPluginAPI-Inputs-IntegerUpDown-#ctor-System-Int32,System-Int32,System-Int32- 'DesktopMagicPluginAPI.Inputs.IntegerUpDown.#ctor(System.Int32,System.Int32,System.Int32)') - [Maximum](#P-DesktopMagicPluginAPI-Inputs-IntegerUpDown-Maximum 'DesktopMagicPluginAPI.Inputs.IntegerUpDown.Maximum') @@ -323,14 +328,14 @@ Defines properties and methods that provide information about the main applicati ##### Summary -Gets the color of the main application. +Gets the current color of the main application. ### Font `property` ##### Summary -Gets the font of the main application. +Gets the current font of the main application. ### PluginName `property` @@ -346,6 +351,13 @@ Gets the name of the plugin. Gets the path of the parent directory of the plugin. + +### Theme `property` + +##### Summary + +Gets the current theme setting of the main application. + ### WindowPosition `property` @@ -371,6 +383,38 @@ Updates the plugin window. This method has no parameters. + +## ITheme `type` + +##### Namespace + +DesktopMagicPluginAPI + +##### Summary + +The theme settings of the main application. + + +### Font `property` + +##### Summary + +Gets the font of the main application. + + +### PrimaryColor `property` + +##### Summary + +Gets the primary color of the main application. + + +### SecondaryColor `property` + +##### Summary + +Gets the secondary color of the main application. + ## IntegerUpDown `type` @@ -588,7 +632,7 @@ Occurs when the user rotates the mouse wheel while the mouse pointer is over thi ##### Summary -Occurs once when the pugin gets activated. +Occurs once when the plugin gets activated. ##### Parameters diff --git a/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.xml b/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.xml index 40dd348..a449dab 100644 --- a/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.xml +++ b/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.xml @@ -283,12 +283,17 @@ - Gets the font of the main application. + Gets the current font of the main application. - Gets the color of the main application. + Gets the current color of the main application. + + + + + Gets the current theme setting of the main application. @@ -316,6 +321,26 @@ Updates the plugin window. + + + The theme settings of the main application. + + + + + Gets the primary color of the main application. + + + + + Gets the secondary color of the main application. + + + + + Gets the font of the main application. + + The plugin class. @@ -338,7 +363,7 @@ - Occurs once when the pugin gets activated. + Occurs once when the plugin gets activated. diff --git a/src/DesktopMagicPluginAPI/IPluginData.cs b/src/DesktopMagicPluginAPI/IPluginData.cs index a7c0c1e..823ac85 100644 --- a/src/DesktopMagicPluginAPI/IPluginData.cs +++ b/src/DesktopMagicPluginAPI/IPluginData.cs @@ -1,4 +1,5 @@ -using System.Drawing; +using System; +using System.Drawing; namespace DesktopMagicPluginAPI { @@ -8,15 +9,22 @@ namespace DesktopMagicPluginAPI public interface IPluginData { /// - /// Gets the font of the main application. + /// Gets the current font of the main application. /// + [Obsolete("Use the \"Theme\" property instead")] string Font { get; } /// - /// Gets the color of the main application. + /// Gets the current color of the main application. /// + [Obsolete("Use the \"Theme\" property instead")] Color Color { get; } + /// + /// Gets the current theme setting of the main application. + /// + ITheme Theme { get; } + /// /// Gets the window size of the plugin window. /// diff --git a/src/DesktopMagicPluginAPI/ITheme.cs b/src/DesktopMagicPluginAPI/ITheme.cs new file mode 100644 index 0000000..007c9ca --- /dev/null +++ b/src/DesktopMagicPluginAPI/ITheme.cs @@ -0,0 +1,25 @@ +using System.Drawing; + +namespace DesktopMagicPluginAPI +{ + /// + /// The theme settings of the main application. + /// + public interface ITheme + { + /// + /// Gets the primary color of the main application. + /// + Color PrimaryColor { get; } + + /// + /// Gets the secondary color of the main application. + /// + Color SecondaryColor { get; } + + /// + /// Gets the font of the main application. + /// + string Font { get; } + } +} \ No newline at end of file diff --git a/src/DesktopMagicPluginAPI/Plugin.cs b/src/DesktopMagicPluginAPI/Plugin.cs index d34ceaa..5c0f235 100644 --- a/src/DesktopMagicPluginAPI/Plugin.cs +++ b/src/DesktopMagicPluginAPI/Plugin.cs @@ -43,7 +43,7 @@ namespace DesktopMagicPluginAPI public virtual RenderQuality RenderQuality { get; set; } = RenderQuality.High; /// - /// Occurs once when the pugin gets activated. + /// Occurs once when the plugin gets activated. /// public virtual void Start() {