diff --git a/Agent/Program.cs b/Agent/Program.cs index 16cf02c1..25af995b 100644 --- a/Agent/Program.cs +++ b/Agent/Program.cs @@ -4,6 +4,7 @@ using Remotely.Agent.Interfaces; using Remotely.Agent.Services; using Remotely.Shared.Utilities; using System; +using System.Diagnostics; using System.IO; using System.ServiceProcess; using System.Threading; @@ -87,7 +88,8 @@ namespace Remotely.Agent SetWorkingDirectory(); - if (!EnvironmentHelper.IsDebug && EnvironmentHelper.IsWindows) + if (EnvironmentHelper.IsWindows && + Process.GetCurrentProcess().SessionId == 0) { _ = Task.Run(() => { diff --git a/Agent/Services/AppLauncherWin.cs b/Agent/Services/AppLauncherWin.cs index 65916cb2..d6dfa365 100644 --- a/Agent/Services/AppLauncherWin.cs +++ b/Agent/Services/AppLauncherWin.cs @@ -34,7 +34,7 @@ namespace Remotely.Agent.Services // Start Desktop app. await hubConnection.SendAsync("DisplayMessage", $"Starting chat service...", "Starting chat service.", requesterID); - if (EnvironmentHelper.IsDebug) + if (Process.GetCurrentProcess().SessionId > 0) { return Process.Start(rcBinaryPath, $"-mode Chat -requester \"{requesterID}\" -organization \"{orgName}\"").Id; } @@ -78,7 +78,7 @@ namespace Remotely.Agent.Services // Start Desktop app. await hubConnection.SendAsync("DisplayMessage", $"Starting remote control...", "Starting remote control.", requesterID); - if (EnvironmentHelper.IsDebug) + if (Process.GetCurrentProcess().SessionId > 0) { // SignalR Connection IDs might start with a hyphen. We surround them // with quotes so the command line will be parsed correctly. @@ -111,7 +111,7 @@ namespace Remotely.Agent.Services var rcBinaryPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Desktop", EnvironmentHelper.DesktopExecutableFileName); // Start Desktop app. Logger.Write("Restarting screen caster."); - if (EnvironmentHelper.IsDebug) + if (Process.GetCurrentProcess().SessionId > 0) { // SignalR Connection IDs might start with a hyphen. We surround them // with quotes so the command line will be parsed correctly. diff --git a/Desktop.Core/Services/Viewer.cs b/Desktop.Core/Services/Viewer.cs index 71f5ceaf..6a190f5c 100644 --- a/Desktop.Core/Services/Viewer.cs +++ b/Desktop.Core/Services/Viewer.cs @@ -16,9 +16,9 @@ namespace Remotely.Desktop.Core.Services { public class Viewer : IDisposable { - private readonly int defaultImageQuality = 60; - private int imageQuality; - private DateTimeOffset lastQualityAdjustment; + private readonly int _defaultImageQuality = 60; + private int _imageQuality; + private DateTimeOffset _lastQualityAdjustment; public Viewer(CasterSocket casterSocket, IScreenCapturer screenCapturer, IClipboardService clipboardService, @@ -29,7 +29,7 @@ namespace Remotely.Desktop.Core.Services CasterSocket = casterSocket; WebRtcSessionFactory = webRtcSessionFactory; EncoderParams = new EncoderParameters(); - ImageQuality = defaultImageQuality; + ImageQuality = _defaultImageQuality; ClipboardService = clipboardService; ClipboardService.ClipboardTextChanged += ClipboardService_ClipboardTextChanged; AudioCapturer = audioCapturer; @@ -47,21 +47,21 @@ namespace Remotely.Desktop.Core.Services { get { - return imageQuality; + return _imageQuality; } set { - if (imageQuality == value) + if (_imageQuality == value) { return; } - if (imageQuality > 100 || imageQuality < 0) + if (_imageQuality > 100 || _imageQuality < 0) { return; } - imageQuality = value; + _imageQuality = value; EncoderParams.Param[0] = new EncoderParameter(Encoder.Quality, value); } @@ -250,7 +250,7 @@ namespace Remotely.Desktop.Core.Services Height = height, EndOfFrame = false, ImageBytes = encodedImageBytes.Skip(i).Take(50_000).ToArray(), - ImageQuality = imageQuality + ImageQuality = _imageQuality }; await SendToViewer(() => RtcSession.SendDto(dto), @@ -264,7 +264,7 @@ namespace Remotely.Desktop.Core.Services Width = width, Height = height, EndOfFrame = true, - ImageQuality = imageQuality + ImageQuality = _imageQuality }; await SendToViewer(() => RtcSession.SendDto(endOfFrameDto), @@ -301,17 +301,17 @@ namespace Remotely.Desktop.Core.Services public void ThrottleIfNeeded() { - if (AutoAdjustQuality && DateTimeOffset.Now - lastQualityAdjustment > TimeSpan.FromSeconds(2)) + if (AutoAdjustQuality && DateTimeOffset.Now - _lastQualityAdjustment > TimeSpan.FromSeconds(2)) { - lastQualityAdjustment = DateTimeOffset.Now; + _lastQualityAdjustment = DateTimeOffset.Now; if (PendingSentFrames.TryPeek(out var result) && DateTimeOffset.Now - result > TimeSpan.FromMilliseconds(200)) { var latency = (DateTimeOffset.Now - result).TotalMilliseconds; - ImageQuality = (int)(200 / latency * defaultImageQuality); + ImageQuality = (int)(200 / latency * _defaultImageQuality); } - else + else if (ImageQuality != _defaultImageQuality) { - ImageQuality = defaultImageQuality; + ImageQuality = Math.Min(_defaultImageQuality, ImageQuality + 5); } } diff --git a/Server/Areas/Identity/Pages/Account/Manage/ApiTokens.cshtml b/Server/Areas/Identity/Pages/Account/Manage/ApiTokens.cshtml index d6036950..608c8a31 100644 --- a/Server/Areas/Identity/Pages/Account/Manage/ApiTokens.cshtml +++ b/Server/Areas/Identity/Pages/Account/Manage/ApiTokens.cshtml @@ -94,6 +94,7 @@