JPersson77 / LGTVCompanion

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

Prevent power on (and any other commands) when PC is not connected to the TV #158

Open thomasfw opened 1 year ago

thomasfw commented 1 year ago

Is it possible to prevent LGTVCompanion from powering on the TV when the PC isn't connected to it?

I frequently move my pc between two displays (one being the LG TV), and the LG TV powers on at startup even when I'm not connected to it.

I've enabled the Process power and screen off events only when the display input source is set to HDMI: setting. Does this only apply to power/screen off, and not the power on command? Either way it doesn't seem to stop the on command from being sent to the TV when i'm not connected to it. Presumably this also wouldn't prevent the on/off command being sent if another device (or nothing at all) is plugged into the configured HDMI.

I see that I can retrieve the TV's serialNumber with LGTVCli.exe -request system/getSystemInfo. Maybe this can be used to verify that the TV selected in LGTVCompanion is currently connected to the PC. For example, by checking Window's connected display(s) serial number(s) match the selected display before sending the power/screen on/off (and any other automatic) commands?

JPersson77 commented 1 year ago

Hi @thomasfw

I think the answer is "yes and no". I understand what you want to achieve, but it's not entirely straightforward to implement full "discoverability" of connected HDMI-devices.

Firstly, the option you mention indeed only works to prevent powering off the display when the display has been set by the user to another input/app. The reason a similar option does not exist for powering on, is because communication is not possible with the TV when it is off (unless "always ready" is enabled on supported models)., So, generally speaking, the logic cannot assume that communication is always possible with the display.

Then, to know the windows internal state of connected devices, windows/ the graphics card(s) must be queried for connected devices. I've researched that a bit already when I implemented the multi display topology feature. I think there is indeed the potential for more effective management of HDMI-connections but it becomes complex for a windows service to get access to the required lower-level info. I think there is more to discover, but when I last looked at this I concluded at the time that to dig further I'd probably need to write a display device driver, which is arguably no simple feat.

For now however, there is the multi display topology option which should do some of what you need - if you have a 2-series or later display. There is one caveat though, when the PC is powering on from being fully off (i e when loading the lgtv companion service), all devices will power on initially until after the user login process when the user mode daemon loads and can discover which devices are currently connected and ensure they are powered on/off accordingly.

Some other ways to achieve what you want, is to disable the automatic management of the device and either bind a keyboard shortcut to a script which power on the LG on and enable automatic management - so you can manually trigger it when you need it. Or for a bit more automation you could attempt to write a script which automate the HDMI-connected/disconnected state, ie monitor the connected/disconnected state of output devices and use lgtv companion to power on/off accordingly. Yes, this requires implementing your own solution or using other third party solutions to enumerate active displays and I'm not sure you can achieve more than what the topology feature already does, since it needs to be done in user mode.

So, I hope that answers your question in the shortest amount of words :)

thomasfw commented 1 year ago

@JPersson77 many thanks for the explanation, and thanks for your work on this.

I see that this would require a substantial amount of work. In my case (using LG C1 so unfortunately can’t use the multi display topology option) it sounds like a custom script and disabling auto management would be the best option, like you say.

Regarding disabling the app’s automatic management though, how do I stop the app/service from starting automatically when Windows boots? If I use "LGTV Companion.exe" -autodisable Device1 I assume this is reset on shutdown meaning the TV will still switch on when Windows next boots up?

If I can reliably disable all automatic management permanently, I can then make use of the cli to handle things for my use case. Is this possible?

JPersson77 commented 1 year ago

Hi again,

Yes sure. You can simply uncheck the checkbox on the main UI per device to disable automatic management. Then you can use -autoenable and the CLI etc

thomasfw commented 1 year ago

Ah yes I somehow missed that checkbox. Thanks again, I'll close this now.

thomasfw commented 4 months ago

Hi @JPersson77, not sure if there's been a regression since this discussion, but when I disable 'Automatically manage this device' in the UI the TV still powers on at startup.

JPersson77 commented 4 months ago

Hi again, can you confirm that you clicked the "apply" button after unchecking the checkbox?

thomasfw commented 4 months ago

Actually, I suspect the issue might've had more to do with my use of the cli -autodisable / -autoenable commands. The UI doesn’t sync with this by the looks of it which is probably what had me confused. I did click "apply" to (re-)disable auto management and restarted my PC, and the TV didn't turn on as desired.

