1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Merge pull request #534 from Artemis-RGB/feature/webserver

Added web server & expanded plugin features
This commit is contained in:
Robert Beekman 2021-01-30 21:58:47 +01:00 committed by GitHub
commit 45bf7e7c82
43 changed files with 1279 additions and 243 deletions

View File

@ -39,6 +39,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Ben.Demystifier" Version="0.1.6" />
<PackageReference Include="EmbedIO" Version="3.4.3" />
<PackageReference Include="HidSharp" Version="2.1.0" />
<PackageReference Include="Humanizer.Core" Version="2.8.26" />
<PackageReference Include="LiteDB" Version="5.0.9" />

View File

@ -64,6 +64,11 @@
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=services_005Cregistration_005Cinterfaces/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=services_005Cstorage/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=services_005Cstorage_005Cinterfaces/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=services_005Cwebserver/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=services_005Cwebserver_005Ccontrollers/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=services_005Cwebserver_005Cendpoints/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=services_005Cwebserver_005Cinterfaces/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=services_005Cwebserver_005Cjson/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=stores/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=stores_005Cregistrations/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=utilities/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

View File

@ -78,7 +78,7 @@ namespace Artemis.Core
public event EventHandler<LayerPropertyEventArgs>? CurrentValueSet;
/// <summary>
/// Occurs when the <see cref="IsHidden" /> value of the layer property was updated
/// Occurs when the visibility value of the layer property was updated
/// </summary>
public event EventHandler<LayerPropertyEventArgs>? VisibilityChanged;

View File

