Adding functionality to not sleep

This commit is contained in:
Den Delimarsky 2021-04-08 16:09:59 -07:00
parent c141e4eec3
commit 18f94fc0e6
No known key found for this signature in database
GPG key ID: E1BE1355085F0BCF
2 changed files with 37 additions and 18 deletions

View file

@ -49,15 +49,15 @@ namespace Espresso.Shell.Core
}
}
public static bool SetIndefiniteKeepAwake(bool keepDisplayOn = true)
public static bool SetIndefiniteKeepAwake(bool? keepDisplayOn = true)
{
if (keepDisplayOn)
if ((bool)keepDisplayOn)
{
return SetAwakeState(EXECUTION_STATE.ES_DISPLAY_REQUIRED | EXECUTION_STATE.ES_CONTINUOUS);
return SetAwakeState(EXECUTION_STATE.ES_SYSTEM_REQUIRED | EXECUTION_STATE.ES_DISPLAY_REQUIRED | EXECUTION_STATE.ES_CONTINUOUS);
}
else
{
return SetAwakeState(EXECUTION_STATE.ES_CONTINUOUS);
return SetAwakeState(EXECUTION_STATE.ES_SYSTEM_REQUIRED | EXECUTION_STATE.ES_CONTINUOUS);
}
}

View file

@ -25,17 +25,36 @@ namespace Espresso.Shell
Console.WriteLine("Espresso - Computer Caffeination Engine");
var displayOption = new Option<bool>(
aliases: new[] { "--display-on", "-d" },
getDefaultValue: () => true,
description: "Determines whether the display should be kept awake.")
{
Argument = new Argument<bool>(() => false)
{
Arity = ArgumentArity.ZeroOrOne,
},
};
displayOption.Required = false;
var timeOption = new Option<long>(
aliases: new[] { "--time-limit", "-t" },
getDefaultValue: () => 0,
description: "Determines the interval, in seconds, during which the computer is kept awake.")
{
Argument = new Argument<long>(() => 0)
{
Arity = ArgumentArity.ExactlyOne,
},
};
timeOption.Required = false;
var rootCommand = new RootCommand
{
new Option<bool>(
aliases: new string[] {"--display-on", "-d" },
getDefaultValue: () => false,
description: "Determines whether the display should be kept awake."),
new Option<long>(
aliases: new string[] {"--time-limit", "-t" },
getDefaultValue: () => 0,
description: "Determines the interval, in seconds, during which the computer is kept awake.")
displayOption,
timeOption
};
rootCommand.Description = appName;
@ -45,18 +64,18 @@ namespace Espresso.Shell
return rootCommand.InvokeAsync(args).Result;
}
private static void HandleCommandLineArguments(bool displayOption, long timeOption)
private static void HandleCommandLineArguments(bool displayOn, long timeLimit)
{
Console.WriteLine($"The value for --display-on is: {displayOption}");
Console.WriteLine($"The value for --time-limit is: {timeOption}");
Console.WriteLine($"The value for --display-on is: {displayOn}");
Console.WriteLine($"The value for --time-limit is: {timeLimit}");
if (timeOption <= 0)
if (timeLimit <= 0)
{
// Indefinite keep awake.
bool success = APIHelper.SetIndefiniteKeepAwake(displayOption);
bool success = APIHelper.SetIndefiniteKeepAwake(displayOn);
if (success)
{
Console.WriteLine($"Currently in indefinite keep awake. Display always on: {displayOption}");
Console.WriteLine($"Currently in indefinite keep awake. Display always on: {displayOn}");
}
else
{