mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Web server - Added web server service
UI - Added remote management for bringing to foreground, restarting and shutting down UI - Simplified services namespaces
This commit is contained in:
parent
7d7a985d35
commit
28e1532064
@ -39,6 +39,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Ben.Demystifier" Version="0.1.6" />
|
<PackageReference Include="Ben.Demystifier" Version="0.1.6" />
|
||||||
|
<PackageReference Include="EmbedIO" Version="3.4.3" />
|
||||||
<PackageReference Include="HidSharp" Version="2.1.0" />
|
<PackageReference Include="HidSharp" Version="2.1.0" />
|
||||||
<PackageReference Include="Humanizer.Core" Version="2.8.26" />
|
<PackageReference Include="Humanizer.Core" Version="2.8.26" />
|
||||||
<PackageReference Include="LiteDB" Version="5.0.9" />
|
<PackageReference Include="LiteDB" Version="5.0.9" />
|
||||||
|
|||||||
@ -64,6 +64,8 @@
|
|||||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=services_005Cregistration_005Cinterfaces/@EntryIndexedValue">True</s:Boolean>
|
<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/@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_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_005Cinterfaces/@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/@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/=stores_005Cregistrations/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=utilities/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=utilities/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
||||||
@ -78,7 +78,7 @@ namespace Artemis.Core
|
|||||||
public event EventHandler<LayerPropertyEventArgs>? CurrentValueSet;
|
public event EventHandler<LayerPropertyEventArgs>? CurrentValueSet;
|
||||||
|
|
||||||
/// <summary>
|
/// <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>
|
/// </summary>
|
||||||
public event EventHandler<LayerPropertyEventArgs>? VisibilityChanged;
|
public event EventHandler<LayerPropertyEventArgs>? VisibilityChanged;
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,34 @@
|
|||||||
|
using System;
|
||||||
|
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 currently active instance of the web server
|
||||||
|
/// </summary>
|
||||||
|
WebServer? Server { get; }
|
||||||
|
|
||||||
|
/// <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 a new instance of the web server was been created
|
||||||
|
/// </summary>
|
||||||
|
event EventHandler? WebServerCreated;
|
||||||
|
}
|
||||||
|
}
|
||||||
25
src/Artemis.Core/Services/WebServer/PluginsModule.cs
Normal file
25
src/Artemis.Core/Services/WebServer/PluginsModule.cs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
using System.Threading.Tasks;
|
||||||
|
using EmbedIO;
|
||||||
|
|
||||||
|
namespace Artemis.Core.Services
|
||||||
|
{
|
||||||
|
internal class PluginsModule : WebModuleBase
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public PluginsModule(string baseRoute) : base(baseRoute)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Overrides of WebModuleBase
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override async Task OnRequestAsync(IHttpContext context)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override bool IsFinalHandler => true;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
117
src/Artemis.Core/Services/WebServer/WebServerService.cs
Normal file
117
src/Artemis.Core/Services/WebServer/WebServerService.cs
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using EmbedIO;
|
||||||
|
using EmbedIO.Actions;
|
||||||
|
using EmbedIO.WebApi;
|
||||||
|
using Ninject;
|
||||||
|
using Serilog;
|
||||||
|
|
||||||
|
namespace Artemis.Core.Services
|
||||||
|
{
|
||||||
|
internal class WebServerService : IWebServerService, IDisposable
|
||||||
|
{
|
||||||
|
private readonly IKernel _kernel;
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly PluginsModule _pluginModule;
|
||||||
|
private readonly PluginSetting<int> _webServerPortSetting;
|
||||||
|
private readonly List<WebApiControllerRegistration> _controllers;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
_pluginModule = new PluginsModule("/plugin");
|
||||||
|
Server = CreateWebServer();
|
||||||
|
Server.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public WebServer? Server { get; private set; }
|
||||||
|
|
||||||
|
#region Web server managament
|
||||||
|
|
||||||
|
private WebServer CreateWebServer()
|
||||||
|
{
|
||||||
|
Server?.Dispose();
|
||||||
|
Server = null;
|
||||||
|
|
||||||
|
string url = $"http://localhost:{_webServerPortSetting.Value}/";
|
||||||
|
WebApiModule apiModule = new("/api/");
|
||||||
|
WebServer server = new WebServer(o => o.WithUrlPrefix(url).WithMode(HttpListenerMode.EmbedIO))
|
||||||
|
.WithLocalSessionManager()
|
||||||
|
.WithModule(apiModule)
|
||||||
|
.WithModule(_pluginModule)
|
||||||
|
.WithModule(new ActionModule("/", HttpVerbs.Any, ctx => ctx.SendDataAsync(new {Message = "Error"})));
|
||||||
|
|
||||||
|
// Add 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);
|
||||||
|
OnWebServerCreated();
|
||||||
|
|
||||||
|
return server;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Event handlers
|
||||||
|
|
||||||
|
private void WebServerPortSettingOnSettingChanged(object? sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Server = CreateWebServer();
|
||||||
|
Server.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region IDisposable
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
Server?.Dispose();
|
||||||
|
_webServerPortSetting.SettingChanged -= WebServerPortSettingOnSettingChanged;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Controller management
|
||||||
|
|
||||||
|
public void AddController<T>() where T : WebApiController
|
||||||
|
{
|
||||||
|
_controllers.Add(new WebApiControllerRegistration<T>(_kernel));
|
||||||
|
Server = CreateWebServer();
|
||||||
|
Server.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RemoveController<T>() where T : WebApiController
|
||||||
|
{
|
||||||
|
_controllers.RemoveAll(r => r.ControllerType == typeof(T));
|
||||||
|
Server = CreateWebServer();
|
||||||
|
Server.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Events
|
||||||
|
|
||||||
|
public event EventHandler? WebServerCreated;
|
||||||
|
|
||||||
|
protected virtual void OnWebServerCreated()
|
||||||
|
{
|
||||||
|
WebServerCreated?.Invoke(this, EventArgs.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -12,6 +12,15 @@
|
|||||||
"System.Threading.Tasks.Extensions": "4.5.3"
|
"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": {
|
"HidSharp": {
|
||||||
"type": "Direct",
|
"type": "Direct",
|
||||||
"requested": "[2.1.0, )",
|
"requested": "[2.1.0, )",
|
||||||
@ -1226,6 +1235,11 @@
|
|||||||
"System.Xml.ReaderWriter": "4.3.0"
|
"System.Xml.ReaderWriter": "4.3.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"Unosquare.Swan.Lite": {
|
||||||
|
"type": "Transitive",
|
||||||
|
"resolved": "3.0.0",
|
||||||
|
"contentHash": "noPwJJl1Q9uparXy1ogtkmyAPGNfSGb0BLT1292nFH1jdMKje6o2kvvrQUvF9Xklj+IoiAI0UzF6Aqxlvo10lw=="
|
||||||
|
},
|
||||||
"artemis.storage": {
|
"artemis.storage": {
|
||||||
"type": "Project",
|
"type": "Project",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@ -5,7 +5,7 @@ namespace Artemis.UI.Shared.Services
|
|||||||
{
|
{
|
||||||
internal class MessageService : IMessageService
|
internal class MessageService : IMessageService
|
||||||
{
|
{
|
||||||
private INotificationProvider _notificationProvider;
|
private INotificationProvider? _notificationProvider;
|
||||||
public ISnackbarMessageQueue MainMessageQueue { get; }
|
public ISnackbarMessageQueue MainMessageQueue { get; }
|
||||||
|
|
||||||
public MessageService(ISnackbarMessageQueue mainMessageQueue)
|
public MessageService(ISnackbarMessageQueue mainMessageQueue)
|
||||||
@ -74,20 +74,20 @@ namespace Artemis.UI.Shared.Services
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void ShowNotification(string title, string message)
|
public void ShowNotification(string title, string message)
|
||||||
{
|
{
|
||||||
_notificationProvider.ShowNotification(title, message, PackIconKind.None);
|
_notificationProvider?.ShowNotification(title, message, PackIconKind.None);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void ShowNotification(string title, string message, PackIconKind icon)
|
public void ShowNotification(string title, string message, PackIconKind icon)
|
||||||
{
|
{
|
||||||
_notificationProvider.ShowNotification(title, message, icon);
|
_notificationProvider?.ShowNotification(title, message, icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void ShowNotification(string title, string message, string icon)
|
public void ShowNotification(string title, string message, string icon)
|
||||||
{
|
{
|
||||||
Enum.TryParse(typeof(PackIconKind), icon, true, out object? iconKind);
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -66,14 +66,12 @@ namespace Artemis.UI.Shared.Services
|
|||||||
|
|
||||||
public void OpenMainWindow()
|
public void OpenMainWindow()
|
||||||
{
|
{
|
||||||
IsMainWindowOpen = true;
|
_mainWindowManager?.OpenMainWindow();
|
||||||
OnMainWindowOpened();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CloseMainWindow()
|
public void CloseMainWindow()
|
||||||
{
|
{
|
||||||
IsMainWindowOpen = false;
|
_mainWindowManager?.CloseMainWindow();
|
||||||
OnMainWindowClosed();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public event EventHandler? MainWindowOpened;
|
public event EventHandler? MainWindowOpened;
|
||||||
|
|||||||
@ -142,6 +142,14 @@
|
|||||||
"System.Xml.XmlDocument": "4.3.0"
|
"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": {
|
"HidSharp": {
|
||||||
"type": "Transitive",
|
"type": "Transitive",
|
||||||
"resolved": "2.1.0",
|
"resolved": "2.1.0",
|
||||||
@ -1305,11 +1313,17 @@
|
|||||||
"System.Xml.ReaderWriter": "4.3.0"
|
"System.Xml.ReaderWriter": "4.3.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"Unosquare.Swan.Lite": {
|
||||||
|
"type": "Transitive",
|
||||||
|
"resolved": "3.0.0",
|
||||||
|
"contentHash": "noPwJJl1Q9uparXy1ogtkmyAPGNfSGb0BLT1292nFH1jdMKje6o2kvvrQUvF9Xklj+IoiAI0UzF6Aqxlvo10lw=="
|
||||||
|
},
|
||||||
"artemis.core": {
|
"artemis.core": {
|
||||||
"type": "Project",
|
"type": "Project",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"Artemis.Storage": "1.0.0",
|
"Artemis.Storage": "1.0.0",
|
||||||
"Ben.Demystifier": "0.1.6",
|
"Ben.Demystifier": "0.1.6",
|
||||||
|
"EmbedIO": "3.4.3",
|
||||||
"HidSharp": "2.1.0",
|
"HidSharp": "2.1.0",
|
||||||
"Humanizer.Core": "2.8.26",
|
"Humanizer.Core": "2.8.26",
|
||||||
"LiteDB": "5.0.9",
|
"LiteDB": "5.0.9",
|
||||||
|
|||||||
@ -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">
|
<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>
|
||||||
@ -89,6 +89,7 @@ namespace Artemis.UI
|
|||||||
});
|
});
|
||||||
|
|
||||||
Kernel.Get<IRegistrationService>().RegisterInputProvider();
|
Kernel.Get<IRegistrationService>().RegisterInputProvider();
|
||||||
|
Kernel.Get<IRemoteManagementService>();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void ConfigureIoC(IKernel kernel)
|
protected override void ConfigureIoC(IKernel kernel)
|
||||||
|
|||||||
@ -4,7 +4,7 @@ using Artemis.UI.Ninject.InstanceProviders;
|
|||||||
using Artemis.UI.Screens;
|
using Artemis.UI.Screens;
|
||||||
using Artemis.UI.Screens.ProfileEditor;
|
using Artemis.UI.Screens.ProfileEditor;
|
||||||
using Artemis.UI.Screens.Splash;
|
using Artemis.UI.Screens.Splash;
|
||||||
using Artemis.UI.Services.Interfaces;
|
using Artemis.UI.Services;
|
||||||
using Artemis.UI.Shared.Services;
|
using Artemis.UI.Shared.Services;
|
||||||
using Artemis.UI.Stylet;
|
using Artemis.UI.Stylet;
|
||||||
using FluentValidation;
|
using FluentValidation;
|
||||||
|
|||||||
@ -3,13 +3,11 @@ using Artemis.Core.Modules;
|
|||||||
using Artemis.Core.Services;
|
using Artemis.Core.Services;
|
||||||
using Artemis.UI.Shared.Services;
|
using Artemis.UI.Shared.Services;
|
||||||
using ICSharpCode.AvalonEdit.Document;
|
using ICSharpCode.AvalonEdit.Document;
|
||||||
using MaterialDesignThemes.Wpf;
|
|
||||||
|
|
||||||
namespace Artemis.UI.Screens.ProfileEditor.Dialogs
|
namespace Artemis.UI.Screens.ProfileEditor.Dialogs
|
||||||
{
|
{
|
||||||
public class ProfileImportViewModel : DialogViewModelBase
|
public class ProfileImportViewModel : DialogViewModelBase
|
||||||
{
|
{
|
||||||
private readonly ISnackbarMessageQueue _mainMessageQueue;
|
|
||||||
private readonly IProfileService _profileService;
|
private readonly IProfileService _profileService;
|
||||||
private readonly IMessageService _messageService;
|
private readonly IMessageService _messageService;
|
||||||
private string _profileJson;
|
private string _profileJson;
|
||||||
|
|||||||
@ -6,7 +6,7 @@ using System.Windows.Media;
|
|||||||
using Artemis.Core;
|
using Artemis.Core;
|
||||||
using Artemis.UI.Extensions;
|
using Artemis.UI.Extensions;
|
||||||
using Artemis.UI.Screens.Shared;
|
using Artemis.UI.Screens.Shared;
|
||||||
using Artemis.UI.Services.Interfaces;
|
using Artemis.UI.Services;
|
||||||
using Artemis.UI.Shared.Services;
|
using Artemis.UI.Shared.Services;
|
||||||
|
|
||||||
namespace Artemis.UI.Screens.ProfileEditor.Visualization
|
namespace Artemis.UI.Screens.ProfileEditor.Visualization
|
||||||
|
|||||||
@ -5,7 +5,7 @@ using System.Windows.Media;
|
|||||||
using Artemis.Core;
|
using Artemis.Core;
|
||||||
using Artemis.UI.Events;
|
using Artemis.UI.Events;
|
||||||
using Artemis.UI.Screens.Shared;
|
using Artemis.UI.Screens.Shared;
|
||||||
using Artemis.UI.Services.Interfaces;
|
using Artemis.UI.Services;
|
||||||
using Artemis.UI.Shared.Services;
|
using Artemis.UI.Shared.Services;
|
||||||
using SkiaSharp;
|
using SkiaSharp;
|
||||||
using SkiaSharp.Views.WPF;
|
using SkiaSharp.Views.WPF;
|
||||||
|
|||||||
@ -14,7 +14,6 @@ using Artemis.UI.Screens.Settings.Tabs.General;
|
|||||||
using Artemis.UI.Screens.Sidebar;
|
using Artemis.UI.Screens.Sidebar;
|
||||||
using Artemis.UI.Screens.StartupWizard;
|
using Artemis.UI.Screens.StartupWizard;
|
||||||
using Artemis.UI.Services;
|
using Artemis.UI.Services;
|
||||||
using Artemis.UI.Services.Interfaces;
|
|
||||||
using Artemis.UI.Shared.Services;
|
using Artemis.UI.Shared.Services;
|
||||||
using Artemis.UI.Utilities;
|
using Artemis.UI.Utilities;
|
||||||
using MaterialDesignExtensions.Controls;
|
using MaterialDesignExtensions.Controls;
|
||||||
|
|||||||
@ -14,7 +14,6 @@ using Artemis.Core.Services;
|
|||||||
using Artemis.UI.Properties;
|
using Artemis.UI.Properties;
|
||||||
using Artemis.UI.Screens.StartupWizard;
|
using Artemis.UI.Screens.StartupWizard;
|
||||||
using Artemis.UI.Services;
|
using Artemis.UI.Services;
|
||||||
using Artemis.UI.Services.Interfaces;
|
|
||||||
using Artemis.UI.Shared;
|
using Artemis.UI.Shared;
|
||||||
using Artemis.UI.Shared.Services;
|
using Artemis.UI.Shared.Services;
|
||||||
using MaterialDesignThemes.Wpf;
|
using MaterialDesignThemes.Wpf;
|
||||||
|
|||||||
@ -9,7 +9,6 @@ using Artemis.Core.Services;
|
|||||||
using Artemis.UI.Events;
|
using Artemis.UI.Events;
|
||||||
using Artemis.UI.Screens.Splash;
|
using Artemis.UI.Screens.Splash;
|
||||||
using Artemis.UI.Services;
|
using Artemis.UI.Services;
|
||||||
using Artemis.UI.Services.Interfaces;
|
|
||||||
using Artemis.UI.Shared.Services;
|
using Artemis.UI.Shared.Services;
|
||||||
using Hardcodet.Wpf.TaskbarNotification;
|
using Hardcodet.Wpf.TaskbarNotification;
|
||||||
using MaterialDesignThemes.Wpf;
|
using MaterialDesignThemes.Wpf;
|
||||||
@ -25,7 +24,6 @@ namespace Artemis.UI.Screens
|
|||||||
private readonly IEventAggregator _eventAggregator;
|
private readonly IEventAggregator _eventAggregator;
|
||||||
private readonly IKernel _kernel;
|
private readonly IKernel _kernel;
|
||||||
private readonly IWindowManager _windowManager;
|
private readonly IWindowManager _windowManager;
|
||||||
private bool _canShowRootViewModel;
|
|
||||||
private RootViewModel _rootViewModel;
|
private RootViewModel _rootViewModel;
|
||||||
private SplashViewModel _splashViewModel;
|
private SplashViewModel _splashViewModel;
|
||||||
private TaskbarIcon _taskBarIcon;
|
private TaskbarIcon _taskBarIcon;
|
||||||
@ -44,7 +42,6 @@ namespace Artemis.UI.Screens
|
|||||||
_windowManager = windowManager;
|
_windowManager = windowManager;
|
||||||
_eventAggregator = eventAggregator;
|
_eventAggregator = eventAggregator;
|
||||||
_debugService = debugService;
|
_debugService = debugService;
|
||||||
CanShowRootViewModel = true;
|
|
||||||
|
|
||||||
Core.Utilities.ShutdownRequested += UtilitiesOnShutdownRequested;
|
Core.Utilities.ShutdownRequested += UtilitiesOnShutdownRequested;
|
||||||
Core.Utilities.RestartRequested += 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()
|
public void TrayBringToForeground()
|
||||||
{
|
{
|
||||||
if (!CanShowRootViewModel)
|
if (IsMainWindowOpen)
|
||||||
|
{
|
||||||
|
Execute.PostToUIThread(FocusMainWindow);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize the shared UI when first showing the window
|
// Initialize the shared UI when first showing the window
|
||||||
if (!UI.Shared.Bootstrapper.Initialized)
|
if (!UI.Shared.Bootstrapper.Initialized)
|
||||||
UI.Shared.Bootstrapper.Initialize(_kernel);
|
UI.Shared.Bootstrapper.Initialize(_kernel);
|
||||||
|
|
||||||
CanShowRootViewModel = false;
|
Execute.OnUIThreadSync(() =>
|
||||||
Execute.OnUIThread(() =>
|
|
||||||
{
|
{
|
||||||
_splashViewModel?.RequestClose();
|
_splashViewModel?.RequestClose();
|
||||||
_splashViewModel = null;
|
_splashViewModel = null;
|
||||||
@ -115,11 +108,13 @@ namespace Artemis.UI.Screens
|
|||||||
|
|
||||||
public void OnTrayBalloonTipClicked(object sender, EventArgs e)
|
public void OnTrayBalloonTipClicked(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (CanShowRootViewModel)
|
if (!IsMainWindowOpen)
|
||||||
{
|
|
||||||
TrayBringToForeground();
|
TrayBringToForeground();
|
||||||
}
|
|
||||||
else
|
else
|
||||||
|
FocusMainWindow();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FocusMainWindow()
|
||||||
{
|
{
|
||||||
// Wrestle the main window to the front
|
// Wrestle the main window to the front
|
||||||
Window mainWindow = (Window) _rootViewModel.View;
|
Window mainWindow = (Window) _rootViewModel.View;
|
||||||
@ -130,9 +125,8 @@ namespace Artemis.UI.Screens
|
|||||||
mainWindow.Topmost = false;
|
mainWindow.Topmost = false;
|
||||||
mainWindow.Focus();
|
mainWindow.Focus();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void UtilitiesOnShutdownRequested(object? sender, EventArgs e)
|
private void UtilitiesOnShutdownRequested(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Execute.OnUIThread(() => _taskBarIcon?.Dispose());
|
Execute.OnUIThread(() => _taskBarIcon?.Dispose());
|
||||||
}
|
}
|
||||||
@ -150,8 +144,6 @@ namespace Artemis.UI.Screens
|
|||||||
{
|
{
|
||||||
_rootViewModel.Closed -= RootViewModelOnClosed;
|
_rootViewModel.Closed -= RootViewModelOnClosed;
|
||||||
_rootViewModel = null;
|
_rootViewModel = null;
|
||||||
|
|
||||||
CanShowRootViewModel = true;
|
|
||||||
OnMainWindowClosed();
|
OnMainWindowClosed();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,16 +190,16 @@ namespace Artemis.UI.Screens
|
|||||||
|
|
||||||
public bool OpenMainWindow()
|
public bool OpenMainWindow()
|
||||||
{
|
{
|
||||||
if (CanShowRootViewModel)
|
if (IsMainWindowOpen)
|
||||||
return false;
|
Execute.OnUIThread(FocusMainWindow);
|
||||||
|
else
|
||||||
TrayBringToForeground();
|
TrayBringToForeground();
|
||||||
return true;
|
return _rootViewModel.ScreenState == ScreenState.Active;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool CloseMainWindow()
|
public bool CloseMainWindow()
|
||||||
{
|
{
|
||||||
_rootViewModel.RequestClose();
|
Execute.OnUIThread(() => _rootViewModel.RequestClose());
|
||||||
return _rootViewModel.ScreenState == ScreenState.Closed;
|
return _rootViewModel.ScreenState == ScreenState.Closed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
using System.Windows;
|
using System.Windows;
|
||||||
using Artemis.UI.Screens.Settings.Debug;
|
using Artemis.UI.Screens.Settings.Debug;
|
||||||
using Artemis.UI.Services.Interfaces;
|
|
||||||
using MaterialDesignExtensions.Controls;
|
using MaterialDesignExtensions.Controls;
|
||||||
using Ninject;
|
using Ninject;
|
||||||
using Stylet;
|
using Stylet;
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
namespace Artemis.UI.Services.Interfaces
|
namespace Artemis.UI.Services
|
||||||
{
|
{
|
||||||
// ReSharper disable once InconsistentNaming
|
// ReSharper disable once InconsistentNaming
|
||||||
public interface IArtemisUIService
|
public interface IArtemisUIService
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
namespace Artemis.UI.Services.Interfaces
|
namespace Artemis.UI.Services
|
||||||
{
|
{
|
||||||
public interface IDebugService : IArtemisUIService
|
public interface IDebugService : IArtemisUIService
|
||||||
{
|
{
|
||||||
|
|||||||
@ -3,7 +3,7 @@ using System.Windows.Media;
|
|||||||
using Artemis.Core;
|
using Artemis.Core;
|
||||||
using SkiaSharp;
|
using SkiaSharp;
|
||||||
|
|
||||||
namespace Artemis.UI.Services.Interfaces
|
namespace Artemis.UI.Services
|
||||||
{
|
{
|
||||||
public interface ILayerEditorService : IArtemisUIService
|
public interface ILayerEditorService : IArtemisUIService
|
||||||
{
|
{
|
||||||
|
|||||||
@ -2,7 +2,6 @@
|
|||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using Artemis.Core;
|
using Artemis.Core;
|
||||||
using Artemis.UI.Services.Interfaces;
|
|
||||||
using SkiaSharp;
|
using SkiaSharp;
|
||||||
using SkiaSharp.Views.WPF;
|
using SkiaSharp.Views.WPF;
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,6 @@ using Artemis.UI.DefaultTypes.DataModel.Input;
|
|||||||
using Artemis.UI.InputProviders;
|
using Artemis.UI.InputProviders;
|
||||||
using Artemis.UI.Ninject;
|
using Artemis.UI.Ninject;
|
||||||
using Artemis.UI.PropertyInput;
|
using Artemis.UI.PropertyInput;
|
||||||
using Artemis.UI.Services.Interfaces;
|
|
||||||
using Artemis.UI.Shared.Services;
|
using Artemis.UI.Shared.Services;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,6 @@
|
|||||||
|
namespace Artemis.UI.Services
|
||||||
|
{
|
||||||
|
public interface IRemoteManagementService : IArtemisUIService
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
39
src/Artemis.UI/Services/RemoteManagement/RemoteController.cs
Normal file
39
src/Artemis.UI/Services/RemoteManagement/RemoteController.cs
Normal 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.Services
|
||||||
|
{
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,12 @@
|
|||||||
|
using Artemis.Core.Services;
|
||||||
|
|
||||||
|
namespace Artemis.UI.Services
|
||||||
|
{
|
||||||
|
public class RemoteManagementService : IRemoteManagementService
|
||||||
|
{
|
||||||
|
public RemoteManagementService(IWebServerService webServerService)
|
||||||
|
{
|
||||||
|
webServerService.AddController<RemoteController>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -10,7 +10,6 @@ using Artemis.Core;
|
|||||||
using Artemis.Core.Services;
|
using Artemis.Core.Services;
|
||||||
using Artemis.UI.Exceptions;
|
using Artemis.UI.Exceptions;
|
||||||
using Artemis.UI.Screens.Settings.Dialogs;
|
using Artemis.UI.Screens.Settings.Dialogs;
|
||||||
using Artemis.UI.Services.Interfaces;
|
|
||||||
using Artemis.UI.Shared.Services;
|
using Artemis.UI.Shared.Services;
|
||||||
using MaterialDesignThemes.Wpf;
|
using MaterialDesignThemes.Wpf;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
@ -209,7 +208,7 @@ namespace Artemis.UI.Services
|
|||||||
AutoUpdate();
|
AutoUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void WindowServiceOnMainWindowOpened(object? sender, EventArgs e)
|
private void WindowServiceOnMainWindowOpened(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
_logger.Information("Main window opened!");
|
_logger.Information("Main window opened!");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -195,6 +195,14 @@
|
|||||||
"System.Xml.XmlDocument": "4.3.0"
|
"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": {
|
"HidSharp": {
|
||||||
"type": "Transitive",
|
"type": "Transitive",
|
||||||
"resolved": "2.1.0",
|
"resolved": "2.1.0",
|
||||||
@ -1357,6 +1365,11 @@
|
|||||||
"System.Xml.ReaderWriter": "4.3.0"
|
"System.Xml.ReaderWriter": "4.3.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"Unosquare.Swan.Lite": {
|
||||||
|
"type": "Transitive",
|
||||||
|
"resolved": "3.0.0",
|
||||||
|
"contentHash": "noPwJJl1Q9uparXy1ogtkmyAPGNfSGb0BLT1292nFH1jdMKje6o2kvvrQUvF9Xklj+IoiAI0UzF6Aqxlvo10lw=="
|
||||||
|
},
|
||||||
"WriteableBitmapEx": {
|
"WriteableBitmapEx": {
|
||||||
"type": "Transitive",
|
"type": "Transitive",
|
||||||
"resolved": "1.6.7",
|
"resolved": "1.6.7",
|
||||||
@ -1367,6 +1380,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"Artemis.Storage": "1.0.0",
|
"Artemis.Storage": "1.0.0",
|
||||||
"Ben.Demystifier": "0.1.6",
|
"Ben.Demystifier": "0.1.6",
|
||||||
|
"EmbedIO": "3.4.3",
|
||||||
"HidSharp": "2.1.0",
|
"HidSharp": "2.1.0",
|
||||||
"Humanizer.Core": "2.8.26",
|
"Humanizer.Core": "2.8.26",
|
||||||
"LiteDB": "5.0.9",
|
"LiteDB": "5.0.9",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user