From 3196de2e296977edcfa70c8deefdd562391133c3 Mon Sep 17 00:00:00 2001
From: Den Delimarsky <1389609+dend@users.noreply.github.com>
Date: Tue, 11 May 2021 14:42:42 -0700
Subject: [PATCH] Update loops
---
.../espresso/Espresso/Core/APIHelper.cs | 30 ++++++++++++++-----
src/modules/espresso/Espresso/Espresso.csproj | 6 ++++
.../Microsoft.PowerToys.Settings.UI.csproj | 1 +
3 files changed, 29 insertions(+), 8 deletions(-)
diff --git a/src/modules/espresso/Espresso/Core/APIHelper.cs b/src/modules/espresso/Espresso/Core/APIHelper.cs
index 11e7949a08..e0f23315c4 100644
--- a/src/modules/espresso/Espresso/Core/APIHelper.cs
+++ b/src/modules/espresso/Espresso/Core/APIHelper.cs
@@ -95,14 +95,10 @@ namespace Espresso.Shell.Core
/// Status of the attempt. True if successful, false if not.
public static bool SetIndefiniteKeepAwake(bool keepDisplayOn = true)
{
- if (keepDisplayOn)
- {
- return SetAwakeState(EXECUTION_STATE.ES_SYSTEM_REQUIRED | EXECUTION_STATE.ES_DISPLAY_REQUIRED | EXECUTION_STATE.ES_CONTINUOUS);
- }
- else
- {
- return SetAwakeState(EXECUTION_STATE.ES_SYSTEM_REQUIRED | EXECUTION_STATE.ES_CONTINUOUS);
- }
+ TokenSource = new CancellationTokenSource();
+ ThreadToken = TokenSource.Token;
+
+ //Put thread for indefinite loop.
}
public static void SetTimedKeepAwake(long seconds, Action callback, Action failureCallback, bool keepDisplayOn = true)
@@ -116,12 +112,30 @@ namespace Espresso.Shell.Core
}
+ private static void RunIndefiniteLoop(bool keepDisplayOn = true)
+ {
+ bool success = false;
+
+ // In case cancellation was already requested.
+ ThreadToken.ThrowIfCancellationRequested();
+
+ if (keepDisplayOn)
+ {
+ SetAwakeState(EXECUTION_STATE.ES_SYSTEM_REQUIRED | EXECUTION_STATE.ES_DISPLAY_REQUIRED | EXECUTION_STATE.ES_CONTINUOUS);
+ }
+ else
+ {
+ return SetAwakeState(EXECUTION_STATE.ES_SYSTEM_REQUIRED | EXECUTION_STATE.ES_CONTINUOUS);
+ }
+ }
+
private static bool RunTimedLoop(long seconds, bool keepDisplayOn = true)
{
bool success = false;
// In case cancellation was already requested.
ThreadToken.ThrowIfCancellationRequested();
+
try
{
if (keepDisplayOn)
diff --git a/src/modules/espresso/Espresso/Espresso.csproj b/src/modules/espresso/Espresso/Espresso.csproj
index 6f847d6715..3669444ea8 100644
--- a/src/modules/espresso/Espresso/Espresso.csproj
+++ b/src/modules/espresso/Espresso/Espresso.csproj
@@ -12,6 +12,12 @@
true
PowerToys.Espresso
+ Espresso.ico
+ Den Delimarsky
+ Den Delimarsky
+ Espresso
+ https://espresso.den.dev
+ Espresso.png
diff --git a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Microsoft.PowerToys.Settings.UI.csproj b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Microsoft.PowerToys.Settings.UI.csproj
index 77aa5811fe..20f1a6e98c 100644
--- a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Microsoft.PowerToys.Settings.UI.csproj
+++ b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Microsoft.PowerToys.Settings.UI.csproj
@@ -202,6 +202,7 @@
+