From 8d1cd6d369e37567c718636c17322bf47df98e41 Mon Sep 17 00:00:00 2001 From: Stone_Red <56473591+Stone-Red-Code@users.noreply.github.com> Date: Wed, 17 Jun 2026 00:02:33 +0200 Subject: [PATCH] Add remote desktop start/stop commands and process with server support --- Kernel.cs | 4 +- Processes/RemoteDesktopProcess.cs | 58 ++++++++++++++++++++ Processing/ProcessManiest.cs | 3 +- UI/CLI/Commands/StartRemoteDesktopCommand.cs | 29 ++++++++++ UI/CLI/Commands/StopRemoteDesktopCommand.cs | 26 +++++++++ 5 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 Processes/RemoteDesktopProcess.cs create mode 100644 UI/CLI/Commands/StartRemoteDesktopCommand.cs create mode 100644 UI/CLI/Commands/StopRemoteDesktopCommand.cs diff --git a/Kernel.cs b/Kernel.cs index 55a07bb..e544ac7 100644 --- a/Kernel.cs +++ b/Kernel.cs @@ -28,7 +28,9 @@ public class Kernel : Sys.Kernel new StartGuiCommand(), new StopGuiCommand(), new ViewProcessLogs(), - new YesNtCommand() + new YesNtCommand(), + new StartRemoteDesktopCommand(), + new StopRemoteDesktopCommand() ]); Sys.Graphics.Canvas canvas = Sys.Graphics.FullScreenCanvas.GetFullScreenCanvas(); diff --git a/Processes/RemoteDesktopProcess.cs b/Processes/RemoteDesktopProcess.cs new file mode 100644 index 0000000..b646958 --- /dev/null +++ b/Processes/RemoteDesktopProcess.cs @@ -0,0 +1,58 @@ +using RemSox.Networking; +using RemSox.Processing; +using RemSox.UI.GUI.Rendering; +using RemSox.UI.GUI.Windows; + +namespace RemSox.Processes; + +internal sealed class RemoteDesktopProcess() : Process("Remote Desktop Server") +{ + private TcpRpcServer? server; + private NetworkRenderSource? networkSource; + private CancellationTokenSource? cts; + + public int Port { get; private set; } + + internal override void Start(string[] args) + { + if (args.Length == 0 || !int.TryParse(args[0], out int port) || port <= 0 || port > 65535) + { + Logger.Log("Invalid port. Usage: rdp-start (1-65535)", Logging.LogSeverity.Error); + RequestStop(); + return; + } + + Port = port; + cts = new CancellationTokenSource(); + server = new TcpRpcServer(); + networkSource = new NetworkRenderSource(server); + + server.ListenTo("SyncRequest", async _ => + { + WindowManager.InvalidateAll(); + }); + + _ = Task.Run(() => server.StartAsync(port, cts.Token)); + + WindowManager.AddRenderSource(networkSource); + + Logger.Log($"Remote desktop server started on port {port}.", Logging.LogSeverity.Info); + } + + internal override void Tick() + { + } + + internal override void Stop() + { + cts?.Cancel(); + server?.Stop(); + + if (networkSource is not null) + { + WindowManager.RemoveRenderSource(networkSource); + } + + Logger.Log("Remote desktop server stopped.", Logging.LogSeverity.Info); + } +} diff --git a/Processing/ProcessManiest.cs b/Processing/ProcessManiest.cs index 9433893..2f72195 100644 --- a/Processing/ProcessManiest.cs +++ b/Processing/ProcessManiest.cs @@ -15,7 +15,8 @@ public static class ProcessManifest private static readonly Dictionary map = new() { { typeof(DesktopProcess), ProcessManifestFlags.Singleton | ProcessManifestFlags.System }, - { typeof(CliProcess), ProcessManifestFlags.Singleton | ProcessManifestFlags.System } + { typeof(CliProcess), ProcessManifestFlags.Singleton | ProcessManifestFlags.System }, + { typeof(RemoteDesktopProcess), ProcessManifestFlags.Singleton } }; public static bool HasFlag(ProcessManifestFlags flag) where T : Process diff --git a/UI/CLI/Commands/StartRemoteDesktopCommand.cs b/UI/CLI/Commands/StartRemoteDesktopCommand.cs new file mode 100644 index 0000000..297633b --- /dev/null +++ b/UI/CLI/Commands/StartRemoteDesktopCommand.cs @@ -0,0 +1,29 @@ +using RemSox.Processes; +using RemSox.Processing; + +namespace RemSox.UI.CLI.Commands; + +public class StartRemoteDesktopCommand : ICommand +{ + public string Name => "rdp-start"; + public string Description => "Starts the remote desktop server on the specified port (rdp-start )"; + + public Task ExecuteAsync(string? arguments, Action printLine) + { + if (string.IsNullOrWhiteSpace(arguments) || !int.TryParse(arguments.Trim(), out int port) || port <= 0 || port > 65535) + { + printLine("Usage: rdp-start (1-65535)"); + return Task.CompletedTask; + } + + if (ProcessManager.IsProcessRunning()) + { + printLine("Remote desktop server is already running."); + return Task.CompletedTask; + } + + _ = ProcessManager.SpawnProcess([port.ToString()]); + printLine($"Remote desktop server started on port {port}."); + return Task.CompletedTask; + } +} diff --git a/UI/CLI/Commands/StopRemoteDesktopCommand.cs b/UI/CLI/Commands/StopRemoteDesktopCommand.cs new file mode 100644 index 0000000..f0afb40 --- /dev/null +++ b/UI/CLI/Commands/StopRemoteDesktopCommand.cs @@ -0,0 +1,26 @@ +using RemSox.Processes; +using RemSox.Processing; + +namespace RemSox.UI.CLI.Commands; + +public class StopRemoteDesktopCommand : ICommand +{ + public string Name => "rdp-stop"; + public string Description => "Stops the remote desktop server"; + + public async Task ExecuteAsync(string? arguments, Action printLine) + { + if (!ProcessManager.IsProcessRunning()) + { + printLine("Remote desktop server is not running."); + return; + } + + foreach (RemoteDesktopProcess process in ProcessManager.GetProcessesOfType()) + { + await ProcessManager.StopProcessAndWaitAsync(process.Id); + } + + printLine("Remote desktop server stopped."); + } +}