mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-07-01 07:59:36 +02:00
Compare commits
2 Commits
stable
...
copilot/ad
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3a3e5e79e6 | ||
|
|
9ef957be3b |
@@ -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();
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user