From 8f650ac35a60b8aa0c180996e35a6f706b7f37cd Mon Sep 17 00:00:00 2001 From: Stone-Red-Code <56473591+Stone-Red-Code@users.noreply.github.com> Date: Wed, 27 Oct 2021 22:01:20 +0200 Subject: [PATCH] - Add Corner Radius option - Improved API documentation - Fix updater check time - Fix logging --- src/DesktopMagic/App.xaml.cs | 4 +- .../BuiltInWindowElements/CpuUsageWindow.xaml | 8 +- .../CpuUsageWindow.xaml.cs | 11 +- .../BuiltInWindowElements/DateWindow.xaml | 9 +- .../BuiltInWindowElements/DateWindow.xaml.cs | 5 +- .../MusicVisualizerWindow.xaml | 12 +- .../MusicVisualizerWindow.xaml.cs | 4 +- .../BuiltInWindowElements/TimeWindow.xaml | 6 +- .../BuiltInWindowElements/TimeWindow.xaml.cs | 4 +- .../Helpers/SettingElementGenerator.cs | 208 +++++++++++++ src/DesktopMagic/MainWindow.xaml | 55 ++-- src/DesktopMagic/MainWindow.xaml.cs | 280 ++++-------------- src/DesktopMagic/Plugins/PluginData.cs | 2 +- src/DesktopMagic/Plugins/PluginWindow.xaml | 11 +- src/DesktopMagic/Plugins/PluginWindow.xaml.cs | 4 +- src/DesktopMagic/Plugins/Theme.cs | 5 +- .../DesktopMagicPluginAPI.md | 20 +- .../DesktopMagicPluginAPI.xml | 17 +- src/DesktopMagicPluginAPI/IPluginData.cs | 6 +- src/DesktopMagicPluginAPI/ITheme.cs | 13 +- 20 files changed, 394 insertions(+), 290 deletions(-) create mode 100644 src/DesktopMagic/Helpers/SettingElementGenerator.cs diff --git a/src/DesktopMagic/App.xaml.cs b/src/DesktopMagic/App.xaml.cs index 3bfd725..afca6ea 100644 --- a/src/DesktopMagic/App.xaml.cs +++ b/src/DesktopMagic/App.xaml.cs @@ -18,7 +18,7 @@ namespace DesktopMagic #if DEBUG private readonly Updater updater = new Updater(TimeSpan.FromDays(1), "https://raw.githubusercontent.com/Stone-Red-Code/DesktopMagic/develop/update/updateInfo.json"); #else - private readonly Updater updater = new Updater(TimeSpan.FromHours(1), "https://raw.githubusercontent.com/Stone-Red-Code/DesktopMagic/main/update/updateInfo.json"); + private readonly Updater updater = new Updater(TimeSpan.FromDays(1), "https://raw.githubusercontent.com/Stone-Red-Code/DesktopMagic/main/update/updateInfo.json"); #endif public const string AppName = "Desktop Magic"; @@ -104,7 +104,7 @@ namespace DesktopMagic InfoConfig = new OutputConfig() { Color = ConsoleColor.White, - LogTarget = LogTarget.Console | LogTarget.File, + LogTarget = LogTarget.DebugConsole | LogTarget.File, FilePath = logFilePath }, DebugConfig = new OutputConfig() diff --git a/src/DesktopMagic/BuiltInWindowElements/CpuUsageWindow.xaml b/src/DesktopMagic/BuiltInWindowElements/CpuUsageWindow.xaml index 6a5cc4a..59cad89 100644 --- a/src/DesktopMagic/BuiltInWindowElements/CpuUsageWindow.xaml +++ b/src/DesktopMagic/BuiltInWindowElements/CpuUsageWindow.xaml @@ -14,10 +14,14 @@ x:Name="window"> - + + + + + - + diff --git a/src/DesktopMagic/BuiltInWindowElements/CpuUsageWindow.xaml.cs b/src/DesktopMagic/BuiltInWindowElements/CpuUsageWindow.xaml.cs index df25a92..1ba4cc1 100644 --- a/src/DesktopMagic/BuiltInWindowElements/CpuUsageWindow.xaml.cs +++ b/src/DesktopMagic/BuiltInWindowElements/CpuUsageWindow.xaml.cs @@ -87,12 +87,13 @@ namespace DesktopMagic ResizeMode = ResizeMode.NoResize; } - textBlock.Background = MainWindow.Theme.BackgroundBrush; + rectangleGeometry.Rect = new Rect(0, 0, border.ActualWidth, border.ActualHeight); + border.Background = MainWindow.Theme.BackgroundBrush; + border.CornerRadius = new CornerRadius(MainWindow.Theme.CornerRadius); textBlock.FontFamily = new FontFamily(MainWindow.Theme.Font); textBlock.Foreground = MainWindow.Theme.PrimaryBrush; - valuetextBlock.Background = MainWindow.Theme.BackgroundBrush; - valuetextBlock.FontFamily = new FontFamily(MainWindow.Theme.Font); - valuetextBlock.Foreground = MainWindow.Theme.PrimaryBrush; + valueTextBlock.FontFamily = new FontFamily(MainWindow.Theme.Font); + valueTextBlock.Foreground = MainWindow.Theme.PrimaryBrush; ClculateWidth(); }); @@ -103,7 +104,7 @@ namespace DesktopMagic string cpuUsage = GetCpuUsage(); Dispatcher.Invoke(() => { - valuetextBlock.Text = cpuUsage; + valueTextBlock.Text = cpuUsage; }); } diff --git a/src/DesktopMagic/BuiltInWindowElements/DateWindow.xaml b/src/DesktopMagic/BuiltInWindowElements/DateWindow.xaml index 74d72b4..432daf9 100644 --- a/src/DesktopMagic/BuiltInWindowElements/DateWindow.xaml +++ b/src/DesktopMagic/BuiltInWindowElements/DateWindow.xaml @@ -13,8 +13,13 @@ x:Name="window"> - - + + + + + + + diff --git a/src/DesktopMagic/BuiltInWindowElements/DateWindow.xaml.cs b/src/DesktopMagic/BuiltInWindowElements/DateWindow.xaml.cs index 07ef217..71fe0d9 100644 --- a/src/DesktopMagic/BuiltInWindowElements/DateWindow.xaml.cs +++ b/src/DesktopMagic/BuiltInWindowElements/DateWindow.xaml.cs @@ -69,10 +69,13 @@ namespace DesktopMagic WindowPos.SetIsLocked(this, true); ResizeMode = ResizeMode.NoResize; } + + rectangleGeometry.Rect = new Rect(0, 0, border.ActualWidth, border.ActualHeight); + border.Background = MainWindow.Theme.BackgroundBrush; + border.CornerRadius = new CornerRadius(MainWindow.Theme.CornerRadius); textBlock.FontFamily = new FontFamily(MainWindow.Theme.Font); textBlock.Foreground = MainWindow.Theme.PrimaryBrush; textBlock.Text = DateTime.Now.ToLongDateString(); - textBlock.Background = MainWindow.Theme.BackgroundBrush; }); } diff --git a/src/DesktopMagic/BuiltInWindowElements/MusicVisualizerWindow.xaml b/src/DesktopMagic/BuiltInWindowElements/MusicVisualizerWindow.xaml index 99b632e..bca74e6 100644 --- a/src/DesktopMagic/BuiltInWindowElements/MusicVisualizerWindow.xaml +++ b/src/DesktopMagic/BuiltInWindowElements/MusicVisualizerWindow.xaml @@ -11,16 +11,18 @@ AllowsTransparency="True" LocationChanged="Window_LocationChanged" SizeChanged="Window_SizeChanged" - x:Name="window"> + x:Name="window"> - - - - + + + + + + \ No newline at end of file diff --git a/src/DesktopMagic/BuiltInWindowElements/MusicVisualizerWindow.xaml.cs b/src/DesktopMagic/BuiltInWindowElements/MusicVisualizerWindow.xaml.cs index 12bd3e3..82e1754 100644 --- a/src/DesktopMagic/BuiltInWindowElements/MusicVisualizerWindow.xaml.cs +++ b/src/DesktopMagic/BuiltInWindowElements/MusicVisualizerWindow.xaml.cs @@ -102,7 +102,9 @@ namespace DesktopMagic ResizeMode = ResizeMode.NoResize; } calculate = IsLoaded; - backgroundGrid.Background = MainWindow.Theme.BackgroundBrush; + rectangleGeometry.Rect = new Rect(0, 0, border.ActualWidth, border.ActualHeight); + border.CornerRadius = new CornerRadius(MainWindow.Theme.CornerRadius); + border.Background = MainWindow.Theme.BackgroundBrush; }); } diff --git a/src/DesktopMagic/BuiltInWindowElements/TimeWindow.xaml b/src/DesktopMagic/BuiltInWindowElements/TimeWindow.xaml index c69bf64..b70eedd 100644 --- a/src/DesktopMagic/BuiltInWindowElements/TimeWindow.xaml +++ b/src/DesktopMagic/BuiltInWindowElements/TimeWindow.xaml @@ -13,7 +13,11 @@ x:Name="window"> - + + + + + diff --git a/src/DesktopMagic/BuiltInWindowElements/TimeWindow.xaml.cs b/src/DesktopMagic/BuiltInWindowElements/TimeWindow.xaml.cs index 363184f..edc65b9 100644 --- a/src/DesktopMagic/BuiltInWindowElements/TimeWindow.xaml.cs +++ b/src/DesktopMagic/BuiltInWindowElements/TimeWindow.xaml.cs @@ -72,7 +72,9 @@ namespace DesktopMagic ResizeMode = ResizeMode.NoResize; } - textBlock.Background = MainWindow.Theme.BackgroundBrush; + rectangleGeometry.Rect = new Rect(0, 0, border.ActualWidth, border.ActualHeight); + border.Background = MainWindow.Theme.BackgroundBrush; + border.CornerRadius = new CornerRadius(MainWindow.Theme.CornerRadius); textBlock.FontFamily = new FontFamily(MainWindow.Theme.Font); textBlock.Foreground = MainWindow.Theme.PrimaryBrush; //textBlock.Text = DateTime.Now.ToString("hh:mm:ss tt"); diff --git a/src/DesktopMagic/Helpers/SettingElementGenerator.cs b/src/DesktopMagic/Helpers/SettingElementGenerator.cs new file mode 100644 index 0000000..50248ef --- /dev/null +++ b/src/DesktopMagic/Helpers/SettingElementGenerator.cs @@ -0,0 +1,208 @@ +using DesktopMagic.Plugins; + +using System; +using System.Windows; +using System.Windows.Controls; + +namespace DesktopMagic.Helpers +{ + internal class SettingElementGenerator + { + private readonly ComboBox optionsComboBox; + + public SettingElementGenerator(ComboBox optionsComboBox) + { + this.optionsComboBox = optionsComboBox; + } + + public void Generate(SettingElement settingElement, DockPanel dockPanel, TextBlock textBlock) + { + dockPanel.UpdateLayout(); + textBlock.UpdateLayout(); + if (settingElement.Element is DesktopMagicPluginAPI.Inputs.Label eLabel) + { + textBlock.Text = eLabel.Value; + textBlock.Margin = new Thickness(0, 5, 3, 0); + textBlock.HorizontalAlignment = HorizontalAlignment.Stretch; + textBlock.TextWrapping = TextWrapping.WrapWithOverflow; + + if (eLabel.Bold) + { + textBlock.FontWeight = FontWeights.Bold; + } + eLabel.OnValueChanged += () => + { + textBlock.Dispatcher.Invoke(() => + { + textBlock.Text = eLabel.Value; + }); + }; + } + else if (settingElement.Element is DesktopMagicPluginAPI.Inputs.Button eButton) + { + Button button = new() + { + Content = eButton.Value, + FontSize = 10, + Height = 20, + Margin = new Thickness(0, 10, 0, 10), + Padding = new Thickness(0), + VerticalAlignment = VerticalAlignment.Center, + HorizontalAlignment = HorizontalAlignment.Stretch + }; + button.Click += (_s, _e) => + { + try + { + eButton.Click(); + } + catch (Exception ex) + { + DisplayException(ex.Message); + } + }; + eButton.OnValueChanged += () => + { + button.Dispatcher.Invoke(() => + { + button.Content = eButton.Value; + }); + }; + + _ = dockPanel.Children.Add(button); + } + else if (settingElement.Element is DesktopMagicPluginAPI.Inputs.CheckBox eCheckBox) + { + CheckBox checkBox = new() + { + IsChecked = eCheckBox.Value, + Style = (Style)dockPanel.FindResource("MaterialDesignDarkCheckBox"), + VerticalAlignment = VerticalAlignment.Center, + HorizontalAlignment = HorizontalAlignment.Stretch + }; + checkBox.Click += (_s, _e) => + { + try + { + eCheckBox.Value = checkBox.IsChecked.GetValueOrDefault(); + } + catch (Exception ex) + { + DisplayException(ex.Message); + } + }; + eCheckBox.OnValueChanged += () => + { + checkBox.Dispatcher.Invoke(() => + { + checkBox.IsChecked = eCheckBox.Value; + }); + }; + + _ = dockPanel.Children.Add(checkBox); + } + else if (settingElement.Element is DesktopMagicPluginAPI.Inputs.TextBox eTextBox) + { + TextBox textBox = new() + { + Text = eTextBox.Value, + TextWrapping = TextWrapping.Wrap, + VerticalAlignment = VerticalAlignment.Center, + HorizontalAlignment = HorizontalAlignment.Stretch + }; + textBox.TextChanged += (_s, _e) => + { + try + { + eTextBox.Value = textBox.Text; + } + catch (Exception ex) + { + DisplayException(ex.Message); + } + }; + eTextBox.OnValueChanged += () => + { + textBox.Dispatcher.Invoke(() => + { + textBox.Text = eTextBox.Value; + }); + }; + _ = dockPanel.Children.Add(textBox); + } + else if (settingElement.Element is DesktopMagicPluginAPI.Inputs.IntegerUpDown eIntegerUpDown) + { + Xceed.Wpf.Toolkit.IntegerUpDown integerUpDown = new() + { + Value = eIntegerUpDown.Value, + Minimum = eIntegerUpDown.Minimum, + Maximum = eIntegerUpDown.Maximum, + VerticalAlignment = VerticalAlignment.Center, + HorizontalAlignment = HorizontalAlignment.Stretch + }; + integerUpDown.ValueChanged += (_s, _e) => + { + try + { + eIntegerUpDown.Value = integerUpDown.Value.GetValueOrDefault(); + } + catch (Exception ex) + { + DisplayException(ex.Message); + } + }; + eIntegerUpDown.OnValueChanged += () => + { + integerUpDown.Dispatcher.Invoke(() => + { + integerUpDown.Value = eIntegerUpDown.Value; + }); + }; + _ = dockPanel.Children.Add(integerUpDown); + } + else if (settingElement.Element is DesktopMagicPluginAPI.Inputs.Slider eSlider) + { + Slider slider = new() + { + Value = eSlider.Value, + Minimum = eSlider.Minimum, + Maximum = eSlider.Maximum, + TickFrequency = 1, + IsSnapToTickEnabled = true, + VerticalAlignment = VerticalAlignment.Center, + HorizontalAlignment = HorizontalAlignment.Stretch + }; + slider.ValueChanged += (_s, _e) => + { + try + { + eSlider.Value = slider.Value; + } + catch (Exception ex) + { + DisplayException(ex.Message); + } + }; + eSlider.OnValueChanged += () => + { + slider.Dispatcher.Invoke(() => + { + slider.Value = eSlider.Value; + }); + }; + + _ = dockPanel.Children.Add(slider); + } + } + + private void DisplayException(string message) + { + App.Logger.Log(message, "PluginInput"); + _ = MessageBox.Show("File execution error:\n" + message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); + int index = MainWindow.WindowNames.IndexOf(((Tuple)optionsComboBox.SelectedItem).Item1.ToString()); + + PluginWindow window = MainWindow.Windows[index] as PluginWindow; + window?.Exit(); + } + } +} \ No newline at end of file diff --git a/src/DesktopMagic/MainWindow.xaml b/src/DesktopMagic/MainWindow.xaml index 5b7bb31..11eeeed 100644 --- a/src/DesktopMagic/MainWindow.xaml +++ b/src/DesktopMagic/MainWindow.xaml @@ -46,7 +46,7 @@ - + @@ -62,7 +62,7 @@ @@ -74,23 +74,36 @@ - - - - + + + + + + + + + + + + + + + + + + + + + + + +