From 49e910dc98a9ac698b158d599ad9150a57f975b3 Mon Sep 17 00:00:00 2001 From: Jared Goodwin Date: Tue, 16 Jul 2024 11:09:13 -0700 Subject: [PATCH] Merge in abstractions in Desktop projects. --- Desktop.Linux/Program.cs | 7 +-- Desktop.Linux/Services/AppStartup.cs | 1 + .../Startup/IServiceCollectionExtensions.cs | 6 +-- .../Abstractions/IBrandingProvider.cs | 11 ----- Desktop.Shared/Services/BrandingProvider.cs | 36 ++++++++++------ .../Startup/IServiceCollectionExtensions.cs | 9 ++-- .../Startup/RemoteControlClientBuilder.cs | 42 ------------------ Desktop.UI/Services/ViewModelFactory.cs | 1 + Desktop.UI/ViewModels/BrandedViewModelBase.cs | 3 +- Desktop.UI/ViewModels/ChatWindowViewModel.cs | 1 + .../ViewModels/FileTransferWindowViewModel.cs | 1 + .../ViewModels/HostNamePromptViewModel.cs | 1 + Desktop.UI/ViewModels/MainViewViewModel.cs | 2 +- Desktop.UI/ViewModels/MainWindowViewModel.cs | 1 + Desktop.UI/ViewModels/MessageBoxViewModel.cs | 1 + .../PromptForAccessWindowViewModel.cs | 1 + .../SessionIndicatorWindowViewModel.cs | 1 + Desktop.Win/Program.cs | 11 ++--- Desktop.Win/Services/AppStartup.cs | 1 + .../Startup/IServiceCollectionExtensions.cs | 6 +-- Server/API/RemoteControlController.cs | 2 +- Server/Components/Devices/DeviceCard.razor.cs | 2 +- Server/Components/Layout/NavMenu.razor | 2 +- .../IApplicationBuilderExtensions.cs | 9 +--- Server/Models/RemoteControlSession.cs | 2 +- Server/Pages/Viewer.cshtml | 43 ++++++------------- Server/Pages/Viewer.cshtml.cs | 6 +-- Server/Program.cs | 5 ++- Server/wwwroot/manifest-rc.json | 8 ++-- 29 files changed, 79 insertions(+), 143 deletions(-) delete mode 100644 Desktop.Shared/Abstractions/IBrandingProvider.cs delete mode 100644 Desktop.Shared/Startup/RemoteControlClientBuilder.cs diff --git a/Desktop.Linux/Program.cs b/Desktop.Linux/Program.cs index 11d859089..ee0c02872 100644 --- a/Desktop.Linux/Program.cs +++ b/Desktop.Linux/Program.cs @@ -44,12 +44,7 @@ public static async Task Main(string[] args) services.AddSingleton(); services.AddSingleton(); - - services.AddRemoteControlLinux( - config => - { - config.AddBrandingProvider(); - }); + services.AddRemoteControlLinux(); services.AddLogging(builder => { diff --git a/Desktop.Linux/Services/AppStartup.cs b/Desktop.Linux/Services/AppStartup.cs index fd9e5ff2b..5695f9f51 100644 --- a/Desktop.Linux/Services/AppStartup.cs +++ b/Desktop.Linux/Services/AppStartup.cs @@ -4,6 +4,7 @@ using Remotely.Desktop.UI.Services; using Remotely.Shared.Models; using Microsoft.Extensions.Logging; +using Desktop.Shared.Services; namespace Remotely.Desktop.Linux.Services; diff --git a/Desktop.Linux/Startup/IServiceCollectionExtensions.cs b/Desktop.Linux/Startup/IServiceCollectionExtensions.cs index b3c29440c..da9d6fe08 100644 --- a/Desktop.Linux/Startup/IServiceCollectionExtensions.cs +++ b/Desktop.Linux/Startup/IServiceCollectionExtensions.cs @@ -17,11 +17,9 @@ public static class IServiceCollectionExtensions /// /// /// - public static void AddRemoteControlLinux( - this IServiceCollection services, - Action clientConfig) + public static void AddRemoteControlLinux(this IServiceCollection services) { - services.AddRemoteControlXplat(clientConfig); + services.AddRemoteControlXplat(); services.AddRemoteControlUi(); services.AddSingleton(); diff --git a/Desktop.Shared/Abstractions/IBrandingProvider.cs b/Desktop.Shared/Abstractions/IBrandingProvider.cs deleted file mode 100644 index 9ee292eb6..000000000 --- a/Desktop.Shared/Abstractions/IBrandingProvider.cs +++ /dev/null @@ -1,11 +0,0 @@ -using Remotely.Shared.Models; -using Remotely.Shared.Entities; - -namespace Remotely.Desktop.Shared.Abstractions; - -public interface IBrandingProvider -{ - BrandingInfo CurrentBranding { get; } - Task Initialize(); - void SetBrandingInfo(BrandingInfo brandingInfo); -} diff --git a/Desktop.Shared/Services/BrandingProvider.cs b/Desktop.Shared/Services/BrandingProvider.cs index 4be90692c..305b4c829 100644 --- a/Desktop.Shared/Services/BrandingProvider.cs +++ b/Desktop.Shared/Services/BrandingProvider.cs @@ -10,6 +10,13 @@ namespace Desktop.Shared.Services; +public interface IBrandingProvider +{ + BrandingInfo CurrentBranding { get; } + Task Initialize(); + void SetBrandingInfo(BrandingInfo brandingInfo); +} + public class BrandingProvider : IBrandingProvider { private readonly IAppState _appState; @@ -56,9 +63,9 @@ public async Task Initialize() }; } - if (_brandingInfo.Icon?.Any() != true) + if (_brandingInfo.Icon is not { Length: > 0 }) { - using var mrs = typeof(BrandingProvider).Assembly.GetManifestResourceStream("Desktop.Shared.Assets.Remotely_Icon.png"); + using var mrs = typeof(BrandingProvider).Assembly.GetManifestResourceStream("Remotely.Desktop.Shared.Assets.Remotely_Icon.png"); using var ms = new MemoryStream(); mrs!.CopyTo(ms); @@ -87,21 +94,24 @@ private async Task> TryGetBrandingInfo() var result = _embeddedDataSearcher.TryGetEmbeddedData(filePath); - if (!result.IsSuccess) - { - return result.HadException ? - Result.Fail(result.Exception) : - Result.Fail(result.Reason); - } - - if (!string.IsNullOrWhiteSpace(result.Value.OrganizationId)) + if (result.IsSuccess) { - _orgIdProvider.OrganizationId = result.Value.OrganizationId; + if (!string.IsNullOrWhiteSpace(result.Value.OrganizationId)) + { + _orgIdProvider.OrganizationId = result.Value.OrganizationId; + } + + if (result.Value.ServerUrl is not null) + { + _appState.Host = result.Value.ServerUrl.AbsoluteUri; + } } - if (result.Value.ServerUrl is not null) + if (string.IsNullOrWhiteSpace(_appState.Host)) { - _appState.Host = result.Value.ServerUrl.AbsoluteUri; + return result.HadException ? + Result.Fail(result.Exception) : + Result.Fail(result.Reason); } } diff --git a/Desktop.Shared/Startup/IServiceCollectionExtensions.cs b/Desktop.Shared/Startup/IServiceCollectionExtensions.cs index 648e294be..7d5f1fe81 100644 --- a/Desktop.Shared/Startup/IServiceCollectionExtensions.cs +++ b/Desktop.Shared/Startup/IServiceCollectionExtensions.cs @@ -5,19 +5,15 @@ using Microsoft.Extensions.Logging; using Bitbound.SimpleMessenger; using Desktop.Shared.Services; +using Remotely.Desktop.Shared.Abstractions; namespace Remotely.Desktop.Shared.Startup; public static class IServiceCollectionExtensions { internal static void AddRemoteControlXplat( - this IServiceCollection services, - Action clientConfig) + this IServiceCollection services) { - var builder = new RemoteControlClientBuilder(services); - clientConfig.Invoke(builder); - builder.Validate(); - services.AddLogging(builder => { builder.AddConsole().AddDebug(); @@ -31,6 +27,7 @@ internal static void AddRemoteControlXplat( services.AddSingleton(s => WeakReferenceMessenger.Default); services.AddSingleton(); services.AddSingleton(); + services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddTransient(); diff --git a/Desktop.Shared/Startup/RemoteControlClientBuilder.cs b/Desktop.Shared/Startup/RemoteControlClientBuilder.cs deleted file mode 100644 index 364be89e0..000000000 --- a/Desktop.Shared/Startup/RemoteControlClientBuilder.cs +++ /dev/null @@ -1,42 +0,0 @@ -using Remotely.Desktop.Shared.Abstractions; -using Microsoft.Extensions.DependencyInjection; - -namespace Remotely.Desktop.Shared.Startup; - -public interface IRemoteControlClientBuilder -{ - void AddBrandingProvider() - where T : class, IBrandingProvider; -} - -internal class RemoteControlClientBuilder : IRemoteControlClientBuilder -{ - private readonly IServiceCollection _services; - - public RemoteControlClientBuilder(IServiceCollection services) - { - _services = services; - } - - public void AddBrandingProvider() - where T : class, IBrandingProvider - { - _services.AddSingleton(); - } - - internal void Validate() - { - var serviceTypes = new[] - { - typeof(IBrandingProvider) - }; - - foreach (var type in serviceTypes) - { - if (!_services.Any(x => x.ServiceType == type)) - { - throw new Exception($"Missing service registration for type {type.Name}."); - } - } - } -} diff --git a/Desktop.UI/Services/ViewModelFactory.cs b/Desktop.UI/Services/ViewModelFactory.cs index e6b1b3b81..be9157613 100644 --- a/Desktop.UI/Services/ViewModelFactory.cs +++ b/Desktop.UI/Services/ViewModelFactory.cs @@ -3,6 +3,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using System.IO; +using Desktop.Shared.Services; namespace Remotely.Desktop.UI.Services; diff --git a/Desktop.UI/ViewModels/BrandedViewModelBase.cs b/Desktop.UI/ViewModels/BrandedViewModelBase.cs index 7c11f828d..927d4f882 100644 --- a/Desktop.UI/ViewModels/BrandedViewModelBase.cs +++ b/Desktop.UI/ViewModels/BrandedViewModelBase.cs @@ -8,6 +8,7 @@ using Remotely.Shared.Entities; using System.IO; using System.Reflection; +using Desktop.Shared.Services; namespace Remotely.Desktop.UI.ViewModels; @@ -66,7 +67,7 @@ private void ApplyBrandingImpl() ProductName = _brandingInfo.Product; - if (_brandingInfo.Icon?.Any() == true) + if (_brandingInfo.Icon is { Length: > 0 }) { using var imageStream = new MemoryStream(_brandingInfo.Icon); Icon = new Bitmap(imageStream); diff --git a/Desktop.UI/ViewModels/ChatWindowViewModel.cs b/Desktop.UI/ViewModels/ChatWindowViewModel.cs index ee17c6222..04cdf4cba 100644 --- a/Desktop.UI/ViewModels/ChatWindowViewModel.cs +++ b/Desktop.UI/ViewModels/ChatWindowViewModel.cs @@ -8,6 +8,7 @@ using Remotely.Desktop.Shared.Reactive; using Microsoft.Extensions.DependencyInjection; using Remotely.Shared.Models; +using Desktop.Shared.Services; namespace Remotely.Desktop.UI.ViewModels; diff --git a/Desktop.UI/ViewModels/FileTransferWindowViewModel.cs b/Desktop.UI/ViewModels/FileTransferWindowViewModel.cs index 56a6ff575..98b1a4556 100644 --- a/Desktop.UI/ViewModels/FileTransferWindowViewModel.cs +++ b/Desktop.UI/ViewModels/FileTransferWindowViewModel.cs @@ -7,6 +7,7 @@ using Remotely.Desktop.Shared.Abstractions; using Microsoft.Extensions.Logging; using Remotely.Desktop.Shared.Reactive; +using Desktop.Shared.Services; namespace Remotely.Desktop.UI.ViewModels; diff --git a/Desktop.UI/ViewModels/HostNamePromptViewModel.cs b/Desktop.UI/ViewModels/HostNamePromptViewModel.cs index 6685deda4..eefdeab96 100644 --- a/Desktop.UI/ViewModels/HostNamePromptViewModel.cs +++ b/Desktop.UI/ViewModels/HostNamePromptViewModel.cs @@ -3,6 +3,7 @@ using Remotely.Desktop.Shared.Abstractions; using Microsoft.Extensions.Logging; using Remotely.Desktop.Shared.Reactive; +using Desktop.Shared.Services; namespace Remotely.Desktop.UI.ViewModels; diff --git a/Desktop.UI/ViewModels/MainViewViewModel.cs b/Desktop.UI/ViewModels/MainViewViewModel.cs index 7f0862921..4e2cbf866 100644 --- a/Desktop.UI/ViewModels/MainViewViewModel.cs +++ b/Desktop.UI/ViewModels/MainViewViewModel.cs @@ -135,7 +135,7 @@ public async Task CopyLink() return; } - await _dispatcher.Clipboard.SetTextAsync($"{Host}/RemoteControl/Viewer?sessionId={StatusMessage.Replace(" ", "")}"); + await _dispatcher.Clipboard.SetTextAsync($"{Host}/Viewer?sessionId={StatusMessage.Replace(" ", "")}"); CopyMessageOpacity = 1; IsCopyMessageVisible = true; diff --git a/Desktop.UI/ViewModels/MainWindowViewModel.cs b/Desktop.UI/ViewModels/MainWindowViewModel.cs index fbf6bb5c4..34d69dee1 100644 --- a/Desktop.UI/ViewModels/MainWindowViewModel.cs +++ b/Desktop.UI/ViewModels/MainWindowViewModel.cs @@ -1,5 +1,6 @@ using Remotely.Desktop.Shared.Abstractions; using Microsoft.Extensions.Logging; +using Desktop.Shared.Services; namespace Remotely.Desktop.UI.ViewModels; diff --git a/Desktop.UI/ViewModels/MessageBoxViewModel.cs b/Desktop.UI/ViewModels/MessageBoxViewModel.cs index e14e78d5a..ad07f06fc 100644 --- a/Desktop.UI/ViewModels/MessageBoxViewModel.cs +++ b/Desktop.UI/ViewModels/MessageBoxViewModel.cs @@ -4,6 +4,7 @@ using Remotely.Desktop.Shared.Abstractions; using Microsoft.Extensions.Logging; using Remotely.Desktop.UI.Controls.Dialogs; +using Desktop.Shared.Services; namespace Remotely.Desktop.UI.ViewModels; diff --git a/Desktop.UI/ViewModels/PromptForAccessWindowViewModel.cs b/Desktop.UI/ViewModels/PromptForAccessWindowViewModel.cs index 65cf892a0..fa70d37ac 100644 --- a/Desktop.UI/ViewModels/PromptForAccessWindowViewModel.cs +++ b/Desktop.UI/ViewModels/PromptForAccessWindowViewModel.cs @@ -3,6 +3,7 @@ using Remotely.Desktop.Shared.Reactive; using Microsoft.Extensions.Logging; using System.Windows.Input; +using Desktop.Shared.Services; namespace Remotely.Desktop.UI.ViewModels; diff --git a/Desktop.UI/ViewModels/SessionIndicatorWindowViewModel.cs b/Desktop.UI/ViewModels/SessionIndicatorWindowViewModel.cs index 364d97f75..6ac785ef4 100644 --- a/Desktop.UI/ViewModels/SessionIndicatorWindowViewModel.cs +++ b/Desktop.UI/ViewModels/SessionIndicatorWindowViewModel.cs @@ -2,6 +2,7 @@ using Remotely.Desktop.Shared.Abstractions; using Remotely.Desktop.UI.Controls.Dialogs; using Microsoft.Extensions.Logging; +using Desktop.Shared.Services; namespace Remotely.Desktop.UI.ViewModels; diff --git a/Desktop.Win/Program.cs b/Desktop.Win/Program.cs index b8fd9efeb..13f48a2e4 100644 --- a/Desktop.Win/Program.cs +++ b/Desktop.Win/Program.cs @@ -11,6 +11,9 @@ using System.Diagnostics; using System.Runtime.Versioning; using System.Threading; +using Remotely.Desktop.Shared.Abstractions; +using Remotely.Desktop.UI.Startup; +using Remotely.Desktop.Win.Services; namespace Remotely.Desktop.Win; @@ -45,11 +48,9 @@ public static async Task Main(string[] args) services.AddSingleton(); services.AddSingleton(EmbeddedServerDataProvider.Instance); - services.AddRemoteControlWindows( - config => - { - config.AddBrandingProvider(); - }); + services.AddRemoteControlXplat(); + services.AddRemoteControlUi(); + services.AddRemoteControlWindows(); services.AddLogging(builder => { diff --git a/Desktop.Win/Services/AppStartup.cs b/Desktop.Win/Services/AppStartup.cs index c5d167771..42160ee02 100644 --- a/Desktop.Win/Services/AppStartup.cs +++ b/Desktop.Win/Services/AppStartup.cs @@ -1,3 +1,4 @@ +using Desktop.Shared.Services; using Remotely.Desktop.Shared.Abstractions; using Remotely.Desktop.Shared.Enums; using Remotely.Desktop.Shared.Native.Windows; diff --git a/Desktop.Win/Startup/IServiceCollectionExtensions.cs b/Desktop.Win/Startup/IServiceCollectionExtensions.cs index dbbf4f8cd..15440e8b8 100644 --- a/Desktop.Win/Startup/IServiceCollectionExtensions.cs +++ b/Desktop.Win/Startup/IServiceCollectionExtensions.cs @@ -17,11 +17,9 @@ public static class IServiceCollectionExtensions /// /// [SupportedOSPlatform("windows")] - public static void AddRemoteControlWindows( - this IServiceCollection services, - Action clientConfig) + public static void AddRemoteControlWindows(this IServiceCollection services) { - services.AddRemoteControlXplat(clientConfig); + services.AddRemoteControlXplat(); services.AddRemoteControlUi(); services.AddSingleton(); diff --git a/Server/API/RemoteControlController.cs b/Server/API/RemoteControlController.cs index 85e3b7959..15c58953b 100644 --- a/Server/API/RemoteControlController.cs +++ b/Server/API/RemoteControlController.cs @@ -173,6 +173,6 @@ await _agentHub.Clients.Client(serviceConnectionId).RemoteControl( var otp = _otpProvider.GetOtp(targetDevice.ID); - return Ok($"{HttpContext.Request.Scheme}://{Request.Host}/RemoteControl/Viewer?mode=Unattended&sessionId={sessionId}&accessKey={accessKey}&otp={otp}"); + return Ok($"{HttpContext.Request.Scheme}://{Request.Host}/Viewer?mode=Unattended&sessionId={sessionId}&accessKey={accessKey}&otp={otp}"); } } diff --git a/Server/Components/Devices/DeviceCard.razor.cs b/Server/Components/Devices/DeviceCard.razor.cs index fed232ac8..ccd14236c 100644 --- a/Server/Components/Devices/DeviceCard.razor.cs +++ b/Server/Components/Devices/DeviceCard.razor.cs @@ -334,7 +334,7 @@ private async Task StartRemoteControl(bool viewOnly) } JsInterop.OpenWindow( - $"/RemoteControl/Viewer" + + $"/Viewer" + $"?mode=Unattended&sessionId={session.UnattendedSessionId}" + $"&accessKey={session.AccessKey}" + $"&viewonly={viewOnly}", diff --git a/Server/Components/Layout/NavMenu.razor b/Server/Components/Layout/NavMenu.razor index 585ab1352..10c1e3286 100644 --- a/Server/Components/Layout/NavMenu.razor +++ b/Server/Components/Layout/NavMenu.razor @@ -40,7 +40,7 @@