Add macOS support
MODIFY
WalletWasabi.Tests/UnitTests/Clients/PreventSleepTests.cs
WalletWasabi.Tests/UnitTests/Clients/PreventSleepTests.cs
+using System.Threading.Tasks;
using WalletWasabi.Helpers;
using Xunit;
@@ -6,9 +7,9 @@ namespace WalletWasabi.Tests.UnitTests.Clients
public class PreventSleepTests
{
[Fact]
- public void PreventSleep()
+ public async Task PreventSleepAsync()
{
- EnvironmentHelpers.KeepSystemAwake();
+ await EnvironmentHelpers.KeepSystemAwakeAsync();
}
}
}

MODIFY
WalletWasabi/Helpers/EnvironmentHelpers.cs
WalletWasabi/Helpers/EnvironmentHelpers.cs
@@ -264,14 +264,24 @@ namespace WalletWasabi.Helpers
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern EXECUTION_STATE SetThreadExecutionState(EXECUTION_STATE esFlags);
- public static void KeepSystemAwake()
+ public static async Task KeepSystemAwakeAsync()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
var result = SetThreadExecutionState(EXECUTION_STATE.ES_SYSTEM_REQUIRED);
if (result == 0)
{
- Logger.LogInfo("SetThreadExecutionState failed.");
+ throw new InvalidOperationException("SetThreadExecutionState failed.");
+ }
+ }
+ else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
+ {
+ ProcessStartInfo startInfo = ProcessStartInfoFactory.Make("caffeinate", "-i -t 120 &");
+ var processInvoker = new ProcessInvoker();
+ (string rawResponse, int exitCode) = await processInvoker.SendCommandAsync(startInfo, CancellationToken.None).ConfigureAwait(false);
+ if (exitCode != 0)
+ {
+ throw new InvalidOperationException($"Caffeinate failed. {rawResponse}");
}
}
}

MODIFY
WalletWasabi/Services/SystemAwakeChecker.cs
WalletWasabi/Services/SystemAwakeChecker.cs
@@ -18,14 +18,12 @@ namespace WalletWasabi.Services
private WalletManager WalletManager { get; }
- protected override Task ActionAsync(CancellationToken cancel)
+ protected override async Task ActionAsync(CancellationToken cancel)
{
if (WalletManager.IsAnyCoinJoinInProgress())
{
- EnvironmentHelpers.KeepSystemAwake();
+ await EnvironmentHelpers.KeepSystemAwakeAsync().ConfigureAwait(false);
}
-
- return Task.CompletedTask;
}
}
}

Add macOS support