@ -5,6 +5,7 @@ using System.Linq;
using System.Reflection;
using Artemis.Core.Modules;
using Humanizer;
using Newtonsoft.Json;
namespace Artemis.Core.DataModelExpansions
{
@ -28,12 +29,14 @@ namespace Artemis.Core.DataModelExpansions
/// <summary>
/// Gets the plugin feature this data model belongs to
/// </summary>
[JsonIgnore]
[DataModelIgnore]
public DataModelPluginFeature Feature { get; internal set; }
/// <summary>
/// Gets the <see cref="DataModelPropertyAttribute" /> describing this data model
/// </summary>
[JsonIgnore]
[DataModelIgnore]
public DataModelPropertyAttribute DataModelDescription { get; internal set; }

View File

@ -44,7 +44,6 @@ namespace Artemis.Core
/// </summary>
public DirectoryInfo Directory { get; }
/// <summary>
/// Gets or sets a configuration dialog for this plugin that is accessible in the UI under Settings > Plugins
/// </summary>

View File

@ -13,6 +13,11 @@ namespace Artemis.Core
private bool _isEnabled;
private Exception? _loadException;
/// <summary>
/// Gets the plugin feature info related to this feature
/// </summary>
public PluginFeatureInfo Info { get; internal set; } = null!; // Will be set right after construction
/// <summary>
/// Gets the plugin that provides this feature
/// </summary>

View File

@ -0,0 +1,27 @@
using System;
namespace Artemis.Core
{
/// <summary>
/// Represents an attribute that describes a plugin feature
/// </summary>
[AttributeUsage(AttributeTargets.Class)]
public class PluginFeatureAttribute : Attribute
{
/// <summary>
/// Gets or sets the user-friendly name for this property, shown in the UI.
/// </summary>
public string? Name { get; set; }
/// <summary>
/// Gets or sets the user-friendly description for this property, shown in the UI.
/// </summary>
public string? Description { get; set; }
/// <summary>
/// The plugins display icon that's shown in the settings see <see href="https://materialdesignicons.com" /> for
/// available icons
/// </summary>
public string? Icon { get; set; }
}
}

View File

@ -0,0 +1,92 @@
using Artemis.Core.DataModelExpansions;
using Artemis.Core.DeviceProviders;
using Artemis.Core.LayerBrushes;
using Artemis.Core.LayerEffects;
using Artemis.Core.Modules;
using Humanizer;
using Newtonsoft.Json;
namespace Artemis.Core
{
/// <summary>
/// Represents basic info about a plugin feature and contains a reference to the instance of said feature
/// </summary>
[JsonObject(MemberSerialization.OptIn)]
public class PluginFeatureInfo : CorePropertyChanged
{
private string? _description;
private string? _icon;
private string _name = null!;
private PluginFeature _pluginFeature = null!;
internal PluginFeatureInfo()
{
}
internal PluginFeatureInfo(PluginFeature instance, PluginFeatureAttribute? attribute)
{
Name = attribute?.Name ?? instance.GetType().Name.Humanize(LetterCasing.Title);
Description = attribute?.Description;
Icon = attribute?.Icon;
PluginFeature = instance;
if (Icon != null) return;
Icon = PluginFeature switch
{
BaseDataModelExpansion => "TableAdd",
DeviceProvider => "Devices",
ProfileModule => "VectorRectangle",
Module => "GearBox",
LayerBrushProvider => "Brush",
LayerEffectProvider => "AutoAwesome",
_ => "Plugin"
};
}
/// <summary>
/// The name of the plugin
/// </summary>
[JsonProperty(Required = Required.Always)]
public string Name
{
get => _name;
internal set => SetAndNotify(ref _name, value);
}
/// <summary>
/// A short description of the plugin
/// </summary>
[JsonProperty]
public string? Description
{
get => _description;
set => SetAndNotify(ref _description, value);
}
/// <summary>
/// The plugins display icon that's shown in the settings see <see href="https://materialdesignicons.com" /> for
/// available icons
/// </summary>
[JsonProperty]
public string? Icon
{
get => _icon;
set => SetAndNotify(ref _icon, value);
}
/// <summary>
/// Gets the plugin this info is associated with
/// </summary>
public PluginFeature PluginFeature
{
get => _pluginFeature;
internal set => SetAndNotify(ref _pluginFeature, value);
}
/// <inheritdoc />
public override string ToString()
{
return PluginFeature.Id;
}
}
}

View File

@ -9,6 +9,7 @@ using Artemis.Core.DeviceProviders;
using Artemis.Core.Ninject;
using Artemis.Storage.Entities.Plugins;
using Artemis.Storage.Repositories.Interfaces;
using Humanizer;
using McMaster.NETCore.Plugins;
using Ninject;
using Ninject.Extensions.ChildKernel;
@ -342,6 +343,10 @@ namespace Artemis.Core.Services
// Include Plugin as a parameter for the PluginSettingsProvider
IParameter[] parameters = {new Parameter("Plugin", plugin, false)};
PluginFeature instance = (PluginFeature) plugin.Kernel.Get(featureType, parameters);
// Get the PluginFeature attribute which contains extra info on the feature
PluginFeatureAttribute? pluginFeatureAttribute = (PluginFeatureAttribute?) Attribute.GetCustomAttribute(featureType, typeof(PluginFeatureAttribute));
instance.Info = new PluginFeatureInfo(instance, pluginFeatureAttribute);
plugin.AddFeature(instance);
// Load the enabled state and if not found, default to true

View File

@ -0,0 +1,80 @@
using System;
using System.IO;
using System.Threading.Tasks;
using EmbedIO;
using Newtonsoft.Json;
namespace Artemis.Core.Services
{
/// <summary>
/// Represents a plugin web endpoint receiving an object of type <typeparamref name="T" /> and returning any
/// <see cref="object" /> or <see langword="null" />.
/// <para>Note: Both will be deserialized and serialized respectively using JSON.</para>
/// </summary>
public class JsonPluginEndPoint<T> : PluginEndPoint
{
private readonly Action<T>? _requestHandler;
private readonly Func<T, object?>? _responseRequestHandler;
internal JsonPluginEndPoint(PluginFeature pluginFeature, string name, PluginsModule pluginsModule, Action<T> requestHandler) : base(pluginFeature, name, pluginsModule)
{
_requestHandler = requestHandler;
ThrowOnFail = true;
Accepts = MimeType.Json;
}
internal JsonPluginEndPoint(PluginFeature pluginFeature, string name, PluginsModule pluginsModule, Func<T, object?> responseRequestHandler) : base(pluginFeature, name, pluginsModule)
{
_responseRequestHandler = responseRequestHandler;
ThrowOnFail = true;
Accepts = MimeType.Json;
Returns = MimeType.Json;
}
/// <summary>
/// Whether or not the end point should throw an exception if deserializing the received JSON fails.
/// If set to <see langword="false" /> malformed JSON is silently ignored; if set to <see langword="true" /> malformed
/// JSON throws a <see cref="JsonException" />.
/// </summary>
public bool ThrowOnFail { get; set; }
#region Overrides of PluginEndPoint
/// <inheritdoc />
protected override async Task ProcessRequest(IHttpContext context)
{
if (context.Request.HttpVerb != HttpVerbs.Post)
throw HttpException.MethodNotAllowed("This end point only accepts POST calls");
context.Response.ContentType = MimeType.Json;
using TextReader reader = context.OpenRequestText();
object? response = null;
try
{
T deserialized = JsonConvert.DeserializeObject<T>(await reader.ReadToEndAsync());
if (_requestHandler != null)
{
_requestHandler(deserialized);
return;
}
if (_responseRequestHandler != null)
response = _responseRequestHandler(deserialized);
else
throw new ArtemisCoreException("JSON plugin end point has no request handler");
}
catch (JsonException)
{
if (ThrowOnFail)
throw;
}
await using TextWriter writer = context.OpenResponseText();
await writer.WriteAsync(JsonConvert.SerializeObject(response));
}
#endregion
}
}

View File

@ -0,0 +1,72 @@
using System;
using System.Threading.Tasks;
using EmbedIO;
using Newtonsoft.Json;
namespace Artemis.Core.Services
{
/// <summary>
/// Represents a base type for plugin end points to be targeted by the <see cref="PluginsModule" />
/// </summary>
public abstract class PluginEndPoint
{
private readonly PluginsModule _pluginsModule;
internal PluginEndPoint(PluginFeature pluginFeature, string name, PluginsModule pluginsModule)
{
_pluginsModule = pluginsModule;
PluginFeature = pluginFeature;
Name = name;
PluginFeature.Disabled += OnDisabled;
}
/// <summary>
/// Gets the name of the end point
/// </summary>
public string Name { get; }
/// <summary>
/// Gets the full URL of the end point
/// </summary>
public string Url => $"{_pluginsModule.ServerUrl.TrimEnd('/')}{_pluginsModule.BaseRoute}{PluginFeature.Plugin.Guid}/{Name}";
/// <summary>
/// Gets the plugin the end point is associated with
/// </summary>
[JsonIgnore]
public PluginFeature PluginFeature { get; }
/// <summary>
/// Gets the plugin info of the plugin the end point is associated with
/// </summary>
public PluginInfo PluginInfo => PluginFeature.Plugin.Info;
/// <summary>
/// Gets the mime type of the input this end point accepts
/// </summary>
public string Accepts { get; protected set; }
/// <summary>
/// Gets the mime type of the output this end point returns
/// </summary>
public string Returns { get; protected set; }
/// <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);
internal async Task InternalProcessRequest(IHttpContext context)
{
await ProcessRequest(context);
}
private void OnDisabled(object? sender, EventArgs e)
{
PluginFeature.Disabled -= OnDisabled;
_pluginsModule.RemovePluginEndPoint(this);
}
}
}

View File

@ -0,0 +1,53 @@
using System;
using System.Threading.Tasks;
using EmbedIO;
namespace Artemis.Core.Services
{
/// <summary>
/// Represents a plugin web endpoint that handles a raw <see cref="IHttpContext" />.
/// <para>
/// Note: This requires that you reference the EmbedIO
/// <see href="https://www.nuget.org/packages/embedio">Nuget package</see>.
/// </para>
/// </summary>
public class RawPluginEndPoint : PluginEndPoint
{
/// <inheritdoc />
internal RawPluginEndPoint(PluginFeature pluginFeature, string name, PluginsModule pluginsModule, Func<IHttpContext, Task> requestHandler) : base(pluginFeature, name, pluginsModule)
{
RequestHandler = requestHandler;
}
/// <summary>
/// Gets or sets the handler used to handle incoming requests to this endpoint
/// </summary>
public Func<IHttpContext, Task> RequestHandler { get; }
/// <summary>
/// Sets the mime type this plugin end point accepts
/// </summary>
public void SetAcceptType(string type)
{
Accepts = type;
}
/// <summary>
/// Sets the mime type this plugin end point returns
/// </summary>
public void SetReturnType(string type)
{
Returns = type;
}
#region Overrides of PluginEndPoint
/// <inheritdoc />
protected override async Task ProcessRequest(IHttpContext context)
{
await RequestHandler(context);
}
#endregion
}
}

View File

@ -0,0 +1,59 @@
using System;
using System.IO;
using System.Threading.Tasks;
using EmbedIO;
namespace Artemis.Core.Services
{
/// <summary>
/// Represents a plugin web endpoint receiving an a <see cref="string" /> and returning a <see cref="string" /> or
/// <see langword="null" />.
/// </summary>
public class StringPluginEndPoint : PluginEndPoint
{
private readonly Action<string>? _requestHandler;
private readonly Func<string, string?>? _responseRequestHandler;
internal StringPluginEndPoint(PluginFeature pluginFeature, string name, PluginsModule pluginsModule, Action<string> requestHandler) : base(pluginFeature, name, pluginsModule)
{
_requestHandler = requestHandler;
Accepts = MimeType.PlainText;
}
internal StringPluginEndPoint(PluginFeature pluginFeature, string name, PluginsModule pluginsModule, Func<string, string?> requestHandler) : base(pluginFeature, name, pluginsModule)
{
_responseRequestHandler = requestHandler;
Accepts = MimeType.PlainText;
Returns = MimeType.PlainText;
}
#region Overrides of PluginEndPoint
/// <inheritdoc />
protected override async Task ProcessRequest(IHttpContext context)
{
if (context.Request.HttpVerb != HttpVerbs.Post)
throw HttpException.MethodNotAllowed("This end point only accepts POST calls");
context.Response.ContentType = MimeType.PlainText;
using TextReader reader = context.OpenRequestText();
string? response;
if (_requestHandler != null)
{
_requestHandler(await reader.ReadToEndAsync());
return;
}
if (_responseRequestHandler != null)
response = _responseRequestHandler(await reader.ReadToEndAsync());
else
throw new ArtemisCoreException("String plugin end point has no request handler");
await using TextWriter writer = context.OpenResponseText();
await writer.WriteAsync(response);
}
#endregion
}
}

View File

@ -0,0 +1,101 @@
using System;
using System.Threading.Tasks;
using EmbedIO;
using EmbedIO.WebApi;
namespace Artemis.Core.Services
{
/// <summary>
/// A service that provides access to the local Artemis web server
/// </summary>
public interface IWebServerService : IArtemisService
{
/// <summary>
/// Gets the current instance of the web server, replaced when <see cref="WebServerStarting" /> occurs.
/// </summary>
WebServer? Server { get; }
/// <summary>
/// Gets the plugins module containing all plugin end points
/// </summary>
PluginsModule PluginsModule { get; }
/// <summary>
/// Adds a new endpoint for the given plugin feature receiving an object of type <typeparamref name="T" />
/// <para>Note: Object will be deserialized using JSON.</para>
/// </summary>
/// <typeparam name="T">The type of object to be received</typeparam>
/// <param name="feature">The plugin feature the end point is associated with</param>
/// <param name="endPointName">The name of the end point, must be unique</param>
/// <param name="requestHandler"></param>
/// <returns>The resulting end point</returns>
JsonPluginEndPoint<T> AddJsonEndPoint<T>(PluginFeature feature, string endPointName, Action<T> requestHandler);
/// <summary>
/// Adds a new endpoint for the given plugin feature receiving an object of type <typeparamref name="T" /> and
/// returning any <see cref="object" />.
/// <para>Note: Both will be deserialized and serialized respectively using JSON.</para>
/// </summary>
/// <typeparam name="T">The type of object to be received</typeparam>
/// <param name="feature">The plugin feature the end point is associated with</param>
/// <param name="endPointName">The name of the end point, must be unique</param>
/// <param name="requestHandler"></param>
/// <returns>The resulting end point</returns>
JsonPluginEndPoint<T> AddResponsiveJsonEndPoint<T>(PluginFeature feature, string endPointName, Func<T, object?> requestHandler);
/// <summary>
/// Adds a new endpoint for the given plugin feature receiving an a <see cref="string" />.
/// </summary>
/// <param name="feature">The plugin feature the end point is associated with</param>
/// <param name="endPointName">The name of the end point, must be unique</param>
/// <param name="requestHandler"></param>
/// <returns>The resulting end point</returns>
StringPluginEndPoint AddStringEndPoint(PluginFeature feature, string endPointName, Action<string> requestHandler);
/// <summary>
/// Adds a new endpoint for the given plugin feature receiving an a <see cref="string" /> and returning a
/// <see cref="string" /> or <see langword="null" />.
/// </summary>
/// <param name="feature">The plugin feature the end point is associated with</param>
/// <param name="endPointName">The name of the end point, must be unique</param>
/// <param name="requestHandler"></param>
/// <returns>The resulting end point</returns>
StringPluginEndPoint AddResponsiveStringEndPoint(PluginFeature feature, string endPointName, Func<string, string?> requestHandler);
/// <summary>
/// Adds a new endpoint for the given plugin feature that handles a raw <see cref="IHttpContext" />.
/// <para>
/// Note: This requires that you reference the EmbedIO
/// <see href="https://www.nuget.org/packages/embedio">Nuget package</see>.
/// </para>
/// </summary>
/// <param name="feature">The plugin feature the end point is associated with</param>
/// <param name="endPointName">The name of the end point, must be unique</param>
/// <param name="requestHandler"></param>
/// <returns>The resulting end point</returns>
RawPluginEndPoint AddRawEndPoint(PluginFeature feature, string endPointName, Func<IHttpContext, Task> requestHandler);
/// <summary>
/// Removes an existing endpoint
/// </summary>
/// <param name="endPoint">The end point to remove</param>
void RemovePluginEndPoint(PluginEndPoint endPoint);
/// <summary>
/// Adds a new Web API controller and restarts the web server
/// </summary>
/// <typeparam name="T">The type of Web API controller to remove</typeparam>
void AddController<T>() where T : WebApiController;
/// <summary>
/// Removes an existing Web API controller and restarts the web server
/// </summary>
/// <typeparam name="T">The type of Web API controller to remove</typeparam>
void RemoveController<T>() where T : WebApiController;
/// <summary>
/// Occurs when the web server has been created and is about to start. This is the ideal place to add your own modules.
/// </summary>
event EventHandler? WebServerStarting;
}
}

View File

@ -0,0 +1,89 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EmbedIO;
using Newtonsoft.Json;
namespace Artemis.Core.Services
{
/// <summary>
/// Represents an EmbedIO web module used to process web requests and forward them to the right
/// <see cref="PluginEndPoint" />.
/// </summary>
public class PluginsModule : WebModuleBase
{
private readonly Dictionary<string, Dictionary<string, PluginEndPoint>> _pluginEndPoints;
internal PluginsModule(string baseRoute) : base(baseRoute)
{
_pluginEndPoints = new Dictionary<string, Dictionary<string, PluginEndPoint>>();
}
internal void AddPluginEndPoint(PluginEndPoint registration)
{
string id = registration.PluginFeature.Plugin.Guid.ToString();
if (!_pluginEndPoints.TryGetValue(id, out Dictionary<string, PluginEndPoint>? registrations))
{
registrations = new Dictionary<string, PluginEndPoint>();
_pluginEndPoints.Add(id, registrations);
}
if (registrations.ContainsKey(registration.Name))
throw new ArtemisPluginException(registration.PluginFeature.Plugin, $"Plugin already registered an endpoint at {registration.Name}.");
registrations.Add(registration.Name, registration);
}
internal void RemovePluginEndPoint(PluginEndPoint registration)
{
string id = registration.PluginFeature.Plugin.Guid.ToString();
if (!_pluginEndPoints.TryGetValue(id, out Dictionary<string, PluginEndPoint>? registrations))
return;
if (!registrations.ContainsKey(registration.Name))
return;
registrations.Remove(registration.Name);
}
#region Overrides of WebModuleBase
/// <inheritdoc />
protected override async Task OnRequestAsync(IHttpContext context)
{
if (context.Route.SubPath == null)
throw HttpException.NotFound();
// Split the sub path
string[] pathParts = context.Route.SubPath.Substring(1).Split('/');
// Expect a plugin ID and an endpoint
if (pathParts == null || pathParts.Length != 2)
throw HttpException.BadRequest("Path must contain a plugin ID and endpoint and nothing else.");
// Find a matching plugin
if (!_pluginEndPoints.TryGetValue(pathParts[0], out Dictionary<string, PluginEndPoint>? endPoints))
throw HttpException.NotFound($"Found no plugin with ID {pathParts[0]}.");
// Find a matching endpoint
if (!endPoints.TryGetValue(pathParts[1], out PluginEndPoint? endPoint))
throw HttpException.NotFound($"Found no endpoint called {pathParts[1]} for plugin with ID {pathParts[0]}.");
// It is up to the registration how the request is eventually handled, it might even set a response here
await endPoint.InternalProcessRequest(context);
// No need to return ourselves, assume the request is fully handled by the end point
context.SetHandled();
}
/// <inheritdoc />
public override bool IsFinalHandler => true;
internal string? ServerUrl { get; set; }
/// <summary>
/// Gets a read only collection containing all current plugin end points
/// </summary>
public IReadOnlyCollection<PluginEndPoint> PluginEndPoints => new List<PluginEndPoint>(_pluginEndPoints.SelectMany(p => p.Value.Values));
#endregion
}
}

View File

@ -0,0 +1,28 @@
using System;
using EmbedIO.WebApi;
using Ninject;
namespace Artemis.Core.Services
{
internal class WebApiControllerRegistration<T> : WebApiControllerRegistration where T : WebApiController
{
public WebApiControllerRegistration(IKernel kernel) : base(typeof(T))
{
Factory = () => kernel.Get<T>();
}
public Func<T> Factory { get; set; }
public override object UntypedFactory => Factory;
}
internal abstract class WebApiControllerRegistration
{
protected WebApiControllerRegistration(Type controllerType)
{
ControllerType = controllerType;
}
public abstract object UntypedFactory { get; }
public Type ControllerType { get; set; }
}
}

View File

@ -0,0 +1,220 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using EmbedIO;
using EmbedIO.WebApi;
using Newtonsoft.Json;
using Ninject;
using Serilog;
namespace Artemis.Core.Services
{
internal class WebServerService : IWebServerService, IDisposable
{
private readonly List<WebApiControllerRegistration> _controllers;
private readonly IKernel _kernel;
private readonly ILogger _logger;
private readonly PluginSetting<int> _webServerPortSetting;
public WebServerService(IKernel kernel, ILogger logger, ISettingsService settingsService)
{
_kernel = kernel;
_logger = logger;
_controllers = new List<WebApiControllerRegistration>();
_webServerPortSetting = settingsService.GetSetting("WebServer.Port", 9696);
_webServerPortSetting.SettingChanged += WebServerPortSettingOnSettingChanged;
PluginsModule = new PluginsModule("/plugins");
StartWebServer();
}
public WebServer? Server { get; private set; }
public PluginsModule PluginsModule { get; }
#region Web server managament
private WebServer CreateWebServer()
{
Server?.Dispose();
Server = null;
string url = $"http://localhost:{_webServerPortSetting.Value}/";
WebApiModule apiModule = new("/api/", JsonNetSerializer);
PluginsModule.ServerUrl = url;
WebServer server = new WebServer(o => o.WithUrlPrefix(url).WithMode(HttpListenerMode.EmbedIO))
.WithLocalSessionManager()
.WithModule(apiModule)
.WithModule(PluginsModule)
.HandleHttpException((context, exception) => HandleHttpExceptionJson(context, exception))
.HandleUnhandledException(JsonExceptionHandlerCallback);
// Add registered controllers to the API module
foreach (WebApiControllerRegistration registration in _controllers)
apiModule.RegisterController(registration.ControllerType, (Func<WebApiController>) registration.UntypedFactory);
// Listen for state changes.
server.StateChanged += (s, e) => _logger.Verbose("WebServer new state - {state}", e.NewState);
// Store the URL in a webserver.txt file so that remote applications can find it
File.WriteAllText(Path.Combine(Constants.DataFolder, "webserver.txt"), url);
return server;
}
private void StartWebServer()
{
Server = CreateWebServer();
OnWebServerStarting();
Server.Start();
}
#endregion
#region Plugin endpoint management
public JsonPluginEndPoint<T> AddJsonEndPoint<T>(PluginFeature feature, string endPointName, Action<T> requestHandler)
{
if (feature == null) throw new ArgumentNullException(nameof(feature));
if (endPointName == null) throw new ArgumentNullException(nameof(endPointName));
if (requestHandler == null) throw new ArgumentNullException(nameof(requestHandler));
JsonPluginEndPoint<T> endPoint = new(feature, endPointName, PluginsModule, requestHandler);
PluginsModule.AddPluginEndPoint(endPoint);
return endPoint;
}
public JsonPluginEndPoint<T> AddResponsiveJsonEndPoint<T>(PluginFeature feature, string endPointName, Func<T, object?> requestHandler)
{
if (feature == null) throw new ArgumentNullException(nameof(feature));
if (endPointName == null) throw new ArgumentNullException(nameof(endPointName));
if (requestHandler == null) throw new ArgumentNullException(nameof(requestHandler));
JsonPluginEndPoint<T> endPoint = new(feature, endPointName, PluginsModule, requestHandler);
PluginsModule.AddPluginEndPoint(endPoint);
return endPoint;
}
public StringPluginEndPoint AddStringEndPoint(PluginFeature feature, string endPointName, Action<string> requestHandler)
{
if (feature == null) throw new ArgumentNullException(nameof(feature));
if (endPointName == null) throw new ArgumentNullException(nameof(endPointName));
if (requestHandler == null) throw new ArgumentNullException(nameof(requestHandler));
StringPluginEndPoint endPoint = new(feature, endPointName, PluginsModule, requestHandler);
PluginsModule.AddPluginEndPoint(endPoint);
return endPoint;
}
public StringPluginEndPoint AddResponsiveStringEndPoint(PluginFeature feature, string endPointName, Func<string, string?> requestHandler)
{
if (feature == null) throw new ArgumentNullException(nameof(feature));
if (endPointName == null) throw new ArgumentNullException(nameof(endPointName));
if (requestHandler == null) throw new ArgumentNullException(nameof(requestHandler));
StringPluginEndPoint endPoint = new(feature, endPointName, PluginsModule, requestHandler);
PluginsModule.AddPluginEndPoint(endPoint);
return endPoint;
}
public RawPluginEndPoint AddRawEndPoint(PluginFeature feature, string endPointName, Func<IHttpContext, Task> requestHandler)
{
if (feature == null) throw new ArgumentNullException(nameof(feature));
if (endPointName == null) throw new ArgumentNullException(nameof(endPointName));
if (requestHandler == null) throw new ArgumentNullException(nameof(requestHandler));
RawPluginEndPoint endPoint = new(feature, endPointName, PluginsModule, requestHandler);
PluginsModule.AddPluginEndPoint(endPoint);
return endPoint;
}
public void RemovePluginEndPoint(PluginEndPoint endPoint)
{
PluginsModule.RemovePluginEndPoint(endPoint);
}
#endregion
#region Controller management
public void AddController<T>() where T : WebApiController
{
_controllers.Add(new WebApiControllerRegistration<T>(_kernel));
StartWebServer();
}
public void RemoveController<T>() where T : WebApiController
{
_controllers.RemoveAll(r => r.ControllerType == typeof(T));
StartWebServer();
}
#endregion
#region Handlers
private async Task JsonExceptionHandlerCallback(IHttpContext context, Exception exception)
{
context.Response.ContentType = MimeType.Json;
await using TextWriter writer = context.OpenResponseText();
string response = JsonConvert.SerializeObject(new Dictionary<string, object?>()
{
{"StatusCode", context.Response.StatusCode},
{"StackTrace", exception.StackTrace},
{"Type", exception.GetType().FullName},
{"Message", exception.Message},
{"Data", exception.Data},
{"InnerException", exception.InnerException},
{"HelpLink", exception.HelpLink},
{"Source", exception.Source},
{"HResult", exception.HResult}
});
await writer.WriteAsync(response);
}
private async Task JsonNetSerializer(IHttpContext context, object? data)
{
context.Response.ContentType = MimeType.Json;
await using TextWriter writer = context.OpenResponseText();
string json = JsonConvert.SerializeObject(data, new JsonSerializerSettings {PreserveReferencesHandling = PreserveReferencesHandling.Objects});
await writer.WriteAsync(json);
}
private async Task HandleHttpExceptionJson(IHttpContext context, IHttpException httpException)
{
await context.SendStringAsync(JsonConvert.SerializeObject(httpException, Formatting.Indented), MimeType.Json, Encoding.UTF8);
}
#endregion
#region Events
public event EventHandler? WebServerStarting;
protected virtual void OnWebServerStarting()
{
WebServerStarting?.Invoke(this, EventArgs.Empty);
}
#endregion
#region Event handlers
private void WebServerPortSettingOnSettingChanged(object? sender, EventArgs e)
{
StartWebServer();
}
#endregion
#region IDisposable
/// <inheritdoc />
public void Dispose()
{
Server?.Dispose();
_webServerPortSetting.SettingChanged -= WebServerPortSettingOnSettingChanged;
}
#endregion
}
}

View File

@ -12,6 +12,15 @@
"System.Threading.Tasks.Extensions": "4.5.3"
}
},
"EmbedIO": {
"type": "Direct",
"requested": "[3.4.3, )",
"resolved": "3.4.3",
"contentHash": "YM6hpZNAfvbbixfG9T4lWDGfF0D/TqutbTROL4ogVcHKwPF1hp+xS3ABwd3cxxTxvDFkj/zZl57QgWuFA8Igxw==",
"dependencies": {
"Unosquare.Swan.Lite": "3.0.0"
}
},
"HidSharp": {
"type": "Direct",
"requested": "[2.1.0, )",
@ -1226,6 +1235,11 @@
"System.Xml.ReaderWriter": "4.3.0"
}
},
"Unosquare.Swan.Lite": {
"type": "Transitive",
"resolved": "3.0.0",
"contentHash": "noPwJJl1Q9uparXy1ogtkmyAPGNfSGb0BLT1292nFH1jdMKje6o2kvvrQUvF9Xklj+IoiAI0UzF6Aqxlvo10lw=="
},
"artemis.storage": {
"type": "Project",
"dependencies": {

View File

@ -5,7 +5,7 @@ namespace Artemis.UI.Shared.Services
{
internal class MessageService : IMessageService
{
private INotificationProvider _notificationProvider;
private INotificationProvider? _notificationProvider;
public ISnackbarMessageQueue MainMessageQueue { get; }
public MessageService(ISnackbarMessageQueue mainMessageQueue)
@ -74,20 +74,20 @@ namespace Artemis.UI.Shared.Services
/// <inheritdoc />
public void ShowNotification(string title, string message)
{
_notificationProvider.ShowNotification(title, message, PackIconKind.None);
_notificationProvider?.ShowNotification(title, message, PackIconKind.None);
}
/// <inheritdoc />
public void ShowNotification(string title, string message, PackIconKind icon)
{
_notificationProvider.ShowNotification(title, message, icon);
_notificationProvider?.ShowNotification(title, message, icon);
}
/// <inheritdoc />
public void ShowNotification(string title, string message, string icon)
{
Enum.TryParse(typeof(PackIconKind), icon, true, out object? iconKind);
_notificationProvider.ShowNotification(title, message, (PackIconKind) (iconKind ?? PackIconKind.None));
_notificationProvider?.ShowNotification(title, message, (PackIconKind) (iconKind ?? PackIconKind.None));
}
}
}

View File

@ -66,14 +66,12 @@ namespace Artemis.UI.Shared.Services
public void OpenMainWindow()
{
IsMainWindowOpen = true;
OnMainWindowOpened();
_mainWindowManager?.OpenMainWindow();
}
public void CloseMainWindow()
{
IsMainWindowOpen = false;
OnMainWindowClosed();
_mainWindowManager?.CloseMainWindow();
}
public event EventHandler? MainWindowOpened;

View File

@ -142,6 +142,14 @@
"System.Xml.XmlDocument": "4.3.0"
}
},
"EmbedIO": {
"type": "Transitive",
"resolved": "3.4.3",
"contentHash": "YM6hpZNAfvbbixfG9T4lWDGfF0D/TqutbTROL4ogVcHKwPF1hp+xS3ABwd3cxxTxvDFkj/zZl57QgWuFA8Igxw==",
"dependencies": {
"Unosquare.Swan.Lite": "3.0.0"
}
},
"HidSharp": {
"type": "Transitive",
"resolved": "2.1.0",
@ -1305,11 +1313,17 @@
"System.Xml.ReaderWriter": "4.3.0"
}
},
"Unosquare.Swan.Lite": {
"type": "Transitive",
"resolved": "3.0.0",
"contentHash": "noPwJJl1Q9uparXy1ogtkmyAPGNfSGb0BLT1292nFH1jdMKje6o2kvvrQUvF9Xklj+IoiAI0UzF6Aqxlvo10lw=="
},
"artemis.core": {
"type": "Project",
"dependencies": {
"Artemis.Storage": "1.0.0",
"Ben.Demystifier": "0.1.6",
"EmbedIO": "3.4.3",
"HidSharp": "2.1.0",
"Humanizer.Core": "2.8.26",
"LiteDB": "5.0.9",

View File

@ -0,0 +1,127 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Security.Principal;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using Artemis.Core;
using Artemis.UI.Utilities;
using Stylet;
namespace Artemis.UI
{
public class ApplicationStateManager
{
// ReSharper disable once NotAccessedField.Local - Kept in scope to ensure it does not get released
private Mutex _artemisMutex;
public ApplicationStateManager(string[] startupArguments)
{
StartupArguments = startupArguments;
IsElevated = new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator);
Core.Utilities.ShutdownRequested += UtilitiesOnShutdownRequested;
Core.Utilities.RestartRequested += UtilitiesOnRestartRequested;
}
public string[] StartupArguments { get; }
public bool IsElevated { get; }
public bool FocusExistingInstance()
{
_artemisMutex = new Mutex(true, "Artemis-3c24b502-64e6-4587-84bf-9072970e535d", out bool createdNew);
if (createdNew)
return false;
try
{
// Blocking is required here otherwise Artemis shuts down before the remote call gets a chance to finish
RemoteFocus().GetAwaiter().GetResult();
}
catch (Exception)
{
// Not much could go wrong here but this code runs so early it'll crash if something does go wrong
return true;
}
return true;
}
private async Task RemoteFocus()
{
// At this point we cannot read the database yet to retrieve the web server port.
// Instead use the method external applications should use as well.
if (!File.Exists(Path.Combine(Constants.DataFolder, "webserver.txt")))
return;
string url = await File.ReadAllTextAsync(Path.Combine(Constants.DataFolder, "webserver.txt"));
using HttpClient client = new();
await client.PostAsync(url + "api/remote/bring-to-foreground", null!);
}
private void UtilitiesOnRestartRequested(object sender, RestartEventArgs e)
{
List<string> argsList = new();
argsList.AddRange(StartupArguments);
if (e.ExtraArgs != null)
argsList.AddRange(e.ExtraArgs.Except(argsList));
string args = argsList.Any() ? "-ArgumentList " + string.Join(',', argsList) : "";
string command =
$"-Command \"& {{Start-Sleep -Milliseconds {(int) e.Delay.TotalMilliseconds}; " +
"(Get-Process 'Artemis.UI').kill(); " +
$"Start-Process -FilePath '{Constants.ExecutablePath}' -WorkingDirectory '{Constants.ApplicationFolder}' {args}}}\"";
// Elevated always runs with RunAs
if (e.Elevate)
{
ProcessStartInfo info = new()
{
Arguments = command.Replace("}\"", " -Verb RunAs}\""),
WindowStyle = ProcessWindowStyle.Hidden,
CreateNoWindow = true,
FileName = "PowerShell.exe"
};
Process.Start(info);
}
// Non-elevated runs regularly if currently not elevated
else if (!IsElevated)
{
ProcessStartInfo info = new()
{
Arguments = command,
WindowStyle = ProcessWindowStyle.Hidden,
CreateNoWindow = true,
FileName = "PowerShell.exe"
};
Process.Start(info);
}
// Non-elevated runs via a utility method is currently elevated (de-elevating is hacky)
else
{
string powerShell = Path.Combine(Environment.SystemDirectory, "WindowsPowerShell", "v1.0", "powershell.exe");
ProcessUtilities.RunAsDesktopUser(powerShell, command, true);
}
// Lets try a graceful shutdown, PowerShell will kill if needed
Execute.OnUIThread(() => Application.Current.Shutdown());
}
private void UtilitiesOnShutdownRequested(object sender, EventArgs e)
{
// Use PowerShell to kill the process after 2 sec just in case
ProcessStartInfo info = new()
{
Arguments = "-Command \"& {Start-Sleep -s 2; (Get-Process 'Artemis.UI').kill()}",
WindowStyle = ProcessWindowStyle.Hidden,
CreateNoWindow = true,
FileName = "PowerShell.exe"
};
Process.Start(info);
Execute.OnUIThread(() => Application.Current.Shutdown());
}
}
}

View File

@ -1,2 +1,5 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=screens_005Cprofileeditor_005Cconditions_005Cpredicate/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=screens_005Cprofileeditor_005Cconditions_005Cpredicate/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=services_005Cinterfaces/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=services_005Cremotemanagement/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=services_005Cremotemanagement_005Cinterfaces/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

View File

@ -1,16 +1,11 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Markup;
using System.Windows.Threading;
using Artemis.Core;
using Artemis.Core.Ninject;
using Artemis.Core.Services;
using Artemis.UI.Ninject;
@ -19,7 +14,6 @@ using Artemis.UI.Services;
using Artemis.UI.Shared;
using Artemis.UI.Shared.Services;
using Artemis.UI.Stylet;
using Artemis.UI.Utilities;
using Ninject;
using Serilog;
using Stylet;
@ -28,6 +22,7 @@ namespace Artemis.UI
{
public class Bootstrapper : NinjectBootstrapper<TrayViewModel>
{
private ApplicationStateManager _applicationStateManager;
private ICoreService _core;
public static List<string> StartupArguments { get; private set; }
@ -41,14 +36,18 @@ namespace Artemis.UI
protected override void Launch()
{
// TODO: Move shutdown code out of bootstrapper
Core.Utilities.ShutdownRequested += UtilitiesOnShutdownRequested;
Core.Utilities.RestartRequested += UtilitiesOnRestartRequested;
_applicationStateManager = new ApplicationStateManager(Args);
Core.Utilities.PrepareFirstLaunch();
ILogger logger = Kernel.Get<ILogger>();
IViewManager viewManager = Kernel.Get<IViewManager>();
if (_applicationStateManager.FocusExistingInstance())
{
logger.Information("Shutting down because a different instance is already running.");
Application.Current.Shutdown(1);
return;
}
IViewManager viewManager = Kernel.Get<IViewManager>();
StartupArguments = Args.ToList();
// Create the Artemis core
@ -78,7 +77,7 @@ namespace Artemis.UI
try
{
_core.StartupArguments = StartupArguments;
_core.IsElevated = new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator);
_core.IsElevated = _applicationStateManager.IsElevated;
_core.Initialize();
}
catch (Exception e)
@ -88,7 +87,9 @@ namespace Artemis.UI
}
});
Kernel.Get<IRegistrationService>().RegisterInputProvider();
IRegistrationService registrationService = Kernel.Get<IRegistrationService>();
registrationService.RegisterInputProvider();
registrationService.RegisterControllers();
}
protected override void ConfigureIoC(IKernel kernel)
@ -124,67 +125,6 @@ namespace Artemis.UI
e.Handled = true;
}
private void UtilitiesOnShutdownRequested(object sender, EventArgs e)
{
// Use PowerShell to kill the process after 2 sec just in case
ProcessStartInfo info = new()
{
Arguments = "-Command \"& {Start-Sleep -s 2; (Get-Process 'Artemis.UI').kill()}",
WindowStyle = ProcessWindowStyle.Hidden,
CreateNoWindow = true,
FileName = "PowerShell.exe"
};
Process.Start(info);
Execute.OnUIThread(() => Application.Current.Shutdown());
}
private void UtilitiesOnRestartRequested(object sender, RestartEventArgs e)
{
List<string> argsList = new();
argsList.AddRange(Args);
if (e.ExtraArgs != null)
argsList.AddRange(e.ExtraArgs.Except(argsList));
string args = argsList.Any() ? "-ArgumentList " + string.Join(',', argsList) : "";
string command =
$"-Command \"& {{Start-Sleep -Milliseconds {(int) e.Delay.TotalMilliseconds}; " +
$"(Get-Process 'Artemis.UI').kill(); " +
$"Start-Process -FilePath '{Constants.ExecutablePath}' -WorkingDirectory '{Constants.ApplicationFolder}' {args}}}\"";
// Elevated always runs with RunAs
if (e.Elevate)
{
ProcessStartInfo info = new()
{
Arguments = command.Replace("}\"", " -Verb RunAs}\""),
WindowStyle = ProcessWindowStyle.Hidden,
CreateNoWindow = true,
FileName = "PowerShell.exe"
};
Process.Start(info);
}
// Non-elevated runs regularly if currently not elevated
else if (!_core.IsElevated)
{
ProcessStartInfo info = new()
{
Arguments = command,
WindowStyle = ProcessWindowStyle.Hidden,
CreateNoWindow = true,
FileName = "PowerShell.exe"
};
Process.Start(info);
}
// Non-elevated runs via a utility method is currently elevated (de-elevating is hacky)
else
{
string powerShell = Path.Combine(Environment.SystemDirectory, "WindowsPowerShell", "v1.0", "powershell.exe");
ProcessUtilities.RunAsDesktopUser(powerShell, command, true);
}
// Lets try a graceful shutdown, PowerShell will kill if needed
Execute.OnUIThread(() => Application.Current.Shutdown());
}
private void HandleFatalException(Exception e, ILogger logger)
{
logger.Fatal(e, "Fatal exception during initialization, shutting down.");
@ -200,8 +140,5 @@ namespace Artemis.UI
Environment.Exit(1);
});
}
[DllImport("user32.dll")]
private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
}
}

