Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Awake CLI Exceptions related to Tray Icon wtih --time-limit #35222

Closed
lylebrown opened this issue Oct 2, 2024 · 4 comments
Closed

Awake CLI Exceptions related to Tray Icon wtih --time-limit #35222

lylebrown opened this issue Oct 2, 2024 · 4 comments
Assignees
Labels
Issue-Bug Something isn't working Product-Awake Issues regarding the PowerToys Awake utility

Comments

@lylebrown
Copy link

Microsoft PowerToys version

0.85.0

Installation method

GitHub

Running as admin

Yes

Area(s) with issue?

Awake

Steps to reproduce

If I run Awake from the PowerShell CLI with the following command I get the output in the console log below:
.\PowerToys.Awake.exe --time-limit 180

I also get the same output if I combine arguments:
``.\PowerToys.Awake.exe --display-on false --time-limit 180`

Other arguments seem to work.

While reproducing, there were a couple of isolated times it did work without showing this exception.

I have Awake disabled in PowerToys and am using the CLI only.

May be related to issues #34809 #34616 #34148 and PR #34717

Bug Report / Console Log

[12:28:03.9660369] [Info] Program::HandleCommandLineArguments
    The value for --use-pt-config is: False
[12:28:03.9666795] [Info] Program::HandleCommandLineArguments
    The value for --display-on is: False
[12:28:03.9671833] [Info] Program::HandleCommandLineArguments
    The value for --time-limit is: 180
[12:28:03.9677156] [Info] Program::HandleCommandLineArguments
    The value for --pid is: 0
[12:28:03.9690301] [Info] Program::HandleCommandLineArguments
    The value for --expire-at is:
[12:28:03.9696766] [Info] Program::HandleCommandLineArguments
    The value for --use-parent-pid is: False
[12:28:03.9712085] [Info] <>c__DisplayClass17_0::<RunOnMainThread>b__0
    Thread execution is on: 5
[12:28:03.9729920] [Info] Manager::SetTimedKeepAwake
    Timed keep-awake. Expected runtime: 180 seconds with display on setting set to False.
[12:28:03.9752064] [Info] Manager::CancelExistingThread
    Attempting to ensure that the thread is properly cleaned up...
[12:28:03.9762431] [Info] Manager::CancelExistingThread
    Instantiating of new token source and thread token completed.
[12:28:03.9765028] [Info] <>c__DisplayClass13_0::<InitializeTray>b__1
    [12:28:03.9767870] [Info] Manager::SetTimedKeepAwake
    Timed keep awake started for 180 seconds.
Created HWND for the window: 9181516
[12:28:03.9775622] [Info] <>c::<StartMonitor>b__17_0
    Setting state to ES_CONTINUOUS
[12:28:03.9780486] [Info] <>c::<StartMonitor>b__17_0
    Setting state to ES_SYSTEM_REQUIRED, ES_CONTINUOUS
[12:28:03.9818556] [Info] TrayHelper::SetShellIcon
    Could not set the shell icon. Action: Update and error code: -2147467259. HIcon handle is 1448701 and HWnd is 9181516
Unhandled exception: [12:28:03.9843714] [Info] <>c__DisplayClass17_0::<RunOnMainThread>b__0
    Thread execution is on: 5
System.ComponentModel.Win32Exception (0x80004005): Failed to change tray icon. Action: Update and error code: -2147467259
   at Awake.Core.TrayHelper.SetShellIcon(IntPtr hWnd, String text, Icon icon, TrayIconAction action)
   at Awake.Core.Manager.SetTimedKeepAwake(UInt32 seconds, Boolean keepDisplayOn)
   at Awake.Program.HandleCommandLineArguments(Boolean usePtConfig, Boolean displayOn, UInt32 timeLimit, Int32 pid, String expireAt, Boolean useParentPid)
   at System.CommandLine.Handler.<>c__DisplayClass7_0`6.<SetHandler>b__0(InvocationContext context)
   at System.CommandLine.Invocation.AnonymousCommandHandler.Invoke(InvocationContext context)
   at System.CommandLine.Invocation.AnonymousCommandHandler.InvokeAsync(InvocationContext context)
   at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass17_0.<<UseParseErrorReporting>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass12_0.<<UseHelp>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass22_0.<<UseVersionOption>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass19_0.<<UseTypoCorrections>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseSuggestDirective>b__18_0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass16_0.<<UseParseDirective>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<RegisterWithDotnetSuggest>b__5_0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass8_0.<<UseExceptionHandler>b__0>d.MoveNext()

