mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Merge branch 'development'
This commit is contained in:
commit
ea8972a415
@ -178,12 +178,15 @@ namespace Artemis.Core
|
||||
{
|
||||
foreach (PluginFeature feature in Features)
|
||||
feature.Dispose();
|
||||
SetEnabled(false);
|
||||
|
||||
Kernel?.Dispose();
|
||||
PluginLoader?.Dispose();
|
||||
|
||||
GC.Collect();
|
||||
GC.WaitForPendingFinalizers();
|
||||
|
||||
_features.Clear();
|
||||
SetEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -70,6 +70,12 @@ namespace Artemis.Core.Services
|
||||
/// <returns>The resulting plugin</returns>
|
||||
Plugin ImportPlugin(string fileName);
|
||||
|
||||
/// <summary>
|
||||
/// Unloads and permanently removes the provided plugin
|
||||
/// </summary>
|
||||
/// <param name="plugin">The plugin to remove</param>
|
||||
void RemovePlugin(Plugin plugin);
|
||||
|
||||
/// <summary>
|
||||
/// Enables the provided plugin feature
|
||||
/// </summary>
|
||||
|
||||
@ -5,6 +5,7 @@ using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Loader;
|
||||
using Artemis.Core.DeviceProviders;
|
||||
using Artemis.Core.Ninject;
|
||||
using Artemis.Storage.Entities.Plugins;
|
||||
@ -275,6 +276,7 @@ namespace Artemis.Core.Services
|
||||
plugin.PluginLoader = PluginLoader.CreateFromAssemblyFile(mainFile!, configure =>
|
||||
{
|
||||
configure.IsUnloadable = true;
|
||||
configure.LoadInMemory = true;
|
||||
configure.PreferSharedTypes = true;
|
||||
});
|
||||
|
||||
@ -430,7 +432,6 @@ namespace Artemis.Core.Services
|
||||
OnPluginDisabled(new PluginEventArgs(plugin));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Plugin ImportPlugin(string fileName)
|
||||
{
|
||||
DirectoryInfo pluginDirectory = new(Path.Combine(Constants.DataFolder, "plugins"));
|
||||
@ -449,7 +450,16 @@ namespace Artemis.Core.Services
|
||||
|
||||
Plugin? existing = _plugins.FirstOrDefault(p => p.Guid == pluginInfo.Guid);
|
||||
if (existing != null)
|
||||
throw new ArtemisPluginException($"A plugin with the same GUID is already loaded: {existing.Info}");
|
||||
{
|
||||
try
|
||||
{
|
||||
RemovePlugin(existing);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new ArtemisPluginException("A plugin with the same GUID is already loaded, failed to remove old version", e);
|
||||
}
|
||||
}
|
||||
|
||||
string targetDirectory = pluginInfo.Main.Split(".dll")[0].Replace("/", "").Replace("\\", "");
|
||||
string uniqueTargetDirectory = targetDirectory;
|
||||
@ -464,19 +474,38 @@ namespace Artemis.Core.Services
|
||||
|
||||
// Extract everything in the same archive directory to the unique plugin directory
|
||||
DirectoryInfo directoryInfo = new(Path.Combine(pluginDirectory.FullName, uniqueTargetDirectory));
|
||||
Directory.CreateDirectory(directoryInfo.FullName);
|
||||
Utilities.CreateAccessibleDirectory(directoryInfo.FullName);
|
||||
string metaDataDirectory = metaDataFileEntry.FullName.Replace(metaDataFileEntry.Name, "");
|
||||
foreach (ZipArchiveEntry zipArchiveEntry in archive.Entries)
|
||||
{
|
||||
if (zipArchiveEntry.FullName.StartsWith(metaDataDirectory))
|
||||
{
|
||||
string target = Path.Combine(directoryInfo.FullName, zipArchiveEntry.FullName.Remove(0, metaDataDirectory.Length));
|
||||
zipArchiveEntry.ExtractToFile(target);
|
||||
// Create folders
|
||||
if (zipArchiveEntry.FullName.EndsWith("/"))
|
||||
Utilities.CreateAccessibleDirectory(Path.GetDirectoryName(target)!);
|
||||
// Extract files
|
||||
else
|
||||
zipArchiveEntry.ExtractToFile(target);
|
||||
}
|
||||
}
|
||||
|
||||
// Load the newly extracted plugin and return the result
|
||||
return LoadPlugin(directoryInfo);
|
||||
}
|
||||
|
||||
public void RemovePlugin(Plugin plugin)
|
||||
{
|
||||
DirectoryInfo directory = plugin.Directory;
|
||||
lock (_plugins)
|
||||
{
|
||||
if (_plugins.Contains(plugin))
|
||||
UnloadPlugin(plugin);
|
||||
}
|
||||
|
||||
directory.Delete(true);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Features
|
||||
|
||||
@ -74,7 +74,7 @@ namespace Artemis.Core.Services
|
||||
_modifyingProviders = true;
|
||||
|
||||
List<ArtemisDevice> toRemove = _devices.Where(a => deviceProvider.Devices.Any(d => a.RgbDevice == d)).ToList();
|
||||
Surface.Detach(deviceProvider.Devices);
|
||||
Surface.Detach(toRemove.Select(d => d.RgbDevice));
|
||||
foreach (ArtemisDevice device in toRemove)
|
||||
RemoveDevice(device);
|
||||
|
||||
@ -118,7 +118,7 @@ namespace Artemis.Core.Services
|
||||
_modifyingProviders = true;
|
||||
|
||||
List<ArtemisDevice> toRemove = _devices.Where(a => deviceProvider.Devices.Any(d => a.RgbDevice == d)).ToList();
|
||||
Surface.Detach(deviceProvider.Devices);
|
||||
Surface.Detach(toRemove.Select(d => d.RgbDevice));
|
||||
foreach (ArtemisDevice device in toRemove)
|
||||
RemoveDevice(device);
|
||||
|
||||
|
||||
@ -79,6 +79,11 @@ namespace Artemis.Core.Services.Models
|
||||
public void Arrange(List<ArtemisDevice> devices)
|
||||
{
|
||||
ArrangedDevices.Clear();
|
||||
|
||||
// Not much to do here
|
||||
if (!devices.Any())
|
||||
return;
|
||||
|
||||
foreach (ArtemisDevice surfaceDevice in devices)
|
||||
{
|
||||
surfaceDevice.X = 0;
|
||||
|
||||
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
|
||||
namespace Artemis.Core.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides data about endpoint exception related events
|
||||
/// </summary>
|
||||
public class EndpointExceptionEventArgs : EventArgs
|
||||
{
|
||||
internal EndpointExceptionEventArgs(Exception exception)
|
||||
{
|
||||
Exception = exception;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the exception that occurred
|
||||
/// </summary>
|
||||
public Exception Exception { get; }
|
||||
}
|
||||
}
|
||||
@ -52,15 +52,37 @@ namespace Artemis.Core.Services
|
||||
/// </summary>
|
||||
public string? Returns { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// Occurs whenever a request threw an unhandled exception
|
||||
/// </summary>
|
||||
public event EventHandler<EndpointExceptionEventArgs>? RequestException;
|
||||
|
||||
/// <summary>
|
||||
/// Called whenever the end point has to process a request
|
||||
/// </summary>
|
||||
/// <param name="context">The HTTP context of the request</param>
|
||||
protected abstract Task ProcessRequest(IHttpContext context);
|
||||
|
||||
/// <summary>
|
||||
/// Invokes the <see cref="RequestException" /> event
|
||||
/// </summary>
|
||||
/// <param name="e">The exception that occurred during the request</param>
|
||||
protected virtual void OnRequestException(Exception e)
|
||||
{
|
||||
RequestException?.Invoke(this, new EndpointExceptionEventArgs(e));
|
||||
}
|
||||
|
||||
internal async Task InternalProcessRequest(IHttpContext context)
|
||||
{
|
||||
await ProcessRequest(context);
|
||||
try
|
||||
{
|
||||
await ProcessRequest(context);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
OnRequestException(e);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDisabled(object? sender, EventArgs e)
|
||||
|
||||
@ -1,10 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using EmbedIO;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Artemis.Core.Services
|
||||
{
|
||||
@ -67,6 +64,12 @@ namespace Artemis.Core.Services
|
||||
if (!endPoints.TryGetValue(pathParts[1], out PluginEndPoint? endPoint))
|
||||
throw HttpException.NotFound($"Found no endpoint called {pathParts[1]} for plugin with ID {pathParts[0]}.");
|
||||
|
||||
// If Accept-Charset contains a wildcard, remove the header so we default to UTF8
|
||||
// This is a workaround for an EmbedIO ehh issue
|
||||
string? acceptCharset = context.Request.Headers["Accept-Charset"];
|
||||
if (acceptCharset != null && acceptCharset.Contains("*"))
|
||||
context.Request.Headers.Remove("Accept-Charset");
|
||||
|
||||
// It is up to the registration how the request is eventually handled, it might even set a response here
|
||||
await endPoint.InternalProcessRequest(context);
|
||||
|
||||
|
||||
@ -28,7 +28,6 @@ namespace Artemis.Core.Services
|
||||
_webServerPortSetting.SettingChanged += WebServerPortSettingOnSettingChanged;
|
||||
|
||||
PluginsModule = new PluginsModule("/plugins");
|
||||
|
||||
StartWebServer();
|
||||
}
|
||||
|
||||
@ -42,7 +41,7 @@ namespace Artemis.Core.Services
|
||||
Server?.Dispose();
|
||||
Server = null;
|
||||
|
||||
string url = $"http://localhost:{_webServerPortSetting.Value}/";
|
||||
string url = $"http://*:{_webServerPortSetting.Value}/";
|
||||
WebApiModule apiModule = new("/api/", JsonNetSerializer);
|
||||
PluginsModule.ServerUrl = url;
|
||||
WebServer server = new WebServer(o => o.WithUrlPrefix(url).WithMode(HttpListenerMode.EmbedIO))
|
||||
|
||||
@ -138,7 +138,7 @@
|
||||
<PackageReference Include="FluentValidation" Version="9.3.0" />
|
||||
<PackageReference Include="Flurl.Http" Version="3.0.1" />
|
||||
<PackageReference Include="gong-wpf-dragdrop" Version="2.3.2" />
|
||||
<PackageReference Include="Hardcodet.NotifyIcon.Wpf.NetCore" Version="1.0.14" />
|
||||
<PackageReference Include="Hardcodet.NotifyIcon.Wpf.NetCore" Version="1.0.18" />
|
||||
<PackageReference Include="Humanizer.Core" Version="2.8.26" />
|
||||
<PackageReference Include="MaterialDesignExtensions" Version="3.3.0-a01" />
|
||||
<PackageReference Include="MaterialDesignThemes" Version="3.2.0" />
|
||||
|
||||
@ -59,12 +59,7 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
|
||||
{
|
||||
Items.Clear();
|
||||
await Task.Delay(200);
|
||||
_instances = _pluginManagementService.GetAllPlugins()
|
||||
.Select(p => _settingsVmFactory.CreatePluginSettingsViewModel(p))
|
||||
.OrderBy(i => i.Plugin.Info.Name)
|
||||
.ToList();
|
||||
|
||||
UpdatePluginSearch();
|
||||
GetPluginInstances();
|
||||
});
|
||||
|
||||
base.OnActivate();
|
||||
@ -80,14 +75,21 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
|
||||
{
|
||||
Plugin plugin = _pluginManagementService.ImportPlugin(dialog.FileName);
|
||||
|
||||
_instances = _pluginManagementService.GetAllPlugins()
|
||||
.Select(p => _settingsVmFactory.CreatePluginSettingsViewModel(p))
|
||||
.OrderBy(i => i.Plugin.Info.Name)
|
||||
.ToList();
|
||||
GetPluginInstances();
|
||||
SearchPluginInput = plugin.Info.Name;
|
||||
|
||||
|
||||
_messageService.ShowMessage($"Imported plugin: {plugin.Info.Name}");
|
||||
}
|
||||
}
|
||||
|
||||
public void GetPluginInstances()
|
||||
{
|
||||
_instances = _pluginManagementService.GetAllPlugins()
|
||||
.Select(p => _settingsVmFactory.CreatePluginSettingsViewModel(p))
|
||||
.OrderBy(i => i.Plugin.Info.Name)
|
||||
.ToList();
|
||||
|
||||
UpdatePluginSearch();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -53,15 +53,28 @@
|
||||
</Grid>
|
||||
|
||||
|
||||
<Button Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
<StackPanel Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
VerticalAlignment="Bottom"
|
||||
Orientation="Horizontal">
|
||||
<Button
|
||||
VerticalAlignment="Bottom"
|
||||
Style="{StaticResource MaterialDesignOutlinedButton}"
|
||||
ToolTip="Open the plugins settings window"
|
||||
Margin="4"
|
||||
Command="{s:Action OpenSettings}">
|
||||
SETTINGS
|
||||
</Button>
|
||||
SETTINGS
|
||||
</Button>
|
||||
<Button
|
||||
VerticalAlignment="Bottom"
|
||||
Style="{StaticResource MaterialDesignOutlinedButton}"
|
||||
ToolTip="Remove plugin"
|
||||
Margin="4"
|
||||
Command="{s:Action Remove}">
|
||||
<materialDesign:PackIcon Kind="DeleteForever" />
|
||||
</Button>
|
||||
</StackPanel>
|
||||
|
||||
|
||||
<CheckBox Grid.Row="1"
|
||||
Grid.Column="1"
|
||||
@ -70,7 +83,13 @@
|
||||
Margin="8"
|
||||
Visibility="{Binding Enabling, Converter={x:Static s:BoolToVisibilityConverter.InverseInstance}, Mode=OneWay}"
|
||||
Style="{StaticResource MaterialDesignCheckBox}" IsChecked="{Binding IsEnabled}">
|
||||
Plugin enabled
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock>Plugin enabled</TextBlock>
|
||||
<materialDesign:PackIcon Kind="ShieldHalfFull"
|
||||
Margin="5 0 0 0"
|
||||
ToolTip="Plugin requires admin rights"
|
||||
Visibility="{Binding Plugin.Info.RequiresAdmin, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}"/>
|
||||
</StackPanel>
|
||||
</CheckBox>
|
||||
|
||||
<ProgressBar Grid.Row="1"
|
||||
|
||||
@ -19,6 +19,7 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
|
||||
private readonly IDialogService _dialogService;
|
||||
private readonly IPluginManagementService _pluginManagementService;
|
||||
private readonly ISettingsVmFactory _settingsVmFactory;
|
||||
private readonly ICoreService _coreService;
|
||||
private readonly IMessageService _messageService;
|
||||
private readonly IWindowManager _windowManager;
|
||||
private bool _enabling;
|
||||
@ -26,6 +27,7 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
|
||||
|
||||
public PluginSettingsViewModel(Plugin plugin,
|
||||
ISettingsVmFactory settingsVmFactory,
|
||||
ICoreService coreService,
|
||||
IWindowManager windowManager,
|
||||
IDialogService dialogService,
|
||||
IPluginManagementService pluginManagementService,
|
||||
@ -34,6 +36,7 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
|
||||
Plugin = plugin;
|
||||
|
||||
_settingsVmFactory = settingsVmFactory;
|
||||
_coreService = coreService;
|
||||
_windowManager = windowManager;
|
||||
_dialogService = dialogService;
|
||||
_pluginManagementService = pluginManagementService;
|
||||
@ -82,6 +85,24 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
|
||||
}
|
||||
}
|
||||
|
||||
public async Task Remove()
|
||||
{
|
||||
bool confirmed = await _dialogService.ShowConfirmDialog("Delete plugin", "Are you sure you want to delete this plugin?");
|
||||
if (!confirmed)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
_pluginManagementService.RemovePlugin(Plugin);
|
||||
((PluginSettingsTabViewModel) Parent).GetPluginInstances();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_dialogService.ShowExceptionDialog("Failed to remove plugin", e);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void ShowLogsFolder()
|
||||
{
|
||||
try
|
||||
@ -124,6 +145,18 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
|
||||
{
|
||||
Enabling = true;
|
||||
|
||||
if (Plugin.Info.RequiresAdmin && !_coreService.IsElevated)
|
||||
{
|
||||
bool confirmed = await _dialogService.ShowConfirmDialog("Enable plugin", "This plugin requires admin rights, are you sure you want to enable it?");
|
||||
if (!confirmed)
|
||||
{
|
||||
Enabling = false;
|
||||
NotifyOfPropertyChange(nameof(IsEnabled));
|
||||
NotifyOfPropertyChange(nameof(CanOpenSettings));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await Task.Run(() => _pluginManagementService.EnablePlugin(Plugin, true));
|
||||
|
||||
@ -1,24 +1,25 @@
|
||||
<controls:MaterialWindow x:Class="Artemis.UI.Screens.TrayView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:tb="http://www.hardcodet.net/taskbar"
|
||||
xmlns:s="https://github.com/canton7/Stylet"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:controls="clr-namespace:MaterialDesignExtensions.Controls;assembly=MaterialDesignExtensions"
|
||||
mc:Ignorable="d"
|
||||
Title="Artemis"
|
||||
Height="1"
|
||||
Width="1"
|
||||
Visibility="Hidden">
|
||||
<tb:TaskbarIcon x:Name="TrayIcon"
|
||||
IconSource="/Resources/Images/Logo/logo-512.ico"
|
||||
<Window x:Class="Artemis.UI.Screens.TrayView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:tb="http://www.hardcodet.net/taskbar"
|
||||
xmlns:s="https://github.com/canton7/Stylet"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
mc:Ignorable="d">
|
||||
<tb:TaskbarIcon IconSource="/Resources/Images/Logo/logo-512.ico"
|
||||
MenuActivation="LeftOrRightClick"
|
||||
PopupActivation="DoubleClick"
|
||||
ToolTipText="Artemis"
|
||||
DoubleClickCommand="{s:Action TrayBringToForeground}"
|
||||
TrayBalloonTipClicked="{s:Action OnTrayBalloonTipClicked}">
|
||||
|
||||
<tb:TaskbarIcon.TrayToolTip>
|
||||
<Border Background="{DynamicResource MaterialDesignToolTipBackground}" CornerRadius="2" Padding="5">
|
||||
<TextBlock Foreground="{DynamicResource MaterialDesignPaper}">
|
||||
Artemis
|
||||
</TextBlock>
|
||||
</Border>
|
||||
</tb:TaskbarIcon.TrayToolTip>
|
||||
<tb:TaskbarIcon.ContextMenu>
|
||||
<ContextMenu>
|
||||
<MenuItem Header="Home" Command="{s:Action TrayActivateSidebarItem}" CommandParameter="Home">
|
||||
@ -60,4 +61,4 @@
|
||||
</ContextMenu>
|
||||
</tb:TaskbarIcon.ContextMenu>
|
||||
</tb:TaskbarIcon>
|
||||
</controls:MaterialWindow>
|
||||
</Window>
|
||||
@ -27,9 +27,13 @@
|
||||
},
|
||||
"Hardcodet.NotifyIcon.Wpf.NetCore": {
|
||||
"type": "Direct",
|
||||
"requested": "[1.0.14, )",
|
||||
"resolved": "1.0.14",
|
||||
"contentHash": "aNwwax4+C/xhIxTbwKHJnxh0A6hWGnqXZtppZ+/lkE8VOL+a2WuMOBgWpkiUk6Tv+pi1bc+yuHo0lh4Md6KEFw=="
|
||||
"requested": "[1.0.18, )",
|
||||
"resolved": "1.0.18",
|
||||
"contentHash": "oI8YY/gUQooA0XIIZl4TgueexJcu+MbSvCQ2+ZBZRa+rIvFCWiyk8rjgywQ17sVrhLXRn+xF8+FTrWLxetkx0A==",
|
||||
"dependencies": {
|
||||
"H.NotifyIcon": "1.0.18",
|
||||
"System.Drawing.Common": "5.0.0"
|
||||
}
|
||||
},
|
||||
"Humanizer.Core": {
|
||||
"type": "Direct",
|
||||
@ -225,6 +229,11 @@
|
||||
"resolved": "3.0.1",
|
||||
"contentHash": "i7CuPSikVroBaWG8sPvO707Ex9C6BP5+r4JufKNU1FGMmiFgLJvNo1ttUg6ZiXIzUNknvIb1VUTIO9iEDucibg=="
|
||||
},
|
||||
"H.NotifyIcon": {
|
||||
"type": "Transitive",
|
||||
"resolved": "1.0.18",
|
||||
"contentHash": "vV0lNWD9xGeCH4pCmT8vKtax2QOmo8WwhCBgBDO3BYQtPG7Rjuf5Ua+3O8++XkZB7t9zromzxcT5nYdGDg1Puw=="
|
||||
},
|
||||
"HidSharp": {
|
||||
"type": "Transitive",
|
||||
"resolved": "2.1.0",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user