View File

@ -0,0 +1,39 @@
using System;
using Artemis.Core.Services;
using Artemis.UI.Shared.Services;
using EmbedIO;
using EmbedIO.Routing;
using EmbedIO.WebApi;
namespace Artemis.UI.Controllers
{
public class RemoteController : WebApiController
{
private readonly ICoreService _coreService;
private readonly IWindowService _windowService;
public RemoteController(ICoreService coreService, IWindowService windowService)
{
_coreService = coreService;
_windowService = windowService;
}
[Route(HttpVerbs.Post, "/remote/bring-to-foreground")]
public void PostBringToForeground()
{
_windowService.OpenMainWindow();
}
[Route(HttpVerbs.Post, "/remote/restart")]
public void PostRestart()
{
Core.Utilities.Restart(_coreService.IsElevated, TimeSpan.FromMilliseconds(500));
}
[Route(HttpVerbs.Post, "/remote/shutdown")]
public void PostShutdown()
{
Core.Utilities.Shutdown();
}
}
}

View File

@ -4,7 +4,7 @@ using Artemis.UI.Ninject.InstanceProviders;
using Artemis.UI.Screens;
using Artemis.UI.Screens.ProfileEditor;
using Artemis.UI.Screens.Splash;
using Artemis.UI.Services.Interfaces;
using Artemis.UI.Services;
using Artemis.UI.Shared.Services;
using Artemis.UI.Stylet;
using FluentValidation;