However, I am still struggling to conditionally power on the TV and toggle automatic management using the cli. My startup script is essentially as below, and I have 'Automatically manage this device' disabled in the UI.


// On windows startup:
if ( LGTVIsConnected() ) {
    run("LGTV Companion.exe -poweron Device1 -autoenable Device1")
} else {
    run("LGTV Companion.exe -autodisable Device1")
}

function LGTVIsConnected(): bool {
    // Checks list of connected displays
}

The scenario below explains the issue:

I'm assuming that when I call -autodisable / -autoenable, this persists somewhere? In the docs it says that this is effective until next restart of the service, so does a system restart not reset it to whatever is configured in the UI?

JPersson77 commented 4 months ago

Hi,

Yeah you are right. -autoenable and -autodisable is per session only s d overrides the global option, and so it is not reflected in the global options in the UI. It will persist until the service is restarted, which happens at system boot or after clicking "apply", but not after resuming from sleep/hibernate. So it depends a little what you mean by "switching on the PC". Is it resume from sleep or an actual boot?

thomasfw commented 4 months ago

Ah, so from my perspective I've been doing a full shutdown, but after checking the logs and some googling I see that Windows 10/11 has fast startup enabled by default, which saves the OS state across shutdown/startup. You can see this in the first log below (System is resuming from low power state). This is preventing the LGTVCompanion service from restarting as you explained is the case for sleep/hibernation, even when doing a full shutdown.

Seeing as this is the default power setting in Windows, maybe the LGTVCompanion service can be updated to detect this on startup and manually restart itself if necessary before doing anything else.. if that's possible.

I've left fast startup disabled for now but would prefer to leave it on if it's possible to find a fix for this.


Fast Startup Enabled (windows default)

You can see that the power on command is sent after the system is turned on again as the service didn't restart. There are some other errors after this point in the log but the TV did switch on.

