Skip to content

Commit

Permalink
Merge pull request #647 from immense/jaredg-viewer-design-update
Browse files Browse the repository at this point in the history
Implement design updates on Viewer page.
  • Loading branch information
bitbound authored May 22, 2023
2 parents 68dfc56 + 9f10d68 commit 6297175
Show file tree
Hide file tree
Showing 36 changed files with 177 additions and 554 deletions.
13 changes: 12 additions & 1 deletion Agent/Services/CpuUtilizationSampler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public interface ICpuUtilizationSampler : IHostedService

internal class CpuUtilizationSampler : BackgroundService, ICpuUtilizationSampler
{
private readonly HashSet<int> _ignoredProcesses = new();
private readonly ILogger<CpuUtilizationSampler> _logger;
private double _currentUtilization;

Expand Down Expand Up @@ -47,7 +48,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
}
}

private static async Task<double> GetCpuUtilization(CancellationToken cancelToken)
private async Task<double> GetCpuUtilization(CancellationToken cancelToken)
{
double totalUtilization = 0;
var utilizations = new Dictionary<int, Tuple<DateTimeOffset, TimeSpan>>();
Expand All @@ -60,14 +61,24 @@ private static async Task<double> GetCpuUtilization(CancellationToken cancelToke
return 0;
}


try
{
// Processes in other sessions (e.g. session 0) will be inaccessible
// when debugging in a non-privileged process. This prevents errors
// from clogging up the output window.
if (_ignoredProcesses.Contains(proc.Id))
{
continue;
}

var startTime = DateTimeOffset.Now;
var startCpuUsage = proc.TotalProcessorTime;
utilizations.Add(proc.Id, new Tuple<DateTimeOffset, TimeSpan>(startTime, startCpuUsage));
}
catch
{
_ignoredProcesses.Add(proc.Id);
continue;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Desktop.Linux/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"profiles": {
"Desktop.Linux": {
"commandName": "Project",
"commandLineArgs": "-m Attended -s some-session-id -a vERyLonGAndCOMpleXKeY -o Immense -r Han"
"commandLineArgs": "-m Attended -h https://localhost:5001"
}
}
}
2 changes: 1 addition & 1 deletion Desktop.Win/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"profiles": {
"Desktop.Win": {
"commandName": "Project",
"commandLineArgs": "-m Attended -s some-session-id -a vERyLonGAndCOMpleXKeY -o Immense -r Han"
"commandLineArgs": "-m Attended -h https://localhost:5001"
}
}
}
5 changes: 4 additions & 1 deletion Remotely.sln
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Immense.RemoteControl.Share
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Immense.RemoteControl.Desktop", "submodules\Immense.RemoteControl\Immense.RemoteControl.Desktop\Immense.RemoteControl.Desktop.csproj", "{034984DC-4B47-42E9-8648-F258C40C7926}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Immense.RemoteControl.Desktop.Native", "submodules\Immense.RemoteControl\Immense.RemoteControl.Desktop.Native\Immense.RemoteControl.Desktop.Native.csproj", "{7A8378BC-8169-4A33-93C6-47C699C5E74D}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Immense.RemoteControl.Desktop.Native", "submodules\Immense.RemoteControl\Immense.RemoteControl.Desktop.Native\Immense.RemoteControl.Desktop.Native.csproj", "{7A8378BC-8169-4A33-93C6-47C699C5E74D}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{E4D83C37-8B98-44FB-898B-9AA1BB223C66}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -305,6 +307,7 @@ Global
{FEF0D431-EB2F-4C08-A125-8DF59AFDA525} = {48C738FB-359E-43DB-B338-FD7CB1CCF6A8}
{034984DC-4B47-42E9-8648-F258C40C7926} = {48C738FB-359E-43DB-B338-FD7CB1CCF6A8}
{7A8378BC-8169-4A33-93C6-47C699C5E74D} = {48C738FB-359E-43DB-B338-FD7CB1CCF6A8}
{E4D83C37-8B98-44FB-898B-9AA1BB223C66} = {48C738FB-359E-43DB-B338-FD7CB1CCF6A8}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {EAE10B28-119B-437C-9E68-06F0EE3F968A}
Expand Down
11 changes: 11 additions & 0 deletions Remotely.sln.startup.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@
"ProfileName": "Agent"
}
}
},
"Server+Desktop": {
"Projects": {
"Server\\Server.csproj": {
"ProfileName": "Server"
},
"Desktop.Win": {
"ProfileName": "Desktop.Win"
}
}
}

}
}
2 changes: 1 addition & 1 deletion Server/API/AgentUpdateController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class AgentUpdateController : ControllerBase
private readonly IServiceHubSessionCache _serviceSessionCache;

public AgentUpdateController(IWebHostEnvironment hostingEnv,
IDataService dataService,
IDataService dataService,
IApplicationConfig appConfig,
IServiceHubSessionCache serviceSessionCache,
IHubContext<AgentHub> agentHubContext)
Expand Down
2 changes: 1 addition & 1 deletion Server/Data/AppDb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class AppDb : IdentityDbContext
protected override void OnConfiguring(DbContextOptionsBuilder options)
{
options.ConfigureWarnings(x => x.Ignore(RelationalEventId.MultipleCollectionIncludeWarning));
options.LogTo((message) => System.Diagnostics.Debug.Write(message));
//options.LogTo((message) => System.Diagnostics.Debug.Write(message));
}