View File

@ -3,13 +3,11 @@ using Artemis.Core.Modules;
using Artemis.Core.Services;
using Artemis.UI.Shared.Services;
using ICSharpCode.AvalonEdit.Document;
using MaterialDesignThemes.Wpf;
namespace Artemis.UI.Screens.ProfileEditor.Dialogs
{
public class ProfileImportViewModel : DialogViewModelBase
{
private readonly ISnackbarMessageQueue _mainMessageQueue;
private readonly IProfileService _profileService;
private readonly IMessageService _messageService;
private string _profileJson;

View File

@ -6,7 +6,7 @@ using System.Windows.Media;
using Artemis.Core;
using Artemis.UI.Extensions;
using Artemis.UI.Screens.Shared;
using Artemis.UI.Services.Interfaces;
using Artemis.UI.Services;
using Artemis.UI.Shared.Services;
namespace Artemis.UI.Screens.ProfileEditor.Visualization

View File

@ -5,7 +5,7 @@ using System.Windows.Media;
using Artemis.Core;
using Artemis.UI.Events;
using Artemis.UI.Screens.Shared;
using Artemis.UI.Services.Interfaces;
using Artemis.UI.Services;
using Artemis.UI.Shared.Services;
using SkiaSharp;
using SkiaSharp.Views.WPF;

View File

@ -14,7 +14,6 @@ using Artemis.UI.Screens.Settings.Tabs.General;
using Artemis.UI.Screens.Sidebar;
using Artemis.UI.Screens.StartupWizard;
using Artemis.UI.Services;
using Artemis.UI.Services.Interfaces;
using Artemis.UI.Shared.Services;
using Artemis.UI.Utilities;
using MaterialDesignExtensions.Controls;

View File

@ -59,6 +59,28 @@
</Grid>
<Separator Style="{StaticResource MaterialDesignSeparator}" Margin="-15 5" />
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0">
<TextBlock Style="{StaticResource MaterialDesignTextBlock}">Startup delay</TextBlock>
<TextBlock Style="{StaticResource MaterialDesignTextBlock}" Foreground="{DynamicResource MaterialDesignNavigationItemSubheader}" TextWrapping="Wrap">
Set the amount of seconds to wait before running Artemis with Windows. <LineBreak/>
If some devices don't work because Artemis starts before the manufacturer's software, try increasing this value.
</TextBlock>
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center">
<TextBox Text="{Binding AutoRunDelay}" IsEnabled="{Binding StartWithWindows}" Width="80" materialDesign:TextFieldAssist.SuffixText="sec"/>
</StackPanel>
</Grid>
<Separator Style="{StaticResource MaterialDesignSeparator}" Margin="-15 5" />
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
@ -89,62 +111,14 @@
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" VerticalAlignment="Center">
<TextBlock Style="{StaticResource MaterialDesignTextBlock}">Setup wizard</TextBlock>
<TextBlock Style="{StaticResource MaterialDesignTextBlock}" Foreground="{DynamicResource MaterialDesignNavigationItemSubheader}">
Opens the startup wizard usually shown when Artemis first starts.
<StackPanel Grid.Column="0">
<TextBlock Style="{StaticResource MaterialDesignTextBlock}">Log level</TextBlock>
<TextBlock Style="{StaticResource MaterialDesignTextBlock}" Foreground="{DynamicResource MaterialDesignNavigationItemSubheader}" TextWrapping="Wrap">
Sets the logging level, a higher logging level will result in more log files.
</TextBlock>
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center">
<Button Style="{StaticResource MaterialDesignOutlinedButton}" Command="{s:Action ShowSetupWizard}" Width="150">
SHOW WIZARD
</Button>
</StackPanel>
</Grid>
<Separator Style="{StaticResource MaterialDesignSeparator}" Margin="-15 5" />
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" VerticalAlignment="Center">
<TextBlock Style="{StaticResource MaterialDesignTextBlock}">Debugger</TextBlock>
<TextBlock Style="{StaticResource MaterialDesignTextBlock}" Foreground="{DynamicResource MaterialDesignNavigationItemSubheader}">
Use the debugger to see the raw image Artemis is rendering on the surface.
</TextBlock>
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center">
<Button Style="{StaticResource MaterialDesignOutlinedButton}" Command="{s:Action ShowDebugger}" Width="150">
SHOW DEBUGGER
</Button>
</StackPanel>
</Grid>
<Separator Style="{StaticResource MaterialDesignSeparator}" Margin="-15 5" />
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" VerticalAlignment="Center">
<TextBlock Style="{StaticResource MaterialDesignTextBlock}">Application files</TextBlock>
<TextBlock Style="{StaticResource MaterialDesignTextBlock}" Foreground="{DynamicResource MaterialDesignNavigationItemSubheader}">
Opens the directory where application files like plugins and settings are stored.
</TextBlock>
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center">
<Button Style="{StaticResource MaterialDesignOutlinedButton}" Command="{s:Action ShowDataFolder}" Width="150">
SHOW APP FILES
</Button>
<ComboBox Width="80" SelectedValue="{Binding SelectedLogLevel}" ItemsSource="{Binding LogLevels}" SelectedValuePath="Value" DisplayMemberPath="Description" />
</StackPanel>
</Grid>
<Separator Style="{StaticResource MaterialDesignSeparator}" Margin="-15 5" />
@ -170,8 +144,13 @@
</Button>
</StackPanel>
</Grid>
<Separator Style="{StaticResource MaterialDesignSeparator}" Margin="-15 5" />
</StackPanel>
</materialDesign:Card>
<!-- Web server settings -->
<TextBlock Style="{StaticResource MaterialDesignHeadline5TextBlock}" Margin="0 15">Web server</TextBlock>
<materialDesign:Card materialDesign:ShadowAssist.ShadowDepth="Depth1" VerticalAlignment="Stretch" Margin="0,0,5,0">
<StackPanel Margin="15">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
@ -182,16 +161,16 @@
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0">
<TextBlock Style="{StaticResource MaterialDesignTextBlock}">Log level</TextBlock>
<TextBlock Style="{StaticResource MaterialDesignTextBlock}">Web server port</TextBlock>
<TextBlock Style="{StaticResource MaterialDesignTextBlock}" Foreground="{DynamicResource MaterialDesignNavigationItemSubheader}" TextWrapping="Wrap">
Sets the logging level, a higher logging level will result in more log files.
Artemis runs a local web server that can be used to externally interact with the application. <LineBreak />
This web server can only be accessed by applications running on your own computer, e.g. supported games.
</TextBlock>
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center">
<ComboBox Width="80" SelectedValue="{Binding SelectedLogLevel}" ItemsSource="{Binding LogLevels}" SelectedValuePath="Value" DisplayMemberPath="Description" />
<TextBox Text="{Binding WebServerPortSetting.Value}" Width="80" />
</StackPanel>
</Grid>
</StackPanel>
</materialDesign:Card>
@ -391,6 +370,82 @@
</Grid>
</StackPanel>
</materialDesign:Card>
<!-- Tools -->
<TextBlock Style="{StaticResource MaterialDesignHeadline5TextBlock}" Margin="0 15">Tools</TextBlock>
<materialDesign:Card materialDesign:ShadowAssist.ShadowDepth="Depth1" VerticalAlignment="Stretch" Margin="0,0,5,0">
<StackPanel Margin="15">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" VerticalAlignment="Center">
<TextBlock Style="{StaticResource MaterialDesignTextBlock}">Setup wizard</TextBlock>
<TextBlock Style="{StaticResource MaterialDesignTextBlock}" Foreground="{DynamicResource MaterialDesignNavigationItemSubheader}">
Opens the startup wizard usually shown when Artemis first starts.
</TextBlock>
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center">
<Button Style="{StaticResource MaterialDesignOutlinedButton}" Command="{s:Action ShowSetupWizard}" Width="150">
SHOW WIZARD
</Button>
</StackPanel>
</Grid>
<Separator Style="{StaticResource MaterialDesignSeparator}" Margin="-15 5" />
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" VerticalAlignment="Center">
<TextBlock Style="{StaticResource MaterialDesignTextBlock}">Debugger</TextBlock>
<TextBlock Style="{StaticResource MaterialDesignTextBlock}" Foreground="{DynamicResource MaterialDesignNavigationItemSubheader}">
Use the debugger to see the raw image Artemis is rendering on the surface.
</TextBlock>
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center">
<Button Style="{StaticResource MaterialDesignOutlinedButton}" Command="{s:Action ShowDebugger}" Width="150">
SHOW DEBUGGER
</Button>
</StackPanel>
</Grid>
<Separator Style="{StaticResource MaterialDesignSeparator}" Margin="-15 5" />
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" VerticalAlignment="Center">
<TextBlock Style="{StaticResource MaterialDesignTextBlock}">Application files</TextBlock>
<TextBlock Style="{StaticResource MaterialDesignTextBlock}" Foreground="{DynamicResource MaterialDesignNavigationItemSubheader}">
Opens the directory where application files like plugins and settings are stored.
</TextBlock>
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center">
<Button Style="{StaticResource MaterialDesignOutlinedButton}" Command="{s:Action ShowDataFolder}" Width="150">
SHOW APP FILES
</Button>
</StackPanel>
</Grid>
</StackPanel>
</materialDesign:Card>
</StackPanel>
</ScrollViewer>
</UserControl>

View File

@ -14,7 +14,6 @@ using Artemis.Core.Services;
using Artemis.UI.Properties;
using Artemis.UI.Screens.StartupWizard;
using Artemis.UI.Services;
using Artemis.UI.Services.Interfaces;
using Artemis.UI.Shared;
using Artemis.UI.Shared.Services;
using MaterialDesignThemes.Wpf;
@ -80,6 +79,9 @@ namespace Artemis.UI.Screens.Settings.Tabs.General
LayerBrushProviderId = "Artemis.Plugins.LayerBrushes.Color.ColorBrushProvider-92a9d6ba",
BrushType = "ColorBrush"
});
WebServerPortSetting = _settingsService.GetSetting("WebServer.Port", 9696);
WebServerPortSetting.AutoSave = true;
}
public BindableCollection<LayerBrushDescriptor> LayerBrushDescriptors { get; }
@ -123,7 +125,19 @@ namespace Artemis.UI.Screens.Settings.Tabs.General
_settingsService.GetSetting("UI.AutoRun", false).Value = value;
_settingsService.GetSetting("UI.AutoRun", false).Save();
NotifyOfPropertyChange(nameof(StartWithWindows));
Task.Run(ApplyAutorun);
Task.Run(() => ApplyAutorun(false));
}
}
public int AutoRunDelay
{
get => _settingsService.GetSetting("UI.AutoRunDelay", 15).Value;
set
{
_settingsService.GetSetting("UI.AutoRunDelay", 15).Value = value;
_settingsService.GetSetting("UI.AutoRunDelay", 15).Save();
NotifyOfPropertyChange(nameof(AutoRunDelay));
Task.Run(() => ApplyAutorun(true));
}
}
@ -235,6 +249,8 @@ namespace Artemis.UI.Screens.Settings.Tabs.General
}
}
public PluginSetting<int> WebServerPortSetting { get; }
public bool CanOfferUpdatesIfFound
{
get => _canOfferUpdatesIfFound;
@ -289,11 +305,11 @@ namespace Artemis.UI.Screens.Settings.Tabs.General
protected override void OnInitialActivate()
{
Task.Run(ApplyAutorun);
Task.Run(() => ApplyAutorun(false));
base.OnInitialActivate();
}
private void ApplyAutorun()
private void ApplyAutorun(bool recreate)
{
if (!StartWithWindows)
StartMinimized = false;
@ -303,23 +319,29 @@ namespace Artemis.UI.Screens.Settings.Tabs.General
if (File.Exists(autoRunFile))
File.Delete(autoRunFile);
// TODO: Don't do anything if running a development build, only auto-run release builds
// Create or remove the task if necessary
try
{
Process schtasks = new()
bool taskCreated = false;
if (!recreate)
{
StartInfo =
Process schtasks = new()
{
WindowStyle = ProcessWindowStyle.Hidden,
UseShellExecute = true,
FileName = Path.Combine(Environment.SystemDirectory, "schtasks.exe"),
Arguments = "/TN \"Artemis 2 autorun\""
}
};
StartInfo =
{
WindowStyle = ProcessWindowStyle.Hidden,
UseShellExecute = true,
FileName = Path.Combine(Environment.SystemDirectory, "schtasks.exe"),
Arguments = "/TN \"Artemis 2 autorun\""
}
};
schtasks.Start();
schtasks.WaitForExit();
bool taskCreated = schtasks.ExitCode == 0;
schtasks.Start();
schtasks.WaitForExit();
taskCreated = schtasks.ExitCode == 0;
}
if (StartWithWindows && !taskCreated)
CreateAutoRunTask();
@ -343,6 +365,9 @@ namespace Artemis.UI.Screens.Settings.Tabs.General
task.Descendants().First(d => d.Name.LocalName == "RegistrationInfo").Descendants().First(d => d.Name.LocalName == "Author")
.SetValue(System.Security.Principal.WindowsIdentity.GetCurrent().Name);
task.Descendants().First(d => d.Name.LocalName == "Triggers").Descendants().First(d => d.Name.LocalName == "LogonTrigger").Descendants().First(d => d.Name.LocalName == "Delay")
.SetValue(TimeSpan.FromSeconds(AutoRunDelay));
task.Descendants().First(d => d.Name.LocalName == "Principals").Descendants().First(d => d.Name.LocalName == "Principal").Descendants().First(d => d.Name.LocalName == "UserId")
.SetValue(System.Security.Principal.WindowsIdentity.GetCurrent().User.Value);
@ -365,7 +390,7 @@ namespace Artemis.UI.Screens.Settings.Tabs.General
UseShellExecute = true,
Verb = "runas",
FileName = Path.Combine(Environment.SystemDirectory, "schtasks.exe"),
Arguments = $"/Create /XML \"{xmlPath}\" /tn \"Artemis 2 autorun\""
Arguments = $"/Create /XML \"{xmlPath}\" /tn \"Artemis 2 autorun\" /F"
}
};

