Skip to content

Commit

Permalink
Fix erroneous power state during remote session
Browse files Browse the repository at this point in the history
  • Loading branch information
JPersson77 committed Jun 4, 2024
1 parent 79037f5 commit 6bf81ca
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Common/common_app_define.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// common application definitions
#define APPNAME L"LGTV Companion"
#define APP_VERSION L"4.0.2"
#define APP_VERSION L"4.0.3"
#define CONFIG_FILE L"config.json"
#define LOG_FILE L"log.txt"
#define WINDOW_CLASS_UNIQUE L"YOLOx0x0x0181818"
Expand Down
2 changes: 2 additions & 0 deletions Common/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#define EVENT_SYSTEM_BOOT 12
#define EVENT_SYSTEM_TOPOLOGY 13
#define EVENT_SYSTEM_BLANKSCREEN 14
#define EVENT_SYSTEM_REMOTE_CONNECT 15
#define EVENT_SYSTEM_REMOTE_DISCONNECT 16

// user (forced) events
#define EVENT_FORCE_DISPLAYON 30
Expand Down
53 changes: 34 additions & 19 deletions LGTV Companion Service/companion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,8 @@ void Companion::Impl::dispatchEvent(Event& event) {
if(screensaver_active_)
DEBUG("Screensaver is active during DIMMED event");
}
// process event for all devices

// process event for ALL devices
if (event.getDevices().size() == 0)
for (auto& session : sessions_)
processEvent(event, *session);
Expand All @@ -302,6 +303,12 @@ void Companion::Impl::dispatchEvent(Event& event) {
//post processing stuff
switch (event.getType())
{
case EVENT_SYSTEM_REMOTE_CONNECT:
remote_client_connected_ = true;
break;
case EVENT_SYSTEM_REMOTE_DISCONNECT:
remote_client_connected_ = false;
break;
case EVENT_SYSTEM_SHUTDOWN:
case EVENT_SYSTEM_UNSURE:
remote_client_connected_ = false;
Expand Down Expand Up @@ -432,6 +439,23 @@ void Companion::Impl::processEvent(Event& event, SessionWrapper& session)
// Process system events
switch (event.getType())
{
case EVENT_SYSTEM_REMOTE_CONNECT:
if (remote_client_connected_)
break;
if (windows_power_status_on_ == true)
{
if (prefs_.remote_streaming_host_prefer_power_off_)
work_was_enqueued = session.client_.powerOff();
else
work_was_enqueued = session.client_.blankScreen();
}
break;
case EVENT_SYSTEM_REMOTE_DISCONNECT:
if (!remote_client_connected_)
break;
if (windows_power_status_on_ == true)
work_was_enqueued = session.client_.powerOn();
break;
case EVENT_SYSTEM_REBOOT:
case EVENT_SYSTEM_RESUME:
break;
Expand Down Expand Up @@ -464,7 +488,6 @@ void Companion::Impl::processEvent(Event& event, SessionWrapper& session)
work_was_enqueued = session.client_.powerOff();

}
// work_was_enqueued = session.client_.close(true);
break;

case EVENT_SYSTEM_DISPLAYDIMMED:
Expand All @@ -476,8 +499,6 @@ void Companion::Impl::processEvent(Event& event, SessionWrapper& session)
if (windows_power_status_on_ == true)
{
work_was_enqueued = session.client_.powerOff();
// if (time(0) - time_last_suspend < 10)
// work_was_enqueued = session.client_.close(true);
}
}
break;
Expand All @@ -488,8 +509,6 @@ void Companion::Impl::processEvent(Event& event, SessionWrapper& session)
if (windows_power_status_on_ == true)
{
work_was_enqueued = session.client_.powerOff();
// if (time(0) - time_last_suspend < 10)
// work_was_enqueued = session.client_.close(true);
}
break;

Expand Down Expand Up @@ -710,25 +729,21 @@ void Companion::Impl::ipcCallback(std::wstring message)
}
else if (daemon_command == "remote_connect")
{
INFO_(daemon_number, "Remote streaming client connected. All managed devices will %1%", prefs_.remote_streaming_host_prefer_power_off_ ? "power off" : "be blanked");
event(prefs_.remote_streaming_host_prefer_power_off_ ? EVENT_SYSTEM_DISPLAYOFF : EVENT_SYSTEM_BLANKSCREEN);
remote_client_connected_ = true;
if (windows_power_status_on_)
INFO_(daemon_number, "Remote streaming client connected. All managed devices will %1%", prefs_.remote_streaming_host_prefer_power_off_ ? "power OFF" : "be blanked");
else
INFO_(daemon_number, "Remote streaming client connected. Global power status is OFF.");
event(EVENT_SYSTEM_REMOTE_CONNECT);
continue;
}
else if (daemon_command == "remote_disconnect")
{
remote_client_connected_ = false;
if (windows_power_status_on_)
{
INFO_(daemon_number, "Remote streaming client disconnected. All managed devices will power on");
event(EVENT_SYSTEM_DISPLAYON);
continue;
}
INFO_(daemon_number, "Remote streaming client disconnected. All managed devices will power ON");
else
{
INFO_(daemon_number, "Remote streaming client disconnected. All managed devices will remained power off");
continue;
}
INFO_(daemon_number, "Remote streaming client disconnected. Global power status is OFF.");
event(EVENT_SYSTEM_REMOTE_DISCONNECT);
continue;
}
else if (daemon_command == "newversion")
{
Expand Down
2 changes: 1 addition & 1 deletion LGTV Companion Setup/Product.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
<?define LGTV Companion Service_TargetDir=$(var.LGTV Companion Service.TargetDir)?><?define LGTV Companion UI_TargetDir=$(var.LGTV Companion UI.TargetDir)?>
<Product Id="AECE1670-C535-4F6F-8683-E2360D15EF0B" Name="LGTV Companion" Language="1033" Version="4.0.2" Manufacturer="J Persson" UpgradeCode="0BA17E5B-11CE-491D-B1A1-05DD2D9F610A">
<Product Id="524C2902-608C-467D-8A87-0F2638E5888A" Name="LGTV Companion" Language="1033" Version="4.0.3" Manufacturer="J Persson" UpgradeCode="0BA17E5B-11CE-491D-B1A1-05DD2D9F610A">
<Package Id="*" InstallerVersion="301" Compressed="yes" InstallScope="perMachine" Platform='x64' Description="LGTV Companion installer" InstallPrivileges="elevated" AdminImage="yes"/>
<Media Id="1" Cabinet="LGTVapp.cab" EmbedCab="yes" />

Expand Down

0 comments on commit 6bf81ca

Please sign in to comment.