Merge in abstractions in Desktop projects.

This commit is contained in:
Jared Goodwin 2024-07-16 11:09:13 -07:00
parent 9e055af473
commit 49e910dc98
29 changed files with 79 additions and 143 deletions

View File

@ -44,12 +44,7 @@ public class Program
services.AddSingleton<IOrganizationIdProvider, OrganizationIdProvider>();
services.AddSingleton<IEmbeddedServerDataProvider, EmbeddedServerDataProvider>();
services.AddRemoteControlLinux(
config =>
{
config.AddBrandingProvider<BrandingProvider>();
});
services.AddRemoteControlLinux();
services.AddLogging(builder =>
{

View File

@ -4,6 +4,7 @@ using Remotely.Desktop.Shared.Services;
using Remotely.Desktop.UI.Services;
using Remotely.Shared.Models;
using Microsoft.Extensions.Logging;
using Desktop.Shared.Services;
namespace Remotely.Desktop.Linux.Services;

View File

@ -17,11 +17,9 @@ public static class IServiceCollectionExtensions
/// </summary>
/// <param name="services"></param>
/// <param name="clientConfig"></param>
public static void AddRemoteControlLinux(
this IServiceCollection services,
Action<IRemoteControlClientBuilder> clientConfig)
public static void AddRemoteControlLinux(this IServiceCollection services)
{
services.AddRemoteControlXplat(clientConfig);
services.AddRemoteControlXplat();
services.AddRemoteControlUi();
services.AddSingleton<IAppStartup, AppStartup>();

View File

@ -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);
}

View File

@ -10,6 +10,13 @@ using System.Net.Http.Json;
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 class BrandingProvider : IBrandingProvider
};
}
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,22 +94,25 @@ public class BrandingProvider : IBrandingProvider
var result = _embeddedDataSearcher.TryGetEmbeddedData(filePath);
if (!result.IsSuccess)
if (result.IsSuccess)
{
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 (string.IsNullOrWhiteSpace(_appState.Host))
{
return result.HadException ?
Result.Fail<BrandingInfo>(result.Exception) :
Result.Fail<BrandingInfo>(result.Reason);
}
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 (string.IsNullOrWhiteSpace(_appState.Host))

View File

@ -5,19 +5,15 @@ using Microsoft.Extensions.DependencyInjection;
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<IRemoteControlClientBuilder> clientConfig)
this IServiceCollection services)
{
var builder = new RemoteControlClientBuilder(services);
clientConfig.Invoke(builder);
builder.Validate();
services.AddLogging(builder =>
{
builder.AddConsole().AddDebug();
@ -31,6 +27,7 @@ public static class IServiceCollectionExtensions
services.AddSingleton(s => WeakReferenceMessenger.Default);
services.AddSingleton<IDesktopEnvironment, DesktopEnvironment>();
services.AddSingleton<IDtoMessageHandler, DtoMessageHandler>();
services.AddSingleton<IBrandingProvider, BrandingProvider>();
services.AddSingleton<IAppState, AppState>();
services.AddSingleton<IViewerFactory, ViewerFactory>();
services.AddTransient<IScreenCaster, ScreenCaster>();

View File

@ -1,42 +0,0 @@
using Remotely.Desktop.Shared.Abstractions;
using Microsoft.Extensions.DependencyInjection;
namespace Remotely.Desktop.Shared.Startup;
public interface IRemoteControlClientBuilder
{
void AddBrandingProvider<T>()
where T : class, IBrandingProvider;
}
internal class RemoteControlClientBuilder : IRemoteControlClientBuilder
{
private readonly IServiceCollection _services;
public RemoteControlClientBuilder(IServiceCollection services)
{
_services = services;
}
public void AddBrandingProvider<T>()
where T : class, IBrandingProvider
{
_services.AddSingleton<IBrandingProvider, T>();
}
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}.");
}
}
}
}

View File

@ -3,6 +3,7 @@ using Remotely.Desktop.Shared.Services;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System.IO;
using Desktop.Shared.Services;
namespace Remotely.Desktop.UI.Services;

View File

