Separate func into smaller ones
MODIFY
WalletWasabi/Services/SystemAwakeChecker.cs
WalletWasabi/Services/SystemAwakeChecker.cs
@@ -66,21 +66,25 @@ namespace WalletWasabi.Services
protected override async Task ActionAsync(CancellationToken cancel)
{
- IPowerSavingInhibitorTask? task = _powerSavingTask;
-
switch (CoinJoinManager.HighestCoinJoinClientState)
{
case CoinJoinClientState.Idle:
- if (task is not null)
- {
- Logger.LogWarning("Computer idle state is allowed again.");
- await task.StopAsync().ConfigureAwait(false);
- _powerSavingTask = null;
- }
+ await ReleaseAllPreventionAsync().ConfigureAwait(false);
+ break;
+ case CoinJoinClientState.InProgress or CoinJoinClientState.InCriticalPhase:
+ await PreventSleepAsync().ConfigureAwait(false);
break;
- case CoinJoinClientState.InProgress:
+ default:
+ throw new ArgumentOutOfRangeException();
+ }
+ }
+
+ private async Task PreventSleepAsync()
+ {
+ IPowerSavingInhibitorTask? task = _powerSavingTask;
+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
if (task is not null)
@@ -102,15 +106,15 @@ namespace WalletWasabi.Services
{
await EnvironmentHelpers.ProlongSystemAwakeAsync().ConfigureAwait(false);
}
+ }
- break;
-
- case CoinJoinClientState.InCriticalPhase:
-
- break;
-
- default:
- throw new ArgumentOutOfRangeException();
+ private async Task ReleaseAllPreventionAsync()
+ {
+ Logger.LogInfo("Computer idle state is allowed again.");
+ if (_powerSavingTask is not null)
+ {
+ await _powerSavingTask.StopAsync().ConfigureAwait(false);
+ _powerSavingTask = null;
}
}
}

Separate func into smaller ones