Compare commits

...

2 Commits

Author SHA1 Message Date
copilot-swe-agent[bot]
3a3e5e79e6 Add --no-console CLI option to Awake to hide console window
Agent-Logs-Url: https://github.com/microsoft/PowerToys/sessions/c015a5dc-dbf8-4b07-a903-a0f4ae18b53c

Co-authored-by: niels9001 <9866362+niels9001@users.noreply.github.com>
2026-04-18 17:46:22 +00:00
copilot-swe-agent[bot]
9ef957be3b Initial plan 2026-04-18 17:42:19 +00:00
4 changed files with 40 additions and 5 deletions

View File

@@ -34,6 +34,7 @@ namespace Awake
private static readonly string[] _aliasesPidOption = ["--pid", "-p"];
private static readonly string[] _aliasesExpireAtOption = ["--expire-at", "-e"];
private static readonly string[] _aliasesParentPidOption = ["--use-parent-pid", "-u"];
private static readonly string[] _aliasesNoConsoleOption = ["--no-console", "-n"];
private static readonly JsonSerializerOptions _serializerOptions = new() { IncludeFields = true };
private static readonly ETWTrace _etwTrace = new();
@@ -176,6 +177,12 @@ namespace Awake
IsRequired = false,
};
Option<bool> noConsoleOption = new(_aliasesNoConsoleOption, () => false, Resources.AWAKE_CMD_HELP_NO_CONSOLE_OPTION)
{
Arity = ArgumentArity.ZeroOrOne,
IsRequired = false,
};
timeOption.AddValidator(result =>
{
if (result.Tokens.Count != 0 && !uint.TryParse(result.Tokens[0].Value, out _))
@@ -214,10 +221,11 @@ namespace Awake
pidOption,
expireAtOption,
parentPidOption,
noConsoleOption,
];
rootCommand.Description = Core.Constants.AppName;
rootCommand.SetHandler(HandleCommandLineArguments, configOption, displayOption, timeOption, pidOption, expireAtOption, parentPidOption);
rootCommand.SetHandler(HandleCommandLineArguments, configOption, displayOption, timeOption, pidOption, expireAtOption, parentPidOption, noConsoleOption);
return rootCommand;
}
@@ -300,13 +308,21 @@ namespace Awake
}
}
private static void HandleCommandLineArguments(bool usePtConfig, bool displayOn, uint timeLimit, int pid, string expireAt, bool useParentPid)
private static void HandleCommandLineArguments(bool usePtConfig, bool displayOn, uint timeLimit, int pid, string expireAt, bool useParentPid, bool noConsole)
{
if (pid == 0 && !useParentPid)
{
Logger.LogInfo("No PID specified. Allocating console...");
Bridge.FreeConsole();
AllocateLocalConsole();
if (!noConsole)
{
Logger.LogInfo("No PID specified. Allocating console...");
Bridge.FreeConsole();
AllocateLocalConsole();
}
else
{
Logger.LogInfo("No PID specified. Running without console (--no-console).");
Bridge.FreeConsole();
}
}
else
{
@@ -320,6 +336,7 @@ namespace Awake
Logger.LogInfo($"The value for --pid is: {pid}");
Logger.LogInfo($"The value for --expire-at is: {expireAt}");
Logger.LogInfo($"The value for --use-parent-pid is: {useParentPid}");
Logger.LogInfo($"The value for --no-console is: {noConsole}");
// Start the monitor thread that will be used to track the current state.
Manager.StartMonitor();

View File

@@ -105,6 +105,15 @@ namespace Awake.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to When set, the console window will not be shown and Awake will only appear in the system tray..
/// </summary>
internal static string AWAKE_CMD_HELP_NO_CONSOLE_OPTION {
get {
return ResourceManager.GetString("AWAKE_CMD_HELP_NO_CONSOLE_OPTION", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Uses the parent process as the bound target - once the process terminates, Awake stops..
/// </summary>

View File

@@ -194,6 +194,9 @@
<data name="AWAKE_CMD_PARENT_PID_OPTION" xml:space="preserve">
<value>Uses the parent process as the bound target - once the process terminates, Awake stops.</value>
</data>
<data name="AWAKE_CMD_HELP_NO_CONSOLE_OPTION" xml:space="preserve">
<value>When set, the console window will not be shown and Awake will only appear in the system tray.</value>
</data>
<data name="AWAKE_SCREEN_ON" xml:space="preserve">
<value>On</value>
</data>

View File

@@ -51,6 +51,7 @@ Options:
-p, --pid Process ID to bind to
-e, --expire-at Expiration date/time
-u, --use-parent-pid Bind to parent process
-n, --no-console Hide the console window (tray only)
```
### Examples
@@ -75,6 +76,11 @@ Keep awake while another process is running:
PowerToys.Awake.exe --pid 1234
```
Keep awake indefinitely without showing the console window:
```powershell
PowerToys.Awake.exe --no-console
```
## Architecture
### Design Highlights