📄 Log Output ``` [Thu Jul 11 09:32:13][-I--][ System ] --- LGTV Companion Service has started (v 4.0.5) --------------------------- [ . . ][D---][config.json] { [ . . ][D---][config.json] "Device1": { [ . . ][D---][config.json] "Enabled": false, [ . . ][D---][config.json] "HDMIinputcontrol": true, [ . . ][D---][config.json] "IP": "192.168.50.8", [ . . ][D---][config.json] "MAC": [ [ . . ][D---][config.json] "20:28:BC:12:12:2E" [ . . ][D---][config.json] ], [ . . ][D---][config.json] "Name": "[LG] webOS TV OLED65C14LB", [ . . ][D---][config.json] "NewSockConnect": true, [ . . ][D---][config.json] "OnlyTurnOffIfCurrentHDMIInputNumberIs": 1, [ . . ][D---][config.json] "PersistentConnectionLevel": 0, [ . . ][D---][config.json] "SessionKey": "644863f22f622040e81c1efe44f4354b", [ . . ][D---][config.json] "SetHDMIInputOnResume": false, [ . . ][D---][config.json] "SetHDMIInputOnResumeToNumber": 1, [ . . ][D---][config.json] "Subnet": "255.255.255.0", [ . . ][D---][config.json] "WOL": 4 [ . . ][D---][config.json] }, [ . . ][D---][config.json] "LGTV Companion": { [ . . ][D---][config.json] "AdhereDisplayTopology": false, [ . . ][D---][config.json] "AutoUpdate": true, [ . . ][D---][config.json] "BlankWhenIdle": false, [ . . ][D---][config.json] "BlankWhenIdleDelay": 10, [ . . ][D---][config.json] "ExternalAPI": false, [ . . ][D---][config.json] "IdleFsExclusionsEnabled": false, [ . . ][D---][config.json] "IdleFullscreen": false, [ . . ][D---][config.json] "IdleWhiteListEnabled": false, [ . . ][D---][config.json] "KeepTopologyOnBoot": false, [ . . ][D---][config.json] "LogLevel": 4, [ . . ][D---][config.json] "MuteSpeakers": false, [ . . ][D---][config.json] "PowerOnTimeOut": 40, [ . . ][D---][config.json] "RemoteStream": false, [ . . ][D---][config.json] "RemoteStreamPowerOff": true, [ . . ][D---][config.json] "TimingShutdown": 0, [ . . ][D---][config.json] "Version": 3 [ . . ][D---][config.json] } [ . . ][D---][config.json] } [ . . ][D---][ System ] Host IP: 192.168.50.235/24 [ . . ][-I--][ PWR ] *** System requests displays to power on [ . . ][D---][ IPC ] Received IPC/CLI: -daemon 1 started [ . . ][D---][ Daemon 1 ] Daemon started! [ . 09:38:54][D---][ IPC ] Received IPC/CLI: -autoenable Device1 [ . . ][-I--][ CLI ] Automatic management is temporarily enabled (effective until restart of service): Device1 [ . 09:39:56][D---][ System ] System shutdown detected (power off) [ . 09:39:58][-I--][ PWR ] *** System requests displays to power off [ . . ][D---][[LG] webOS ] Enqueueing work of type: 2 [ . . ][D---][ System ] Creating a new thread pool - 2 threads [ . . ][D---][[LG] webOS ] --- Starting work: POWER OFF ----------------- [ . . ][D---][[LG] webOS ] > > > SEND > > >: [webOS handshake] [ . . ][D---][[LG] webOS ] < < < RECV < < <: {"type":"registered","id":"register_0","payload":{"client-key":"644863f22f622040e81c1efe44f4354b"}} [ . . ][D---][[LG] webOS ] > > > SEND > > >: {"type":"request","id":"getPowerState","uri":"ssap://com.webos.service.tvpower/power/getPowerState","payload":{}} [ . . ][D---][[LG] webOS ] < < < RECV < < <: {"type":"response","id":"getPowerState","payload":{"returnValue":true,"state":"Active"}} [ . . ][D---][[LG] webOS ] > > > SEND > > >: {"type":"request","id":"getForegroundApp","uri":"ssap://com.webos.applicationManager/getForegroundAppInfo","payload":{}} [ . . ][D---][[LG] webOS ] < < < RECV < < <: {"type":"response","id":"getForegroundApp","payload":{"appId":"com.webos.app.hdmi1","returnValue":true,"windowId":"","processId":""}} [ . . ][-I--][[LG] webOS ] HDMI input 1 is active. Device will be turned off [ . . ][D---][[LG] webOS ] > > > SEND > > >: {"type":"request","id":"powerToggle","uri":"ssap://system/turnOff","payload":{}} [ . 09:39:59][-I--][ PWR ] *** System is shutting down (suspending to low power mode) [ . . ][D---][[LG] webOS ] < < < RECV < < <: {"type":"response","id":"powerToggle","payload":{"returnValue":true}} [ . . ][-I--][[LG] webOS ] Power state is OFF [ . . ][D---][[LG] webOS ] Work queue is empty [ . . ][D---][[LG] webOS ] Closing connection [ . 09:40:48][-I--][ PWR ] *** System is resuming from low power state [ . 09:40:49][-I--][ PWR ] *** System requests displays to power on [ . . ][D---][[LG] webOS ] Enqueueing work of type: 1 [ . . ][D---][[LG] webOS ] --- Starting work: POWER ON ----------------- [ . . ][D---][[LG] webOS ] > > > SEND > > >: {"type":"request","id":"getPowerState","uri":"ssap://com.webos.service.tvpower/power/getPowerState","payload":{}} [ . . ][D---][[LG] webOS ] The network connection was aborted by the local system (onClose) [ . . ][D---][[LG] webOS ] Failed to send data during POWER ON due to invalid socket / lost connection. [ . . ][D---][[LG] webOS ] The socket was closed due to a timeout (onRead) [ . . ][D---][[LG] webOS ] Failed to send data during POWER ON due to invalid socket / lost connection. [ . . ][D---][[LG] webOS ] The I/O operation has been aborted because of either a thread exit or an application request (onRetryConnection) [ . . ][D---][[LG] webOS ] Failed to send data during POWER ON due to invalid socket / lost connection. [ . . ][D---][[LG] webOS ] The I/O operation has been aborted because of either a thread exit or an application request (onRetryConnection) [ . . ][D---][[LG] webOS ] Failed to send data during POWER ON due to invalid socket / lost connection. [ . . ][D---][[LG] webOS ] The I/O operation has been aborted because of either a thread exit or an application request (onRetryConnection) ```

