Skip to content

Commit

Permalink
Merge in abstractions in Desktop projects.
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbound committed Jul 16, 2024
1 parent 9e055af commit 49e910d
Show file tree
Hide file tree
Showing 29 changed files with 79 additions and 143 deletions.
7 changes: 1 addition & 6 deletions Desktop.Linux/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,7 @@ public static async Task Main(string[] args)

services.AddSingleton<IOrganizationIdProvider, OrganizationIdProvider>();
services.AddSingleton<IEmbeddedServerDataProvider, EmbeddedServerDataProvider>();

services.AddRemoteControlLinux(
config =>
{
config.AddBrandingProvider<BrandingProvider>();
});
services.AddRemoteControlLinux();

services.AddLogging(builder =>
{
Expand Down
1 change: 1 addition & 0 deletions Desktop.Linux/Services/AppStartup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 2 additions & 4 deletions Desktop.Linux/Startup/IServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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>();
Expand Down
11 changes: 0 additions & 11 deletions Desktop.Shared/Abstractions/IBrandingProvider.cs

This file was deleted.

36 changes: 23 additions & 13 deletions Desktop.Shared/Services/BrandingProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -87,21 +94,24 @@ private async Task<Result<BrandingInfo>> TryGetBrandingInfo()

var result = _embeddedDataSearcher.TryGetEmbeddedData(filePath);

if (!result.IsSuccess)
{
return result.HadException ?
Result.Fail<BrandingInfo>(result.Exception) :
Result.Fail<BrandingInfo>(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<BrandingInfo>(result.Exception) :
Result.Fail<BrandingInfo>(result.Reason);
}
}

Expand Down
9 changes: 3 additions & 6 deletions Desktop.Shared/Startup/IServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IRemoteControlClientBuilder> clientConfig)
this IServiceCollection services)
{
var builder = new RemoteControlClientBuilder(services);
clientConfig.Invoke(builder);
builder.Validate();

services.AddLogging(builder =>
{
builder.AddConsole().AddDebug();
Expand All @@ -31,6 +27,7 @@ internal static void AddRemoteControlXplat(
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>();
Expand Down
42 changes: 0 additions & 42 deletions Desktop.Shared/Startup/RemoteControlClientBuilder.cs

This file was deleted.

1 change: 1 addition & 0 deletions Desktop.UI/Services/ViewModelFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System.IO;
using Desktop.Shared.Services;

namespace Remotely.Desktop.UI.Services;

Expand Down
3 changes: 2 additions & 1 deletion Desktop.UI/ViewModels/BrandedViewModelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Remotely.Shared.Entities;
using System.IO;
using System.Reflection;
using Desktop.Shared.Services;

namespace Remotely.Desktop.UI.ViewModels;

Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions Desktop.UI/ViewModels/ChatWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions Desktop.UI/ViewModels/FileTransferWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions Desktop.UI/ViewModels/HostNamePromptViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion Desktop.UI/ViewModels/MainViewViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions Desktop.UI/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Remotely.Desktop.Shared.Abstractions;
using Microsoft.Extensions.Logging;
using Desktop.Shared.Services;

namespace Remotely.Desktop.UI.ViewModels;

Expand Down
1 change: 1 addition & 0 deletions Desktop.UI/ViewModels/MessageBoxViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions Desktop.UI/ViewModels/PromptForAccessWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions Desktop.UI/ViewModels/SessionIndicatorWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
11 changes: 6 additions & 5 deletions Desktop.Win/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -45,11 +48,9 @@ public static async Task Main(string[] args)
services.AddSingleton<IOrganizationIdProvider, OrganizationIdProvider>();
services.AddSingleton<IEmbeddedServerDataProvider>(EmbeddedServerDataProvider.Instance);

services.AddRemoteControlWindows(
config =>
{
config.AddBrandingProvider<BrandingProvider>();
});
services.AddRemoteControlXplat();
services.AddRemoteControlUi();
services.AddRemoteControlWindows();

services.AddLogging(builder =>
{
Expand Down
1 change: 1 addition & 0 deletions Desktop.Win/Services/AppStartup.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Desktop.Shared.Services;
using Remotely.Desktop.Shared.Abstractions;
using Remotely.Desktop.Shared.Enums;
using Remotely.Desktop.Shared.Native.Windows;
Expand Down
6 changes: 2 additions & 4 deletions Desktop.Win/Startup/IServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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>();
Expand Down
2 changes: 1 addition & 1 deletion Server/API/RemoteControlController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
}
}
2 changes: 1 addition & 1 deletion Server/Components/Devices/DeviceCard.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand Down
2 changes: 1 addition & 1 deletion Server/Components/Layout/NavMenu.razor
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
9 changes: 2 additions & 7 deletions Server/Extensions/IApplicationBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion Server/Models/RemoteControlSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public RemoteControlSession()

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>
Expand Down
Loading

0 comments on commit 49e910d

Please sign in to comment.