From 906674bbef899e5dff886503af6a02601a56a623 Mon Sep 17 00:00:00 2001
From: Piripe <77517308+Piripe@users.noreply.github.com>
Date: Wed, 19 Feb 2025 20:18:39 +0100
Subject: [PATCH 01/16] Started UI refactor
---
MacroPad/App.axaml | 1 -
.../Controls/{Home => }/DeviceViewer.axaml | 0
.../Controls/{Home => }/DeviceViewer.axaml.cs | 0
MacroPad/MacroPad.csproj | 2 +-
MacroPad/Styles/MacroPad.axaml | 4 +-
MacroPad/ViewLocator.cs | 28 -----
MacroPad/Views/MainView.axaml | 18 +--
MacroPad/Views/MainView.axaml.cs | 107 ------------------
.../MainViewViewModel.cs | 3 +-
MacroPad/Views/MainWindow.axaml | 22 +++-
.../MainWindowViewModel.cs | 4 +-
MacroPad/Views/Navigation/DeviceNav.axaml | 16 +++
MacroPad/Views/Navigation/DeviceNav.axaml.cs | 13 +++
13 files changed, 60 insertions(+), 158 deletions(-)
rename MacroPad/Controls/{Home => }/DeviceViewer.axaml (100%)
rename MacroPad/Controls/{Home => }/DeviceViewer.axaml.cs (100%)
delete mode 100644 MacroPad/ViewLocator.cs
rename MacroPad/{ViewModels => Views}/MainViewViewModel.cs (96%)
rename MacroPad/{ViewModels => Views}/MainWindowViewModel.cs (55%)
create mode 100644 MacroPad/Views/Navigation/DeviceNav.axaml
create mode 100644 MacroPad/Views/Navigation/DeviceNav.axaml.cs
diff --git a/MacroPad/App.axaml b/MacroPad/App.axaml
index a1bca98..f486beb 100644
--- a/MacroPad/App.axaml
+++ b/MacroPad/App.axaml
@@ -19,7 +19,6 @@
-
diff --git a/MacroPad/Controls/Home/DeviceViewer.axaml b/MacroPad/Controls/DeviceViewer.axaml
similarity index 100%
rename from MacroPad/Controls/Home/DeviceViewer.axaml
rename to MacroPad/Controls/DeviceViewer.axaml
diff --git a/MacroPad/Controls/Home/DeviceViewer.axaml.cs b/MacroPad/Controls/DeviceViewer.axaml.cs
similarity index 100%
rename from MacroPad/Controls/Home/DeviceViewer.axaml.cs
rename to MacroPad/Controls/DeviceViewer.axaml.cs
diff --git a/MacroPad/MacroPad.csproj b/MacroPad/MacroPad.csproj
index f933f3e..5f429d5 100644
--- a/MacroPad/MacroPad.csproj
+++ b/MacroPad/MacroPad.csproj
@@ -36,7 +36,7 @@
-
+
DeviceViewer.axaml
diff --git a/MacroPad/Styles/MacroPad.axaml b/MacroPad/Styles/MacroPad.axaml
index c25bbc0..eef982f 100644
--- a/MacroPad/Styles/MacroPad.axaml
+++ b/MacroPad/Styles/MacroPad.axaml
@@ -4,9 +4,9 @@
-
+
- Coucou
+ FooBar
diff --git a/MacroPad/ViewLocator.cs b/MacroPad/ViewLocator.cs
deleted file mode 100644
index 513b109..0000000
--- a/MacroPad/ViewLocator.cs
+++ /dev/null
@@ -1,28 +0,0 @@
-using Avalonia.Controls;
-using Avalonia.Controls.Templates;
-using MacroPad.ViewModels;
-using System;
-
-namespace MacroPad
-{
- public class ViewLocator : IDataTemplate
- {
- public Control Build(object data)
- {
- var name = data.GetType().FullName!.Replace("ViewModel", "View");
- var type = Type.GetType(name);
-
- if (type != null)
- {
- return (Control)Activator.CreateInstance(type)!;
- }
-
- return new TextBlock { Text = "Not Found: " + name };
- }
-
- public bool Match(object data)
- {
- return data is ViewModelBase;
- }
- }
-}
\ No newline at end of file
diff --git a/MacroPad/Views/MainView.axaml b/MacroPad/Views/MainView.axaml
index 6a0d25c..b8c1a10 100644
--- a/MacroPad/Views/MainView.axaml
+++ b/MacroPad/Views/MainView.axaml
@@ -1,6 +1,6 @@
-
+
-
-
-
-
-
-
+
+
+
+
diff --git a/MacroPad/Views/MainView.axaml.cs b/MacroPad/Views/MainView.axaml.cs
index 129691c..4a70497 100644
--- a/MacroPad/Views/MainView.axaml.cs
+++ b/MacroPad/Views/MainView.axaml.cs
@@ -12,10 +12,8 @@ namespace MacroPad.Views
{
public partial class MainView : UserControl
{
- public static MainView? Instance { get; private set; }
public MainView()
{
- Instance = this;
InitializeComponent();
}
@@ -23,111 +21,6 @@ public MainView()
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
{
base.OnAttachedToVisualTree(e);
-
- var vm = new MainViewViewModel();
- DataContext = vm;
- FrameView.NavigationPageFactory = vm.NavigationFactory;
-
- FrameView.Navigated += OnFrameViewNavigated;
- NavView.ItemInvoked += OnNavigationViewItemInvoked;
-
- NavView.MenuItemsSource = GetNavigationViewItems();
- NavView.FooterMenuItemsSource = GetFooterNavigationViewItems();
-
- NavView.IsPaneOpen = false;
-
- var navViewItems = NavView.MenuItemsSource.Cast();
- FrameView.NavigateFromObject(navViewItems.ElementAt(0).Tag);
-
- }
-
- private void SetNviIcon(NavigationViewItem? item, bool selected)
- {
- // Technically, yes you could set up binding and converters and whatnot to let the icon change
- // between filled and unfilled based on selection, but this is so much simpler
-
- if (item == null)
- return;
-
- var t = item.Tag;
-
- item.IconSource = t switch
- {
- MainPage => this.TryFindResource(selected ? "HomeIconFilled" : "HomeIcon", out var value)
- ? (IconSource)value!
- : null,
- SettingsPage => this.TryFindResource(selected ? "SettingsIconFilled" : "SettingsIcon", out var value)
- ? (IconSource)value!
- : null,
- _ => item.IconSource
- };
- }
-
- private void OnFrameViewNavigated(object sender, NavigationEventArgs e)
- {
- var page = e.Content as Control;
-
- foreach (NavigationViewItem nvi in NavView.MenuItemsSource)
- {
- if (nvi.Tag != null && nvi.Tag.Equals(page))
- {
- NavView.SelectedItem = nvi;
- SetNviIcon(nvi, true);
- }
- else
- {
- SetNviIcon(nvi, false);
- }
- }
-
- foreach (NavigationViewItem nvi in NavView.FooterMenuItemsSource)
- {
- if (nvi.Tag != null && nvi.Tag.Equals(page))
- {
- NavView.SelectedItem = nvi;
- SetNviIcon(nvi, true);
- }
- else
- {
- SetNviIcon(nvi, false);
- }
- }
- }
-
- private IEnumerable GetNavigationViewItems()
- {
- return
- [
- new()
- {
- Content = "Home",
- Tag = NavigationFactory.GetPages()[0],
- IconSource = (IconSource)this.FindResource("HomeIcon")!,
- Classes = { "MacroPadAppNav" }
- }
- ];
- }
-
- private IEnumerable GetFooterNavigationViewItems()
- {
- return
- [
- new()
- {
- Content = "Settings",
- Tag = NavigationFactory.GetPages()[1],
- IconSource = (IconSource)this.FindResource("SettingsIcon")!,
- Classes = { "MacroPadAppNav" }
- }
- ];
- }
-
- private void OnNavigationViewItemInvoked(object? sender, NavigationViewItemInvokedEventArgs e)
- {
- if (e.InvokedItemContainer is NavigationViewItem { Tag: Control c })
- {
- _ = FrameView.NavigateFromObject(c);
- }
}
}
}
diff --git a/MacroPad/ViewModels/MainViewViewModel.cs b/MacroPad/Views/MainViewViewModel.cs
similarity index 96%
rename from MacroPad/ViewModels/MainViewViewModel.cs
rename to MacroPad/Views/MainViewViewModel.cs
index 00a0ba5..42e1e19 100644
--- a/MacroPad/ViewModels/MainViewViewModel.cs
+++ b/MacroPad/Views/MainViewViewModel.cs
@@ -1,9 +1,10 @@
using Avalonia.Controls;
using FluentAvalonia.UI.Controls;
using MacroPad.Pages;
+using MacroPad.ViewModels;
using System;
-namespace MacroPad.ViewModels
+namespace MacroPad.Views
{
public class MainViewViewModel : ViewModelBase
{
diff --git a/MacroPad/Views/MainWindow.axaml b/MacroPad/Views/MainWindow.axaml
index 8c4ea0a..ca2ed6b 100644
--- a/MacroPad/Views/MainWindow.axaml
+++ b/MacroPad/Views/MainWindow.axaml
@@ -2,19 +2,31 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="using:MacroPad.ViewModels"
xmlns:views="using:MacroPad.Views"
+ xmlns:ui="using:FluentAvalonia.UI.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="MacroPad.Views.MainWindow"
- x:DataType="vm:MainWindowViewModel"
+ x:DataType="views:MainWindowViewModel"
Icon="/Assets/avalonia-logo.ico"
Title="MacroPad">
-
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/MacroPad/ViewModels/MainWindowViewModel.cs b/MacroPad/Views/MainWindowViewModel.cs
similarity index 55%
rename from MacroPad/ViewModels/MainWindowViewModel.cs
rename to MacroPad/Views/MainWindowViewModel.cs
index 6b2ac20..ee4f9b1 100644
--- a/MacroPad/ViewModels/MainWindowViewModel.cs
+++ b/MacroPad/Views/MainWindowViewModel.cs
@@ -1,4 +1,6 @@
-namespace MacroPad.ViewModels
+using MacroPad.ViewModels;
+
+namespace MacroPad.Views
{
internal class MainWindowViewModel : ViewModelBase
{
diff --git a/MacroPad/Views/Navigation/DeviceNav.axaml b/MacroPad/Views/Navigation/DeviceNav.axaml
new file mode 100644
index 0000000..752a3d7
--- /dev/null
+++ b/MacroPad/Views/Navigation/DeviceNav.axaml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/MacroPad/Views/Navigation/DeviceNav.axaml.cs b/MacroPad/Views/Navigation/DeviceNav.axaml.cs
new file mode 100644
index 0000000..f0360bb
--- /dev/null
+++ b/MacroPad/Views/Navigation/DeviceNav.axaml.cs
@@ -0,0 +1,13 @@
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Markup.Xaml;
+
+namespace MacroPad.Views.Navigation;
+
+public partial class DeviceNav : UserControl
+{
+ public DeviceNav()
+ {
+ InitializeComponent();
+ }
+}
\ No newline at end of file
From dea14e84bc7a013ebaecbe9df1a894efc804b06f Mon Sep 17 00:00:00 2001
From: Piripe <77517308+Piripe@users.noreply.github.com>
Date: Thu, 20 Feb 2025 01:22:23 +0100
Subject: [PATCH 02/16] Added device navigator
---
MacroPad.Core/Device/DeviceCore.cs | 2 +-
MacroPad.Core/Device/DeviceLayout.cs | 6 ++--
MacroPad.Core/DeviceManager.cs | 10 +++---
MacroPad/AppViewModel.cs | 2 +-
MacroPad/Controls/DeviceViewer.axaml | 14 +++++---
MacroPad/Controls/DeviceViewer.axaml.cs | 10 ++++--
.../DeviceViewerButtonPressedEventArgs.cs | 2 +-
MacroPad/Controls/Settings/DeviceCard.axaml | 4 +--
.../Controls/Settings/DeviceCard.axaml.cs | 4 +--
MacroPad/Pages/MainPage.axaml.cs | 3 +-
MacroPad/Views/MainWindow.axaml | 26 ++++++++++++++-
MacroPad/Views/MainWindowViewModel.cs | 26 +++++++++++++--
MacroPad/Views/Navigation/DeviceNav.axaml | 33 ++++++++++++++-----
MacroPad/Views/Navigation/DeviceNav.axaml.cs | 3 ++
.../Views/Navigation/DeviceNavViewModel.cs | 23 +++++++++++++
15 files changed, 134 insertions(+), 34 deletions(-)
rename MacroPad/Controls/{Home => }/DeviceViewerButtonPressedEventArgs.cs (85%)
create mode 100644 MacroPad/Views/Navigation/DeviceNavViewModel.cs
diff --git a/MacroPad.Core/Device/DeviceCore.cs b/MacroPad.Core/Device/DeviceCore.cs
index 65ba433..2b3e485 100644
--- a/MacroPad.Core/Device/DeviceCore.cs
+++ b/MacroPad.Core/Device/DeviceCore.cs
@@ -21,7 +21,7 @@ public class DeviceCore
public Dictionary ButtonsCurrentValue => _lastValue;
- public string Name => Layout==null?ProtocolDevice.Name:Layout.Name;
+ public string Name => Layout?.Name ?? ProtocolDevice.Name;
public DeviceCore(IProtocolDevice protocolDevice)
{
diff --git a/MacroPad.Core/Device/DeviceLayout.cs b/MacroPad.Core/Device/DeviceLayout.cs
index 25128e7..e1472bf 100644
--- a/MacroPad.Core/Device/DeviceLayout.cs
+++ b/MacroPad.Core/Device/DeviceLayout.cs
@@ -35,8 +35,8 @@ public string GetAssetPath(string path)
}
- public static List LoadLayouts() {
- var layouts = new List();
+ public static HashSet LoadLayouts() {
+ var layouts = new HashSet();
if (Directory.Exists("layouts"))
{
@@ -57,7 +57,7 @@ public static List LoadLayouts() {
public static DeviceLayout? SearchLayout(IProtocolDevice device) {
- return DeviceManager.Layouts.Find((layout) =>
+ return DeviceManager.Layouts.FirstOrDefault((layout) =>
{
if (layout.Protocol != device.Protocol) return false;
string input = layout.DetectionMode.HasFlag(DeviceDetectionMode.Name) ? device.Name : device.Id;
diff --git a/MacroPad.Core/DeviceManager.cs b/MacroPad.Core/DeviceManager.cs
index 00dcb12..80b96aa 100644
--- a/MacroPad.Core/DeviceManager.cs
+++ b/MacroPad.Core/DeviceManager.cs
@@ -8,8 +8,8 @@ namespace MacroPad.Core
public class DeviceManager
{
public static MacroPadConfig Config { get; } = MacroPadConfig.LoadConfig();
- public static List Layouts { get; } = DeviceLayout.LoadLayouts();
- public static List ConnectedDevices { get; } = [];
+ public static HashSet Layouts { get; } = DeviceLayout.LoadLayouts();
+ public static HashSet ConnectedDevices { get; } = [];
public static DeviceCore? SelectedDevice { get; set; }
public static event EventHandler? DeviceDetected;
@@ -60,7 +60,7 @@ private static void Protocol_DeviceDetected(object? sender, DeviceDetectedEventA
private static void Protocol_DeviceDisconnected(object? sender, DeviceDetectedEventArgs e)
{
Console.WriteLine($"Device disconnected: {e.Device.Name} ({e.Device.Id})");
- ConnectedDevices.RemoveAll(device=>device.ProtocolDevice == e.Device);
+ ConnectedDevices.RemoveWhere(device=>device.ProtocolDevice == e.Device);
DeviceDisconnected?.Invoke(sender, e);
}
@@ -94,7 +94,7 @@ public static void DisableProtocol(string pluginId)
public static void EnableDevice(string deviceId)
{
- DeviceCore? device = ConnectedDevices.Find((x) => x.ProtocolDevice.Id == deviceId);
+ DeviceCore? device = ConnectedDevices.FirstOrDefault((x) => x.ProtocolDevice.Id == deviceId);
if (device != null)
{
device.Connect();
@@ -103,7 +103,7 @@ public static void EnableDevice(string deviceId)
}
public static void DisableDevice(string deviceId)
{
- DeviceCore? device = ConnectedDevices.Find((x) => x.ProtocolDevice.Id == deviceId);
+ DeviceCore? device = ConnectedDevices.FirstOrDefault((x) => x.ProtocolDevice.Id == deviceId);
if (device != null)
{
device.Disconnect();
diff --git a/MacroPad/AppViewModel.cs b/MacroPad/AppViewModel.cs
index d9b7787..0d90069 100644
--- a/MacroPad/AppViewModel.cs
+++ b/MacroPad/AppViewModel.cs
@@ -14,7 +14,7 @@ public class AppViewModel
public AppViewModel()
{
- _mainWindow = new MainWindow();
+ _mainWindow = new MainWindow() { DataContext = new MainWindowViewModel()};
ExitCommand = ReactiveCommand.Create(Exit);
}
diff --git a/MacroPad/Controls/DeviceViewer.axaml b/MacroPad/Controls/DeviceViewer.axaml
index bd8e023..0a8061e 100644
--- a/MacroPad/Controls/DeviceViewer.axaml
+++ b/MacroPad/Controls/DeviceViewer.axaml
@@ -4,18 +4,24 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:paz="using:Avalonia.Controls.PanAndZoom"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
- x:Class="MacroPad.Controls.Home.DeviceViewer">
+ x:Class="MacroPad.Controls.DeviceViewer">
+
+
+
+
+
+ HorizontalAlignment="Stretch" >
-
+
+
+
+
diff --git a/MacroPad/Styles/MacroPad.axaml b/MacroPad/Styles/MacroPad.axaml
index eef982f..01a8ade 100644
--- a/MacroPad/Styles/MacroPad.axaml
+++ b/MacroPad/Styles/MacroPad.axaml
@@ -56,6 +56,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/MacroPad/Views/MainSettings.axaml.cs b/MacroPad/Views/MainSettings.axaml.cs
new file mode 100644
index 0000000..6ffac63
--- /dev/null
+++ b/MacroPad/Views/MainSettings.axaml.cs
@@ -0,0 +1,13 @@
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Markup.Xaml;
+
+namespace MacroPad.Views;
+
+public partial class MainSettings : UserControl
+{
+ public MainSettings()
+ {
+ InitializeComponent();
+ }
+}
\ No newline at end of file
diff --git a/MacroPad/Views/MainSettingsViewModel.cs b/MacroPad/Views/MainSettingsViewModel.cs
new file mode 100644
index 0000000..1e7f8f9
--- /dev/null
+++ b/MacroPad/Views/MainSettingsViewModel.cs
@@ -0,0 +1,26 @@
+using Avalonia;
+using Avalonia.Controls;
+using MacroPad.ViewModels;
+using MacroPad.Views.Settings;
+using ReactiveUI;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace MacroPad.Views
+{
+ public class MainSettingsViewModel : ViewModelBase
+ {
+ private bool _openend = false;
+ public bool Openend { get => _openend; set => this.RaiseAndSetIfChanged(ref _openend, value); }
+ private int _selectedCat = 0;
+ public int SelectedCat { get => _selectedCat; set => this.RaiseAndSetIfChanged(ref _selectedCat, value); }
+
+ public void Open() => Openend = true;
+ public void Close() => Openend = false;
+
+ public static StyledElement[] SettingsCategories { get; } = [new General() { DataContext = new GeneralViewModel()}];
+ }
+}
diff --git a/MacroPad/Views/MainWindow.axaml b/MacroPad/Views/MainWindow.axaml
index 757e298..549fa14 100644
--- a/MacroPad/Views/MainWindow.axaml
+++ b/MacroPad/Views/MainWindow.axaml
@@ -22,7 +22,7 @@
-
+
@@ -49,7 +49,7 @@
-
+
@@ -57,6 +57,8 @@
Select a device first
+
+
diff --git a/MacroPad/Views/MainWindowViewModel.cs b/MacroPad/Views/MainWindowViewModel.cs
index 75f4799..a45e27b 100644
--- a/MacroPad/Views/MainWindowViewModel.cs
+++ b/MacroPad/Views/MainWindowViewModel.cs
@@ -3,6 +3,7 @@
using MacroPad.Core.Device;
using MacroPad.ViewModels;
using MacroPad.Views.Navigation;
+using ReactiveUI;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
@@ -12,6 +13,8 @@ namespace MacroPad.Views
public class MainWindowViewModel : ViewModelBase
{
private readonly Dictionary _deviceEditors = [];
+
+ public MainSettingsViewModel Settings { get; } = new();
public MainWindowViewModel() {
DeviceManager.DeviceDetected += DeviceManager_DeviceDetected;
DeviceManager.DeviceDisconnected += DeviceManager_DeviceDisconnected;
diff --git a/MacroPad/Views/Settings/General.axaml b/MacroPad/Views/Settings/General.axaml
new file mode 100644
index 0000000..69be3eb
--- /dev/null
+++ b/MacroPad/Views/Settings/General.axaml
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
+ Run on system startup
+
+
+
+
+
+
+ Minimize on startup
+
+
+
+
+
+
diff --git a/MacroPad/Views/Settings/General.axaml.cs b/MacroPad/Views/Settings/General.axaml.cs
new file mode 100644
index 0000000..ace292f
--- /dev/null
+++ b/MacroPad/Views/Settings/General.axaml.cs
@@ -0,0 +1,14 @@
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Markup.Xaml;
+
+namespace MacroPad.Views.Settings;
+
+public partial class General : UserControl
+{
+ public General()
+ {
+ InitializeComponent();
+ }
+ public override string ToString() => "General";
+}
\ No newline at end of file
diff --git a/MacroPad/Views/Settings/GeneralViewModel.cs b/MacroPad/Views/Settings/GeneralViewModel.cs
new file mode 100644
index 0000000..24be633
--- /dev/null
+++ b/MacroPad/Views/Settings/GeneralViewModel.cs
@@ -0,0 +1,38 @@
+using MacroPad.Utilities;
+using MacroPad.ViewModels;
+using ReactiveUI;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace MacroPad.Views.Settings
+{
+ public class GeneralViewModel : ViewModelBase
+ {
+ private bool _runStartup = false;
+ public bool RunStartup { get => _runStartup; set => this.RaiseAndSetIfChanged(ref _runStartup, value); }
+ private bool _runMin = false;
+ public bool RunMin { get => _runMin; set => this.RaiseAndSetIfChanged(ref _runMin, value); }
+ public GeneralViewModel()
+ {
+ if (OperatingSystem.IsWindows())
+ {
+ WindowsUtils.StartupStatus status = WindowsUtils.GetAppStartupStatus();
+
+ RunStartup = status.OnStartup;
+ RunMin = status.Minimized;
+ }
+ this.PropertyChanged += GeneralViewModel_PropertyChanged;
+ }
+
+ private void GeneralViewModel_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
+ {
+ if (OperatingSystem.IsWindows())
+ {
+ WindowsUtils.SetAppRunOnLaunch(RunStartup, RunMin);
+ }
+ }
+ }
+}
From 770c736509a5188f8b6f1da433d79db632d73a0f Mon Sep 17 00:00:00 2001
From: Piripe <77517308+Piripe@users.noreply.github.com>
Date: Sat, 22 Feb 2025 17:20:54 +0100
Subject: [PATCH 06/16] Added plugins category in settings
---
MacroPad.Core/PluginLoader.cs | 4 +++
MacroPad/Controls/Settings/PluginRow.axaml | 36 +++++++++++++++++++
MacroPad/Controls/Settings/PluginRow.axaml.cs | 11 ++++++
.../Controls/Settings/PluginRowViewModel.cs | 17 +++++++++
MacroPad/Views/MainSettingsViewModel.cs | 2 +-
MacroPad/Views/Settings/General.axaml | 4 +--
MacroPad/Views/Settings/General.axaml.cs | 2 --
MacroPad/Views/Settings/GeneralViewModel.cs | 6 +---
MacroPad/Views/Settings/Plugins.axaml | 22 ++++++++++++
MacroPad/Views/Settings/Plugins.axaml.cs | 12 +++++++
MacroPad/Views/Settings/PluginsViewModel.cs | 21 +++++++++++
11 files changed, 127 insertions(+), 10 deletions(-)
create mode 100644 MacroPad/Controls/Settings/PluginRow.axaml
create mode 100644 MacroPad/Controls/Settings/PluginRow.axaml.cs
create mode 100644 MacroPad/Controls/Settings/PluginRowViewModel.cs
create mode 100644 MacroPad/Views/Settings/Plugins.axaml
create mode 100644 MacroPad/Views/Settings/Plugins.axaml.cs
create mode 100644 MacroPad/Views/Settings/PluginsViewModel.cs
diff --git a/MacroPad.Core/PluginLoader.cs b/MacroPad.Core/PluginLoader.cs
index cf7c3f4..a512aa2 100644
--- a/MacroPad.Core/PluginLoader.cs
+++ b/MacroPad.Core/PluginLoader.cs
@@ -13,6 +13,9 @@ public class PluginLoader
public readonly static HashSet nodeTypes = [..DefaultTypes.types];
public readonly static HashSet nodeCategories = [new BranchingCategory(), new ButtonCategory(), new ConditionsCategory(), new ConstantsCategory(), new DebugCategory(), new MathCategory(), new ProfileCategory(), new TextCategory(), new VariableCategory()];
+ public static event EventHandler? PluginAdded;
+ public static event EventHandler? PluginRemoved;
+
public static void LoadPlugins()
{
if (!Directory.Exists("plugins")) return;
@@ -61,6 +64,7 @@ public static void LoadPlugins()
if (pluginInfos.NodeCategories != null) nodeCategories.UnionWith(pluginInfos.NodeCategories);
if (pluginInfos.NodeTypes != null) nodeTypes.UnionWith(pluginInfos.NodeTypes);
+ PluginAdded?.Invoke(null, pluginInfos);
}
//plugins.Sort((a,b)=>a.Name.CompareTo(b.Name));
diff --git a/MacroPad/Controls/Settings/PluginRow.axaml b/MacroPad/Controls/Settings/PluginRow.axaml
new file mode 100644
index 0000000..678e989
--- /dev/null
+++ b/MacroPad/Controls/Settings/PluginRow.axaml
@@ -0,0 +1,36 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/MacroPad/Controls/Settings/PluginRow.axaml.cs b/MacroPad/Controls/Settings/PluginRow.axaml.cs
new file mode 100644
index 0000000..8f2918e
--- /dev/null
+++ b/MacroPad/Controls/Settings/PluginRow.axaml.cs
@@ -0,0 +1,11 @@
+using Avalonia.Controls;
+
+namespace MacroPad.Controls.Settings;
+
+public partial class PluginRow : UserControl
+{
+ public PluginRow()
+ {
+ InitializeComponent();
+ }
+}
\ No newline at end of file
diff --git a/MacroPad/Controls/Settings/PluginRowViewModel.cs b/MacroPad/Controls/Settings/PluginRowViewModel.cs
new file mode 100644
index 0000000..dd1b674
--- /dev/null
+++ b/MacroPad/Controls/Settings/PluginRowViewModel.cs
@@ -0,0 +1,17 @@
+using MacroPad.Core.BasePlugin;
+using MacroPad.Shared.Plugin;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace MacroPad.Controls.Settings
+{
+ public class PluginRowViewModel
+ {
+ public IPluginInfos Plugin { get; set; }
+ public PluginRowViewModel(IPluginInfos plugin) { Plugin = plugin; }
+ public PluginRowViewModel() { Plugin = new BasePluginInfos(); }
+ }
+}
diff --git a/MacroPad/Views/MainSettingsViewModel.cs b/MacroPad/Views/MainSettingsViewModel.cs
index 1e7f8f9..14df743 100644
--- a/MacroPad/Views/MainSettingsViewModel.cs
+++ b/MacroPad/Views/MainSettingsViewModel.cs
@@ -21,6 +21,6 @@ public class MainSettingsViewModel : ViewModelBase
public void Open() => Openend = true;
public void Close() => Openend = false;
- public static StyledElement[] SettingsCategories { get; } = [new General() { DataContext = new GeneralViewModel()}];
+ public static StyledElement[] SettingsCategories { get; } = [new General() { DataContext = new GeneralViewModel()}, new Plugins() { DataContext = new PluginsViewModel()}];
}
}
diff --git a/MacroPad/Views/Settings/General.axaml b/MacroPad/Views/Settings/General.axaml
index 69be3eb..75d0029 100644
--- a/MacroPad/Views/Settings/General.axaml
+++ b/MacroPad/Views/Settings/General.axaml
@@ -8,8 +8,8 @@
x:DataType="local:GeneralViewModel">
-
-
+
+
Run on system startup
diff --git a/MacroPad/Views/Settings/General.axaml.cs b/MacroPad/Views/Settings/General.axaml.cs
index ace292f..d32a441 100644
--- a/MacroPad/Views/Settings/General.axaml.cs
+++ b/MacroPad/Views/Settings/General.axaml.cs
@@ -1,6 +1,4 @@
-using Avalonia;
using Avalonia.Controls;
-using Avalonia.Markup.Xaml;
namespace MacroPad.Views.Settings;
diff --git a/MacroPad/Views/Settings/GeneralViewModel.cs b/MacroPad/Views/Settings/GeneralViewModel.cs
index 24be633..c3c5756 100644
--- a/MacroPad/Views/Settings/GeneralViewModel.cs
+++ b/MacroPad/Views/Settings/GeneralViewModel.cs
@@ -2,10 +2,6 @@
using MacroPad.ViewModels;
using ReactiveUI;
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace MacroPad.Views.Settings
{
@@ -24,7 +20,7 @@ public GeneralViewModel()
RunStartup = status.OnStartup;
RunMin = status.Minimized;
}
- this.PropertyChanged += GeneralViewModel_PropertyChanged;
+ PropertyChanged += GeneralViewModel_PropertyChanged;
}
private void GeneralViewModel_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
diff --git a/MacroPad/Views/Settings/Plugins.axaml b/MacroPad/Views/Settings/Plugins.axaml
new file mode 100644
index 0000000..a7fb88b
--- /dev/null
+++ b/MacroPad/Views/Settings/Plugins.axaml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/MacroPad/Views/Settings/Plugins.axaml.cs b/MacroPad/Views/Settings/Plugins.axaml.cs
new file mode 100644
index 0000000..d37506a
--- /dev/null
+++ b/MacroPad/Views/Settings/Plugins.axaml.cs
@@ -0,0 +1,12 @@
+using Avalonia.Controls;
+
+namespace MacroPad.Views.Settings;
+
+public partial class Plugins : UserControl
+{
+ public Plugins()
+ {
+ InitializeComponent();
+ }
+ public override string ToString() => "Plugins";
+}
\ No newline at end of file
diff --git a/MacroPad/Views/Settings/PluginsViewModel.cs b/MacroPad/Views/Settings/PluginsViewModel.cs
new file mode 100644
index 0000000..4178012
--- /dev/null
+++ b/MacroPad/Views/Settings/PluginsViewModel.cs
@@ -0,0 +1,21 @@
+using MacroPad.Controls.Settings;
+using MacroPad.Core;
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace MacroPad.Views.Settings
+{
+ public class PluginsViewModel
+ {
+ public ObservableCollection Plugins { get; set; }
+ public PluginsViewModel() {
+ Plugins = [.. PluginLoader.plugins.Select(x => new PluginRowViewModel(x))];
+ PluginLoader.PluginAdded += (s, e) => Plugins.Add(new PluginRowViewModel(e));
+ PluginLoader.PluginRemoved += (s, e) => Plugins.Remove(Plugins.First(x => x.Plugin == e));
+ }
+ }
+}
From 826212af28f062397ba03a095eba48e5c3425576 Mon Sep 17 00:00:00 2001
From: Piripe <77517308+Piripe@users.noreply.github.com>
Date: Sat, 22 Feb 2025 18:38:09 +0100
Subject: [PATCH 07/16] Clarified distinction between NodeResourceManager and
ResourceManager
---
.../BasePlugin/Branching/GetBranch.cs | 4 +-
.../BasePlugin/Branching/RunBranch.cs | 2 +-
.../BasePlugin/Button/GetCurrentValue.cs | 2 +-
.../Button/SetCurrentPaletteColor.cs | 7 +-
.../BasePlugin/Conditions/Condition.cs | 3 +-
MacroPad.Core/BasePlugin/Constants/Boolean.cs | 3 +-
MacroPad.Core/BasePlugin/Constants/Number.cs | 5 +-
MacroPad.Core/BasePlugin/Constants/Text.cs | 3 +-
MacroPad.Core/BasePlugin/DefaultTypes.cs | 1 -
MacroPad.Core/BasePlugin/Math/Absolute.cs | 2 +-
MacroPad.Core/BasePlugin/Math/Floor.cs | 2 +-
MacroPad.Core/BasePlugin/Math/Map.cs | 2 +-
MacroPad.Core/BasePlugin/Math/Max.cs | 2 +-
MacroPad.Core/BasePlugin/Math/Min.cs | 2 +-
MacroPad.Core/BasePlugin/Math/MinMax.cs | 2 +-
MacroPad.Core/BasePlugin/Math/Operation.cs | 3 +-
MacroPad.Core/BasePlugin/Math/Round.cs | 2 +-
.../BasePlugin/Profile/SetProfile.cs | 5 +-
MacroPad.Core/BasePlugin/Text/Join.cs | 7 +-
MacroPad.Core/BasePlugin/Text/Replace.cs | 7 +-
MacroPad.Core/BasePlugin/Variables/Get.cs | 3 +-
MacroPad.Core/BasePlugin/Variables/Set.cs | 3 +-
MacroPad.Core/Node/NodeResourceManager.cs | 17 +-
MacroPad.Core/NodeManager.cs | 6 +-
MacroPad.Core/ResourceManager.cs | 29 +++
MacroPad.Shared/Plugin/Components/ComboBox.cs | 2 +-
.../Plugin/Components/IComponent.cs | 12 ++
.../Plugin/{Nodes => }/IResourceManager.cs | 4 +-
.../Plugin/Nodes/INodeComponent.cs | 6 +-
MacroPad.Shared/Plugin/Nodes/INodeGetter.cs | 2 +-
.../Plugin/Nodes/INodeResourceManager.cs | 13 ++
MacroPad.Shared/Plugin/Nodes/INodeRunner.cs | 2 +-
.../Plugin/Settings/ISettingsComponent.cs | 6 +-
MacroPad.Shared/Plugin/VirtualDataKey.cs | 14 ++
MacroPad/Controls/ComponentDisplay.cs | 185 ++++++++++++++++++
.../Controls/Home/NodeLinksDisplay.axaml.cs | 93 +--------
36 files changed, 314 insertions(+), 149 deletions(-)
create mode 100644 MacroPad.Core/ResourceManager.cs
create mode 100644 MacroPad.Shared/Plugin/Components/IComponent.cs
rename MacroPad.Shared/Plugin/{Nodes => }/IResourceManager.cs (62%)
create mode 100644 MacroPad.Shared/Plugin/Nodes/INodeResourceManager.cs
create mode 100644 MacroPad.Shared/Plugin/VirtualDataKey.cs
create mode 100644 MacroPad/Controls/ComponentDisplay.cs
diff --git a/MacroPad.Core/BasePlugin/Branching/GetBranch.cs b/MacroPad.Core/BasePlugin/Branching/GetBranch.cs
index 80a8b89..60f6e52 100644
--- a/MacroPad.Core/BasePlugin/Branching/GetBranch.cs
+++ b/MacroPad.Core/BasePlugin/Branching/GetBranch.cs
@@ -18,9 +18,9 @@ public class GetBranch : INodeGetter
public INodeComponent[] Components => [];
public bool IsVisible(IDeviceLayoutButton button, IDeviceOutput output) => true;
- public object[] GetOutputs(IResourceManager resource)
+ public object[] GetOutputs(INodeResourceManager resource)
{
- return new object[] { resource.GetValue((bool)resource.GetValue(0) ? 2 : 1) };
+ return [ resource.GetValue((bool)resource.GetValue(0) ? 2 : 1) ];
}
}
}
diff --git a/MacroPad.Core/BasePlugin/Branching/RunBranch.cs b/MacroPad.Core/BasePlugin/Branching/RunBranch.cs
index 677159a..9c5883d 100644
--- a/MacroPad.Core/BasePlugin/Branching/RunBranch.cs
+++ b/MacroPad.Core/BasePlugin/Branching/RunBranch.cs
@@ -21,7 +21,7 @@ public class SetPaletteColor : INodeRunner
public INodeComponent[] Components => [];
public bool IsVisible(IDeviceLayoutButton button, IDeviceOutput output) => true;
- public NodeRunnerResult Run(IResourceManager resource)
+ public NodeRunnerResult Run(INodeResourceManager resource)
{
return new NodeRunnerResult() { Results = [], RunnerOutputIndex = (bool)resource.GetValue(0) ? 1 : 0 };
}
diff --git a/MacroPad.Core/BasePlugin/Button/GetCurrentValue.cs b/MacroPad.Core/BasePlugin/Button/GetCurrentValue.cs
index 781a493..fcff2ad 100644
--- a/MacroPad.Core/BasePlugin/Button/GetCurrentValue.cs
+++ b/MacroPad.Core/BasePlugin/Button/GetCurrentValue.cs
@@ -18,7 +18,7 @@ public class GetCurrentValue : INodeGetter
public INodeComponent[] Components => [];
public bool IsVisible(IDeviceLayoutButton button, IDeviceOutput output) => button.Type == ButtonType.Slider;
- public object[] GetOutputs(IResourceManager resource)
+ public object[] GetOutputs(INodeResourceManager resource)
{
return [(decimal)(NodeManager.CurrentDevice != null && NodeManager.CurrentButton != null ? NodeManager.CurrentDevice.ButtonsCurrentValue[NodeManager.CurrentButton.Id].Value : 0)];
}
diff --git a/MacroPad.Core/BasePlugin/Button/SetCurrentPaletteColor.cs b/MacroPad.Core/BasePlugin/Button/SetCurrentPaletteColor.cs
index 209dfa9..6f6e734 100644
--- a/MacroPad.Core/BasePlugin/Button/SetCurrentPaletteColor.cs
+++ b/MacroPad.Core/BasePlugin/Button/SetCurrentPaletteColor.cs
@@ -1,6 +1,7 @@
using MacroPad.Shared.Device;
using MacroPad.Shared.Plugin.Nodes;
using MacroPad.Shared.Plugin.Components;
+using MacroPad.Shared.Plugin;
namespace MacroPad.Core.BasePlugin.Button
{
@@ -22,9 +23,9 @@ public class SetCurrentPaletteColor : INodeRunner
public INodeComponent[] Components => [
new ComboBox()
{
- GetItems = (IResourceManager resource, IDeviceLayoutButton button, IDeviceOutput output) =>
+ GetItems = (IResourceManager resource) =>
{
- return output.Palette.Select(x=>x.Name).ToArray();
+ return resource.GetVirtual(VirtualDataKey.DeviceOutput)?.Palette.Select(x=>x.Name).ToArray() ?? [];
},
GetSelection = (IResourceManager resource) =>
{
@@ -38,7 +39,7 @@ public class SetCurrentPaletteColor : INodeRunner
];
public bool IsVisible(IDeviceLayoutButton button, IDeviceOutput output) => output.OutputType == OutputType.Palette;
- public NodeRunnerResult Run(IResourceManager resource)
+ public NodeRunnerResult Run(INodeResourceManager resource)
{
if (NodeManager.CurrentButton != null) NodeManager.CurrentDevice?.SetButtonContent(NodeManager.CurrentButton, resource.GetData("color"));
return new NodeRunnerResult() { Results = [], RunnerOutputIndex = 0 };
diff --git a/MacroPad.Core/BasePlugin/Conditions/Condition.cs b/MacroPad.Core/BasePlugin/Conditions/Condition.cs
index 7381dc6..2cb564d 100644
--- a/MacroPad.Core/BasePlugin/Conditions/Condition.cs
+++ b/MacroPad.Core/BasePlugin/Conditions/Condition.cs
@@ -1,6 +1,7 @@
using MacroPad.Shared.Device;
using MacroPad.Shared.Plugin.Nodes;
using MacroPad.Shared.Plugin.Components;
+using MacroPad.Shared.Plugin;
namespace MacroPad.Core.BasePlugin.Conditions
{
@@ -41,7 +42,7 @@ public class Condition : INodeGetter
private static decimal ObjectToDecimal(object x) => (decimal.TryParse(x.ToString(), out decimal val) ? val : 0m);
public bool IsVisible(IDeviceLayoutButton button, IDeviceOutput output) => true;
- public object[] GetOutputs(IResourceManager resource)
+ public object[] GetOutputs(INodeResourceManager resource)
{
return [ _operations[resource.GetData("o")](resource.GetValue(0), resource.GetValue(1)) ];
}
diff --git a/MacroPad.Core/BasePlugin/Constants/Boolean.cs b/MacroPad.Core/BasePlugin/Constants/Boolean.cs
index c32063c..2325e13 100644
--- a/MacroPad.Core/BasePlugin/Constants/Boolean.cs
+++ b/MacroPad.Core/BasePlugin/Constants/Boolean.cs
@@ -1,6 +1,7 @@
using MacroPad.Shared.Device;
using MacroPad.Shared.Plugin.Nodes;
using MacroPad.Shared.Plugin.Components;
+using MacroPad.Shared.Plugin;
namespace MacroPad.Core.BasePlugin.Constants
{
@@ -23,7 +24,7 @@ internal class Boolean : INodeGetter
} ];
public bool IsVisible(IDeviceLayoutButton button, IDeviceOutput output) => true;
- public object[] GetOutputs(IResourceManager resource)
+ public object[] GetOutputs(INodeResourceManager resource)
{
return [resource.GetData("v") ?? false];
}
diff --git a/MacroPad.Core/BasePlugin/Constants/Number.cs b/MacroPad.Core/BasePlugin/Constants/Number.cs
index 2a39afc..1aaf840 100644
--- a/MacroPad.Core/BasePlugin/Constants/Number.cs
+++ b/MacroPad.Core/BasePlugin/Constants/Number.cs
@@ -1,6 +1,7 @@
using MacroPad.Shared.Device;
using MacroPad.Shared.Plugin.Nodes;
using MacroPad.Shared.Plugin.Components;
+using MacroPad.Shared.Plugin;
namespace MacroPad.Core.BasePlugin.Constants
{
@@ -24,9 +25,9 @@ internal class Number : INodeGetter
} ];
public bool IsVisible(IDeviceLayoutButton button, IDeviceOutput output) => true;
- public object[] GetOutputs(IResourceManager resource)
+ public object[] GetOutputs(INodeResourceManager resource)
{
- return new object[] { resource.GetData("v") ?? 0m };
+ return [ resource.GetData("v") ?? 0m ];
}
}
}
diff --git a/MacroPad.Core/BasePlugin/Constants/Text.cs b/MacroPad.Core/BasePlugin/Constants/Text.cs
index f7151cd..46f93ad 100644
--- a/MacroPad.Core/BasePlugin/Constants/Text.cs
+++ b/MacroPad.Core/BasePlugin/Constants/Text.cs
@@ -1,6 +1,7 @@
using MacroPad.Shared.Device;
using MacroPad.Shared.Plugin.Nodes;
using MacroPad.Shared.Plugin.Components;
+using MacroPad.Shared.Plugin;
namespace MacroPad.Core.BasePlugin.Constants
{
@@ -22,7 +23,7 @@ internal class Text : INodeGetter
} ];
public bool IsVisible(IDeviceLayoutButton button, IDeviceOutput output) => true;
- public object[] GetOutputs(IResourceManager resource)
+ public object[] GetOutputs(INodeResourceManager resource)
{
return [resource.GetData("v") ?? ""];
}
diff --git a/MacroPad.Core/BasePlugin/DefaultTypes.cs b/MacroPad.Core/BasePlugin/DefaultTypes.cs
index e298cb1..b434dd1 100644
--- a/MacroPad.Core/BasePlugin/DefaultTypes.cs
+++ b/MacroPad.Core/BasePlugin/DefaultTypes.cs
@@ -1,5 +1,4 @@
using MacroPad.Shared.Plugin;
-using MacroPad.Shared.Plugin.Nodes;
using MacroPad.Shared.Plugin.Components;
namespace MacroPad.Core.BasePlugin
diff --git a/MacroPad.Core/BasePlugin/Math/Absolute.cs b/MacroPad.Core/BasePlugin/Math/Absolute.cs
index 1556304..1fd9430 100644
--- a/MacroPad.Core/BasePlugin/Math/Absolute.cs
+++ b/MacroPad.Core/BasePlugin/Math/Absolute.cs
@@ -18,7 +18,7 @@ public class Absolute : INodeGetter
public INodeComponent[] Components => [];
public bool IsVisible(IDeviceLayoutButton button, IDeviceOutput output) => true;
- public object[] GetOutputs(IResourceManager resource)
+ public object[] GetOutputs(INodeResourceManager resource)
{
return [System.Math.Abs((decimal)resource.GetValue(0))];
}
diff --git a/MacroPad.Core/BasePlugin/Math/Floor.cs b/MacroPad.Core/BasePlugin/Math/Floor.cs
index 4714e94..2454255 100644
--- a/MacroPad.Core/BasePlugin/Math/Floor.cs
+++ b/MacroPad.Core/BasePlugin/Math/Floor.cs
@@ -18,7 +18,7 @@ public class Floor : INodeGetter
public INodeComponent[] Components => [];
public bool IsVisible(IDeviceLayoutButton button, IDeviceOutput output) => true;
- public object[] GetOutputs(IResourceManager resource)
+ public object[] GetOutputs(INodeResourceManager resource)
{
return [System.Math.Floor((decimal)resource.GetValue(0))];
}
diff --git a/MacroPad.Core/BasePlugin/Math/Map.cs b/MacroPad.Core/BasePlugin/Math/Map.cs
index d514792..a01051c 100644
--- a/MacroPad.Core/BasePlugin/Math/Map.cs
+++ b/MacroPad.Core/BasePlugin/Math/Map.cs
@@ -18,7 +18,7 @@ public class Map : INodeGetter
public INodeComponent[] Components => [];
public bool IsVisible(IDeviceLayoutButton button, IDeviceOutput output) => true;
- public object[] GetOutputs(IResourceManager resource)
+ public object[] GetOutputs(INodeResourceManager resource)
{
decimal value = (decimal)resource.GetValue(0);
decimal minIn = (decimal)resource.GetValue(1);
diff --git a/MacroPad.Core/BasePlugin/Math/Max.cs b/MacroPad.Core/BasePlugin/Math/Max.cs
index 98f45ff..e81cdec 100644
--- a/MacroPad.Core/BasePlugin/Math/Max.cs
+++ b/MacroPad.Core/BasePlugin/Math/Max.cs
@@ -18,7 +18,7 @@ public class Max : INodeGetter
public INodeComponent[] Components => [];
public bool IsVisible(IDeviceLayoutButton button, IDeviceOutput output) => true;
- public object[] GetOutputs(IResourceManager resource)
+ public object[] GetOutputs(INodeResourceManager resource)
{
return [System.Math.Max((decimal)resource.GetValue(0), (decimal)resource.GetValue(1))];
}
diff --git a/MacroPad.Core/BasePlugin/Math/Min.cs b/MacroPad.Core/BasePlugin/Math/Min.cs
index 1ecb07f..19cda93 100644
--- a/MacroPad.Core/BasePlugin/Math/Min.cs
+++ b/MacroPad.Core/BasePlugin/Math/Min.cs
@@ -18,7 +18,7 @@ public class Min : INodeGetter
public INodeComponent[] Components => [];
public bool IsVisible(IDeviceLayoutButton button, IDeviceOutput output) => true;
- public object[] GetOutputs(IResourceManager resource)
+ public object[] GetOutputs(INodeResourceManager resource)
{
return [System.Math.Min((decimal)resource.GetValue(0), (decimal)resource.GetValue(1))];
}
diff --git a/MacroPad.Core/BasePlugin/Math/MinMax.cs b/MacroPad.Core/BasePlugin/Math/MinMax.cs
index 1294267..ced0c69 100644
--- a/MacroPad.Core/BasePlugin/Math/MinMax.cs
+++ b/MacroPad.Core/BasePlugin/Math/MinMax.cs
@@ -18,7 +18,7 @@ public class MinMax : INodeGetter
public INodeComponent[] Components => [];
public bool IsVisible(IDeviceLayoutButton button, IDeviceOutput output) => true;
- public object[] GetOutputs(IResourceManager resource)
+ public object[] GetOutputs(INodeResourceManager resource)
{
return [System.Math.Min(System.Math.Max((decimal)resource.GetValue(0), (decimal)resource.GetValue(1)), (decimal)resource.GetValue(2))];
}
diff --git a/MacroPad.Core/BasePlugin/Math/Operation.cs b/MacroPad.Core/BasePlugin/Math/Operation.cs
index 522833d..3938618 100644
--- a/MacroPad.Core/BasePlugin/Math/Operation.cs
+++ b/MacroPad.Core/BasePlugin/Math/Operation.cs
@@ -1,6 +1,7 @@
using MacroPad.Shared.Device;
using MacroPad.Shared.Plugin.Nodes;
using MacroPad.Shared.Plugin.Components;
+using MacroPad.Shared.Plugin;
namespace MacroPad.Core.BasePlugin.Math
{
@@ -41,7 +42,7 @@ public class Operation : INodeGetter
];
public bool IsVisible(IDeviceLayoutButton button, IDeviceOutput output) => true;
- public object[] GetOutputs(IResourceManager resource)
+ public object[] GetOutputs(INodeResourceManager resource)
{
return [_operations[resource.GetData("o")]((decimal)resource.GetValue(0), (decimal)resource.GetValue(1))];
}
diff --git a/MacroPad.Core/BasePlugin/Math/Round.cs b/MacroPad.Core/BasePlugin/Math/Round.cs
index f0df097..6722493 100644
--- a/MacroPad.Core/BasePlugin/Math/Round.cs
+++ b/MacroPad.Core/BasePlugin/Math/Round.cs
@@ -18,7 +18,7 @@ public class Round : INodeGetter
public INodeComponent[] Components => [];
public bool IsVisible(IDeviceLayoutButton button, IDeviceOutput output) => true;
- public object[] GetOutputs(IResourceManager resource)
+ public object[] GetOutputs(INodeResourceManager resource)
{
return [System.Math.Round((decimal)resource.GetValue(0))];
}
diff --git a/MacroPad.Core/BasePlugin/Profile/SetProfile.cs b/MacroPad.Core/BasePlugin/Profile/SetProfile.cs
index 12fa23b..2b4a75d 100644
--- a/MacroPad.Core/BasePlugin/Profile/SetProfile.cs
+++ b/MacroPad.Core/BasePlugin/Profile/SetProfile.cs
@@ -2,6 +2,7 @@
using MacroPad.Shared.Device;
using MacroPad.Shared.Plugin.Nodes;
using MacroPad.Shared.Plugin.Components;
+using MacroPad.Shared.Plugin;
namespace MacroPad.Core.BasePlugin.Profile
{
@@ -33,7 +34,7 @@ private int GetProfileIndex(DeviceCore? device, IResourceManager resource)
public INodeComponent[] Components => [
new ComboBox() {
- GetItems = (IResourceManager resource, IDeviceLayoutButton button, IDeviceOutput output) =>
+ GetItems = (IResourceManager resource) =>
{
return DeviceManager.SelectedDevice?.DeviceProfiles.Select(x=>x.Name).ToArray() ?? [];
},
@@ -47,7 +48,7 @@ private int GetProfileIndex(DeviceCore? device, IResourceManager resource)
];
public bool IsVisible(IDeviceLayoutButton button, IDeviceOutput output) => true;
- public NodeRunnerResult Run(IResourceManager resource)
+ public NodeRunnerResult Run(INodeResourceManager resource)
{
if (NodeManager.CurrentDevice != null) NodeManager.CurrentDevice.SelectProfile(GetProfileIndex(NodeManager.CurrentDevice, resource));
return new NodeRunnerResult() { Results = [], RunnerOutputIndex = 0 };
diff --git a/MacroPad.Core/BasePlugin/Text/Join.cs b/MacroPad.Core/BasePlugin/Text/Join.cs
index 999d45e..26d503e 100644
--- a/MacroPad.Core/BasePlugin/Text/Join.cs
+++ b/MacroPad.Core/BasePlugin/Text/Join.cs
@@ -1,10 +1,5 @@
using MacroPad.Shared.Device;
using MacroPad.Shared.Plugin.Nodes;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace MacroPad.Core.BasePlugin.Text
{
@@ -23,7 +18,7 @@ public class Join : INodeGetter
public INodeComponent[] Components => [];
public bool IsVisible(IDeviceLayoutButton button, IDeviceOutput output) => true;
- public object[] GetOutputs(IResourceManager resource)
+ public object[] GetOutputs(INodeResourceManager resource)
{
return [string.Concat(resource.GetValue(0), resource.GetValue(1))];
}
diff --git a/MacroPad.Core/BasePlugin/Text/Replace.cs b/MacroPad.Core/BasePlugin/Text/Replace.cs
index a6fddc9..fe24d3b 100644
--- a/MacroPad.Core/BasePlugin/Text/Replace.cs
+++ b/MacroPad.Core/BasePlugin/Text/Replace.cs
@@ -1,10 +1,5 @@
using MacroPad.Shared.Device;
using MacroPad.Shared.Plugin.Nodes;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace MacroPad.Core.BasePlugin.Text
{
@@ -23,7 +18,7 @@ public class Replace : INodeGetter
public INodeComponent[] Components => [];
public bool IsVisible(IDeviceLayoutButton button, IDeviceOutput output) => true;
- public object[] GetOutputs(IResourceManager resource)
+ public object[] GetOutputs(INodeResourceManager resource)
{
return [((string)resource.GetValue(0)).Replace((string)resource.GetValue(1), (string)resource.GetValue(2))];
}
diff --git a/MacroPad.Core/BasePlugin/Variables/Get.cs b/MacroPad.Core/BasePlugin/Variables/Get.cs
index 9b62905..5bcb55f 100644
--- a/MacroPad.Core/BasePlugin/Variables/Get.cs
+++ b/MacroPad.Core/BasePlugin/Variables/Get.cs
@@ -2,6 +2,7 @@
using MacroPad.Shared.Plugin.Nodes;
using MacroPad.Shared.Plugin.Components;
using Newtonsoft.Json.Linq;
+using MacroPad.Shared.Plugin;
namespace MacroPad.Core.BasePlugin.Variables
{
@@ -23,7 +24,7 @@ public class Get : INodeGetter
} ];
public bool IsVisible(IDeviceLayoutButton button, IDeviceOutput output) => true;
- public object[] GetOutputs(IResourceManager resource)
+ public object[] GetOutputs(INodeResourceManager resource)
{
string var = resource.GetData("v") ?? "";
return [(DeviceManager.Config.Variables.TryGetValue(var, out JToken? value) ? value.Value
+
diff --git a/MacroPad/Views/Navigation/DeviceNav.axaml b/MacroPad/Views/Navigation/DeviceNav.axaml
index 41de2a3..26c9f85 100644
--- a/MacroPad/Views/Navigation/DeviceNav.axaml
+++ b/MacroPad/Views/Navigation/DeviceNav.axaml
@@ -6,7 +6,7 @@
xmlns:paz="using:Avalonia.Controls.PanAndZoom"
xmlns:nav="using:MacroPad.Views.Navigation"
xmlns:media="using:Avalonia.Media"
- mc:Ignorable="d" d:DesignWidth="192" d:DesignHeight="128"
+ mc:Ignorable="d" d:DesignWidth="198" d:DesignHeight="128"
x:DataType="nav:DeviceNavViewModel"
x:Class="MacroPad.Views.Navigation.DeviceNav">
@@ -22,10 +22,11 @@
-
-
-
-
+
+
+
+
+
diff --git a/MacroPad/Views/Navigation/DeviceNav.axaml.cs b/MacroPad/Views/Navigation/DeviceNav.axaml.cs
index 4c8f32e..7b3e7aa 100644
--- a/MacroPad/Views/Navigation/DeviceNav.axaml.cs
+++ b/MacroPad/Views/Navigation/DeviceNav.axaml.cs
@@ -10,7 +10,6 @@ public partial class DeviceNav : UserControl
public DeviceNav()
{
InitializeComponent();
- enableTextBlock.TextTrimming = new TextTrailingTrimming(" ", true);
deviceViewer.ZoomAndPan.Background = Brushes.Transparent;
}
}
\ No newline at end of file
diff --git a/MacroPad/Views/Settings/Plugins.axaml b/MacroPad/Views/Settings/Plugins.axaml
index a7fb88b..fb50702 100644
--- a/MacroPad/Views/Settings/Plugins.axaml
+++ b/MacroPad/Views/Settings/Plugins.axaml
@@ -8,8 +8,8 @@
x:Class="MacroPad.Views.Settings.Plugins"
x:DataType="local:PluginsViewModel">
-
-
+
+
From 567b0ab55a9d0618f44f871651ba60a712250741 Mon Sep 17 00:00:00 2001
From: Piripe <77517308+Piripe@users.noreply.github.com>
Date: Sun, 23 Feb 2025 18:30:03 +0100
Subject: [PATCH 09/16] Rearrange files in core project
---
ConsoleApp1/Program.cs | 1 +
MacroPad.Core/Device/DeviceCore.cs | 4 ++--
MacroPad.Core/DeviceManager.cs | 6 ++++--
MacroPad.Core/MacroPad.Core.csproj | 2 +-
MacroPad.Core/{ => Models}/Config/ButtonConfig.cs | 2 +-
MacroPad.Core/{ => Models}/Config/ButtonStatus.cs | 2 +-
MacroPad.Core/{ => Models}/Config/DeviceProfile.cs | 5 +++--
MacroPad.Core/{ => Models}/Config/NodeLine.cs | 2 +-
MacroPad.Core/{ => Models}/Config/NodeLinks.cs | 4 ++--
MacroPad.Core/{ => Models}/Config/NodeScript.cs | 4 ++--
MacroPad.Core/{Config => Models}/MacroPadConfig.cs | 9 +++++----
MacroPad.Core/{ => Models}/ResourceManager.cs | 2 +-
MacroPad.Core/Node/NodeResourceManager.cs | 3 ++-
MacroPad.Core/NodeManager.cs | 6 ++++--
MacroPad.Core/{ => Plugin}/PluginLoader.cs | 13 +++++++------
.../Controls/Home/DeviceProfileSelector.axaml.cs | 2 +-
MacroPad/Controls/Home/NodeLinksDisplay.axaml.cs | 2 +-
.../Controls/Home/NodePicker/NodePicker.axaml.cs | 2 +-
MacroPad/Controls/Home/NodesEditor.axaml.cs | 2 +-
.../Home/NodesEditorHistory/Actions/NodeAddition.cs | 2 +-
.../Home/NodesEditorHistory/Actions/NodeDeletion.cs | 2 +-
.../NodesEditorHistory/Actions/NodeLineAddition.cs | 2 +-
.../NodesEditorHistory/Actions/NodeLineDeletion.cs | 2 +-
MacroPad/Controls/Home/StatusEditor.axaml.cs | 2 +-
.../Home/StatusEditorTypes/Palette.axaml.cs | 2 +-
MacroPad/Pages/MainPage.axaml.cs | 2 +-
MacroPad/Pages/Settings/Plugins.axaml.cs | 2 +-
MacroPad/ViewModels/GeneralViewModel.cs | 1 +
MacroPad/Views/MainEditor.axaml.cs | 2 +-
MacroPad/Views/Settings/PluginsViewModel.cs | 2 +-
30 files changed, 52 insertions(+), 42 deletions(-)
rename MacroPad.Core/{ => Models}/Config/ButtonConfig.cs (89%)
rename MacroPad.Core/{ => Models}/Config/ButtonStatus.cs (82%)
rename MacroPad.Core/{ => Models}/Config/DeviceProfile.cs (76%)
rename MacroPad.Core/{ => Models}/Config/NodeLine.cs (82%)
rename MacroPad.Core/{ => Models}/Config/NodeLinks.cs (86%)
rename MacroPad.Core/{ => Models}/Config/NodeScript.cs (75%)
rename MacroPad.Core/{Config => Models}/MacroPadConfig.cs (85%)
rename MacroPad.Core/{ => Models}/ResourceManager.cs (96%)
rename MacroPad.Core/{ => Plugin}/PluginLoader.cs (92%)
diff --git a/ConsoleApp1/Program.cs b/ConsoleApp1/Program.cs
index 2078c7a..7041328 100644
--- a/ConsoleApp1/Program.cs
+++ b/ConsoleApp1/Program.cs
@@ -1,6 +1,7 @@
using MacroPad.Core;
using MacroPad.Core.Device;
+using MacroPad.Core.Plugin;
using MacroPad.Shared.Plugin;
using MacroPad.Shared.Plugin.Protocol;
using System.Reflection;
diff --git a/MacroPad.Core/Device/DeviceCore.cs b/MacroPad.Core/Device/DeviceCore.cs
index 2b3e485..a91740d 100644
--- a/MacroPad.Core/Device/DeviceCore.cs
+++ b/MacroPad.Core/Device/DeviceCore.cs
@@ -1,7 +1,7 @@
-using MacroPad.Core.Config;
-using MacroPad.Shared.Plugin.Protocol;
+using MacroPad.Shared.Plugin.Protocol;
using Newtonsoft.Json.Linq;
using MacroPad.Shared.Device;
+using MacroPad.Core.Models.Config;
namespace MacroPad.Core.Device
{
diff --git a/MacroPad.Core/DeviceManager.cs b/MacroPad.Core/DeviceManager.cs
index 80b96aa..465a3c9 100644
--- a/MacroPad.Core/DeviceManager.cs
+++ b/MacroPad.Core/DeviceManager.cs
@@ -1,5 +1,7 @@
-using MacroPad.Core.Config;
-using MacroPad.Core.Device;
+using MacroPad.Core.Device;
+using MacroPad.Core.Models;
+using MacroPad.Core.Models.Config;
+using MacroPad.Core.Plugin;
using MacroPad.Shared.Plugin;
using MacroPad.Shared.Plugin.Protocol;
diff --git a/MacroPad.Core/MacroPad.Core.csproj b/MacroPad.Core/MacroPad.Core.csproj
index 19d5f9b..6ed2a6a 100644
--- a/MacroPad.Core/MacroPad.Core.csproj
+++ b/MacroPad.Core/MacroPad.Core.csproj
@@ -1,4 +1,4 @@
-
+
net8.0
diff --git a/MacroPad.Core/Config/ButtonConfig.cs b/MacroPad.Core/Models/Config/ButtonConfig.cs
similarity index 89%
rename from MacroPad.Core/Config/ButtonConfig.cs
rename to MacroPad.Core/Models/Config/ButtonConfig.cs
index df07e0c..0e66e80 100644
--- a/MacroPad.Core/Config/ButtonConfig.cs
+++ b/MacroPad.Core/Models/Config/ButtonConfig.cs
@@ -1,7 +1,7 @@
using MacroPad.Core.Device;
using Newtonsoft.Json;
-namespace MacroPad.Core.Config
+namespace MacroPad.Core.Models.Config
{
public class ButtonConfig
{
diff --git a/MacroPad.Core/Config/ButtonStatus.cs b/MacroPad.Core/Models/Config/ButtonStatus.cs
similarity index 82%
rename from MacroPad.Core/Config/ButtonStatus.cs
rename to MacroPad.Core/Models/Config/ButtonStatus.cs
index f2e9dd0..abab12f 100644
--- a/MacroPad.Core/Config/ButtonStatus.cs
+++ b/MacroPad.Core/Models/Config/ButtonStatus.cs
@@ -1,7 +1,7 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
-namespace MacroPad.Core.Config
+namespace MacroPad.Core.Models.Config
{
public class ButtonStatus
{
diff --git a/MacroPad.Core/Config/DeviceProfile.cs b/MacroPad.Core/Models/Config/DeviceProfile.cs
similarity index 76%
rename from MacroPad.Core/Config/DeviceProfile.cs
rename to MacroPad.Core/Models/Config/DeviceProfile.cs
index 5994e14..cd01752 100644
--- a/MacroPad.Core/Config/DeviceProfile.cs
+++ b/MacroPad.Core/Models/Config/DeviceProfile.cs
@@ -1,8 +1,9 @@
using Newtonsoft.Json;
-namespace MacroPad.Core.Config
+namespace MacroPad.Core.Models.Config
{
- public class DeviceProfile {
+ public class DeviceProfile
+ {
[JsonProperty("name")]
public string Name { get; set; } = "";
diff --git a/MacroPad.Core/Config/NodeLine.cs b/MacroPad.Core/Models/Config/NodeLine.cs
similarity index 82%
rename from MacroPad.Core/Config/NodeLine.cs
rename to MacroPad.Core/Models/Config/NodeLine.cs
index d50d8c9..2e924eb 100644
--- a/MacroPad.Core/Config/NodeLine.cs
+++ b/MacroPad.Core/Models/Config/NodeLine.cs
@@ -1,6 +1,6 @@
using Newtonsoft.Json;
-namespace MacroPad.Core.Config
+namespace MacroPad.Core.Models.Config
{
public class NodeLine
{
diff --git a/MacroPad.Core/Config/NodeLinks.cs b/MacroPad.Core/Models/Config/NodeLinks.cs
similarity index 86%
rename from MacroPad.Core/Config/NodeLinks.cs
rename to MacroPad.Core/Models/Config/NodeLinks.cs
index b2e73a0..e6f297d 100644
--- a/MacroPad.Core/Config/NodeLinks.cs
+++ b/MacroPad.Core/Models/Config/NodeLinks.cs
@@ -1,14 +1,14 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
-namespace MacroPad.Core.Config
+namespace MacroPad.Core.Models.Config
{
public class NodeLinks
{
[JsonProperty("id")]
public string Id { get; set; } = "";
[JsonProperty("g")]
- public Dictionary Getters { get; set; } = [];
+ public Dictionary Getters { get; set; } = [];
[JsonProperty("r")]
public Dictionary Runners { get; set; } = [];
[JsonProperty("x")]
diff --git a/MacroPad.Core/Config/NodeScript.cs b/MacroPad.Core/Models/Config/NodeScript.cs
similarity index 75%
rename from MacroPad.Core/Config/NodeScript.cs
rename to MacroPad.Core/Models/Config/NodeScript.cs
index 57de23b..abddf9f 100644
--- a/MacroPad.Core/Config/NodeScript.cs
+++ b/MacroPad.Core/Models/Config/NodeScript.cs
@@ -1,6 +1,6 @@
using Newtonsoft.Json;
-namespace MacroPad.Core.Config
+namespace MacroPad.Core.Models.Config
{
public class NodeScript
{
@@ -9,7 +9,7 @@ public class NodeScript
[JsonProperty("y")]
public int StartY { get; set; }
[JsonProperty("links")]
- public Dictionary NodesLinks { get; set; } = [];
+ public Dictionary NodesLinks { get; set; } = [];
[JsonProperty("lines")]
public Dictionary NodeLines { get; set; } = [];
}
diff --git a/MacroPad.Core/Config/MacroPadConfig.cs b/MacroPad.Core/Models/MacroPadConfig.cs
similarity index 85%
rename from MacroPad.Core/Config/MacroPadConfig.cs
rename to MacroPad.Core/Models/MacroPadConfig.cs
index 126ae6b..9e77928 100644
--- a/MacroPad.Core/Config/MacroPadConfig.cs
+++ b/MacroPad.Core/Models/MacroPadConfig.cs
@@ -1,7 +1,8 @@
-using Newtonsoft.Json;
+using MacroPad.Core.Models.Config;
+using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
-namespace MacroPad.Core.Config
+namespace MacroPad.Core.Models
{
public class MacroPadConfig
{
@@ -23,13 +24,13 @@ public static MacroPadConfig LoadConfig()
if (File.Exists("config.json"))
{
MacroPadConfig? config = JsonConvert.DeserializeObject(File.ReadAllText("config.json"));
- if (config != null ) return config;
+ if (config != null) return config;
}
return new MacroPadConfig();
}
public void SaveConfig()
{
- File.WriteAllText("config.json", JsonConvert.SerializeObject(this,Formatting.None));
+ File.WriteAllText("config.json", JsonConvert.SerializeObject(this, Formatting.None));
}
}
}
diff --git a/MacroPad.Core/ResourceManager.cs b/MacroPad.Core/Models/ResourceManager.cs
similarity index 96%
rename from MacroPad.Core/ResourceManager.cs
rename to MacroPad.Core/Models/ResourceManager.cs
index 1fb990b..78f60ba 100644
--- a/MacroPad.Core/ResourceManager.cs
+++ b/MacroPad.Core/Models/ResourceManager.cs
@@ -1,7 +1,7 @@
using MacroPad.Shared.Plugin;
using Newtonsoft.Json.Linq;
-namespace MacroPad.Core
+namespace MacroPad.Core.Models
{
public class ResourceManager(Dictionary data, Dictionary? virtualData = null) : IResourceManager
{
diff --git a/MacroPad.Core/Node/NodeResourceManager.cs b/MacroPad.Core/Node/NodeResourceManager.cs
index 389ea73..299ac07 100644
--- a/MacroPad.Core/Node/NodeResourceManager.cs
+++ b/MacroPad.Core/Node/NodeResourceManager.cs
@@ -1,4 +1,5 @@
-using MacroPad.Shared.Plugin.Nodes;
+using MacroPad.Core.Models;
+using MacroPad.Shared.Plugin.Nodes;
using Newtonsoft.Json.Linq;
namespace MacroPad.Core.Node
diff --git a/MacroPad.Core/NodeManager.cs b/MacroPad.Core/NodeManager.cs
index ec6a6ea..d678001 100644
--- a/MacroPad.Core/NodeManager.cs
+++ b/MacroPad.Core/NodeManager.cs
@@ -1,6 +1,8 @@
-using MacroPad.Core.Config;
-using MacroPad.Core.Device;
+using MacroPad.Core.Device;
+using MacroPad.Core.Models;
+using MacroPad.Core.Models.Config;
using MacroPad.Core.Node;
+using MacroPad.Core.Plugin;
using MacroPad.Shared.Plugin;
using MacroPad.Shared.Plugin.Nodes;
using Newtonsoft.Json.Linq;
diff --git a/MacroPad.Core/PluginLoader.cs b/MacroPad.Core/Plugin/PluginLoader.cs
similarity index 92%
rename from MacroPad.Core/PluginLoader.cs
rename to MacroPad.Core/Plugin/PluginLoader.cs
index a512aa2..f59e9f9 100644
--- a/MacroPad.Core/PluginLoader.cs
+++ b/MacroPad.Core/Plugin/PluginLoader.cs
@@ -3,14 +3,14 @@
using Newtonsoft.Json.Linq;
using System.Reflection;
-namespace MacroPad.Core
+namespace MacroPad.Core.Plugin
{
public class PluginLoader
{
public readonly static HashSet plugins = [];
public readonly static HashSet protocols = [];
- public readonly static HashSet nodeTypes = [..DefaultTypes.types];
+ public readonly static HashSet nodeTypes = [.. DefaultTypes.types];
public readonly static HashSet nodeCategories = [new BranchingCategory(), new ButtonCategory(), new ConditionsCategory(), new ConstantsCategory(), new DebugCategory(), new MathCategory(), new ProfileCategory(), new TextCategory(), new VariableCategory()];
public static event EventHandler? PluginAdded;
@@ -23,7 +23,7 @@ public static void LoadPlugins()
foreach (var pluginDir in pluginDirs)
{
- string pluginJsonFile = Path.Combine(pluginDir,"plugin.json");
+ string pluginJsonFile = Path.Combine(pluginDir, "plugin.json");
if (!File.Exists(pluginJsonFile)) continue;
@@ -41,13 +41,14 @@ public static void LoadPlugins()
try
{
assembly = pluginLoader.LoadDefaultAssembly();
- } catch
+ }
+ catch
{
throw new Exception("Failed to load plugin assembly");
}
-
- Type? pluginInfosType = assembly.GetTypes().ToList().Find((Type type) => type.Name == "PluginInfos");
+
+ Type? pluginInfosType = assembly.GetTypes().ToList().Find((type) => type.Name == "PluginInfos");
if (pluginInfosType == null) continue;
diff --git a/MacroPad/Controls/Home/DeviceProfileSelector.axaml.cs b/MacroPad/Controls/Home/DeviceProfileSelector.axaml.cs
index fa88513..01b9246 100644
--- a/MacroPad/Controls/Home/DeviceProfileSelector.axaml.cs
+++ b/MacroPad/Controls/Home/DeviceProfileSelector.axaml.cs
@@ -7,10 +7,10 @@
using MacroPad.Pages;
using System.Linq;
using System;
-using MacroPad.Core.Config;
using FluentAvalonia.UI.Controls;
using ReactiveUI;
using Avalonia.Threading;
+using MacroPad.Core.Models.Config;
namespace MacroPad.Controls.Home;
diff --git a/MacroPad/Controls/Home/NodeLinksDisplay.axaml.cs b/MacroPad/Controls/Home/NodeLinksDisplay.axaml.cs
index 49d031b..da02bf9 100644
--- a/MacroPad/Controls/Home/NodeLinksDisplay.axaml.cs
+++ b/MacroPad/Controls/Home/NodeLinksDisplay.axaml.cs
@@ -5,8 +5,8 @@
using Avalonia.Media;
using MacroPad.Controls.Home.NodesEditorHistory.Actions;
using MacroPad.Core;
-using MacroPad.Core.Config;
using MacroPad.Core.Device;
+using MacroPad.Core.Models.Config;
using MacroPad.Core.Node;
using MacroPad.Shared.Plugin;
using MacroPad.Shared.Plugin.Nodes;
diff --git a/MacroPad/Controls/Home/NodePicker/NodePicker.axaml.cs b/MacroPad/Controls/Home/NodePicker/NodePicker.axaml.cs
index bbf17fd..22a9e41 100644
--- a/MacroPad/Controls/Home/NodePicker/NodePicker.axaml.cs
+++ b/MacroPad/Controls/Home/NodePicker/NodePicker.axaml.cs
@@ -2,9 +2,9 @@
using Avalonia.Controls;
using Avalonia.Interactivity;
using MacroPad.Controls.Home.NodesEditorHistory.Actions;
-using MacroPad.Core;
using MacroPad.Core.Config;
using MacroPad.Core.Device;
+using MacroPad.Core.Plugin;
using MacroPad.Shared.Plugin;
using System.Collections.Generic;
using System.Diagnostics;
diff --git a/MacroPad/Controls/Home/NodesEditor.axaml.cs b/MacroPad/Controls/Home/NodesEditor.axaml.cs
index 466b1fd..8576de1 100644
--- a/MacroPad/Controls/Home/NodesEditor.axaml.cs
+++ b/MacroPad/Controls/Home/NodesEditor.axaml.cs
@@ -9,8 +9,8 @@
using FluentAvalonia.UI.Controls;
using MacroPad.Controls.Home.NodesEditorHistory;
using MacroPad.Controls.Home.NodesEditorHistory.Actions;
-using MacroPad.Core.Config;
using MacroPad.Core.Device;
+using MacroPad.Core.Models.Config;
using MacroPad.Shared.Device;
using Newtonsoft.Json;
using System;
diff --git a/MacroPad/Controls/Home/NodesEditorHistory/Actions/NodeAddition.cs b/MacroPad/Controls/Home/NodesEditorHistory/Actions/NodeAddition.cs
index 6debef8..df3bfbb 100644
--- a/MacroPad/Controls/Home/NodesEditorHistory/Actions/NodeAddition.cs
+++ b/MacroPad/Controls/Home/NodesEditorHistory/Actions/NodeAddition.cs
@@ -1,4 +1,4 @@
-using MacroPad.Core.Config;
+using MacroPad.Core.Models.Config;
namespace MacroPad.Controls.Home.NodesEditorHistory.Actions
{
diff --git a/MacroPad/Controls/Home/NodesEditorHistory/Actions/NodeDeletion.cs b/MacroPad/Controls/Home/NodesEditorHistory/Actions/NodeDeletion.cs
index 60a62df..8834297 100644
--- a/MacroPad/Controls/Home/NodesEditorHistory/Actions/NodeDeletion.cs
+++ b/MacroPad/Controls/Home/NodesEditorHistory/Actions/NodeDeletion.cs
@@ -1,6 +1,6 @@
using Avalonia.Controls.Shapes;
using Avalonia.Interactivity;
-using MacroPad.Core.Config;
+using MacroPad.Core.Models.Config;
using System.Collections.Generic;
using System.Linq;
diff --git a/MacroPad/Controls/Home/NodesEditorHistory/Actions/NodeLineAddition.cs b/MacroPad/Controls/Home/NodesEditorHistory/Actions/NodeLineAddition.cs
index 269bcac..f14f103 100644
--- a/MacroPad/Controls/Home/NodesEditorHistory/Actions/NodeLineAddition.cs
+++ b/MacroPad/Controls/Home/NodesEditorHistory/Actions/NodeLineAddition.cs
@@ -1,4 +1,4 @@
-using MacroPad.Core.Config;
+using MacroPad.Core.Models.Config;
namespace MacroPad.Controls.Home.NodesEditorHistory.Actions
{
diff --git a/MacroPad/Controls/Home/NodesEditorHistory/Actions/NodeLineDeletion.cs b/MacroPad/Controls/Home/NodesEditorHistory/Actions/NodeLineDeletion.cs
index 5b8c447..4b32a33 100644
--- a/MacroPad/Controls/Home/NodesEditorHistory/Actions/NodeLineDeletion.cs
+++ b/MacroPad/Controls/Home/NodesEditorHistory/Actions/NodeLineDeletion.cs
@@ -1,7 +1,7 @@
using Avalonia;
using Avalonia.Controls.Shapes;
using Avalonia.Media;
-using MacroPad.Core.Config;
+using MacroPad.Core.Models.Config;
using System.Linq;
namespace MacroPad.Controls.Home.NodesEditorHistory.Actions
diff --git a/MacroPad/Controls/Home/StatusEditor.axaml.cs b/MacroPad/Controls/Home/StatusEditor.axaml.cs
index 5a7057b..97de3e7 100644
--- a/MacroPad/Controls/Home/StatusEditor.axaml.cs
+++ b/MacroPad/Controls/Home/StatusEditor.axaml.cs
@@ -1,8 +1,8 @@
using Avalonia;
using Avalonia.Controls;
using MacroPad.Core.BasePlugin.Device;
-using MacroPad.Core.Config;
using MacroPad.Core.Device;
+using MacroPad.Core.Models.Config;
using MacroPad.Shared.Device;
using Newtonsoft.Json.Linq;
diff --git a/MacroPad/Controls/Home/StatusEditorTypes/Palette.axaml.cs b/MacroPad/Controls/Home/StatusEditorTypes/Palette.axaml.cs
index 61ee11c..bb4e204 100644
--- a/MacroPad/Controls/Home/StatusEditorTypes/Palette.axaml.cs
+++ b/MacroPad/Controls/Home/StatusEditorTypes/Palette.axaml.cs
@@ -8,7 +8,7 @@
using Avalonia.Media;
using MacroPad.Core.Device;
using MacroPad.Core.BasePlugin.Device;
-using MacroPad.Core.Config;
+using MacroPad.Core.Models.Config;
namespace MacroPad.Controls.Home.StatusEditorTypes;
diff --git a/MacroPad/Pages/MainPage.axaml.cs b/MacroPad/Pages/MainPage.axaml.cs
index 5128258..69dfb25 100644
--- a/MacroPad/Pages/MainPage.axaml.cs
+++ b/MacroPad/Pages/MainPage.axaml.cs
@@ -4,8 +4,8 @@
using MacroPad.Controls;
using MacroPad.Controls.Home;
using MacroPad.Core;
-using MacroPad.Core.Config;
using MacroPad.Core.Device;
+using MacroPad.Core.Models.Config;
using System.Collections.Generic;
using System.Linq;
diff --git a/MacroPad/Pages/Settings/Plugins.axaml.cs b/MacroPad/Pages/Settings/Plugins.axaml.cs
index bc7b123..b5b5327 100644
--- a/MacroPad/Pages/Settings/Plugins.axaml.cs
+++ b/MacroPad/Pages/Settings/Plugins.axaml.cs
@@ -1,7 +1,7 @@
using Avalonia;
using Avalonia.Controls;
using MacroPad.Controls.Settings;
-using MacroPad.Core;
+using MacroPad.Core.Plugin;
using MacroPad.Shared.Plugin;
using MacroPad.ViewModels;
diff --git a/MacroPad/ViewModels/GeneralViewModel.cs b/MacroPad/ViewModels/GeneralViewModel.cs
index 63639ed..5c6b6bc 100644
--- a/MacroPad/ViewModels/GeneralViewModel.cs
+++ b/MacroPad/ViewModels/GeneralViewModel.cs
@@ -1,4 +1,5 @@
using MacroPad.Core;
+using MacroPad.Core.Plugin;
namespace MacroPad.ViewModels
{
diff --git a/MacroPad/Views/MainEditor.axaml.cs b/MacroPad/Views/MainEditor.axaml.cs
index 51c9f87..06a7160 100644
--- a/MacroPad/Views/MainEditor.axaml.cs
+++ b/MacroPad/Views/MainEditor.axaml.cs
@@ -5,8 +5,8 @@
using FluentAvalonia.UI.Navigation;
using MacroPad.Controls;
using MacroPad.Controls.Home;
-using MacroPad.Core.Config;
using MacroPad.Core.Device;
+using MacroPad.Core.Models.Config;
using MacroPad.Pages;
using MacroPad.ViewModels;
using System.Collections.Generic;
diff --git a/MacroPad/Views/Settings/PluginsViewModel.cs b/MacroPad/Views/Settings/PluginsViewModel.cs
index 4178012..b419be8 100644
--- a/MacroPad/Views/Settings/PluginsViewModel.cs
+++ b/MacroPad/Views/Settings/PluginsViewModel.cs
@@ -1,5 +1,5 @@
using MacroPad.Controls.Settings;
-using MacroPad.Core;
+using MacroPad.Core.Plugin;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
From b96061a2f136b330632494575b8dc91b3aab35b3 Mon Sep 17 00:00:00 2001
From: Piripe <77517308+Piripe@users.noreply.github.com>
Date: Mon, 24 Feb 2025 01:09:59 +0100
Subject: [PATCH 10/16] Using System.Text.Json instead of Newtonsoft.Json
---
.../Button/SetCurrentPaletteColor.cs | 1 +
MacroPad.Core/BasePlugin/Variables/Get.cs | 4 +-
MacroPad.Core/BasePlugin/Variables/Set.cs | 6 +--
MacroPad.Core/Device/DeviceCore.cs | 5 +--
MacroPad.Core/Device/DeviceLayout.cs | 27 ++++++------
MacroPad.Core/Device/DeviceLayoutButton.cs | 22 +++++-----
MacroPad.Core/Device/DeviceOutput.cs | 41 +++++++++++++------
MacroPad.Core/Device/PaletteValue.cs | 10 ++---
MacroPad.Core/MacroPad.Core.csproj | 1 -
MacroPad.Core/Models/Config/ButtonConfig.cs | 6 +--
MacroPad.Core/Models/Config/ButtonStatus.cs | 8 ++--
MacroPad.Core/Models/Config/DeviceProfile.cs | 6 +--
MacroPad.Core/Models/Config/NodeLine.cs | 10 ++---
MacroPad.Core/Models/Config/NodeLinks.cs | 22 +++++-----
MacroPad.Core/Models/Config/NodeScript.cs | 10 ++---
MacroPad.Core/Models/MacroPadConfig.cs | 21 +++++-----
MacroPad.Core/Models/ResourceManager.cs | 12 +++---
MacroPad.Core/Node/NodeResourceManager.cs | 4 +-
MacroPad.Core/NodeManager.cs | 10 ++---
MacroPad.Core/Plugin/PluginLoader.cs | 8 ++--
MacroPad/Controls/DeviceViewer.axaml.cs | 10 ++---
.../Controls/Home/NodeLinksDisplay.axaml.cs | 7 +++-
.../Home/NodePicker/NodePicker.axaml.cs | 2 +-
.../NodePicker/NodePickerCategory.axaml.cs | 5 ++-
MacroPad/Controls/Home/NodesEditor.axaml.cs | 6 +--
MacroPad/Controls/Home/StatusEditor.axaml.cs | 3 +-
.../Home/StatusEditorTypes/Palette.axaml.cs | 3 +-
27 files changed, 145 insertions(+), 125 deletions(-)
diff --git a/MacroPad.Core/BasePlugin/Button/SetCurrentPaletteColor.cs b/MacroPad.Core/BasePlugin/Button/SetCurrentPaletteColor.cs
index 6f6e734..f905578 100644
--- a/MacroPad.Core/BasePlugin/Button/SetCurrentPaletteColor.cs
+++ b/MacroPad.Core/BasePlugin/Button/SetCurrentPaletteColor.cs
@@ -25,6 +25,7 @@ public class SetCurrentPaletteColor : INodeRunner
{
GetItems = (IResourceManager resource) =>
{
+ System.Diagnostics.Debug.WriteLine(resource.GetVirtual(VirtualDataKey.DeviceOutput));
return resource.GetVirtual(VirtualDataKey.DeviceOutput)?.Palette.Select(x=>x.Name).ToArray() ?? [];
},
GetSelection = (IResourceManager resource) =>
diff --git a/MacroPad.Core/BasePlugin/Variables/Get.cs b/MacroPad.Core/BasePlugin/Variables/Get.cs
index 5bcb55f..392dac9 100644
--- a/MacroPad.Core/BasePlugin/Variables/Get.cs
+++ b/MacroPad.Core/BasePlugin/Variables/Get.cs
@@ -1,8 +1,8 @@
using MacroPad.Shared.Device;
using MacroPad.Shared.Plugin.Nodes;
using MacroPad.Shared.Plugin.Components;
-using Newtonsoft.Json.Linq;
using MacroPad.Shared.Plugin;
+using System.Text.Json.Nodes;
namespace MacroPad.Core.BasePlugin.Variables
{
@@ -27,7 +27,7 @@ public class Get : INodeGetter
public object[] GetOutputs(INodeResourceManager resource)
{
string var = resource.GetData("v") ?? "";
- return [(DeviceManager.Config.Variables.TryGetValue(var, out JToken? value) ? value.Value
-
+
+
+
+
+
+
+
+
diff --git a/MacroPad/Controls/Settings/PluginRowViewModel.cs b/MacroPad/Controls/Settings/PluginRowViewModel.cs
index fd39d1e..9e6db6e 100644
--- a/MacroPad/Controls/Settings/PluginRowViewModel.cs
+++ b/MacroPad/Controls/Settings/PluginRowViewModel.cs
@@ -20,11 +20,18 @@ public PluginRowViewModel(PluginInfos plugin) {
private bool _isEnabled = false;
public bool IsEnabled { get { return _isEnabled; } set {
- this.RaiseAndSetIfChanged(ref _isEnabled, value);
- if (value) PluginManager.EnablePlugin(Plugin);
+ this.RaiseAndSetIfChanged(ref _isEnabled, value);
+ if (value)
+ {
+ PluginManager.EnablePlugin(Plugin);
+ IsUnloadable = Plugin.IsUnloadable;
+ }
else PluginManager.DisablePlugin(Plugin);
} }
public Bitmap? Icon { get; set; }
+
+ private bool _isUnloadable = false;
+ public bool IsUnloadable { get => _isUnloadable; set=>this.RaiseAndSetIfChanged(ref _isUnloadable, value); }
}
}
diff --git a/MacroPad/Views/MainWindowViewModel.cs b/MacroPad/Views/MainWindowViewModel.cs
index a45e27b..0bd9de2 100644
--- a/MacroPad/Views/MainWindowViewModel.cs
+++ b/MacroPad/Views/MainWindowViewModel.cs
@@ -6,6 +6,7 @@
using ReactiveUI;
using System.Collections.Generic;
using System.Collections.ObjectModel;
+using System.Diagnostics;
using System.Linq;
namespace MacroPad.Views
diff --git a/MacroPad/Views/Navigation/DeviceNavViewModel.cs b/MacroPad/Views/Navigation/DeviceNavViewModel.cs
index e8702e4..17bf05c 100644
--- a/MacroPad/Views/Navigation/DeviceNavViewModel.cs
+++ b/MacroPad/Views/Navigation/DeviceNavViewModel.cs
@@ -1,4 +1,5 @@
-using MacroPad.Core.Device;
+using MacroPad.Core;
+using MacroPad.Core.Device;
using MacroPad.ViewModels;
using ReactiveUI;
@@ -15,7 +16,7 @@ public bool Enabled
set
{
this.RaiseAndSetIfChanged(ref _enabled, value);
- if (value) Device.Connect();
+ if (value) DeviceManager.EnableDevice(Device);
else Device.Disconnect();
}
}
From 4e7d37d65fa10e7a854eaeebb8193a1d52f901dc Mon Sep 17 00:00:00 2001
From: Piripe <77517308+Piripe@users.noreply.github.com>
Date: Tue, 25 Feb 2025 18:57:30 +0100
Subject: [PATCH 15/16] Added WriteLine node (missing because of .gitignore)
---
.gitignore | 5 +++-
MacroPad.Core/BasePlugin/Debug/WriteLine.cs | 30 +++++++++++++++++++++
2 files changed, 34 insertions(+), 1 deletion(-)
create mode 100644 MacroPad.Core/BasePlugin/Debug/WriteLine.cs
diff --git a/.gitignore b/.gitignore
index 4fd7c3c..4d858fe 100644
--- a/.gitignore
+++ b/.gitignore
@@ -400,4 +400,7 @@ FodyWeavers.xsd
*.sln.iml
# config file created by Avalonia by error sometimes
-config.json
\ No newline at end of file
+config.json
+
+
+!MacroPad.Core/BasePlugin/**
\ No newline at end of file
diff --git a/MacroPad.Core/BasePlugin/Debug/WriteLine.cs b/MacroPad.Core/BasePlugin/Debug/WriteLine.cs
new file mode 100644
index 0000000..9574e41
--- /dev/null
+++ b/MacroPad.Core/BasePlugin/Debug/WriteLine.cs
@@ -0,0 +1,30 @@
+using MacroPad.Shared.Device;
+using MacroPad.Shared.Plugin.Nodes;
+
+namespace MacroPad.Core.BasePlugin.Debug
+{
+ public class WriteLine : INodeRunner
+ {
+ public string Name => "Write Line";
+
+ public string Description => "Write a line in the console.";
+
+ public string Id => "WriteLine";
+
+ public TypeNamePair[] Inputs => [new(typeof(string), "Text")];
+
+ public TypeNamePair[] Outputs => [];
+
+ public int RunnerOutputCount => 1;
+ public string[] RunnerOutputsName => [];
+
+ public INodeComponent[] Components => [];
+
+ public bool IsVisible(IDeviceLayoutButton button, IDeviceOutput output) => true;
+ public NodeRunnerResult Run(INodeResourceManager resource)
+ {
+ System.Diagnostics.Debug.WriteLine(resource.GetValue(0));
+ return new NodeRunnerResult() { Results = [], RunnerOutputIndex = 0 };
+ }
+ }
+}
From 2acaad1bedc6a6988c6c87d5bcce760d051e483d Mon Sep 17 00:00:00 2001
From: Piripe <77517308+Piripe@users.noreply.github.com>
Date: Tue, 25 Feb 2025 20:52:17 +0100
Subject: [PATCH 16/16] Added plugin enable and disable (it allows to disable
protocol plugins without unloading it when it's not possible)
---
MacroPad.Core/DeviceManager.cs | 24 ++++---
MacroPad.Core/Models/MacroPadConfig.cs | 8 ++-
MacroPad.Core/Models/Plugin/PluginInfos.cs | 71 ++++++++++++++++---
MacroPad.Core/NodeManager.cs | 26 +------
MacroPad.Core/PluginManager.cs | 25 ++++---
MacroPad/Controls/Settings/PluginRow.axaml | 6 +-
.../Controls/Settings/PluginRowViewModel.cs | 21 +++++-
7 files changed, 122 insertions(+), 59 deletions(-)
diff --git a/MacroPad.Core/DeviceManager.cs b/MacroPad.Core/DeviceManager.cs
index 9712059..f760c28 100644
--- a/MacroPad.Core/DeviceManager.cs
+++ b/MacroPad.Core/DeviceManager.cs
@@ -1,6 +1,7 @@
using MacroPad.Core.Device;
using MacroPad.Core.Models;
using MacroPad.Core.Models.Config;
+using MacroPad.Core.Models.Plugin;
using MacroPad.Shared.Plugin;
using MacroPad.Shared.Plugin.Protocol;
using System.Diagnostics;
@@ -52,20 +53,13 @@ private static void PluginManager_PluginEnabled(object? sender, IPluginInfos e)
private static void Protocol_DeviceDetected(object? sender, DeviceDetectedEventArgs e)
{
- Config.EnabledDevices.TryAdd(e.Device.Id, false);
if (!Config.DevicesProfiles.ContainsKey(e.Device.Id)) Config.DevicesProfiles.Add(e.Device.Id, new List() { { new DeviceProfile() { Name= "Profile"} } });
Config.DefaultProfile.TryAdd(e.Device.Id, 0);
if (Config.DevicesProfiles[e.Device.Id].Count <= Config.DefaultProfile[e.Device.Id] || Config.DefaultProfile[e.Device.Id] < 0) Config.DefaultProfile[e.Device.Id] = 0;
DeviceCore device = new(e.Device);
- ConnectedDevices.Add(device);
-
- if (Config.EnabledDevices[e.Device.Id])
- {
- device.Connect();
- }
- DeviceDetected?.Invoke(sender, e);
+ AddDevice(device);
}
private static void Protocol_DeviceDisconnected(object? sender, DeviceDetectedEventArgs e)
@@ -85,7 +79,7 @@ public static void EnableDevice(string deviceId)
public static void EnableDevice(DeviceCore device)
{
device.Connect();
- Config.EnabledDevices[device.ProtocolDevice.Id] = true;
+ Config.EnabledDevices.Add(device.ProtocolDevice.Id);
}
public static void DisableDevice(string deviceId)
{
@@ -98,12 +92,22 @@ public static void DisableDevice(string deviceId)
public static void DisableDevice(DeviceCore device)
{
device.Disconnect();
- Config.EnabledDevices[device.ProtocolDevice.Id] = false;
+ Config.EnabledDevices.Remove(device.ProtocolDevice.Id);
}
public static void RemoveDevice(DeviceCore device)
{
ConnectedDevices.Remove(device);
DeviceDisconnected?.Invoke(null, new DeviceDetectedEventArgs(device.ProtocolDevice));
}
+ public static void AddDevice(DeviceCore device)
+ {
+ ConnectedDevices.Add(device);
+
+ if (Config.EnabledDevices.Contains(device.ProtocolDevice.Id))
+ {
+ device.Connect();
+ }
+ DeviceDetected?.Invoke(null, new DeviceDetectedEventArgs(device.ProtocolDevice));
+ }
}
}
diff --git a/MacroPad.Core/Models/MacroPadConfig.cs b/MacroPad.Core/Models/MacroPadConfig.cs
index 54a424c..53c1af3 100644
--- a/MacroPad.Core/Models/MacroPadConfig.cs
+++ b/MacroPad.Core/Models/MacroPadConfig.cs
@@ -7,10 +7,12 @@ namespace MacroPad.Core.Models
{
public class MacroPadConfig
{
- [JsonPropertyName("plugins")]
- public Dictionary EnabledPlugins { get; set; } = [];
+ [JsonPropertyName("enabledPlugins")]
+ public HashSet EnabledPlugins { get; set; } = [];
+ [JsonPropertyName("loadedPlugins")]
+ public HashSet LoadedPlugins { get; set; } = [];
[JsonPropertyName("enabledDevices")]
- public Dictionary EnabledDevices { get; set; } = [];
+ public HashSet EnabledDevices { get; set; } = [];
[JsonPropertyName("devicesProfile")]
public Dictionary DefaultProfile { get; set; } = [];
[JsonPropertyName("devices")]
diff --git a/MacroPad.Core/Models/Plugin/PluginInfos.cs b/MacroPad.Core/Models/Plugin/PluginInfos.cs
index 025834f..ef61317 100644
--- a/MacroPad.Core/Models/Plugin/PluginInfos.cs
+++ b/MacroPad.Core/Models/Plugin/PluginInfos.cs
@@ -1,9 +1,12 @@
-using MacroPad.Shared.Plugin;
+using MacroPad.Core.Device;
+using MacroPad.Shared.Plugin;
+using MacroPad.Shared.Plugin.Settings;
using McMaster.NETCore.Plugins;
using Microsoft.DotNet.PlatformAbstractions;
using System;
using System.Collections.Generic;
using System.Data;
+using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
@@ -41,7 +44,7 @@ public class PluginInfos
[JsonPropertyName("supportedPlatforms")]
public Platform[] SupportedPlatforms { get; set; } = [Platform.Windows];
[JsonIgnore]
- public bool Enabled => DeviceManager.Config.EnabledPlugins.TryGetValue(PluginId!, out bool value) && value;
+ public bool Enabled => DeviceManager.Config.EnabledPlugins.Contains(PluginId!);
private PluginLoader? _pluginLoader;
[JsonIgnore]
@@ -68,20 +71,52 @@ public void Load()
if (pluginsInfosInstance is not IPluginInfos pluginInfos) throw new InvalidCastException($"Can't cast \"{pluginInfosType.FullName}\" to IPluginInfos");
_pluginInfos = pluginInfos;
- PluginManager.OnPluginEnabled(_pluginInfos);
-
- PluginManager.Protocols.UnionWith(_pluginInfos.Protocols);
+ PluginManager.OnPluginLoaded(_pluginInfos);
}
[JsonIgnore]
public bool IsLoaded => _pluginLoader == null ? false : true;
[JsonIgnore]
public bool IsUnloadable => _pluginInfos?.NodeTypes.Length == 0 && _pluginInfos?.NodeCategories.Length == 0;
- public void Unload()
+ [JsonIgnore]
+ public bool IsReloadable => IsUnloadable || (_pluginInfos?.Protocols.Length >= 1);
+ [JsonIgnore]
+ public ISettingsComponent[]? Settings => _pluginInfos?.Settings;
+ private void Unload()
{
if (_pluginInfos == null) return;
PluginManager.OnPluginDisabled(_pluginInfos);
+ _pluginInfos = null;
+ _pluginLoader?.Dispose();
+ _pluginLoader = null;
+ }
+
+ private readonly HashSet DisabledDevices = [];
+ public void Enable()
+ {
+ if (_pluginInfos == null) Load();
+ if (_pluginInfos == null) return;
+ PluginManager.OnPluginEnabled(_pluginInfos);
+
+ PluginManager.Protocols.UnionWith(_pluginInfos.Protocols);
+
+ if (!IsUnloadable)
+ {
+ foreach (var protocol in _pluginInfos.Protocols)
+ {
+ protocol.Enable();
+ }
+ }
+ foreach (var device in DisabledDevices)
+ {
+ if (DeviceManager.Config.EnabledDevices.Contains(device.ProtocolDevice.Id)) DeviceManager.AddDevice(device);
+ }
+ }
+ public void Disable()
+ {
+
+ if (_pluginInfos == null) return;
PluginManager.Protocols.ExceptWith(_pluginInfos.Protocols);
foreach (var protocol in _pluginInfos.Protocols)
@@ -90,13 +125,31 @@ public void Unload()
{
device.Disconnect();
DeviceManager.RemoveDevice(device);
+ if (!IsUnloadable) DisabledDevices.Add(device);
}
protocol.Disable();
}
- _pluginInfos = null;
- _pluginLoader?.Dispose();
- _pluginLoader = null;
+ if (IsUnloadable)
+ {
+ Unload();
+ }else
+ {
+ PluginManager.OnPluginDisabled(_pluginInfos);
+ }
+ }
+ public void Reload()
+ {
+ if (_pluginInfos == null) return;
+
+ if (IsUnloadable)
+ {
+ Unload();
+ Load();
+ }
+ else
+ {
+ }
}
}
}
diff --git a/MacroPad.Core/NodeManager.cs b/MacroPad.Core/NodeManager.cs
index 3f625ec..95e73e8 100644
--- a/MacroPad.Core/NodeManager.cs
+++ b/MacroPad.Core/NodeManager.cs
@@ -25,12 +25,11 @@ public static class NodeManager
public static void Init()
{
- PluginManager.PluginEnabled += PluginManager_PluginEnabled;
- PluginManager.PluginDisabled += PluginManager_PluginDisabled;
+ PluginManager.PluginLoaded += PluginManager_PluginLoaded;
}
- private static void PluginManager_PluginEnabled(object? sender, IPluginInfos e)
+ private static void PluginManager_PluginLoaded(object? sender, IPluginInfos e)
{
NodeTypes.UnionWith(e.NodeTypes);
NodeCategories.UnionWith(e.NodeCategories);
@@ -52,27 +51,6 @@ private static void PluginManager_PluginEnabled(object? sender, IPluginInfos e)
}
}
}
- private static void PluginManager_PluginDisabled(object? sender, IPluginInfos e)
- {
- NodeTypes.ExceptWith(e.NodeTypes);
- NodeCategories.ExceptWith(e.NodeCategories);
-
- foreach (NodeType type in e.NodeTypes)
- {
- Types.Remove(type.Type);
- }
- foreach(INodeCategory category in e.NodeCategories)
- {
- foreach (INodeRunner node in category.Runners)
- {
- Runners.Remove(category.Id + "." + node.Id);
- }
- foreach (INodeGetter node in category.Getters)
- {
- Getters.Remove(category.Id + "." + node.Id);
- }
- }
- }
public static void Run(NodeScript script, DeviceCore device, DeviceLayoutButton button)
{
diff --git a/MacroPad.Core/PluginManager.cs b/MacroPad.Core/PluginManager.cs
index 3bb510a..f982c9e 100644
--- a/MacroPad.Core/PluginManager.cs
+++ b/MacroPad.Core/PluginManager.cs
@@ -18,6 +18,7 @@ public static class PluginManager
public readonly static HashSet Plugins = [];
public readonly static IPluginInfos BasePlugin = new BasePluginInfos();
+ public static event EventHandler? PluginLoaded;
public static event EventHandler? PluginEnabled;
public static event EventHandler? PluginDisabled;
public static event EventHandler? PluginAdded;
@@ -46,26 +47,34 @@ public static void ScanPlugins()
return pluginInfos;
}).Where(x=>x!=null).Select(x=>x!).ToHashSet());
+ PluginLoaded?.Invoke(null, BasePlugin);
PluginEnabled?.Invoke(null, BasePlugin);
foreach (var plugin in Plugins)
{
- // Ignore if plugin is disabled or not present in the config
- if (!DeviceManager.Config.EnabledPlugins.TryGetValue(plugin.PluginId!, out bool value) || !value) continue;
-
- plugin.Load();
+ if (DeviceManager.Config.LoadedPlugins.Contains(plugin.PluginId!))
+ {
+ if (DeviceManager.Config.EnabledPlugins.Contains(plugin.PluginId!)) plugin.Enable();
+ else plugin.Load();
+ }
}
}
public static void EnablePlugin(PluginInfos plugin)
{
- if (!DeviceManager.Config.EnabledPlugins.TryAdd(plugin.PluginId!, true)) DeviceManager.Config.EnabledPlugins[plugin.PluginId!] = true;
- plugin.Load();
+ DeviceManager.Config.EnabledPlugins.Add(plugin.PluginId!);
+ DeviceManager.Config.LoadedPlugins.Add(plugin.PluginId!);
+ plugin.Enable();
}
public static void DisablePlugin(PluginInfos plugin)
{
- if (!DeviceManager.Config.EnabledPlugins.TryAdd(plugin.PluginId!, false)) DeviceManager.Config.EnabledPlugins[plugin.PluginId!] = false;
- plugin.Unload();
+ DeviceManager.Config.EnabledPlugins.Remove(plugin.PluginId!);
+ if (plugin.IsUnloadable) DeviceManager.Config.LoadedPlugins.Remove(plugin.PluginId!);
+ plugin.Disable();
+ }
+ public static void OnPluginLoaded(IPluginInfos plugin)
+ {
+ PluginLoaded?.Invoke(null, plugin);
}
public static void OnPluginEnabled(IPluginInfos plugin)
{
diff --git a/MacroPad/Controls/Settings/PluginRow.axaml b/MacroPad/Controls/Settings/PluginRow.axaml
index 9756d88..8c4524c 100644
--- a/MacroPad/Controls/Settings/PluginRow.axaml
+++ b/MacroPad/Controls/Settings/PluginRow.axaml
@@ -21,10 +21,10 @@
-
@@ -34,7 +34,7 @@
-
+
diff --git a/MacroPad/Controls/Settings/PluginRowViewModel.cs b/MacroPad/Controls/Settings/PluginRowViewModel.cs
index 9e6db6e..0a5edd4 100644
--- a/MacroPad/Controls/Settings/PluginRowViewModel.cs
+++ b/MacroPad/Controls/Settings/PluginRowViewModel.cs
@@ -14,17 +14,25 @@ public class PluginRowViewModel : ViewModelBase
public PluginRowViewModel(PluginInfos plugin) {
Plugin = plugin;
_isEnabled = plugin.Enabled;
+ if (_isEnabled) UpdatePluginStates();
if (plugin.IconType == PluginIconType.Image) Icon = new Bitmap(Path.Combine(Plugin.PluginDirectory!, Plugin.Icon));
}
public PluginRowViewModel() { Plugin = new PluginInfos() { Name = "Dummy Plugin"}; }
+ private void UpdatePluginStates()
+ {
+ IsUnloadable = Plugin.IsUnloadable;
+ IsReloadable = Plugin.IsReloadable;
+ HasSettings = Plugin.Settings?.Length > 0;
+ }
+
private bool _isEnabled = false;
public bool IsEnabled { get { return _isEnabled; } set {
this.RaiseAndSetIfChanged(ref _isEnabled, value);
if (value)
{
PluginManager.EnablePlugin(Plugin);
- IsUnloadable = Plugin.IsUnloadable;
+ UpdatePluginStates();
}
else PluginManager.DisablePlugin(Plugin);
} }
@@ -32,6 +40,15 @@ public PluginRowViewModel(PluginInfos plugin) {
public Bitmap? Icon { get; set; }
private bool _isUnloadable = false;
- public bool IsUnloadable { get => _isUnloadable; set=>this.RaiseAndSetIfChanged(ref _isUnloadable, value); }
+ public bool IsUnloadable { get => _isUnloadable; set => this.RaiseAndSetIfChanged(ref _isUnloadable, value); }
+ private bool _isReloadable = false;
+ public bool IsReloadable { get => _isReloadable; set => this.RaiseAndSetIfChanged(ref _isReloadable, value); }
+ private bool _hasSettings= false;
+ public bool HasSettings { get => _hasSettings; set => this.RaiseAndSetIfChanged(ref _hasSettings, value); }
+
+ public void Reload()
+ {
+
+ }
}
}