@ -8,6 +8,7 @@ using Microsoft.Extensions.Logging;
using Remotely.Shared.Entities;
using System.IO;
using System.Reflection;
using Desktop.Shared.Services;
namespace Remotely.Desktop.UI.ViewModels;
@ -66,7 +67,7 @@ public class BrandedViewModelBase : ObservableObject, IBrandedViewModelBase
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);

View File

@ -8,6 +8,7 @@ using Microsoft.Extensions.Logging;
using Remotely.Desktop.Shared.Reactive;
using Microsoft.Extensions.DependencyInjection;
using Remotely.Shared.Models;
using Desktop.Shared.Services;
namespace Remotely.Desktop.UI.ViewModels;

View File

@ -7,6 +7,7 @@ using System.Windows.Input;
using Remotely.Desktop.Shared.Abstractions;
using Microsoft.Extensions.Logging;
using Remotely.Desktop.Shared.Reactive;
using Desktop.Shared.Services;
namespace Remotely.Desktop.UI.ViewModels;

View File

@ -3,6 +3,7 @@ using System.Windows.Input;
using Remotely.Desktop.Shared.Abstractions;
using Microsoft.Extensions.Logging;
using Remotely.Desktop.Shared.Reactive;
using Desktop.Shared.Services;
namespace Remotely.Desktop.UI.ViewModels;

View File

@ -135,7 +135,7 @@ public class MainViewViewModel : BrandedViewModelBase, IMainViewViewModel
return;
}
await _dispatcher.Clipboard.SetTextAsync($"{Host}/RemoteControl/Viewer?sessionId={StatusMessage.Replace(" ", "")}");
await _dispatcher.Clipboard.SetTextAsync($"{Host}/Viewer?sessionId={StatusMessage.Replace(" ", "")}");
CopyMessageOpacity = 1;
IsCopyMessageVisible = true;

View File

@ -1,5 +1,6 @@
using Remotely.Desktop.Shared.Abstractions;
using Microsoft.Extensions.Logging;
using Desktop.Shared.Services;
namespace Remotely.Desktop.UI.ViewModels;

View File

@ -4,6 +4,7 @@ using Remotely.Desktop.Shared.Reactive;
using Remotely.Desktop.Shared.Abstractions;
using Microsoft.Extensions.Logging;
using Remotely.Desktop.UI.Controls.Dialogs;
using Desktop.Shared.Services;
namespace Remotely.Desktop.UI.ViewModels;

View File

@ -3,6 +3,7 @@ using Remotely.Desktop.Shared.Abstractions;
using Remotely.Desktop.Shared.Reactive;
using Microsoft.Extensions.Logging;
using System.Windows.Input;
using Desktop.Shared.Services;
namespace Remotely.Desktop.UI.ViewModels;

View File

@ -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;

View File

@ -11,6 +11,9 @@ using Remotely.Shared.Utilities;
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 class Program
services.AddSingleton<IOrganizationIdProvider, OrganizationIdProvider>();
services.AddSingleton<IEmbeddedServerDataProvider>(EmbeddedServerDataProvider.Instance);
services.AddRemoteControlWindows(
config =>
{
config.AddBrandingProvider<BrandingProvider>();
});
services.AddRemoteControlXplat();
services.AddRemoteControlUi();
services.AddRemoteControlWindows();
services.AddLogging(builder =>
{

View File

@ -1,3 +1,4 @@
using Desktop.Shared.Services;
using Remotely.Desktop.Shared.Abstractions;
using Remotely.Desktop.Shared.Enums;
using Remotely.Desktop.Shared.Native.Windows;

View File

@ -17,11 +17,9 @@ public static class IServiceCollectionExtensions
/// <param name="services"></param>
/// <param name="clientConfig"></param>
[SupportedOSPlatform("windows")]
public static void AddRemoteControlWindows(
this IServiceCollection services,
Action<IRemoteControlClientBuilder> clientConfig)
public static void AddRemoteControlWindows(this IServiceCollection services)
{
services.AddRemoteControlXplat(clientConfig);
services.AddRemoteControlXplat();
services.AddRemoteControlUi();
services.AddSingleton<ICursorIconWatcher, CursorIconWatcherWin>();

View File

@ -173,6 +173,6 @@ public class RemoteControlController : ControllerBase
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}");
}
}

