From 36e09acd0e844a98d03f50eec7b6af7e7b52a355 Mon Sep 17 00:00:00 2001 From: Stone-Red-Code <56473591+Stone-Red-Code@users.noreply.github.com> Date: Sat, 11 Sep 2021 14:24:27 +0200 Subject: [PATCH 01/18] - Add MouseButton enum to plugin API to determine which mouse button was pressed - Add some missing documentation --- src/DesktopMagic/Plugin/PluginWindow.xaml.cs | 27 ++++++++-- src/DesktopMagicPlugin.Test/PluginScript.cs | 42 +++------------ .../DesktopMagicPluginAPI.csproj | 10 ++-- .../DesktopMagicPluginAPI.md | 51 ++++++++++++++++--- .../DesktopMagicPluginAPI.xml | 31 +++++++++-- src/DesktopMagicPluginAPI/IPluginData.cs | 4 +- .../Inputs/MouseButton.cs | 29 +++++++++++ src/DesktopMagicPluginAPI/Plugin.cs | 10 ++-- 8 files changed, 145 insertions(+), 59 deletions(-) create mode 100644 src/DesktopMagicPluginAPI/Inputs/MouseButton.cs diff --git a/src/DesktopMagic/Plugin/PluginWindow.xaml.cs b/src/DesktopMagic/Plugin/PluginWindow.xaml.cs index fee07c4..cc63216 100644 --- a/src/DesktopMagic/Plugin/PluginWindow.xaml.cs +++ b/src/DesktopMagic/Plugin/PluginWindow.xaml.cs @@ -210,7 +210,7 @@ namespace DesktopMagic private void LoadOptions(object instance) { Debug.WriteLine(instance.GetType().FullName); - FieldInfo[] props = instance.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField); + FieldInfo[] props = instance.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.GetField); List settingElements = new List(); foreach (FieldInfo prop in props) @@ -330,7 +330,26 @@ namespace DesktopMagic BitmapSource bitmapImage = (BitmapSource)imageSource; double pixelMousePositionX = e.GetPosition(image).X * bitmapImage.PixelWidth / image.ActualHeight; double pixelMousePositionY = e.GetPosition(image).Y * bitmapImage.PixelHeight / image.ActualHeight; - Clicked(new System.Drawing.Point((int)pixelMousePositionX, (int)pixelMousePositionY)); + + MouseButton mouseButton; + + switch (e.ChangedButton) + { + case System.Windows.Input.MouseButton.Left: + mouseButton = MouseButton.Left; + break; + + case System.Windows.Input.MouseButton.Middle: + mouseButton = MouseButton.Middle; + break; + + case System.Windows.Input.MouseButton.Right: + mouseButton = MouseButton.Right; + break; + + default: return; + }; + Clicked(new System.Drawing.Point((int)pixelMousePositionX, (int)pixelMousePositionY), mouseButton); } private void Window_MouseMove(object sender, System.Windows.Input.MouseEventArgs e) @@ -346,9 +365,9 @@ namespace DesktopMagic #region Plugin Methods - private void Clicked(System.Drawing.Point positon) + private void Clicked(System.Drawing.Point positon, MouseButton mouseButton) { - pluginClassInstance.OnMouseClick(positon); + pluginClassInstance.OnMouseClick(positon, mouseButton); } private void Moved(System.Drawing.Point positon) diff --git a/src/DesktopMagicPlugin.Test/PluginScript.cs b/src/DesktopMagicPlugin.Test/PluginScript.cs index 090bdcc..b63bc08 100644 --- a/src/DesktopMagicPlugin.Test/PluginScript.cs +++ b/src/DesktopMagicPlugin.Test/PluginScript.cs @@ -1,54 +1,28 @@ using DesktopMagicPluginAPI; using DesktopMagicPluginAPI.Inputs; using System.Drawing; -using System.Drawing.Imaging; -using System.Drawing.Drawing2D; -using System.IO; -using System.Collections.Generic; +using System.Diagnostics; namespace DesktopMagicPlugin.Test { public class GifPlugin : Plugin { [Element("Gif path:")] - private TextBox input = new TextBox(""); - - private List bitmaps = new List(); + public TextBox input = new TextBox(""); public override int UpdateInterval { get; set; } = 100; - private int frameCount = -1; - public GifPlugin() + public override void OnMouseClick(Point position, MouseButton mouseButton) { - input.OnValueChanged += Input_OnValueChanged; - } - - private void Input_OnValueChanged() - { - if (File.Exists(input.Value)) - { - Image gif = Image.FromFile(input.Value); - bitmaps.Clear(); - for (int i = 0; i < gif.GetFrameCount(FrameDimension.Time); i++) - { - gif.SelectActiveFrame(FrameDimension.Time, i); - - bitmaps.Add(new Bitmap(gif)); - } - } + Debug.WriteLine(position + " | " + mouseButton); } public override Bitmap Main() { - if (bitmaps.Count == 0) - return new Bitmap(1, 1); - - frameCount++; - - if (frameCount >= bitmaps.Count) - frameCount = 0; - - return bitmaps[frameCount]; + Bitmap bmp = new Bitmap(100, 100); + using Graphics graphics = Graphics.FromImage(bmp); + graphics.Clear(Color.Red); + return bmp; } } } \ No newline at end of file diff --git a/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.csproj b/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.csproj index b6dbfaf..b428bd2 100644 --- a/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.csproj +++ b/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.csproj @@ -4,19 +4,23 @@ net5.0 Stone_Red Stone_Red - 0.0.0.2 + 0.0.0.4 https://github.com/Stone-Red-Code/DesktopMagic LICENSE true - 0.0.0.2 + 0.0.0.4 - 0.0.0.2 + 0.0.0.4 C:\Users\David\Programmieren\DesktopMagic\src\DesktopMagicPluginAPI\DesktopMagicPluginAPI.xml + + C:\Users\David\Programmieren\DesktopMagic\src\DesktopMagicPluginAPI\DesktopMagicPluginAPI.xml + + diff --git a/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.md b/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.md index 876a43e..a085413 100644 --- a/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.md +++ b/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.md @@ -38,11 +38,15 @@ - [#ctor(value,bold)](#M-DesktopMagicPluginAPI-Inputs-Label-#ctor-System-String,System-Boolean- 'DesktopMagicPluginAPI.Inputs.Label.#ctor(System.String,System.Boolean)') - [Bold](#P-DesktopMagicPluginAPI-Inputs-Label-Bold 'DesktopMagicPluginAPI.Inputs.Label.Bold') - [Value](#P-DesktopMagicPluginAPI-Inputs-Label-Value 'DesktopMagicPluginAPI.Inputs.Label.Value') +- [MouseButton](#T-DesktopMagicPluginAPI-Inputs-MouseButton 'DesktopMagicPluginAPI.Inputs.MouseButton') + - [Left](#F-DesktopMagicPluginAPI-Inputs-MouseButton-Left 'DesktopMagicPluginAPI.Inputs.MouseButton.Left') + - [Middle](#F-DesktopMagicPluginAPI-Inputs-MouseButton-Middle 'DesktopMagicPluginAPI.Inputs.MouseButton.Middle') + - [Right](#F-DesktopMagicPluginAPI-Inputs-MouseButton-Right 'DesktopMagicPluginAPI.Inputs.MouseButton.Right') - [Plugin](#T-DesktopMagicPluginAPI-Plugin 'DesktopMagicPluginAPI.Plugin') - [Application](#P-DesktopMagicPluginAPI-Plugin-Application 'DesktopMagicPluginAPI.Plugin.Application') - [UpdateInterval](#P-DesktopMagicPluginAPI-Plugin-UpdateInterval 'DesktopMagicPluginAPI.Plugin.UpdateInterval') - [Main()](#M-DesktopMagicPluginAPI-Plugin-Main 'DesktopMagicPluginAPI.Plugin.Main') - - [OnMouseClick(position)](#M-DesktopMagicPluginAPI-Plugin-OnMouseClick-System-Drawing-Point- 'DesktopMagicPluginAPI.Plugin.OnMouseClick(System.Drawing.Point)') + - [OnMouseClick(position,mouseButton)](#M-DesktopMagicPluginAPI-Plugin-OnMouseClick-System-Drawing-Point,DesktopMagicPluginAPI-Inputs-MouseButton- 'DesktopMagicPluginAPI.Plugin.OnMouseClick(System.Drawing.Point,DesktopMagicPluginAPI.Inputs.MouseButton)') - [OnMouseMove(position)](#M-DesktopMagicPluginAPI-Plugin-OnMouseMove-System-Drawing-Point- 'DesktopMagicPluginAPI.Plugin.OnMouseMove(System.Drawing.Point)') - [Start()](#M-DesktopMagicPluginAPI-Plugin-Start 'DesktopMagicPluginAPI.Plugin.Start') - [Slider](#T-DesktopMagicPluginAPI-Inputs-Slider 'DesktopMagicPluginAPI.Inputs.Slider') @@ -325,14 +329,14 @@ Gets the font of the main application. ##### Summary -Gets the window position of the main application. +Gets the window position of the plugin window. ### WindowSize `property` ##### Summary -Gets the window size of the main application. +Gets the window size of the plugin window. ### UpdateWindow() `method` @@ -437,6 +441,38 @@ Gets or set a value indicating whether the content of the [Label](#T-DesktopMagi Gets or sets the text associated with this [Label](#T-DesktopMagicPluginAPI-Inputs-Label 'DesktopMagicPluginAPI.Inputs.Label'). + +## MouseButton `type` + +##### Namespace + +DesktopMagicPluginAPI.Inputs + +##### Summary + +Mouse Buttons + + +### Left `constants` + +##### Summary + +The left mouse button. + + +### Middle `constants` + +##### Summary + +The middle mouse button. + + +### Right `constants` + +##### Summary + +The right mouse button. + ## Plugin `type` @@ -477,8 +513,8 @@ Occurs when the [UpdateInterval](#P-DesktopMagicPluginAPI-Plugin-UpdateInterval This method has no parameters. - -### OnMouseClick(position) `method` + +### OnMouseClick(position,mouseButton) `method` ##### Summary @@ -488,7 +524,8 @@ Occurs when the window is clicked by the mouse. | Name | Type | Description | | ---- | ---- | ----------- | -| position | [System.Drawing.Point](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Point 'System.Drawing.Point') | | +| position | [System.Drawing.Point](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Point 'System.Drawing.Point') | The x- and y-coordinates of the mouse pointer position relative to the plugin window. | +| mouseButton | [DesktopMagicPluginAPI.Inputs.MouseButton](#T-DesktopMagicPluginAPI-Inputs-MouseButton 'DesktopMagicPluginAPI.Inputs.MouseButton') | Gets the button associated with the event. | ### OnMouseMove(position) `method` @@ -501,7 +538,7 @@ Occurs when the mouse pointer is moved over the control. | Name | Type | Description | | ---- | ---- | ----------- | -| position | [System.Drawing.Point](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Point 'System.Drawing.Point') | | +| position | [System.Drawing.Point](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Point 'System.Drawing.Point') | The x- and y-coordinates of the mouse pointer position relative to the plugin window. | ### Start() `method` diff --git a/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.xml b/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.xml index 147c378..2b97ae5 100644 --- a/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.xml +++ b/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.xml @@ -192,6 +192,26 @@ The text associated with this A value indicating whether the content of the is bold or not. + + + Mouse Buttons + + + + + The left mouse button. + + + + + The middle mouse button. + + + + + The right mouse button. + + Represents a slider control. @@ -253,12 +273,12 @@ - Gets the window size of the main application. + Gets the window size of the plugin window. - Gets the window position of the main application. + Gets the window position of the plugin window. @@ -292,17 +312,18 @@ - + Occurs when the window is clicked by the mouse. - + The x- and y-coordinates of the mouse pointer position relative to the plugin window. + Gets the button associated with the event. Occurs when the mouse pointer is moved over the control. - + The x- and y-coordinates of the mouse pointer position relative to the plugin window. diff --git a/src/DesktopMagicPluginAPI/IPluginData.cs b/src/DesktopMagicPluginAPI/IPluginData.cs index 3b05e01..9eeef60 100644 --- a/src/DesktopMagicPluginAPI/IPluginData.cs +++ b/src/DesktopMagicPluginAPI/IPluginData.cs @@ -18,12 +18,12 @@ namespace DesktopMagicPluginAPI Color Color { get; } /// - /// Gets the window size of the main application. + /// Gets the window size of the plugin window. /// Point WindowSize { get; } /// - /// Gets the window position of the main application. + /// Gets the window position of the plugin window. /// Point WindowPosition { get; } diff --git a/src/DesktopMagicPluginAPI/Inputs/MouseButton.cs b/src/DesktopMagicPluginAPI/Inputs/MouseButton.cs new file mode 100644 index 0000000..498b38b --- /dev/null +++ b/src/DesktopMagicPluginAPI/Inputs/MouseButton.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DesktopMagicPluginAPI.Inputs +{ + /// + /// Mouse Buttons + /// + public enum MouseButton + { + /// + /// The left mouse button. + /// + Left, + + /// + /// The middle mouse button. + /// + Middle, + + /// + /// The right mouse button. + /// + Right, + } +} \ No newline at end of file diff --git a/src/DesktopMagicPluginAPI/Plugin.cs b/src/DesktopMagicPluginAPI/Plugin.cs index 0a2c345..6f141a8 100644 --- a/src/DesktopMagicPluginAPI/Plugin.cs +++ b/src/DesktopMagicPluginAPI/Plugin.cs @@ -1,4 +1,5 @@ -using System; +using DesktopMagicPluginAPI.Inputs; +using System; using System.Drawing; namespace DesktopMagicPluginAPI @@ -50,15 +51,16 @@ namespace DesktopMagicPluginAPI /// /// Occurs when the window is clicked by the mouse. /// - /// - public virtual void OnMouseClick(Point position) + /// The x- and y-coordinates of the mouse pointer position relative to the plugin window. + /// Gets the button associated with the event. + public virtual void OnMouseClick(Point position, MouseButton mouseButton) { } /// /// Occurs when the mouse pointer is moved over the control. /// - /// + /// The x- and y-coordinates of the mouse pointer position relative to the plugin window. public virtual void OnMouseMove(Point position) { } From f94f24297e5d00e3c24974d6f53c3a70dd9664db Mon Sep 17 00:00:00 2001 From: Stone-Red-Code <56473591+Stone-Red-Code@users.noreply.github.com> Date: Sat, 11 Sep 2021 17:13:02 +0200 Subject: [PATCH 02/18] - Add `OnMouseWheel` event --- src/DesktopMagic/Plugin/PluginWindow.xaml | 2 +- src/DesktopMagic/Plugin/PluginWindow.xaml.cs | 33 ++++++++++--------- .../DesktopMagicPlugin.Test.csproj | 1 + src/DesktopMagicPlugin.Test/PluginScript.cs | 4 +-- .../DesktopMagicPluginAPI.md | 17 +++++++++- .../DesktopMagicPluginAPI.xml | 9 ++++- src/DesktopMagicPluginAPI/Plugin.cs | 11 ++++++- 7 files changed, 55 insertions(+), 22 deletions(-) diff --git a/src/DesktopMagic/Plugin/PluginWindow.xaml b/src/DesktopMagic/Plugin/PluginWindow.xaml index 83e7267..d845850 100644 --- a/src/DesktopMagic/Plugin/PluginWindow.xaml +++ b/src/DesktopMagic/Plugin/PluginWindow.xaml @@ -18,7 +18,7 @@ - + diff --git a/src/DesktopMagic/Plugin/PluginWindow.xaml.cs b/src/DesktopMagic/Plugin/PluginWindow.xaml.cs index cc63216..26eb572 100644 --- a/src/DesktopMagic/Plugin/PluginWindow.xaml.cs +++ b/src/DesktopMagic/Plugin/PluginWindow.xaml.cs @@ -349,7 +349,9 @@ namespace DesktopMagic default: return; }; - Clicked(new System.Drawing.Point((int)pixelMousePositionX, (int)pixelMousePositionY), mouseButton); + + System.Drawing.Point point = new System.Drawing.Point((int)pixelMousePositionX, (int)pixelMousePositionY); + pluginClassInstance.OnMouseClick(point, mouseButton); } private void Window_MouseMove(object sender, System.Windows.Input.MouseEventArgs e) @@ -358,23 +360,22 @@ namespace DesktopMagic BitmapSource bitmapImage = (BitmapSource)imageSource; double pixelMousePositionX = e.GetPosition(image).X * bitmapImage.PixelWidth / image.ActualHeight; double pixelMousePositionY = e.GetPosition(image).Y * bitmapImage.PixelHeight / image.ActualHeight; - Moved(new System.Drawing.Point((int)pixelMousePositionX, (int)pixelMousePositionY)); + + System.Drawing.Point point = new System.Drawing.Point((int)pixelMousePositionX, (int)pixelMousePositionY); + pluginClassInstance.OnMouseMove(point); + } + + private void Window_MouseWheel(object sender, System.Windows.Input.MouseWheelEventArgs e) + { + ImageSource imageSource = image.Source; + BitmapSource bitmapImage = (BitmapSource)imageSource; + double pixelMousePositionX = e.GetPosition(image).X * bitmapImage.PixelWidth / image.ActualHeight; + double pixelMousePositionY = e.GetPosition(image).Y * bitmapImage.PixelHeight / image.ActualHeight; + + System.Drawing.Point point = new System.Drawing.Point((int)pixelMousePositionX, (int)pixelMousePositionY); + pluginClassInstance.OnMouseWheel(point, e.Delta); } #endregion Window Events - - #region Plugin Methods - - private void Clicked(System.Drawing.Point positon, MouseButton mouseButton) - { - pluginClassInstance.OnMouseClick(positon, mouseButton); - } - - private void Moved(System.Drawing.Point positon) - { - pluginClassInstance.OnMouseMove(positon); - } - - #endregion Plugin Methods } } \ No newline at end of file diff --git a/src/DesktopMagicPlugin.Test/DesktopMagicPlugin.Test.csproj b/src/DesktopMagicPlugin.Test/DesktopMagicPlugin.Test.csproj index d2240e9..19fb9b6 100644 --- a/src/DesktopMagicPlugin.Test/DesktopMagicPlugin.Test.csproj +++ b/src/DesktopMagicPlugin.Test/DesktopMagicPlugin.Test.csproj @@ -5,6 +5,7 @@ + diff --git a/src/DesktopMagicPlugin.Test/PluginScript.cs b/src/DesktopMagicPlugin.Test/PluginScript.cs index b63bc08..67a7c0d 100644 --- a/src/DesktopMagicPlugin.Test/PluginScript.cs +++ b/src/DesktopMagicPlugin.Test/PluginScript.cs @@ -12,9 +12,9 @@ namespace DesktopMagicPlugin.Test public override int UpdateInterval { get; set; } = 100; - public override void OnMouseClick(Point position, MouseButton mouseButton) + public override void OnMouseWheel(Point position, int delta) { - Debug.WriteLine(position + " | " + mouseButton); + Debug.WriteLine(position + " | " + delta); } public override Bitmap Main() diff --git a/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.md b/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.md index a085413..90b9321 100644 --- a/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.md +++ b/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.md @@ -48,6 +48,7 @@ - [Main()](#M-DesktopMagicPluginAPI-Plugin-Main 'DesktopMagicPluginAPI.Plugin.Main') - [OnMouseClick(position,mouseButton)](#M-DesktopMagicPluginAPI-Plugin-OnMouseClick-System-Drawing-Point,DesktopMagicPluginAPI-Inputs-MouseButton- 'DesktopMagicPluginAPI.Plugin.OnMouseClick(System.Drawing.Point,DesktopMagicPluginAPI.Inputs.MouseButton)') - [OnMouseMove(position)](#M-DesktopMagicPluginAPI-Plugin-OnMouseMove-System-Drawing-Point- 'DesktopMagicPluginAPI.Plugin.OnMouseMove(System.Drawing.Point)') + - [OnMouseWheel(position,Delta)](#M-DesktopMagicPluginAPI-Plugin-OnMouseWheel-System-Drawing-Point,System-Int32- 'DesktopMagicPluginAPI.Plugin.OnMouseWheel(System.Drawing.Point,System.Int32)') - [Start()](#M-DesktopMagicPluginAPI-Plugin-Start 'DesktopMagicPluginAPI.Plugin.Start') - [Slider](#T-DesktopMagicPluginAPI-Inputs-Slider 'DesktopMagicPluginAPI.Inputs.Slider') - [#ctor(min,max,value)](#M-DesktopMagicPluginAPI-Inputs-Slider-#ctor-System-Double,System-Double,System-Double- 'DesktopMagicPluginAPI.Inputs.Slider.#ctor(System.Double,System.Double,System.Double)') @@ -525,7 +526,7 @@ Occurs when the window is clicked by the mouse. | Name | Type | Description | | ---- | ---- | ----------- | | position | [System.Drawing.Point](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Point 'System.Drawing.Point') | The x- and y-coordinates of the mouse pointer position relative to the plugin window. | -| mouseButton | [DesktopMagicPluginAPI.Inputs.MouseButton](#T-DesktopMagicPluginAPI-Inputs-MouseButton 'DesktopMagicPluginAPI.Inputs.MouseButton') | Gets the button associated with the event. | +| mouseButton | [DesktopMagicPluginAPI.Inputs.MouseButton](#T-DesktopMagicPluginAPI-Inputs-MouseButton 'DesktopMagicPluginAPI.Inputs.MouseButton') | The button associated with the event. | ### OnMouseMove(position) `method` @@ -540,6 +541,20 @@ Occurs when the mouse pointer is moved over the control. | ---- | ---- | ----------- | | position | [System.Drawing.Point](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Point 'System.Drawing.Point') | The x- and y-coordinates of the mouse pointer position relative to the plugin window. | + +### OnMouseWheel(position,Delta) `method` + +##### Summary + +Occurs when the user rotates the mouse wheel while the mouse pointer is over this element. + +##### Parameters + +| Name | Type | Description | +| ---- | ---- | ----------- | +| position | [System.Drawing.Point](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Drawing.Point 'System.Drawing.Point') | The x- and y-coordinates of the mouse pointer position relative to the plugin window. | +| Delta | [System.Int32](http://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k:System.Int32 'System.Int32') | A value that indicates the amount that the mouse wheel has changed. | + ### Start() `method` diff --git a/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.xml b/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.xml index 2b97ae5..a02771b 100644 --- a/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.xml +++ b/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.xml @@ -317,7 +317,7 @@ Occurs when the window is clicked by the mouse. The x- and y-coordinates of the mouse pointer position relative to the plugin window. - Gets the button associated with the event. + The button associated with the event. @@ -325,5 +325,12 @@ The x- and y-coordinates of the mouse pointer position relative to the plugin window. + + + Occurs when the user rotates the mouse wheel while the mouse pointer is over this element. + + The x- and y-coordinates of the mouse pointer position relative to the plugin window. + A value that indicates the amount that the mouse wheel has changed. + diff --git a/src/DesktopMagicPluginAPI/Plugin.cs b/src/DesktopMagicPluginAPI/Plugin.cs index 6f141a8..abac60e 100644 --- a/src/DesktopMagicPluginAPI/Plugin.cs +++ b/src/DesktopMagicPluginAPI/Plugin.cs @@ -52,7 +52,7 @@ namespace DesktopMagicPluginAPI /// Occurs when the window is clicked by the mouse. /// /// The x- and y-coordinates of the mouse pointer position relative to the plugin window. - /// Gets the button associated with the event. + /// The button associated with the event. public virtual void OnMouseClick(Point position, MouseButton mouseButton) { } @@ -64,5 +64,14 @@ namespace DesktopMagicPluginAPI public virtual void OnMouseMove(Point position) { } + + /// + /// Occurs when the user rotates the mouse wheel while the mouse pointer is over this element. + /// + /// The x- and y-coordinates of the mouse pointer position relative to the plugin window. + /// A value that indicates the amount that the mouse wheel has changed. + public virtual void OnMouseWheel(Point position, int Delta) + { + } } } \ No newline at end of file From d70e6229cc2ca79b471488251a48d1be4d0b17bb Mon Sep 17 00:00:00 2001 From: Stone-Red-Code <56473591+Stone-Red-Code@users.noreply.github.com> Date: Sun, 12 Sep 2021 13:24:46 +0200 Subject: [PATCH 03/18] - Remove unnecessary code - Improve startup performance --- src/DesktopMagic/MainWindow.xaml.cs | 7 ++-- src/DesktopMagic/Plugin/PluginWindow.xaml.cs | 32 ++++--------------- .../DesktopMagicPlugin.Test.csproj | 1 - src/DesktopMagicPlugin.Test/PluginScript.cs | 2 +- 4 files changed, 11 insertions(+), 31 deletions(-) diff --git a/src/DesktopMagic/MainWindow.xaml.cs b/src/DesktopMagic/MainWindow.xaml.cs index da90875..d4e7457 100644 --- a/src/DesktopMagic/MainWindow.xaml.cs +++ b/src/DesktopMagic/MainWindow.xaml.cs @@ -636,10 +636,9 @@ namespace DesktopMagic foreach (char c in chars) { textBlock.Text = ""; - for (int i = 0; i < 100; i++) - { - textBlock.Text += c.ToString(); - } + + textBlock.Text += c.ToString(); + textBlock.UpdateLayout(); if (charWidth != textBlock.ActualWidth && charWidth != -1) diff --git a/src/DesktopMagic/Plugin/PluginWindow.xaml.cs b/src/DesktopMagic/Plugin/PluginWindow.xaml.cs index 26eb572..25abc25 100644 --- a/src/DesktopMagic/Plugin/PluginWindow.xaml.cs +++ b/src/DesktopMagic/Plugin/PluginWindow.xaml.cs @@ -117,7 +117,6 @@ namespace DesktopMagic private void LoadPlugin() { - string sourceText; string PluginPath; pluginFolderPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\\{MainWindow.AppName}\\Plugins\\{pluginName}"; @@ -128,38 +127,26 @@ namespace DesktopMagic } else { - MessageBox.Show("File does not exist!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); + _ = MessageBox.Show("File does not exist!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); Exit(); return; } try { - sourceText = File.ReadAllText(PluginPath); + ExecuteSource(); } catch (Exception ex) { MainWindow.Logger.Log(ex.ToString(), "Plugin"); - MessageBox.Show("File could not be read:\n" + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); - Exit(); - return; - } - - try - { - ExecuteSource(sourceText); - } - catch (Exception ex) - { - MainWindow.Logger.Log(ex.ToString(), "Plugin"); - MessageBox.Show("File execution error:\n" + ex, "Error", MessageBoxButton.OK, MessageBoxImage.Error); + _ = MessageBox.Show("File execution error:\n" + ex, "Error", MessageBoxButton.OK, MessageBoxImage.Error); Exit(); return; } PluginLoaded?.Invoke(); } - private void ExecuteSource(string sourceText) + private void ExecuteSource() { byte[] assemblyBytes = File.ReadAllBytes($"{pluginFolderPath}\\{pluginName}.dll"); Assembly dll = Assembly.Load(assemblyBytes); @@ -173,7 +160,7 @@ namespace DesktopMagic if (instanceType is null) { - MessageBox.Show($"The \"Plugin\" class could not be found! It has to inherit from \"{typeof(Plugin).FullName}\"", "Error", MessageBoxButton.OK, MessageBoxImage.Error); + _ = MessageBox.Show($"The \"Plugin\" class could not be found! It has to inherit from \"{typeof(Plugin).FullName}\"", "Error", MessageBoxButton.OK, MessageBoxImage.Error); Exit(); return; } @@ -186,7 +173,7 @@ namespace DesktopMagic } else { - MessageBox.Show($"The \"Plugin\" class has to inherit from \"{typeof(Plugin).FullName}\"", "Error", MessageBoxButton.OK, MessageBoxImage.Error); + _ = MessageBox.Show($"The \"Plugin\" class has to inherit from \"{typeof(Plugin).FullName}\"", "Error", MessageBoxButton.OK, MessageBoxImage.Error); Exit(); return; } @@ -242,11 +229,6 @@ namespace DesktopMagic private void ValueTimer_Elapsed(object sender, ElapsedEventArgs e) { - //Set Arguments - SolidBrush newBrush = (SolidBrush)MainWindow.GlobalSystemColor; - System.Drawing.Color color = newBrush.Color; - string font = MainWindow.GlobalFont; - try { Bitmap result = pluginClassInstance.Main(); @@ -269,7 +251,7 @@ namespace DesktopMagic catch (Exception ex) { MainWindow.Logger.Log(ex.ToString(), "Plugin"); - MessageBox.Show("File execution error:\n" + ex, "Error", MessageBoxButton.OK, MessageBoxImage.Error); + _ = MessageBox.Show("File execution error:\n" + ex, "Error", MessageBoxButton.OK, MessageBoxImage.Error); Exit(); return; } diff --git a/src/DesktopMagicPlugin.Test/DesktopMagicPlugin.Test.csproj b/src/DesktopMagicPlugin.Test/DesktopMagicPlugin.Test.csproj index 19fb9b6..d2240e9 100644 --- a/src/DesktopMagicPlugin.Test/DesktopMagicPlugin.Test.csproj +++ b/src/DesktopMagicPlugin.Test/DesktopMagicPlugin.Test.csproj @@ -5,7 +5,6 @@ - diff --git a/src/DesktopMagicPlugin.Test/PluginScript.cs b/src/DesktopMagicPlugin.Test/PluginScript.cs index 67a7c0d..175a2db 100644 --- a/src/DesktopMagicPlugin.Test/PluginScript.cs +++ b/src/DesktopMagicPlugin.Test/PluginScript.cs @@ -21,7 +21,7 @@ namespace DesktopMagicPlugin.Test { Bitmap bmp = new Bitmap(100, 100); using Graphics graphics = Graphics.FromImage(bmp); - graphics.Clear(Color.Red); + graphics.Clear(Application.Color); return bmp; } } From e00c873bd537fe8d2db8f98a9c1100bf3007c767 Mon Sep 17 00:00:00 2001 From: Stone-Red-Code <56473591+Stone-Red-Code@users.noreply.github.com> Date: Mon, 13 Sep 2021 19:49:05 +0200 Subject: [PATCH 04/18] - Remove unnecessary code - Execute `OnValueChanged` event in task --- src/DesktopMagic/MainWindow.xaml.cs | 20 -------- src/DesktopMagic/Plugin/PluginWindow.xaml.cs | 8 +--- src/DesktopMagicPlugin.Test/PluginScript.cs | 50 ++++++++++++++++---- src/DesktopMagicPluginAPI/Inputs/Button.cs | 5 +- src/DesktopMagicPluginAPI/Inputs/Element.cs | 3 +- 5 files changed, 45 insertions(+), 41 deletions(-) diff --git a/src/DesktopMagic/MainWindow.xaml.cs b/src/DesktopMagic/MainWindow.xaml.cs index d4e7457..4edf8f8 100644 --- a/src/DesktopMagic/MainWindow.xaml.cs +++ b/src/DesktopMagic/MainWindow.xaml.cs @@ -473,7 +473,6 @@ namespace DesktopMagic Dispatcher.Invoke(() => { label.Text = eLabel.Value; - Option_ValueChanged(); }); }; } @@ -498,7 +497,6 @@ namespace DesktopMagic Dispatcher.Invoke(() => { button.Content = eButton.Value; - Option_ValueChanged(); }); }; @@ -522,7 +520,6 @@ namespace DesktopMagic Dispatcher.Invoke(() => { checkBox.IsChecked = eCheckBox.Value; - Option_ValueChanged(); }); }; @@ -546,7 +543,6 @@ namespace DesktopMagic Dispatcher.Invoke(() => { textBox.Text = eTextBox.Value; - Option_ValueChanged(); }); }; _ = stackPanel.Children.Add(textBox); @@ -570,7 +566,6 @@ namespace DesktopMagic Dispatcher.Invoke(() => { integerUpDown.Value = eIntegerUpDown.Value; - Option_ValueChanged(); }); }; _ = stackPanel.Children.Add(integerUpDown); @@ -596,7 +591,6 @@ namespace DesktopMagic Dispatcher.Invoke(() => { slider.Value = eSlider.Value; - Option_ValueChanged(); }); }; @@ -606,20 +600,6 @@ namespace DesktopMagic } } - private void Option_ValueChanged() - { - //Plugin settings save currenty disabled. Not sure if I want to add it back in the future. - /* - string pluginName = ((Tuple)optionsComboBox.SelectedItem).Item1.ToString(); - - if (PluginsSettings.ContainsKey(pluginName)) - { - string jsonSettings = JsonSerializer.Serialize(PluginsSettings[pluginName]); - File.WriteAllText($"{applicationDataPath}\\Plugins\\{pluginName}\\{pluginName}.save", jsonSettings); - } - */ - } - #endregion options private void TextBlock_Loaded(object sender, RoutedEventArgs e) diff --git a/src/DesktopMagic/Plugin/PluginWindow.xaml.cs b/src/DesktopMagic/Plugin/PluginWindow.xaml.cs index 25abc25..f7a110c 100644 --- a/src/DesktopMagic/Plugin/PluginWindow.xaml.cs +++ b/src/DesktopMagic/Plugin/PluginWindow.xaml.cs @@ -117,15 +117,9 @@ namespace DesktopMagic private void LoadPlugin() { - string PluginPath; - pluginFolderPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\\{MainWindow.AppName}\\Plugins\\{pluginName}"; - if (File.Exists($"{pluginFolderPath}\\{pluginName}.dll")) - { - PluginPath = $"{pluginFolderPath}\\{pluginName}.dll"; - } - else + if (!File.Exists($"{pluginFolderPath}\\{pluginName}.dll")) { _ = MessageBox.Show("File does not exist!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); Exit(); diff --git a/src/DesktopMagicPlugin.Test/PluginScript.cs b/src/DesktopMagicPlugin.Test/PluginScript.cs index 175a2db..a6f5f15 100644 --- a/src/DesktopMagicPlugin.Test/PluginScript.cs +++ b/src/DesktopMagicPlugin.Test/PluginScript.cs @@ -1,28 +1,60 @@ using DesktopMagicPluginAPI; using DesktopMagicPluginAPI.Inputs; using System.Drawing; -using System.Diagnostics; +using System.Drawing.Imaging; +using System.Drawing.Drawing2D; +using System.IO; +using System.Collections.Generic; namespace DesktopMagicPlugin.Test { public class GifPlugin : Plugin { [Element("Gif path:")] - public TextBox input = new TextBox(""); + private TextBox input = new TextBox(""); - public override int UpdateInterval { get; set; } = 100; + private List bitmaps = new List(); - public override void OnMouseWheel(Point position, int delta) + private int frameCount = -1; + + public override void Start() { - Debug.WriteLine(position + " | " + delta); + input.OnValueChanged += Input_OnValueChanged; + } + + private void Input_OnValueChanged() + { + try + { + if (File.Exists(input.Value)) + { + Image gif = Image.FromFile(input.Value); + PropertyItem item = gif.GetPropertyItem(0x5100); // FrameDelay in libgdiplus + + UpdateInterval = (item.Value[0] + item.Value[1] * 256) * 10; //FrameDelay in ms + bitmaps.Clear(); + for (int i = 0; i < gif.GetFrameCount(FrameDimension.Time); i++) + { + gif.SelectActiveFrame(FrameDimension.Time, i); + + bitmaps.Add(new Bitmap(gif)); + } + } + } + catch { } } public override Bitmap Main() { - Bitmap bmp = new Bitmap(100, 100); - using Graphics graphics = Graphics.FromImage(bmp); - graphics.Clear(Application.Color); - return bmp; + if (bitmaps.Count == 0) + return new Bitmap(1, 1); + + frameCount++; + + if (frameCount >= bitmaps.Count) + frameCount = 0; + + return bitmaps[frameCount]; } } } \ No newline at end of file diff --git a/src/DesktopMagicPluginAPI/Inputs/Button.cs b/src/DesktopMagicPluginAPI/Inputs/Button.cs index 5ea1fc4..15c23fb 100644 --- a/src/DesktopMagicPluginAPI/Inputs/Button.cs +++ b/src/DesktopMagicPluginAPI/Inputs/Button.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Threading.Tasks; namespace DesktopMagicPluginAPI.Inputs @@ -48,7 +45,7 @@ namespace DesktopMagicPluginAPI.Inputs /// public void Click() { - OnClick?.Invoke(); + _ = Task.Run(() => OnClick?.Invoke()); } } } \ No newline at end of file diff --git a/src/DesktopMagicPluginAPI/Inputs/Element.cs b/src/DesktopMagicPluginAPI/Inputs/Element.cs index b23b4fa..810cfcf 100644 --- a/src/DesktopMagicPluginAPI/Inputs/Element.cs +++ b/src/DesktopMagicPluginAPI/Inputs/Element.cs @@ -1,4 +1,5 @@ using System; +using System.Threading.Tasks; namespace DesktopMagicPluginAPI.Inputs { @@ -17,7 +18,7 @@ namespace DesktopMagicPluginAPI.Inputs /// protected void ValueChanged() { - OnValueChanged?.Invoke(); + _ = Task.Run(() => OnValueChanged?.Invoke()); } } } \ No newline at end of file From 6e4757adeaf750150ccdef9ca890dfd7295738dd Mon Sep 17 00:00:00 2001 From: Stone-Red-Code <56473591+Stone-Red-Code@users.noreply.github.com> Date: Tue, 14 Sep 2021 14:07:08 +0200 Subject: [PATCH 05/18] - Exception handling for plugin events - Revert: Execute `OnValueChanged` event in task --- src/DesktopMagic/MainWindow.xaml.cs | 55 ++++++++++++++++++-- src/DesktopMagic/Plugin/PluginWindow.xaml.cs | 35 +++++++------ src/DesktopMagicPlugin.Test/PluginScript.cs | 50 +++++++++++++----- src/DesktopMagicPluginAPI/Inputs/Button.cs | 3 +- src/DesktopMagicPluginAPI/Inputs/Element.cs | 3 +- 5 files changed, 109 insertions(+), 37 deletions(-) diff --git a/src/DesktopMagic/MainWindow.xaml.cs b/src/DesktopMagic/MainWindow.xaml.cs index 4edf8f8..5750cdb 100644 --- a/src/DesktopMagic/MainWindow.xaml.cs +++ b/src/DesktopMagic/MainWindow.xaml.cs @@ -490,7 +490,14 @@ namespace DesktopMagic }; button.Click += (_s, _e) => { - eButton.Click(); + try + { + eButton.Click(); + } + catch (Exception ex) + { + DisplayException(ex.Message); + } }; eButton.OnValueChanged += () => { @@ -513,7 +520,14 @@ namespace DesktopMagic }; checkBox.Click += (_s, _e) => { - eCheckBox.Value = checkBox.IsChecked.GetValueOrDefault(); + try + { + eCheckBox.Value = checkBox.IsChecked.GetValueOrDefault(); + } + catch (Exception ex) + { + DisplayException(ex.Message); + } }; eCheckBox.OnValueChanged += () => { @@ -536,7 +550,14 @@ namespace DesktopMagic }; textBox.TextChanged += (_s, _e) => { - eTextBox.Value = textBox.Text; + try + { + eTextBox.Value = textBox.Text; + } + catch (Exception ex) + { + DisplayException(ex.Message); + } }; eTextBox.OnValueChanged += () => { @@ -559,7 +580,14 @@ namespace DesktopMagic }; integerUpDown.ValueChanged += (_s, _e) => { - eIntegerUpDown.Value = integerUpDown.Value.GetValueOrDefault(); + try + { + eIntegerUpDown.Value = integerUpDown.Value.GetValueOrDefault(); + } + catch (Exception ex) + { + DisplayException(ex.Message); + } }; eIntegerUpDown.OnValueChanged += () => { @@ -584,7 +612,14 @@ namespace DesktopMagic }; slider.ValueChanged += (_s, _e) => { - eSlider.Value = slider.Value; + try + { + eSlider.Value = slider.Value; + } + catch (Exception ex) + { + DisplayException(ex.Message); + } }; eSlider.OnValueChanged += () => { @@ -600,6 +635,16 @@ namespace DesktopMagic } } + private void DisplayException(string message) + { + Logger.Log(message, "PluginInput"); + _ = MessageBox.Show("File execution error:\n" + message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); + int index = WindowNames.IndexOf(((Tuple)optionsComboBox.SelectedItem).Item1.ToString()); + + PluginWindow window = Windows[index] as PluginWindow; + window?.Exit(); + } + #endregion options private void TextBlock_Loaded(object sender, RoutedEventArgs e) diff --git a/src/DesktopMagic/Plugin/PluginWindow.xaml.cs b/src/DesktopMagic/Plugin/PluginWindow.xaml.cs index f7a110c..6a7bc1f 100644 --- a/src/DesktopMagic/Plugin/PluginWindow.xaml.cs +++ b/src/DesktopMagic/Plugin/PluginWindow.xaml.cs @@ -225,25 +225,29 @@ namespace DesktopMagic { try { - Bitmap result = pluginClassInstance.Main(); + if (!stop) + { + Bitmap result = pluginClassInstance.Main(); - if (pluginClassInstance.UpdateInterval > 0) - { - valueTimer.Interval = pluginClassInstance.UpdateInterval; - } - else - { - valueTimer.Stop(); - } + if (pluginClassInstance.UpdateInterval > 0) + { + valueTimer.Interval = pluginClassInstance.UpdateInterval; + } + else + { + valueTimer.Stop(); + } - //Update Image - Dispatcher.Invoke(() => - { - image.Source = BitmapToImageSource(result); - }); + //Update Image + Dispatcher.Invoke(() => + { + image.Source = BitmapToImageSource(result); + }); + } } catch (Exception ex) { + stop = true; MainWindow.Logger.Log(ex.ToString(), "Plugin"); _ = MessageBox.Show("File execution error:\n" + ex, "Error", MessageBoxButton.OK, MessageBoxImage.Error); Exit(); @@ -272,8 +276,9 @@ namespace DesktopMagic return bitmapSource; } - private void Exit() + public void Exit() { + stop = true; Dispatcher.Invoke(() => { OnExit?.Invoke(); diff --git a/src/DesktopMagicPlugin.Test/PluginScript.cs b/src/DesktopMagicPlugin.Test/PluginScript.cs index a6f5f15..0f9a18a 100644 --- a/src/DesktopMagicPlugin.Test/PluginScript.cs +++ b/src/DesktopMagicPlugin.Test/PluginScript.cs @@ -2,9 +2,10 @@ using DesktopMagicPluginAPI.Inputs; using System.Drawing; using System.Drawing.Imaging; -using System.Drawing.Drawing2D; using System.IO; using System.Collections.Generic; +using System.Threading.Tasks; +using System; namespace DesktopMagicPlugin.Test { @@ -13,35 +14,58 @@ namespace DesktopMagicPlugin.Test [Element("Gif path:")] private TextBox input = new TextBox(""); + [Element] + private Label info = new Label(""); + private List bitmaps = new List(); private int frameCount = -1; + private const string SaveFilePath = "gifPath.txt"; + public override void Start() { input.OnValueChanged += Input_OnValueChanged; + if (File.Exists(SaveFilePath)) + { + input.Value = File.ReadAllText(SaveFilePath); + } } private void Input_OnValueChanged() { - try + _ = Task.Run(() => { - if (File.Exists(input.Value)) + try { - Image gif = Image.FromFile(input.Value); - PropertyItem item = gif.GetPropertyItem(0x5100); // FrameDelay in libgdiplus - - UpdateInterval = (item.Value[0] + item.Value[1] * 256) * 10; //FrameDelay in ms - bitmaps.Clear(); - for (int i = 0; i < gif.GetFrameCount(FrameDimension.Time); i++) + info.Value = "Loading..."; + if (File.Exists(input.Value)) { - gif.SelectActiveFrame(FrameDimension.Time, i); + Image gif = Image.FromFile(input.Value); - bitmaps.Add(new Bitmap(gif)); + PropertyItem item = gif.GetPropertyItem(0x5100); // FrameDelay in libgdiplus + + UpdateInterval = (item.Value[0] + item.Value[1] * 256) * 10; //FrameDelay in ms + bitmaps.Clear(); + for (int i = 0; i < gif.GetFrameCount(FrameDimension.Time); i++) + { + gif.SelectActiveFrame(FrameDimension.Time, i); + + bitmaps.Add(new Bitmap(gif)); + } + File.WriteAllText(SaveFilePath, input.Value); + info.Value = string.Empty; + } + else + { + info.Value = "File not found!"; } } - } - catch { } + catch (Exception ex) + { + info.Value = $"Error: {ex.Message}"; + } + }); } public override Bitmap Main() diff --git a/src/DesktopMagicPluginAPI/Inputs/Button.cs b/src/DesktopMagicPluginAPI/Inputs/Button.cs index 15c23fb..c8e813c 100644 --- a/src/DesktopMagicPluginAPI/Inputs/Button.cs +++ b/src/DesktopMagicPluginAPI/Inputs/Button.cs @@ -1,5 +1,4 @@ using System; -using System.Threading.Tasks; namespace DesktopMagicPluginAPI.Inputs { @@ -45,7 +44,7 @@ namespace DesktopMagicPluginAPI.Inputs /// public void Click() { - _ = Task.Run(() => OnClick?.Invoke()); + OnClick?.Invoke(); } } } \ No newline at end of file diff --git a/src/DesktopMagicPluginAPI/Inputs/Element.cs b/src/DesktopMagicPluginAPI/Inputs/Element.cs index 810cfcf..b23b4fa 100644 --- a/src/DesktopMagicPluginAPI/Inputs/Element.cs +++ b/src/DesktopMagicPluginAPI/Inputs/Element.cs @@ -1,5 +1,4 @@ using System; -using System.Threading.Tasks; namespace DesktopMagicPluginAPI.Inputs { @@ -18,7 +17,7 @@ namespace DesktopMagicPluginAPI.Inputs /// protected void ValueChanged() { - _ = Task.Run(() => OnValueChanged?.Invoke()); + OnValueChanged?.Invoke(); } } } \ No newline at end of file From 7d2f68a66a3ee6fdcaf9a43cdf9bb53d19b505d4 Mon Sep 17 00:00:00 2001 From: Stone-Red-Code <56473591+Stone-Red-Code@users.noreply.github.com> Date: Tue, 14 Sep 2021 19:03:36 +0200 Subject: [PATCH 06/18] - Add GitHub and Download plugins button - Add auto updater - Disable calender --- src/DesktopMagic/App.xaml.cs | 36 +++++++++++++++++- src/DesktopMagic/CalendarManagment.cs | 16 ++------ src/DesktopMagic/DesktopMagic.csproj | 7 ++-- src/DesktopMagic/MainWindow.xaml | 13 +++++-- src/DesktopMagic/MainWindow.xaml.cs | 21 +++++++++- .../Resources/StringResources.de.xaml | 1 + .../Resources/StringResources.en.xaml | 1 + src/DesktopMagicPlugin.Test/PluginScript.cs | 2 +- update/DesktopMagic.zip | Bin 0 -> 6935126 bytes update/updateInfo.json | 4 ++ 10 files changed, 77 insertions(+), 24 deletions(-) create mode 100644 update/DesktopMagic.zip create mode 100644 update/updateInfo.json diff --git a/src/DesktopMagic/App.xaml.cs b/src/DesktopMagic/App.xaml.cs index 4a87422..7120f71 100644 --- a/src/DesktopMagic/App.xaml.cs +++ b/src/DesktopMagic/App.xaml.cs @@ -1,4 +1,6 @@ -using System; +using AlwaysUpToDate; +using System; +using System.Diagnostics; using System.Threading; using System.Windows; @@ -10,6 +12,11 @@ namespace DesktopMagic public partial class App : Application { private Mutex _mutex; +#if DEBUG + private readonly Updater updater = new Updater(TimeSpan.FromHours(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"); +#endif public App() { @@ -25,11 +32,36 @@ namespace DesktopMagic } else { - // Add Event handler to exit event. Exit += CloseMutexHandler; + + updater.ProgressChanged += Updater_ProgressChanged; + updater.OnException += Updater_OnException; + updater.NoUpdateAvailible += Updater_NoUpdateAvailible; + updater.UpdateAvailible += Updater_UpdateAvailible; + updater.Start(); } } + private void Updater_UpdateAvailible(string version, string additionalInformation) + { + updater.Update(); + } + + private void Updater_NoUpdateAvailible() + { + Debug.WriteLine("No update avalible."); + } + + private void Updater_OnException(Exception exception) + { + Debug.WriteLine("Update exception: " + exception); + } + + private void Updater_ProgressChanged(long? totalFileSize, long totalBytesDownloaded, double? progressPercentage) + { + Debug.WriteLine($"{progressPercentage}% {totalBytesDownloaded}/{totalFileSize}"); + } + protected virtual void CloseMutexHandler(object sender, EventArgs e) { _mutex?.Close(); diff --git a/src/DesktopMagic/CalendarManagment.cs b/src/DesktopMagic/CalendarManagment.cs index 63bd82b..96f0f6b 100644 --- a/src/DesktopMagic/CalendarManagment.cs +++ b/src/DesktopMagic/CalendarManagment.cs @@ -5,6 +5,7 @@ using Google.Apis.Services; using Google.Apis.Util.Store; using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Threading; @@ -21,14 +22,11 @@ namespace DesktopMagic List upcomingEventNames = new List(); List upcomingEventTimes = new List(); UserCredential credential; - Console.WriteLine("1"); if (!File.Exists("credentials.json")) return (new(), new()); - using (var stream = - new FileStream("credentials.json", FileMode.Open, FileAccess.Read)) + using (var stream = new FileStream("credentials.json", FileMode.Open, FileAccess.Read)) { - Console.WriteLine("2"); // The file token.json stores the user's access and refresh tokens, and is created // automatically when the authorization flow completes for the first time. string credPath = "token.json"; @@ -38,9 +36,8 @@ namespace DesktopMagic "user", CancellationToken.None, new FileDataStore(credPath, true)).Result; - Console.WriteLine("Credential file saved to: " + credPath); + Debug.WriteLine("Credential file saved to: " + credPath); } - Console.WriteLine("3"); // Create Google Calendar API service. var service = new CalendarService(new BaseClientService.Initializer() @@ -49,8 +46,6 @@ namespace DesktopMagic ApplicationName = ApplicationName, }); - Console.WriteLine("4"); - // Define parameters of request. EventsResource.ListRequest request = service.Events.List("primary"); request.TimeMin = DateTime.Now; @@ -59,11 +54,8 @@ namespace DesktopMagic request.MaxResults = 10; request.OrderBy = EventsResource.ListRequest.OrderByEnum.StartTime; - Console.WriteLine("5"); // List events. Events events = request.Execute(); - Console.WriteLine("6"); - Console.WriteLine("Upcoming events:"); if (events.Items != null && events.Items.Count > 0) { foreach (var eventItem in events.Items) @@ -80,8 +72,6 @@ namespace DesktopMagic } } } - - Console.WriteLine("7"); return (upcomingEventNames, upcomingEventTimes); } } diff --git a/src/DesktopMagic/DesktopMagic.csproj b/src/DesktopMagic/DesktopMagic.csproj index 836e3b8..9b79f9a 100644 --- a/src/DesktopMagic/DesktopMagic.csproj +++ b/src/DesktopMagic/DesktopMagic.csproj @@ -20,11 +20,12 @@ + - + - - + + diff --git a/src/DesktopMagic/MainWindow.xaml b/src/DesktopMagic/MainWindow.xaml index 52b8869..0cdac8e 100644 --- a/src/DesktopMagic/MainWindow.xaml +++ b/src/DesktopMagic/MainWindow.xaml @@ -9,9 +9,9 @@ Background="{DynamicResource MaterialDesignPaper}" FontFamily="{DynamicResource MaterialDesignFont}" Height="520" - Width="550" + Width="570" MinHeight="520" - MinWidth="500" + MinWidth="570" WindowState="Minimized" StateChanged="Window_StateChanged" Loaded="Window_Loaded"> @@ -38,7 +38,7 @@ - + @@ -104,15 +104,20 @@ + - +