Fast Startup Disabled

After temporarily disabling fast startup in Windows, I followed the same steps and confirm that the LGTVCompanion service restarted on startup, and the LG TV did not switch on.

📄 Log Output (no fast startup) ``` [Thu Jul 11 10:01:10][-I--][ System ] --- LGTV Companion Service has started (v 4.0.5) --------------------------- [ . . ][D---][config.json] { [ . . ][D---][config.json] "Device1": { [ . . ][D---][config.json] "Enabled": false, [ . . ][D---][config.json] "HDMIinputcontrol": true, [ . . ][D---][config.json] "IP": "192.168.50.8", [ . . ][D---][config.json] "MAC": [ [ . . ][D---][config.json] "20:28:BC:12:12:2E" [ . . ][D---][config.json] ], [ . . ][D---][config.json] "Name": "[LG] webOS TV OLED65C14LB", [ . . ][D---][config.json] "NewSockConnect": true, [ . . ][D---][config.json] "OnlyTurnOffIfCurrentHDMIInputNumberIs": 1, [ . . ][D---][config.json] "PersistentConnectionLevel": 0, [ . . ][D---][config.json] "SessionKey": "644863f22f622040e81c1efe44f4354b", [ . . ][D---][config.json] "SetHDMIInputOnResume": false, [ . . ][D---][config.json] "SetHDMIInputOnResumeToNumber": 1, [ . . ][D---][config.json] "Subnet": "255.255.255.0", [ . . ][D---][config.json] "WOL": 4 [ . . ][D---][config.json] }, [ . . ][D---][config.json] "LGTV Companion": { [ . . ][D---][config.json] "AdhereDisplayTopology": false, [ . . ][D---][config.json] "AutoUpdate": true, [ . . ][D---][config.json] "BlankWhenIdle": false, [ . . ][D---][config.json] "BlankWhenIdleDelay": 10, [ . . ][D---][config.json] "ExternalAPI": false, [ . . ][D---][config.json] "IdleFsExclusionsEnabled": false, [ . . ][D---][config.json] "IdleFullscreen": false, [ . . ][D---][config.json] "IdleWhiteListEnabled": false, [ . . ][D---][config.json] "KeepTopologyOnBoot": false, [ . . ][D---][config.json] "LogLevel": 4, [ . . ][D---][config.json] "MuteSpeakers": false, [ . . ][D---][config.json] "PowerOnTimeOut": 40, [ . . ][D---][config.json] "RemoteStream": false, [ . . ][D---][config.json] "RemoteStreamPowerOff": true, [ . . ][D---][config.json] "TimingShutdown": 0, [ . . ][D---][config.json] "Version": 3 [ . . ][D---][config.json] } [ . . ][D---][config.json] } [ . . ][D---][ System ] Host IP: 192.168.50.235/24 [ . . ][-I--][ PWR ] *** System requests displays to power on [ . . ][D---][ IPC ] Received IPC/CLI: -daemon 2 started [ . . ][D---][ Daemon 2 ] Daemon started! [ . 10:01:58][D---][ IPC ] Received IPC/CLI: -autoenable device1 [ . . ][-I--][ CLI ] Automatic management is temporarily enabled (effective until restart of service): Device1 [ . 10:02:28][---E][ PWR ] Did not receive the anticipated event subscription callback prior to shutting down. Unable to determine if system is shutting down or restarting! [ . . ][D---][[LG] webOS ] Enqueueing work of type: 2 [ . . ][D---][ System ] Creating a new thread pool - 2 threads [ . . ][D---][[LG] webOS ] --- Starting work: POWER OFF ----------------- [ . . ][D---][[LG] webOS ] The socket was closed due to a timeout (onSSLhandshake) [ . . ][D---][[LG] webOS ] Failed to send data due to invalid socket / lost connection [ . . ][D---][[LG] webOS ] Retrying connection... [ . . ][D---][[LG] webOS ] The socket was closed due to a timeout (onConnect) [ . . ][D---][[LG] webOS ] Failed to send data due to invalid socket / lost connection [ . . ][D---][[LG] webOS ] Retrying connection... [ . . ][D---][[LG] webOS ] The socket was closed due to a timeout (onConnect) [ . . ][--W-][[LG] webOS ] Retried twice but failed to perform work of type 2. Aborting! [ . . ][D---][[LG] webOS ] Work queue is empty [ . . ][D---][[LG] webOS ] Closing connection. Socket is already closed [ . 10:02:30][-I--][ System ] The service has terminated [Thu Jul 11 10:04:05][-I--][ System ] --- LGTV Companion Service has started (v 4.0.5) --------------------------- [ . . ][D---][config.json] { [ . . ][D---][config.json] "Device1": { [ . . ][D---][config.json] "Enabled": false, [ . . ][D---][config.json] "HDMIinputcontrol": true, [ . . ][D---][config.json] "IP": "192.168.50.8", [ . . ][D---][config.json] "MAC": [ [ . . ][D---][config.json] "20:28:BC:12:12:2E" [ . . ][D---][config.json] ], [ . . ][D---][config.json] "Name": "[LG] webOS TV OLED65C14LB", [ . . ][D---][config.json] "NewSockConnect": true, [ . . ][D---][config.json] "OnlyTurnOffIfCurrentHDMIInputNumberIs": 1, [ . . ][D---][config.json] "PersistentConnectionLevel": 0, [ . . ][D---][config.json] "SessionKey": "644863f22f622040e81c1efe44f4354b", [ . . ][D---][config.json] "SetHDMIInputOnResume": false, [ . . ][D---][config.json] "SetHDMIInputOnResumeToNumber": 1, [ . . ][D---][config.json] "Subnet": "255.255.255.0", [ . . ][D---][config.json] "WOL": 4 [ . . ][D---][config.json] }, [ . . ][D---][config.json] "LGTV Companion": { [ . . ][D---][config.json] "AdhereDisplayTopology": false, [ . . ][D---][config.json] "AutoUpdate": true, [ . . ][D---][config.json] "BlankWhenIdle": false, [ . . ][D---][config.json] "BlankWhenIdleDelay": 10, [ . . ][D---][config.json] "ExternalAPI": false, [ . . ][D---][config.json] "IdleFsExclusionsEnabled": false, [ . . ][D---][config.json] "IdleFullscreen": false, [ . . ][D---][config.json] "IdleWhiteListEnabled": false, [ . . ][D---][config.json] "KeepTopologyOnBoot": false, [ . . ][D---][config.json] "LogLevel": 4, [ . . ][D---][config.json] "MuteSpeakers": false, [ . . ][D---][config.json] "PowerOnTimeOut": 40, [ . . ][D---][config.json] "RemoteStream": false, [ . . ][D---][config.json] "RemoteStreamPowerOff": true, [ . . ][D---][config.json] "TimingShutdown": 0, [ . . ][D---][config.json] "Version": 3 [ . . ][D---][config.json] } [ . . ][D---][config.json] } [ . . ][-I--][ PWR ] *** System requests displays to power on [ . 10:04:17][D---][ IPC ] Received IPC/CLI: -daemon 1 started [ . . ][D---][ Daemon 1 ] Daemon started! ```