✔️ Expected Behavior

Awake CLI window should appear with no exceptions.

❌ Actual Behavior

Exception listed in the Steps to Reproduce appears in the Awake CLI window.

Other Software

No response

@lylebrown lylebrown added Issue-Bug Something isn't working Needs-Triage For issues raised to be triaged and prioritized by internal Microsoft teams labels Oct 2, 2024
@davidegiacometti davidegiacometti added the Product-Awake Issues regarding the PowerToys Awake utility label Oct 3, 2024
@dend dend self-assigned this Oct 4, 2024
@dend
Copy link
Collaborator

dend commented Oct 4, 2024

I am trying to repro this locally and I can't get it to error out - it works as expected:

Awake running from CLI

If I try to repeatedly launch the app after expiration, I can get it into an error state but that seems like a limited scenario:

Awake erroring out in the CLI

Looks like I need to implement some additional edge case detection for icon changes, thank you for the report @lylebrown. At the very least, I can add some retry logic to try and set the icon several times before completely erroring out.

@dend dend removed the Needs-Triage For issues raised to be triaged and prioritized by internal Microsoft teams label Oct 4, 2024
@lylebrown
Copy link
Author

I did try running it multiple times in a row (closing each instance first) in an attempt to reproduce the error, so maybe that in itself is the issue.

I will say my background implementation is working correctly. I effectively just run "C:\Program Files\PowerToys\PowerToys.Awake.exe" --display-on true --time-limit 1800 in the background with an extension for my Stream Deck. Doing so, the tray icon appears correctly, hovering over the tray icon displays the correct time remaining, and it terminates once the time limit is reached.

However, doing it this way, I also am not seeing that CLI window, so it could be showing this exception in the background.

I would argue this is low priority, at least for executing PowerToys Awake standalone (disabled in PowerToys Settings/Dashboard). But #35250 suggests it may be an issue for those who have it enabled in PowerToys Settings.

@lylebrown
Copy link
Author

There may be more to this issue than just the exception.

Using the implementation I mentioned above, I've noticed that sometimes the tray shows the timer/time remaining, other times it's just the static "Awake" icon. And when it's static, I don't believe the timer has been applied. This might be related to terminating the process and then restarting it.

To be clear, every time I start Awake, I'm doing so with the argument for the same timer duration (1800 seconds).

I think I've isolated the relevant debug log section for this.

[09:33:38.5724115] [Info] Manager::SetTimedKeepAwake
    Timed keep-awake. Expected runtime: 1800 seconds with display on setting set to True.
[09:33:38.5740386] [Info] Manager::CancelExistingThread
    Attempting to ensure that the thread is properly cleaned up...
[09:33:38.5741274] [Info] <>c__DisplayClass13_0::<InitializeTray>b__1
    Created HWND for the window: 7804718
[09:33:38.5745565] [Info] Manager::CancelExistingThread
    Instantiating of new token source and thread token completed.
[09:33:38.5747522] [Info] Manager::SetTimedKeepAwake
    Timed keep awake started for 1800 seconds.
[09:33:38.5760311] [Info] <>c::<StartMonitor>b__17_0
    Setting state to ES_CONTINUOUS
[09:33:38.5761979] [Info] TrayHelper::SetShellIcon
    Could not set the shell icon. Action: Update and error code: -2147467259. HIcon handle is 1136072315 and HWnd is 7804718
[09:33:38.5764050] [Info] <>c::<StartMonitor>b__17_0
    Setting state to ES_SYSTEM_REQUIRED, ES_DISPLAY_REQUIRED, ES_CONTINUOUS
[09:33:38.5781466] [Info] <>c__DisplayClass17_0::<RunOnMainThread>b__0
    Thread execution is on: 5

@dend
Copy link
Collaborator

dend commented Dec 5, 2024

The root cause is addressed in #35250.

@dend dend closed this as completed Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Bug Something isn't working Product-Awake Issues regarding the PowerToys Awake utility
Projects
None yet
Development

No branches or pull requests

3 participants