View File

@ -334,7 +334,7 @@ public partial class DeviceCard : AuthComponentBase
}
JsInterop.OpenWindow(
$"/RemoteControl/Viewer" +
$"/Viewer" +
$"?mode=Unattended&sessionId={session.UnattendedSessionId}" +
$"&accessKey={session.AccessKey}" +
$"&viewonly={viewOnly}",

View File

@ -40,7 +40,7 @@
</li>
<li class="nav-item px-3">
<NavLink class="nav-link" href="/RemoteControl/Viewer" target="_blank">
<NavLink class="nav-link" href="/Viewer" target="_blank">
<span class="oi oi-monitor" aria-hidden="true"></span> Remote Control
</NavLink>

View File

@ -8,7 +8,7 @@ public static class IApplicationBuilderExtensions
/// <summary>
/// <para>
/// Maps Razor pages and SignalR hubs. The remote control viewer page will be mapped
/// to path "/RemoteControl/Viewer", the desktop hub to "/hubs/desktop", and viewer hub
/// to path "/Viewer", the desktop hub to "/hubs/desktop", and viewer hub
/// to "/hubs/viewer".
/// </para>
/// <para>
@ -19,12 +19,7 @@ public static class IApplicationBuilderExtensions
/// <returns></returns>
public static IApplicationBuilder UseRemoteControlServer(this IApplicationBuilder app)
{
app.UseEndpoints(config =>
{
config.MapRazorPages();
config.MapHub<DesktopHub>("/hubs/desktop");
config.MapHub<ViewerHub>("/hubs/viewer");
});
return app;
}

View File

@ -37,7 +37,7 @@ public class RemoteControlSession : IDisposable
public string OrganizationId { get; set; } = string.Empty;
public string OrganizationName { get; internal set; } = string.Empty;
public string RelativeAccessUri => $"/RemoteControl/Viewer?mode=Unattended&sessionId={UnattendedSessionId}&accessKey={AccessKey}&viewonly=False";
public string RelativeAccessUri => $"/Viewer?mode=Unattended&sessionId={UnattendedSessionId}&accessKey={AccessKey}&viewonly=False";
public string RequesterName { get; set; } = string.Empty;
public string RequesterUserName { get; internal set; } = string.Empty;
/// <summary>

View File

@ -15,27 +15,27 @@
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="mobile-web-app-capable" content="yes" />
<meta name="description" content="@(Model.PageDescription)" />
<link href="/_content/Remotely.Server/manifest.json" rel="manifest" />
<link href="/manifest.json" rel="manifest" />
<link rel="icon" href="@(Model.FaviconUrl)" />
<link href="/_content/Remotely.Server/css/remote-control.css" rel="stylesheet" asp-append-version="true" />
<link href="/css/remote-control.css" rel="stylesheet" asp-append-version="true" />
@if (!string.IsNullOrWhiteSpace(Model.ThemeUrl))
{
<link href="@(Model.ThemeUrl)" rel="stylesheet" asp-append-version="true" />
}
<link href="/_content/Remotely.Server/lib/fontawesome/css/all.min.css" rel="stylesheet" />
<link href="/_content/Remotely.Server/lib/fontawesome/css/brands.min.css" rel="stylesheet" />
<link href="/lib/fontawesome/css/all.min.css" rel="stylesheet" />
<link href="/lib/fontawesome/css/brands.min.css" rel="stylesheet" />
<environment include="Development">
<script src="/_content/Remotely.Server/lib/microsoft-signalr/signalr.js"></script>
<script src="/_content/Remotely.Server/lib/microsoft/signalr-protocol-msgpack/dist/browser/signalr-protocol-msgpack.js"></script>
<script src="/_content/Remotely.Server/lib/msgpack/dist.es5+umd/msgpack.js"></script>
<script src="/lib/microsoft-signalr/signalr.js"></script>
<script src="/lib/microsoft/signalr-protocol-msgpack/dist/browser/signalr-protocol-msgpack.js"></script>
<script src="/lib/msgpack/dist.es5+umd/msgpack.js"></script>
</environment>
<environment exclude="Development">
<script src="/_content/Remotely.Server/lib/microsoft-signalr/signalr.min.js"></script>
<script src="/_content/Remotely.Server/lib/microsoft/signalr-protocol-msgpack/dist/browser/signalr-protocol-msgpack.min.js"></script>
<script src="/_content/Remotely.Server/lib/msgpack/dist.es5+umd/msgpack.min.js"></script>
<script src="/lib/microsoft-signalr/signalr.min.js"></script>
<script src="/lib/microsoft/signalr-protocol-msgpack/dist/browser/signalr-protocol-msgpack.min.js"></script>
<script src="/lib/msgpack/dist.es5+umd/msgpack.min.js"></script>
</environment>
</head>
<body>
@ -43,16 +43,6 @@
<div class="background-layer-1"></div>
<div class="background-layer-2"></div>
<div class="background-layer-3"></div>
@if (!string.IsNullOrWhiteSpace(Model.LogoUrl))
{
<div class="logo-frame">
<img src="@(Model.LogoUrl)" />
<div class="beta-pill beta-pill-logo absolute-right-middle">
BETA
</div>
</div>
}
</div>
<div id="screenSelectMenu" class="popup-menu">
@ -160,13 +150,7 @@
<div>
<div id="menuFrame">
<div class="menu-column menu-column-left">
@if (!string.IsNullOrWhiteSpace(Model.LogoUrl))
{
<img class="menu-logo" src="@(Model.LogoUrl)" />
<div id="betaPillLogo" class="beta-pill beta-pill-logo ms-1">
BETA
</div>
}
</div>
<div class="menu-column menu-column-middle">
<button id="changeScreenButton"
@ -228,9 +212,6 @@
</div>
<div class="text-center">
<div id="betaPillPullDown" class="beta-pill ms-1">
BETA
</div>
<button id="menuButton">
<i class="fas fa-chevron-down"></i>
</button>
@ -269,7 +250,7 @@
</div>
</footer>
<script src="/_content/Remotely.Server/src/App.js" type="module"></script>
<script src="/src/App.js" type="module"></script>
<script>
window.addEventListener("load", () => {
ViewerApp.Init();

View File

@ -22,9 +22,9 @@ public class ViewerModel(IDataService _dataService) : PageModel
ThemeUrl = theme switch
{
ViewerPageTheme.Dark => "/_content/Remotely.Server/css/remote-control-dark.css",
ViewerPageTheme.Light => "/_content/Remotely.Server/css/remote-control-light.css",
_ => "/_content/Remotely.Server/css/remote-control-dark.css"
ViewerPageTheme.Dark => "/css/remote-control-dark.css",
ViewerPageTheme.Light => "/css/remote-control-light.css",
_ => "/css/remote-control-dark.css"
};
UserDisplayName = await GetUserDisplayName();
LogoUrl = await GetLogoUrl();

View File

@ -24,6 +24,7 @@ using Serilog;
using System.Net;
using RatePolicyNames = Remotely.Server.RateLimiting.PolicyNames;
using Remotely.Server.Filters;
using static Org.BouncyCastle.Math.EC.ECCurve;
var builder = WebApplication.CreateBuilder(args);
var configuration = builder.Configuration;
@ -303,8 +304,10 @@ app.UseCors("TrustedOriginPolicy");
app.UseAntiforgery();
app.UseRemoteControlServer();
app.MapRazorPages();
app.MapHub<DesktopHub>("/hubs/desktop");
app.MapHub<ViewerHub>("/hubs/viewer");
app.MapHub<AgentHub>("/hubs/service");
app.MapControllers();

View File

@ -2,7 +2,7 @@
"id": "Remotely Remote Control",
"name": "Remotely Remote Control",
"short_name": "Remotely Remote Control",
"start_url": "./remotecontrol/viewer",
"start_url": "./viewer",
"display": "standalone",
"background_color": "black",
"theme_color": "white",
@ -23,15 +23,15 @@
"related_applications": [
{
"platform": "windows",
"url": "./remotecontrol/viewer"
"url": "./viewer"
},
{
"platform": "play",
"url": "./remotecontrol/viewer"
"url": "./viewer"
},
{
"platform": "itunes",
"url": "./remotecontrol/viewer"
"url": "./viewer"
}
]
}