Also not sure if this is related to disabling fast startup, but the TV is no longer switching off when I power down the PC, as you can see in the log. I'll look into this some more anyway.

JPersson77 commented 4 months ago

Hey, yeah that would explain the observed behaviour.

Starting with the last issue - I can see that, with fast startup disabled, the app had issues leading to 1) the app cpuld not determine whether the shutdown was a reboot or shutdown and 2) the app could not turn the TV off due to communications errors. Both of these can likely be fixed by setting the shutdown timing to "delayed" and/or enabling persistent connections.

Regarding the restart of the service. The service is already loaded in memory and operating, so enforcing a restart on resume from hibernate/fast boot is not really desirable.

Thinking out loud, here are some ways, to achieve what you want. a) I could redefine what a session means, so that the -autoenable/-autodisable commands are reset after a resume. b) I could add additional parameters for the user to determine the behaviour. c) You could expand on your script to, using the LGTVC API, to send -autoenable and -autodisable on various system events (boot/resume/suspend/shutdown). Or you could use other means of detecting these events yourself in the script if you don't want to use the LGTVC implementation.

I will think about a nice implementation for a) and b) however. c) you can work with immediately if you'd like. Can you share the code for detecting availability of the TV (function LGTVIsConnected()) ?

thomasfw commented 4 months ago