View File

@ -7,6 +7,7 @@
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:s="https://github.com/canton7/Stylet"
xmlns:converters="clr-namespace:Artemis.UI.Converters"
xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
d:DataContext="{d:DesignInstance local:PluginFeatureViewModel}">
@ -21,8 +22,9 @@
</Grid.ColumnDefinitions>
<!-- Icon column -->
<materialDesign:PackIcon Grid.Column="0"
Kind="{Binding Icon}"
<shared:ArtemisIcon Grid.Column="0"
Icon="{Binding Feature.Info.Icon}"
Width="20"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Visibility="{Binding LoadException, Converter={StaticResource NullToVisibilityConverter}, ConverterParameter=Inverted}" />
@ -40,7 +42,7 @@
</Button>
<!-- Display name column -->
<TextBlock Grid.Column="1" Text="{Binding Name}" Style="{StaticResource MaterialDesignTextBlock}" VerticalAlignment="Center" />
<TextBlock Grid.Column="1" Text="{Binding Feature.Info.Name}" Style="{StaticResource MaterialDesignTextBlock}" VerticalAlignment="Center" ToolTip="{Binding Feature.Info.Description}" />
<!-- Enable toggle column -->
<StackPanel Grid.Column="2" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="8"

View File

@ -3,15 +3,8 @@ using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using Artemis.Core;
using Artemis.Core.DataModelExpansions;
using Artemis.Core.DeviceProviders;
using Artemis.Core.LayerBrushes;
using Artemis.Core.LayerEffects;
using Artemis.Core.Modules;
using Artemis.Core.Services;
using Artemis.UI.Shared.Services;
using Humanizer;
using MaterialDesignThemes.Wpf;
using Stylet;
namespace Artemis.UI.Screens.Settings.Tabs.Plugins
@ -20,9 +13,9 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
{
private readonly IDialogService _dialogService;
private readonly IPluginManagementService _pluginManagementService;
private IMessageService _messageService;
private bool _enabling;
private readonly IMessageService _messageService;
public PluginFeatureViewModel(PluginFeature feature,
IDialogService dialogService,
IPluginManagementService pluginManagementService,
@ -33,14 +26,9 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
_messageService = messageService;
Feature = feature;
Icon = GetIconKind();
}
public PluginFeature Feature { get; }
public PackIconKind Icon { get; }
public string Name => Feature.GetType().Name.Humanize();
public Exception LoadException => Feature.LoadException;
public bool Enabling
@ -109,7 +97,7 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
}
catch (Exception e)
{
_messageService.ShowMessage($"Failed to enable {Name}\r\n{e.Message}", "VIEW LOGS", ShowLogsFolder);
_messageService.ShowMessage($"Failed to enable {Feature.Info.Name}\r\n{e.Message}", "VIEW LOGS", ShowLogsFolder);
}
finally
{
@ -123,20 +111,6 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
}
}
private PackIconKind GetIconKind()
{
return Feature switch
{
BaseDataModelExpansion => PackIconKind.TableAdd,
DeviceProvider => PackIconKind.Devices,
ProfileModule => PackIconKind.VectorRectangle,
Module => PackIconKind.GearBox,
LayerBrushProvider => PackIconKind.Brush,
LayerEffectProvider => PackIconKind.AutoAwesome,
_ => PackIconKind.Plugin
};
}
#region Event handlers
private void OnFeatureEnabling(object sender, PluginFeatureEventArgs e)

