diff --git a/src/DesktopMagic.Installer/DesktopMagic-Installer.exe b/src/DesktopMagic.Installer/DesktopMagic-Installer.exe index cef97e4..a719f83 100644 Binary files a/src/DesktopMagic.Installer/DesktopMagic-Installer.exe and b/src/DesktopMagic.Installer/DesktopMagic-Installer.exe differ diff --git a/src/DesktopMagic.Installer/Installer.iss b/src/DesktopMagic.Installer/Installer.iss index 3656655..c4b6638 100644 --- a/src/DesktopMagic.Installer/Installer.iss +++ b/src/DesktopMagic.Installer/Installer.iss @@ -2,7 +2,7 @@ ; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES! #define MyAppName "DesktopMagic" -#define MyAppVersion "0.0.2.1" +#define MyAppVersion "0.0.2.2" #define MyAppPublisher "Stone_Red" #define MyAppExeName "DesktopMagic.exe" @@ -36,40 +36,7 @@ Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{ Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked; OnlyBelowVersion: 6.1; Check: not IsAdminInstallMode [Files] -Source: "..\DesktopMagic\bin\Release\net5.0-windows\DesktopMagic.exe"; DestDir: "{app}"; Flags: ignoreversion -Source: "..\DesktopMagic\bin\Release\net5.0-windows\Stone_Red-C-Sharp-Utilities.dll"; DestDir: "{app}"; Flags: ignoreversion -Source: "..\DesktopMagic\bin\Release\net5.0-windows\DesktopMagic.deps.json"; DestDir: "{app}"; Flags: ignoreversion -Source: "..\DesktopMagic\bin\Release\net5.0-windows\DesktopMagic.dll"; DestDir: "{app}"; Flags: ignoreversion -Source: "..\DesktopMagic\bin\Release\net5.0-windows\DesktopMagic.exe"; DestDir: "{app}"; Flags: ignoreversion -Source: "..\DesktopMagic\bin\Release\net5.0-windows\DesktopMagic.pdb"; DestDir: "{app}"; Flags: ignoreversion -Source: "..\DesktopMagic\bin\Release\net5.0-windows\DesktopMagic.runtimeconfig.dev.json"; DestDir: "{app}"; Flags: ignoreversion -Source: "..\DesktopMagic\bin\Release\net5.0-windows\DesktopMagic.runtimeconfig.json"; DestDir: "{app}"; Flags: ignoreversion -Source: "..\DesktopMagic\bin\Release\net5.0-windows\DesktopMagicPluginAPI.dll"; DestDir: "{app}"; Flags: ignoreversion -Source: "..\DesktopMagic\bin\Release\net5.0-windows\DesktopMagicPluginAPI.pdb"; DestDir: "{app}"; Flags: ignoreversion -Source: "..\DesktopMagic\bin\Release\net5.0-windows\Google.Apis.Auth.dll"; DestDir: "{app}"; Flags: ignoreversion -Source: "..\DesktopMagic\bin\Release\net5.0-windows\Google.Apis.Auth.PlatformServices.dll"; DestDir: "{app}"; Flags: ignoreversion -Source: "..\DesktopMagic\bin\Release\net5.0-windows\Google.Apis.Calendar.v3.dll"; DestDir: "{app}"; Flags: ignoreversion -Source: "..\DesktopMagic\bin\Release\net5.0-windows\Google.Apis.Core.dll"; DestDir: "{app}"; Flags: ignoreversion -Source: "..\DesktopMagic\bin\Release\net5.0-windows\Google.Apis.dll"; DestDir: "{app}"; Flags: ignoreversion -Source: "..\DesktopMagic\bin\Release\net5.0-windows\Hardcodet.NotifyIcon.Wpf.dll"; DestDir: "{app}"; Flags: ignoreversion -Source: "..\DesktopMagic\bin\Release\net5.0-windows\MaterialDesignColors.dll"; DestDir: "{app}"; Flags: ignoreversion -Source: "..\DesktopMagic\bin\Release\net5.0-windows\MaterialDesignThemes.Wpf.dll"; DestDir: "{app}"; Flags: ignoreversion -Source: "..\DesktopMagic\bin\Release\net5.0-windows\NAudio.Asio.dll"; DestDir: "{app}"; Flags: ignoreversion -Source: "..\DesktopMagic\bin\Release\net5.0-windows\NAudio.Core.dll"; DestDir: "{app}"; Flags: ignoreversion -Source: "..\DesktopMagic\bin\Release\net5.0-windows\NAudio.dll"; DestDir: "{app}"; Flags: ignoreversion -Source: "..\DesktopMagic\bin\Release\net5.0-windows\NAudio.Midi.dll"; DestDir: "{app}"; Flags: ignoreversion -Source: "..\DesktopMagic\bin\Release\net5.0-windows\NAudio.Wasapi.dll"; DestDir: "{app}"; Flags: ignoreversion -Source: "..\DesktopMagic\bin\Release\net5.0-windows\NAudio.WinForms.dll"; DestDir: "{app}"; Flags: ignoreversion -Source: "..\DesktopMagic\bin\Release\net5.0-windows\NAudio.WinMM.dll"; DestDir: "{app}"; Flags: ignoreversion -Source: "..\DesktopMagic\bin\Release\net5.0-windows\Newtonsoft.Json.dll"; DestDir: "{app}"; Flags: ignoreversion -Source: "..\DesktopMagic\bin\Release\net5.0-windows\System.Drawing.Common.dll"; DestDir: "{app}"; Flags: ignoreversion -Source: "..\DesktopMagic\bin\Release\net5.0-windows\System.Management.dll"; DestDir: "{app}"; Flags: ignoreversion -Source: "..\DesktopMagic\bin\Release\net5.0-windows\Xceed.Wpf.AvalonDock.dll"; DestDir: "{app}"; Flags: ignoreversion -Source: "..\DesktopMagic\bin\Release\net5.0-windows\Xceed.Wpf.AvalonDock.Themes.Aero.dll"; DestDir: "{app}"; Flags: ignoreversion -Source: "..\DesktopMagic\bin\Release\net5.0-windows\Xceed.Wpf.AvalonDock.Themes.Metro.dll"; DestDir: "{app}"; Flags: ignoreversion -Source: "..\DesktopMagic\bin\Release\net5.0-windows\Xceed.Wpf.AvalonDock.Themes.VS2010.dll"; DestDir: "{app}"; Flags: ignoreversion -Source: "..\DesktopMagic\bin\Release\net5.0-windows\Xceed.Wpf.Toolkit.dll"; DestDir: "{app}"; Flags: ignoreversion -Source: "..\DesktopMagic\bin\Release\net5.0-windows\runtimes\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs +Source: "..\DesktopMagic\bin\Release\net5.0-windows\publish\DesktopMagic.exe"; DestDir: "{app}"; Flags: ignoreversion ; NOTE: Don't use "Flags: ignoreversion" on any shared system files [Icons] diff --git a/src/DesktopMagic.sln b/src/DesktopMagic.sln index 99227ac..19346aa 100644 --- a/src/DesktopMagic.sln +++ b/src/DesktopMagic.sln @@ -4,9 +4,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 VisualStudioVersion = 16.0.31205.134 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DesktopMagic", "DesktopMagic\DesktopMagic.csproj", "{B56B4CCC-CF92-4C05-9DEA-57666D81889A}" - ProjectSection(ProjectDependencies) = postProject - {A06BD685-7F92-4799-846B-3EC38345108E} = {A06BD685-7F92-4799-846B-3EC38345108E} - EndProjectSection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DesktopMagicPluginAPI", "DesktopMagicPluginAPI\DesktopMagicPluginAPI.csproj", "{9D193A10-3E8E-447F-89F1-4B316C2EE37D}" EndProject diff --git a/src/DesktopMagic/App.xaml.cs b/src/DesktopMagic/App.xaml.cs index 47f0e38..4a87422 100644 --- a/src/DesktopMagic/App.xaml.cs +++ b/src/DesktopMagic/App.xaml.cs @@ -1,4 +1,6 @@ -using System.Windows; +using System; +using System.Threading; +using System.Windows; namespace DesktopMagic { @@ -7,5 +9,30 @@ namespace DesktopMagic /// public partial class App : Application { + private Mutex _mutex; + + public App() + { + // Try to grab mutex + bool createdNew; + _mutex = new Mutex(true, $"Stone_Red{DesktopMagic.MainWindow.AppName}", out createdNew); + + //check if creating new was succesfull + if (!createdNew) + { + //Shutdown Aplication + Current.Shutdown(); + } + else + { + // Add Event handler to exit event. + Exit += CloseMutexHandler; + } + } + + protected virtual void CloseMutexHandler(object sender, EventArgs e) + { + _mutex?.Close(); + } } } \ No newline at end of file diff --git a/src/DesktopMagic/DesktopMagic.csproj b/src/DesktopMagic/DesktopMagic.csproj index 71ed275..836e3b8 100644 --- a/src/DesktopMagic/DesktopMagic.csproj +++ b/src/DesktopMagic/DesktopMagic.csproj @@ -7,11 +7,16 @@ DesktopMagic icon.ico OnBuildSuccess + Stone_Red + 0.0.2.2 + https://github.com/Stone-Red-Code/DesktopMagic + https://github.com/Stone-Red-Code/DesktopMagic + @@ -29,6 +34,11 @@ - + + Always + + + Always + \ No newline at end of file diff --git a/src/DesktopMagic/MainWindow.xaml.cs b/src/DesktopMagic/MainWindow.xaml.cs index 9b22cbc..da90875 100644 --- a/src/DesktopMagic/MainWindow.xaml.cs +++ b/src/DesktopMagic/MainWindow.xaml.cs @@ -72,6 +72,7 @@ public MainWindow() notifyIcon.Visible = true; notifyIcon.Text = AppName; notifyIcon.Icon = new System.Drawing.Icon(iconStream); + notifyIcon.ContextMenuStrip = new System.Windows.Forms.ContextMenuStrip(); InitializeComponent(); @@ -772,7 +773,7 @@ private void LayoutsComboBox_SelectionChanged(object sender, SelectionChangedEve private void NewLayoutButton_Click(object sender, RoutedEventArgs e) { - InputDialog inputDialog = new("Layoutnamen eingeben:"); + InputDialog inputDialog = new((string)FindResource("enterLayoutName")); if (inputDialog.ShowDialog() == true) { string content = ""; diff --git a/src/DesktopMagic/Plugin/PluginData.cs b/src/DesktopMagic/Plugin/PluginData.cs index 04b0018..f301d7f 100644 --- a/src/DesktopMagic/Plugin/PluginData.cs +++ b/src/DesktopMagic/Plugin/PluginData.cs @@ -20,9 +20,6 @@ public PluginData(PluginWindow win) public Point WindowPosition => new Point((int)window.Left, (int)window.Top); - public void UpdateWindow() - { - window.UpdatePluginWindow(); - } + public void UpdateWindow() => window.UpdatePluginWindow(); } } \ No newline at end of file diff --git a/src/DesktopMagic/Plugin/PluginWindow.xaml.cs b/src/DesktopMagic/Plugin/PluginWindow.xaml.cs index 08cf1e0..fee07c4 100644 --- a/src/DesktopMagic/Plugin/PluginWindow.xaml.cs +++ b/src/DesktopMagic/Plugin/PluginWindow.xaml.cs @@ -13,6 +13,7 @@ using System.Timers; using System.Windows; using System.Windows.Interop; +using System.Windows.Media; using System.Windows.Media.Imaging; namespace DesktopMagic @@ -190,19 +191,13 @@ private void ExecuteSource(string sourceText) return; } - if (instanceType.Namespace == nameof(DesktopMagic)) - { - MessageBox.Show("NO!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); - Exit(); - return; - } - LoadOptions(instance); valueTimer = new System.Timers.Timer(); valueTimer.Interval = 1000; valueTimer.Elapsed += ValueTimer_Elapsed; + pluginClassInstance.Start(); UpdatePluginWindow(); if (pluginClassInstance.UpdateInterval > 0) @@ -249,16 +244,35 @@ private void ValueTimer_Elapsed(object sender, ElapsedEventArgs e) { //Set Arguments SolidBrush newBrush = (SolidBrush)MainWindow.GlobalSystemColor; - Color color = newBrush.Color; + System.Drawing.Color color = newBrush.Color; string font = MainWindow.GlobalFont; - Bitmap result = pluginClassInstance.Main(); + try + { + Bitmap result = pluginClassInstance.Main(); - //Update Image - Dispatcher.Invoke(() => + if (pluginClassInstance.UpdateInterval > 0) + { + valueTimer.Interval = pluginClassInstance.UpdateInterval; + } + else + { + valueTimer.Stop(); + } + + //Update Image + Dispatcher.Invoke(() => + { + image.Source = BitmapToImageSource(result); + }); + } + catch (Exception ex) { - image.Source = BitmapToImageSource(result); - }); + MainWindow.Logger.Log(ex.ToString(), "Plugin"); + MessageBox.Show("File execution error:\n" + ex, "Error", MessageBoxButton.OK, MessageBoxImage.Error); + Exit(); + return; + } if (stop) { @@ -312,12 +326,20 @@ private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs private void Window_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { - Clicked(new System.Drawing.Point((int)e.GetPosition(this).X, (int)e.GetPosition(this).Y)); + 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; + Clicked(new System.Drawing.Point((int)pixelMousePositionX, (int)pixelMousePositionY)); } private void Window_MouseMove(object sender, System.Windows.Input.MouseEventArgs e) { - Moved(new System.Drawing.Point((int)e.GetPosition(this).X, (int)e.GetPosition(this).Y)); + 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; + Moved(new System.Drawing.Point((int)pixelMousePositionX, (int)pixelMousePositionY)); } #endregion Window Events diff --git a/src/DesktopMagic/Resources/StringResources.de.xaml b/src/DesktopMagic/Resources/StringResources.de.xaml index 7666fcd..c5bc0e3 100644 --- a/src/DesktopMagic/Resources/StringResources.de.xaml +++ b/src/DesktopMagic/Resources/StringResources.de.xaml @@ -23,6 +23,7 @@ Layout Löschen Ok Abbrechen + Layoutnamen eingeben: Unten Mitte diff --git a/src/DesktopMagic/Resources/StringResources.en.xaml b/src/DesktopMagic/Resources/StringResources.en.xaml index d351e65..56c1417 100644 --- a/src/DesktopMagic/Resources/StringResources.en.xaml +++ b/src/DesktopMagic/Resources/StringResources.en.xaml @@ -23,6 +23,7 @@ Delete Layout Ok Cancel + Enter layout name Bottom Middle diff --git a/src/DesktopMagic/icon.ico b/src/DesktopMagic/icon.ico index 0151a8f..f0a01c0 100644 Binary files a/src/DesktopMagic/icon.ico and b/src/DesktopMagic/icon.ico differ diff --git a/src/DesktopMagic/icon_Dark.ico b/src/DesktopMagic/icon_Dark.ico new file mode 100644 index 0000000..ff58950 Binary files /dev/null and b/src/DesktopMagic/icon_Dark.ico differ diff --git a/src/DesktopMagicPlugin.Test/PluginScript.cs b/src/DesktopMagicPlugin.Test/PluginScript.cs index 0ffe3eb..090bdcc 100644 --- a/src/DesktopMagicPlugin.Test/PluginScript.cs +++ b/src/DesktopMagicPlugin.Test/PluginScript.cs @@ -1,39 +1,54 @@ using DesktopMagicPluginAPI; using DesktopMagicPluginAPI.Inputs; -using DesktopMagicPluginAPI.Drawing; using System.Drawing; +using System.Drawing.Imaging; +using System.Drawing.Drawing2D; +using System.IO; +using System.Collections.Generic; namespace DesktopMagicPlugin.Test { - public class InputExamplePlugin : Plugin + public class GifPlugin : Plugin { - public override int UpdateInterval { get; set; } = 0; + [Element("Gif path:")] + private TextBox input = new TextBox(""); - [Element("Text:")] //Mark the property as element with the specified description - private TextBox textBox = new TextBox("abc"); //Create a text box with the specified default value. + private List bitmaps = new List(); - public InputExamplePlugin() + public override int UpdateInterval { get; set; } = 100; + private int frameCount = -1; + + public GifPlugin() { - textBox.OnValueChanged += TextBox_OnValueChanged; //Add an event handler to the "OnValueChanged" event. + input.OnValueChanged += Input_OnValueChanged; } - private void TextBox_OnValueChanged() + private void Input_OnValueChanged() { - Application.UpdateWindow(); //Update the pugin window. (Calls the "Main" method.) + 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)); + } + } } public override Bitmap Main() { - Bitmap bmp = new Bitmap(1000, 1000); + if (bitmaps.Count == 0) + return new Bitmap(1, 1); - using (Graphics g = Graphics.FromImage(bmp)) - { - g.Clear(Application.Color); //Set the background color to the color specified in the Desktop Magic application. + frameCount++; - g.DrawStringFixedWidth(textBox.Value, new Font(Application.Font, 100), Brushes.Black, new PointF(0, 0), 120); //Draw the value of the text box to the image. - } + if (frameCount >= bitmaps.Count) + frameCount = 0; - return bmp; //Return the image. + return bitmaps[frameCount]; } } } \ No newline at end of file diff --git a/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.csproj b/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.csproj index 6c7be81..b6dbfaf 100644 --- a/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.csproj +++ b/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.csproj @@ -10,6 +10,7 @@ true 0.0.0.2 + 0.0.0.2 diff --git a/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.md b/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.md index 9fd0421..876a43e 100644 --- a/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.md +++ b/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.md @@ -44,6 +44,7 @@ - [Main()](#M-DesktopMagicPluginAPI-Plugin-Main 'DesktopMagicPluginAPI.Plugin.Main') - [OnMouseClick(position)](#M-DesktopMagicPluginAPI-Plugin-OnMouseClick-System-Drawing-Point- 'DesktopMagicPluginAPI.Plugin.OnMouseClick(System.Drawing.Point)') - [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') - [#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)') - [Maximum](#P-DesktopMagicPluginAPI-Inputs-Slider-Maximum 'DesktopMagicPluginAPI.Inputs.Slider.Maximum') @@ -338,7 +339,7 @@ Gets the window size of the main application. ##### Summary -Updates the plugin window +Updates the plugin window. ##### Parameters @@ -445,14 +446,14 @@ DesktopMagicPluginAPI ##### Summary -The plugin class +The plugin class. ### Application `property` ##### Summary -Informations about the main application +Informations about the main application. ### UpdateInterval `property` @@ -502,6 +503,17 @@ 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') | | + +### Start() `method` + +##### Summary + +Occurs once when the pugin gets activated. + +##### Parameters + +This method has no parameters. + ## Slider `type` diff --git a/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.xml b/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.xml index 468b558..147c378 100644 --- a/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.xml +++ b/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.xml @@ -60,7 +60,7 @@ - Occurs when the button is clicked. + Occurs when the button gets clicked. @@ -263,17 +263,17 @@ - Updates the plugin window + Updates the plugin window. - The plugin class + The plugin class. - Informations about the main application + Informations about the main application. @@ -281,6 +281,11 @@ Gets or sets the interval, expressed in milliseconds, at which to call the method. + + + Occurs once when the pugin gets activated. + + Occurs when the elapses. diff --git a/src/DesktopMagicPluginAPI/IPluginData.cs b/src/DesktopMagicPluginAPI/IPluginData.cs index f31780b..3b05e01 100644 --- a/src/DesktopMagicPluginAPI/IPluginData.cs +++ b/src/DesktopMagicPluginAPI/IPluginData.cs @@ -28,7 +28,7 @@ public interface IPluginData Point WindowPosition { get; } /// - /// Updates the plugin window + /// Updates the plugin window. /// void UpdateWindow(); } diff --git a/src/DesktopMagicPluginAPI/Inputs/Button.cs b/src/DesktopMagicPluginAPI/Inputs/Button.cs index 9e2be09..5ea1fc4 100644 --- a/src/DesktopMagicPluginAPI/Inputs/Button.cs +++ b/src/DesktopMagicPluginAPI/Inputs/Button.cs @@ -12,7 +12,7 @@ namespace DesktopMagicPluginAPI.Inputs public class Button : Element { /// - /// Occurs when the button is clicked. + /// Occurs when the button gets clicked. /// public event Action OnClick; diff --git a/src/DesktopMagicPluginAPI/Plugin.cs b/src/DesktopMagicPluginAPI/Plugin.cs index 38449be..0a2c345 100644 --- a/src/DesktopMagicPluginAPI/Plugin.cs +++ b/src/DesktopMagicPluginAPI/Plugin.cs @@ -4,14 +4,14 @@ namespace DesktopMagicPluginAPI { /// - /// The plugin class + /// The plugin class. /// public abstract class Plugin { private IPluginData application = null; /// - /// Informations about the main application + /// Informations about the main application. /// public IPluginData Application { @@ -34,6 +34,13 @@ public IPluginData Application /// public virtual int UpdateInterval { get; set; } = 1000; + /// + /// Occurs once when the pugin gets activated. + /// + public virtual void Start() + { + } + /// /// Occurs when the elapses. ///