Thanks for the reply. Option (a) sounds logical to me, assuming it would Distinguish Fast Startup from Wake-from-Hibernation and sleep. Imo -autoenable/-autodisable should be reset after a full power cycle, not on wake from sleep/hibernation.

My LGTVIsConnected() is below (ahk v2). It's rudimentary but works for my needs as I only have one LG display (where name matches "LG TV"):

isLGTVConnected()
{
  ; This is the string we search for in connected monitor names:
  LGTVNameIdentifier := "LG TV"
  WmiMonitorNames:=Map(), i:=0
  Wmi:=ComObjGet("winmgmts:\\.\root\WMI")
  For MonitorID in Wmi.ExecQuery("SELECT * FROM WmiMonitorID WHERE Active=TRUE")
  {
      if (!MonitorID.UserFriendlyName) {
          continue
      }
      UserFriendlyName := ""
      For N in MonitorID.UserFriendlyName.Clone() {
        UserFriendlyName .= Chr(N)
      }
      WmiMonitorNames[++i] := UserFriendlyName
  }
  hasConnectedLGTV := false
  For key, monitorName in WmiMonitorNames {
    if ( InStr(monitorName, LGTVNameIdentifier, False) > 0 ) {
      hasConnectedLGTV := true
      Break
    }
  }
  return hasConnectedLGTV
}

Going back to the separate shutdown issue, I've switched shutdown timing to delayed but still having the same issue. How do I go about enabling persistent connections?