View File

@ -9,7 +9,6 @@ using Artemis.Core.Services;
using Artemis.UI.Events;
using Artemis.UI.Screens.Splash;
using Artemis.UI.Services;
using Artemis.UI.Services.Interfaces;
using Artemis.UI.Shared.Services;
using Hardcodet.Wpf.TaskbarNotification;
using MaterialDesignThemes.Wpf;
@ -25,7 +24,6 @@ namespace Artemis.UI.Screens
private readonly IEventAggregator _eventAggregator;
private readonly IKernel _kernel;
private readonly IWindowManager _windowManager;
private bool _canShowRootViewModel;
private RootViewModel _rootViewModel;
private SplashViewModel _splashViewModel;
private TaskbarIcon _taskBarIcon;
@ -44,7 +42,6 @@ namespace Artemis.UI.Screens
_windowManager = windowManager;
_eventAggregator = eventAggregator;
_debugService = debugService;
CanShowRootViewModel = true;
Core.Utilities.ShutdownRequested += UtilitiesOnShutdownRequested;
Core.Utilities.RestartRequested += UtilitiesOnShutdownRequested;
@ -64,23 +61,19 @@ namespace Artemis.UI.Screens
}
}
public bool CanShowRootViewModel
{
get => _canShowRootViewModel;
set => SetAndNotify(ref _canShowRootViewModel, value);
}
public void TrayBringToForeground()
{
if (!CanShowRootViewModel)
if (IsMainWindowOpen)
{
Execute.PostToUIThread(FocusMainWindow);
return;
}
// Initialize the shared UI when first showing the window
if (!UI.Shared.Bootstrapper.Initialized)
UI.Shared.Bootstrapper.Initialize(_kernel);
CanShowRootViewModel = false;
Execute.OnUIThread(() =>
Execute.OnUIThreadSync(() =>
{
_splashViewModel?.RequestClose();
_splashViewModel = null;
@ -115,24 +108,25 @@ namespace Artemis.UI.Screens
public void OnTrayBalloonTipClicked(object sender, EventArgs e)
{
if (CanShowRootViewModel)
{
if (!IsMainWindowOpen)
TrayBringToForeground();
}
else
{
// Wrestle the main window to the front
Window mainWindow = (Window) _rootViewModel.View;
if (mainWindow.WindowState == WindowState.Minimized)
mainWindow.WindowState = WindowState.Normal;
mainWindow.Activate();
mainWindow.Topmost = true;
mainWindow.Topmost = false;
mainWindow.Focus();
}
FocusMainWindow();
}
private void UtilitiesOnShutdownRequested(object? sender, EventArgs e)
private void FocusMainWindow()
{
// Wrestle the main window to the front
Window mainWindow = (Window) _rootViewModel.View;
if (mainWindow.WindowState == WindowState.Minimized)
mainWindow.WindowState = WindowState.Normal;
mainWindow.Activate();
mainWindow.Topmost = true;
mainWindow.Topmost = false;
mainWindow.Focus();
}
private void UtilitiesOnShutdownRequested(object sender, EventArgs e)
{
Execute.OnUIThread(() => _taskBarIcon?.Dispose());
}
@ -150,8 +144,6 @@ namespace Artemis.UI.Screens
{
_rootViewModel.Closed -= RootViewModelOnClosed;
_rootViewModel = null;
CanShowRootViewModel = true;
OnMainWindowClosed();
}
@ -198,16 +190,16 @@ namespace Artemis.UI.Screens
public bool OpenMainWindow()
{
if (CanShowRootViewModel)
return false;
TrayBringToForeground();
return true;
if (IsMainWindowOpen)
Execute.OnUIThread(FocusMainWindow);
else
TrayBringToForeground();
return _rootViewModel.ScreenState == ScreenState.Active;
}
public bool CloseMainWindow()
{
_rootViewModel.RequestClose();
Execute.OnUIThread(() => _rootViewModel.RequestClose());
return _rootViewModel.ScreenState == ScreenState.Closed;
}

View File

@ -1,6 +1,5 @@
using System.Windows;
using Artemis.UI.Screens.Settings.Debug;
using Artemis.UI.Services.Interfaces;
using MaterialDesignExtensions.Controls;
using Ninject;
using Stylet;

View File

@ -1,4 +1,4 @@
namespace Artemis.UI.Services.Interfaces
namespace Artemis.UI.Services
{
// ReSharper disable once InconsistentNaming
public interface IArtemisUIService

View File

@ -1,4 +1,4 @@
namespace Artemis.UI.Services.Interfaces
namespace Artemis.UI.Services
{
public interface IDebugService : IArtemisUIService
{

View File

@ -3,7 +3,7 @@ using System.Windows.Media;
using Artemis.Core;
using SkiaSharp;
namespace Artemis.UI.Services.Interfaces
namespace Artemis.UI.Services
{
public interface ILayerEditorService : IArtemisUIService
{

View File

@ -2,7 +2,6 @@
using System.Windows;
using System.Windows.Media;
using Artemis.Core;
using Artemis.UI.Services.Interfaces;
using SkiaSharp;
using SkiaSharp.Views.WPF;

View File

@ -1,12 +1,12 @@
using System.Linq;
using Artemis.Core;
using Artemis.Core.Services;
using Artemis.UI.Controllers;
using Artemis.UI.DefaultTypes.DataModel.Display;
using Artemis.UI.DefaultTypes.DataModel.Input;
using Artemis.UI.InputProviders;
using Artemis.UI.Ninject;
using Artemis.UI.PropertyInput;
using Artemis.UI.Services.Interfaces;
using Artemis.UI.Shared.Services;
using Serilog;
@ -20,6 +20,7 @@ namespace Artemis.UI.Services
private readonly IPluginManagementService _pluginManagementService;
private readonly ISurfaceService _surfaceService;
private readonly IInputService _inputService;
private readonly IWebServerService _webServerService;
private bool _registeredBuiltInDataModelDisplays;
private bool _registeredBuiltInDataModelInputs;
private bool _registeredBuiltInPropertyEditors;
@ -29,7 +30,8 @@ namespace Artemis.UI.Services
IProfileEditorService profileEditorService,
IPluginManagementService pluginManagementService,
ISurfaceService surfaceService,
IInputService inputService)
IInputService inputService,
IWebServerService webServerService)
{
_logger = logger;
_dataModelUIService = dataModelUIService;
@ -37,6 +39,7 @@ namespace Artemis.UI.Services
_pluginManagementService = pluginManagementService;
_surfaceService = surfaceService;
_inputService = inputService;
_webServerService = webServerService;
LoadPluginModules();
pluginManagementService.PluginEnabling += PluginServiceOnPluginEnabling;
@ -92,6 +95,11 @@ namespace Artemis.UI.Services
_inputService.AddInputProvider(new NativeWindowInputProvider(_logger, _inputService));
}
public void RegisterControllers()
{
_webServerService.AddController<RemoteController>();
}
private void PluginServiceOnPluginEnabling(object sender, PluginEventArgs e)
{
e.Plugin.Kernel.Load(new[] {new PluginUIModule(e.Plugin)});
@ -110,5 +118,6 @@ namespace Artemis.UI.Services
void RegisterBuiltInDataModelInputs();
void RegisterBuiltInPropertyEditors();
void RegisterInputProvider();
void RegisterControllers();
}
}

View File

@ -10,7 +10,6 @@ using Artemis.Core;
using Artemis.Core.Services;
using Artemis.UI.Exceptions;
using Artemis.UI.Screens.Settings.Dialogs;
using Artemis.UI.Services.Interfaces;
using Artemis.UI.Shared.Services;
using MaterialDesignThemes.Wpf;
using Newtonsoft.Json.Linq;
@ -209,7 +208,7 @@ namespace Artemis.UI.Services
AutoUpdate();
}
private void WindowServiceOnMainWindowOpened(object? sender, EventArgs e)
private void WindowServiceOnMainWindowOpened(object sender, EventArgs e)
{
_logger.Information("Main window opened!");
}

View File

@ -195,6 +195,14 @@
"System.Xml.XmlDocument": "4.3.0"
}
},
"EmbedIO": {
"type": "Transitive",
"resolved": "3.4.3",
"contentHash": "YM6hpZNAfvbbixfG9T4lWDGfF0D/TqutbTROL4ogVcHKwPF1hp+xS3ABwd3cxxTxvDFkj/zZl57QgWuFA8Igxw==",
"dependencies": {
"Unosquare.Swan.Lite": "3.0.0"
}
},
"HidSharp": {
"type": "Transitive",
"resolved": "2.1.0",
@ -1357,6 +1365,11 @@
"System.Xml.ReaderWriter": "4.3.0"
}
},
"Unosquare.Swan.Lite": {
"type": "Transitive",
"resolved": "3.0.0",
"contentHash": "noPwJJl1Q9uparXy1ogtkmyAPGNfSGb0BLT1292nFH1jdMKje6o2kvvrQUvF9Xklj+IoiAI0UzF6Aqxlvo10lw=="
},
"WriteableBitmapEx": {
"type": "Transitive",
"resolved": "1.6.7",
@ -1367,6 +1380,7 @@
"dependencies": {
"Artemis.Storage": "1.0.0",
"Ben.Demystifier": "0.1.6",
"EmbedIO": "3.4.3",
"HidSharp": "2.1.0",
"Humanizer.Core": "2.8.26",
"LiteDB": "5.0.9",