protected override void OnModelCreating(ModelBuilder builder)
Expand Down
1 change: 1 addition & 0 deletions Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@
services.AddSignalR(options =>
{
options.EnableDetailedErrors = builder.Environment.IsDevelopment();
options.MaximumParallelInvocationsPerClient = 5;
options.MaximumReceiveMessageSize = 100_000;
})
.AddJsonProtocol(options =>
Expand Down
13 changes: 7 additions & 6 deletions Server/Services/RcImplementations/ViewerAuthorizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Microsoft.Extensions.Caching.Memory;
using Remotely.Shared.Utilities;
using System;
using System.Threading.Tasks;

namespace Remotely.Server.Services.RcImplementations
{
Expand All @@ -20,25 +21,25 @@ public ViewerAuthorizer(IApplicationConfig appConfig, IOtpProvider otpProvider)

public string UnauthorizedRedirectUrl { get; } = "/Identity/Account/Login";

public bool IsAuthorized(AuthorizationFilterContext context)
public Task<bool> IsAuthorized(AuthorizationFilterContext context)
{
if (!_appConfig.RemoteControlRequiresAuthentication)
{
return true;
return Task.FromResult(true);
}

if (context.HttpContext.User.Identity.IsAuthenticated)
if (context.HttpContext.User.Identity?.IsAuthenticated == true)
{
return true;
return Task.FromResult(true);
}

if (context.HttpContext.Request.Query.TryGetValue("otp", out var otp) &&
_otpProvider.Exists($"{otp}"))
{
return true;
return Task.FromResult(true);
}

return false;
return Task.FromResult(false);
}
}
}
59 changes: 29 additions & 30 deletions Server/Services/RcImplementations/ViewerPageDataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,53 +20,52 @@ public ViewerPageDataProvider(IDataService dataService, IApplicationConfig appCo
_appConfig = appConfig;
}

public Task<string> GetFaviconUrl(ViewerModel viewerModel)
public Task<string> GetFaviconUrl(PageModel viewerModel)
{
return Task.FromResult("/_content/Immense.RemoteControl.Server/favicon.ico");
}

public Task<string> GetPageDescription(ViewerModel viewerModel)
public async Task<string> GetLogoUrl(PageModel viewerModel)
{
return Task.FromResult("Open-source remote support tools.");
}

public Task<string> GetPageTitle(PageModel pageModel)
{
return Task.FromResult("Remotely Remote Control");
return await GetTheme(viewerModel) == ViewerPageTheme.Dark ?
"/images/viewer/remotely-logo-dark.svg" :
"/images/viewer/remotely-logo-light.svg";
}

public Task<string> GetProductName(PageModel pageModel)
public Task<string> GetPageDescription(PageModel viewerModel)
{
return Task.FromResult("Remotely");
return Task.FromResult("Open-source remote support tools.");
}

public Task<string> GetProductSubtitle(PageModel pageModel)
public Task<string> GetPageTitle(PageModel pageModel)
{
return Task.FromResult("Remote Control");
return Task.FromResult("Remotely Remote Control");
}

public Task<ViewerPageTheme> GetTheme(PageModel pageModel)
{
if (pageModel.User.Identity.IsAuthenticated)
{
var user = _dataService.GetUserByNameWithOrg(pageModel.User.Identity.Name);
// TODO: Implement light theme in new viewer design.
return Task.FromResult(ViewerPageTheme.Dark);
//if (pageModel.User.Identity.IsAuthenticated)
//{
// var user = _dataService.GetUserByNameWithOrg(pageModel.User.Identity.Name);

var userTheme = user.UserOptions.Theme switch
{
Theme.Light => ViewerPageTheme.Light,
Theme.Dark => ViewerPageTheme.Dark,
_ => ViewerPageTheme.Dark
};
return Task.FromResult(userTheme);
}
// var userTheme = user.UserOptions.Theme switch
// {
// Theme.Light => ViewerPageTheme.Light,
// Theme.Dark => ViewerPageTheme.Dark,
// _ => ViewerPageTheme.Dark
// };
// return Task.FromResult(userTheme);
//}

var appTheme = _appConfig.Theme switch
{
Theme.Light => ViewerPageTheme.Light,
Theme.Dark => ViewerPageTheme.Dark,
_ => ViewerPageTheme.Dark
};
return Task.FromResult(appTheme);
//var appTheme = _appConfig.Theme switch
//{
// Theme.Light => ViewerPageTheme.Light,
// Theme.Dark => ViewerPageTheme.Dark,
// _ => ViewerPageTheme.Dark
//};
//return Task.FromResult(appTheme);
}

public Task<string> GetUserDisplayName(PageModel pageModel)
Expand Down
54 changes: 54 additions & 0 deletions Server/wwwroot/images/viewer/remotely-logo-dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 54 additions & 0 deletions Server/wwwroot/images/viewer/remotely-logo-light.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 6297175

Please sign in to comment.