📄 Log Output (delayed shutdown) ``` [Thu Jul 11 12:20:04][-I--][ System ] --- LGTV Companion Service has started (v 4.0.5) --------------------------- [ . . ][D---][config.json] { [ . . ][D---][config.json] "Device1": { [ . . ][D---][config.json] "Enabled": false, [ . . ][D---][config.json] "HDMIinputcontrol": true, [ . . ][D---][config.json] "IP": "192.168.50.8", [ . . ][D---][config.json] "MAC": [ [ . . ][D---][config.json] "20:28:BC:12:12:2E" [ . . ][D---][config.json] ], [ . . ][D---][config.json] "Name": "[LG] webOS TV OLED65C14LB", [ . . ][D---][config.json] "NewSockConnect": true, [ . . ][D---][config.json] "OnlyTurnOffIfCurrentHDMIInputNumberIs": 1, [ . . ][D---][config.json] "PersistentConnectionLevel": 0, [ . . ][D---][config.json] "SessionKey": "644863f22f622040e81c1efe44f4354b", [ . . ][D---][config.json] "SetHDMIInputOnResume": false, [ . . ][D---][config.json] "SetHDMIInputOnResumeToNumber": 1, [ . . ][D---][config.json] "Subnet": "255.255.255.0", [ . . ][D---][config.json] "WOL": 4 [ . . ][D---][config.json] }, [ . . ][D---][config.json] "LGTV Companion": { [ . . ][D---][config.json] "AdhereDisplayTopology": false, [ . . ][D---][config.json] "AutoUpdate": true, [ . . ][D---][config.json] "BlankWhenIdle": false, [ . . ][D---][config.json] "BlankWhenIdleDelay": 10, [ . . ][D---][config.json] "ExternalAPI": false, [ . . ][D---][config.json] "IdleFsExclusionsEnabled": false, [ . . ][D---][config.json] "IdleFullscreen": false, [ . . ][D---][config.json] "IdleWhiteListEnabled": false, [ . . ][D---][config.json] "KeepTopologyOnBoot": false, [ . . ][D---][config.json] "LogLevel": 4, [ . . ][D---][config.json] "MuteSpeakers": false, [ . . ][D---][config.json] "PowerOnTimeOut": 40, [ . . ][D---][config.json] "RemoteStream": false, [ . . ][D---][config.json] "RemoteStreamPowerOff": true, [ . . ][D---][config.json] "TimingShutdown": 2, [ . . ][D---][config.json] "Version": 3 [ . . ][D---][config.json] } [ . . ][D---][config.json] } [ . . ][D---][ System ] Host IP: 192.168.50.235/24 [ . . ][-I--][ PWR ] *** System requests displays to power on [ . . ][D---][ IPC ] Received IPC/CLI: -daemon 1 started [ . . ][D---][ Daemon 1 ] Daemon started! [ . 12:20:28][D---][ IPC ] Received IPC/CLI: -poweron device1 -autoenable device1 [ . . ][-I--][ CLI ] Force power on: Device1 [ . . ][D---][[LG] webOS ] Enqueueing work of type: 1 [ . . ][D---][ System ] Creating a new thread pool - 2 threads [ . . ][-I--][ CLI ] Automatic management is temporarily enabled (effective until restart of service): Device1 [ . . ][D---][[LG] webOS ] --- Starting work: POWER ON ----------------- [ . . ][D---][[LG] webOS ] > > > SEND > > >: [webOS handshake] [ . . ][D---][[LG] webOS ] < < < RECV < < <: {"type":"registered","id":"register_0","payload":{"client-key":"644863f22f622040e81c1efe44f4354b"}} [ . . ][D---][[LG] webOS ] > > > SEND > > >: {"type":"request","id":"getPowerState","uri":"ssap://com.webos.service.tvpower/power/getPowerState","payload":{}} [ . . ][D---][[LG] webOS ] < < < RECV < < <: {"type":"response","id":"getPowerState","payload":{"returnValue":true,"state":"Active"}} [ . . ][-I--][[LG] webOS ] Power state is ON [ . . ][D---][[LG] webOS ] Work queue is empty [ . . ][D---][[LG] webOS ] Closing connection [ . . ][D---][[LG] webOS ] Socket closed gracefully [ . . ][D---][[LG] webOS ] The I/O operation has been aborted because of either a thread exit or an application request (onRead) [ . 12:21:20][D---][ System ] System shutdown detected (power off) [ . 12:21:24][-I--][ PWR ] *** System is shutting down [ . . ][D---][ System ] I/O context was stopped. Resetting! [ . . ][D---][[LG] webOS ] Enqueueing work of type: 2 [ . . ][D---][ System ] Creating a new thread pool - 2 threads [ . . ][D---][[LG] webOS ] --- Starting work: POWER OFF ----------------- [ . . ][D---][[LG] webOS ] The socket was closed due to a timeout (onSSLhandshake) [ . . ][D---][[LG] webOS ] Failed to send data due to invalid socket / lost connection [ . . ][D---][[LG] webOS ] Retrying connection... [ . . ][D---][[LG] webOS ] A socket operation was attempted to an unreachable host (onConnect) [ . . ][D---][[LG] webOS ] Failed to send data due to invalid socket / lost connection [ . . ][D---][[LG] webOS ] Retrying connection... [ . . ][D---][[LG] webOS ] A socket operation was attempted to an unreachable host (onConnect) [ . . ][--W-][[LG] webOS ] Retried twice but failed to perform work of type 2. Aborting! [ . . ][D---][[LG] webOS ] Work queue is empty [ . . ][D---][[LG] webOS ] Closing connection. Socket is already closed [ . 12:21:26][-I--][ System ] The service has terminated ```
JPersson77 commented 4 months ago

Your system now properly detected a shutdown so that is an improvement. Persistent connections are enabled in the device configuration here:

image

Thanks for the code! Going to think about what the WMI approach can add and if it should be combined with the current topology support.

As well as options a), b) as discussed above. At the moment I don't think it's much desirable to create additional routines around "fast boot", as that will add nothing to the core functionality. Still I understand that there is a difference in what -autodisable/enable does, so it should be handled better. Your link is interesting but I can't help shuddering at the thought of integrating a device kernel driver to read system IRP's 😊

Twinki14 commented 3 weeks ago

Bumping this issue, I extensively use my laptop for work and personal. When I'm using it for work in the morning I'll plug it in and my LG C4 will switch automagically, which is great and exactly what I desire, but outside of work whenever I power on my laptop for personal use in my apartment, it switches off my desktop to the HDMI it would be plugged into (Laptop), but since it isn't connected my LG C4 just switches to an HDMI that has no active connection. Forcing me to switch it back to my desktop HDMI source manually.

Gets quite annoying after sometime, to the point that it's probably easier just to remove LGTV Companion completely from my Laptop and rely on manual source switching.

I did think of some other logical solutions that might minimize the above but wouldn't rely on recognizing what type of display is connected to which port, these would be configuration options in the LG TV Companion UI