JPersson77 / LGTVCompanion

Power On and Off WebOS LG TVs together with your PC
MIT License
992 stars 40 forks source link

TV shutting off on restart #95

Closed droscoe closed 1 year ago

droscoe commented 1 year ago

Hello! I just started using this app, and I found that it intermittently shuts off the TV on restart. I saw a similar post in the closed issues. Where can I find the logs you reference there? I created a custom view for Event Viewer and can confirm that Windows reported a "restart", yet the display still powered off. I would appreciate any help. - Dave IMG_2821

JPersson77 commented 1 year ago

Hi @droscoe

On win11 the log is found here: c:/ProgramData/LGTV Companion/log.txt. It should be quite easy to find the appropriate log entries for the restart vs shutdown events.

Also, can you confirm you have configured the "restart words" properly in the global configuration (in case of a non-english localised OS-version)?

Let me know what you find out

droscoe commented 1 year ago

Hello. I am running Windows 10. I could not find a log file at the location you indicated. I found a .json file however. Also, my localization is English and my restart keywords are correct. IMG_2822 IMG_2824

IMG_2823

JPersson77 commented 1 year ago

Hi again, apologies you need to enable "perform logging" in the global options too. Looks like you are running an order version too

droscoe commented 1 year ago

Oops! Sorted. I captured the log file. I can update the software in the interim. Log.txt

droscoe commented 1 year ago

I can confirm problem persists in v1.9

JPersson77 commented 1 year ago

Thanks,

I notice this in the log: Mon 12:32:20 > WARNING! The application did not receive an Event Subscription Callback prior to system shutting down. Unable to determine if system is shutting down or restarting. Mon 12:32:20 > Device1, spawning DisplayPowerOffThread(). Mon 12:32:20 > Event subscription callback: System restart detected.

For some reason the event written to the event log is coming a fraction of a second after the "power off" event. Unfortunately the timing of this in the OS is undefined or at least not well documented. But this is the first time I've seen this issue you are ecperiencing actually so lets's see if something can be done to shift that timing ever so slightly without messing up the time-critical things going on at shutdown /reboot

droscoe commented 1 year ago

I dont do Windows development, but I came across several articles saying the only real way to do things is the way you're doing it, but also came across this: https://www.apriorit.com/dev-blog/413-win-api-shutdown-events

I dont know if it'll help you or not. Ignore me if its rubbish

JPersson77 commented 1 year ago

There is no straightforward way unfortunately to discover if the user is rebooting or shutting down. Microsoft design decisions. The article outlines ways to get notified when the system is shutting down but that is only half the equation.

Potentially, for the issue you are seeing (and i assume more than you also then), it could work to implement a ShutdownBlockReasonCreate() to delay the shutdown a bit so the event can be properly picked up.

Also, there are times when the event is not written to the event log at all, probably for timing reasons

droscoe commented 1 year ago

Possible idea is to bypass Windows state and go through ACPI? Sorry, I’m a software dev too. Can’t help it! https://learn.microsoft.com/en-us/windows-hardware/drivers/display/supporting-display-output

JPersson77 commented 1 year ago

Yes maybe! Will read up on it! Do you have any example code or suggestions how to work with ACPI?

droscoe commented 1 year ago

I’ve never worked with it, but it deals with a bunch of different power states directly to/from the hardware. I suggested looking there for future improvements. Having to read a log to determine state just seems kludgy. Would bug the hell out of me.

JPersson77 commented 1 year ago

Haha yes it definitely is what it is :P

I did spend a little time looking into it. There seems to be some major obstacles. ACPI s very far from user space but maybe there are some drivers bundled with windows it might be possible to tap into to be able to work with it. Cool idea!

droscoe commented 1 year ago

I found this: https://learn.microsoft.com/en-us/windows-hardware/drivers/kernel/acpi-driver Also, https://learn.microsoft.com/en-us/windows-hardware/drivers/samples/windows-management-instrumentation--wmi--driver-samples

We've kinda gone off on a tangent, LOL! As for my problem, I think I've planted the bug (no pun intended). I can live with the app as-is until (or if) you create something that works better. This tool is a godsend. I appreciate you writing and maintaining it. I especially appreciate you being so responsive. I'm going to drop a donation as a token of my thanks!

JPersson77 commented 1 year ago

Hehe yeah I think you are right about that! When I start prototyping I will ping you to come help with the kernel driver testing ok? ;) You're welcome, and thanks too buddy! 😊

droscoe commented 1 year ago

[...] When I start prototyping I will ping you to come help with the kernel driver testing ok? [...]

Please do! :-)

JPersson77 commented 1 year ago

Closing this issue