Skip to content

Commit

Permalink
- Support for newest firmware,
Browse files Browse the repository at this point in the history
- NVIDIA Gamestream, Steam Link, Sunshine and RDP
- Fixed a bug where the fullscreen detection for user idle mode was triggered by the NVIDIA GFE overlay sometimes
- Improved logic for the monitor topology feature
  • Loading branch information
JPersson77 committed Jan 19, 2023
1 parent 6f1dd31 commit c320fc0
Show file tree
Hide file tree
Showing 12 changed files with 942 additions and 419 deletions.
12 changes: 6 additions & 6 deletions LGTV Companion Service/LGTV Companion Service.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>C:\Users\jorge\Programs\boost_1_75_0;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>C:\Users\jorge\Programs\boost_1_75_0;C:\Users\jorge\Programs\OpenSSL-Win64\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>C:\Users\jorge\Programs\boost_1_75_0\lib64-msvc-14.2;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>C:\Users\jorge\Programs\OpenSSL-Win64\lib\VC\static\libcrypto64MTd.lib;C:\Users\jorge\Programs\OpenSSL-Win64\lib\VC\static\libssl64MTd.lib;crypt32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>C:\Users\jorge\Programs\OpenSSL-Win64\lib;C:\Users\jorge\Programs\boost_1_75_0\lib64-msvc-14.2;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
Expand All @@ -136,16 +136,16 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>C:\Users\jorge\Programs\boost_1_75_0;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>C:\Users\jorge\Programs\boost_1_75_0;C:\Users\jorge\Programs\OpenSSL-Win64\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>C:\Users\jorge\Programs\boost_1_75_0\lib64-msvc-14.2;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>C:\Users\jorge\Programs\OpenSSL-Win64\lib\VC\static\libcrypto64MT.lib;C:\Users\jorge\Programs\OpenSSL-Win64\lib\VC\static\libssl64MT.lib;crypt32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>C:\Users\jorge\Programs\OpenSSL-Win64\lib;C:\Users\jorge\Programs\boost_1_75_0\lib64-msvc-14.2;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
Expand Down
65 changes: 29 additions & 36 deletions LGTV Companion Service/Service.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// See LGTV Companion UI.cpp for additional details

#include "Service.h"
#include <powrprof.h>

using namespace std;
using json = nlohmann::json;
Expand Down Expand Up @@ -697,9 +698,9 @@ bool ReadConfigFile()
if (!j.empty() && j.is_number())
Prefs.BlankScreenWhenIdleDelay = j.get<int>();

j = jsonPrefs[JSON_PREFS_NODE][JSON_RDP_POWEROFF];
j = jsonPrefs[JSON_PREFS_NODE][JSON_TOPOLOGYMODE];
if (!j.empty() && j.is_boolean())
Prefs.PowerOffDuringRDP = j.get<bool>();
Prefs.TopologyPreferPowerEfficiency = j.get<bool>();

Log(st);
Log("Configuration file successfully read");
Expand Down Expand Up @@ -744,6 +745,10 @@ void InitDeviceSessions()
if (item.value()["Enabled"].is_boolean())
params.Enabled = item.value()["Enabled"].get<bool>();
s << "Enabled:" << (params.Enabled ? "yes" : "no") << ", ";
//NewConnectionMethod
if (item.value()["NewSockConnect"].is_boolean())
params.SSL = item.value()["NewSockConnect"].get<bool>();
s << "NewConn:" << (params.SSL ? "yes" : "no") << ", ";
//SUBNET AND WOL TYPE
if (item.value()["Subnet"].is_string())
params.Subnet = item.value()["Subnet"].get<string>();
Expand Down Expand Up @@ -1086,50 +1091,30 @@ void IPCThread(void)
}
DispatchSystemPowerEvent(SYSTEM_EVENT_USERIDLE);
}
else if (param == "remoteconnect_busy")
else if (param == "remote_connect")
{
if (Prefs.PowerOffDuringRDP)
{
Log("IPC, Remote session connected. User idle management disabled, Powering off managed displays.");
DispatchSystemPowerEvent(SYSTEM_EVENT_DISPLAYOFF);
}
else
Log("IPC, Remote session connected. User idle management disabled.");
}
else if (param == "remoteconnect_idle")
{
if (Prefs.PowerOffDuringRDP)
{
Log("IPC, Remote session connected. User idle management disabled. Powering off managed displays.");
Log("IPC, Remote streaming client connected. Managed devices will power off.");
DispatchSystemPowerEvent(SYSTEM_EVENT_DISPLAYOFF);
}
else
{
Log("IPC, Remote session connected. User idle management disabled");
DispatchSystemPowerEvent(SYSTEM_EVENT_UNBLANK);
}

for (auto& d : DeviceCtrlSessions)
{
d.RemoteHostConnected();
}
}
else if (param == "remoteconnect")
else if (param == "remote_disconnect")
{
if (Prefs.PowerOffDuringRDP)
for (auto& d : DeviceCtrlSessions)
{
Log("IPC, Remote session connected. Powering off managed displays.");
DispatchSystemPowerEvent(SYSTEM_EVENT_DISPLAYOFF);
d.RemoteHostDisconnected();
}
else
Log("IPC, Remote session connected.");
}
else if (param == "remotedisconnect")
{
if (Prefs.DisplayIsCurrentlyRequestedPoweredOnByWindows)
{
Log("IPC, Remote session disconnected. Powering on managed displays.");
Log("IPC, Remote streaming client disconnected. Powering on managed displays");
DispatchSystemPowerEvent(SYSTEM_EVENT_DISPLAYON);
}
else
{
Log("IPC, Remote session disconnected.");
}
Log("IPC, Remote streaming client disconnected. Managed displays will remain powered off,");

}
else if (param == "topology")
{
Expand All @@ -1140,15 +1125,23 @@ void IPCThread(void)
d.SetTopology(false);
}
}
else if (param == "gfe")
{

Log("IPC, NVIDIA GFE overlay fullscreen compatibility set");
}
}
else if (param1 == APP_IPC_DAEMON_TOPOLOGY)
{
if (param == "invalid")
{
Log("IPC, A recent change to the system seem to have invalidated the monitor topology configuration. "
Log("IPC, A recent change to the system have invalidated the monitor topology configuration. "
"Please run the configuration guide in the global options again to ensure correct operation.");
}
if (param == "undetermined")
{
Log("IPC, No active devices detected when verifying Windows Monitor Topology. Topology feature has been disabled");
}
if (param == "*")
{
string s;
Expand Down
18 changes: 12 additions & 6 deletions LGTV Companion Service/Service.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <SDKDDKVer.h>
#include <boost/beast.hpp>
#include <boost/asio.hpp>
//#include <boost/beast/websocket/ssl.hpp>
#include <Windows.h>
#include <system_error>
#include <memory>
Expand All @@ -13,7 +14,6 @@
#include <iomanip>
#include <string>
#include <powerbase.h>
#include <powrprof.h>
#include <Shlobj_core.h>
#include <winevt.h>
#include <thread>
Expand All @@ -26,6 +26,8 @@
#include <boost/optional.hpp>
#include <boost/utility/string_view.hpp>
#include <Iphlpapi.h>
//#include <powrprof.h>


#include "nlohmann/json.hpp"
#include "Handshake.h"
Expand All @@ -37,10 +39,11 @@
#pragma comment(lib, "Iphlpapi.lib")

#define APPNAME L"LGTV Companion"
#define APPVERSION L"1.9.0"
#define APPVERSION L"2.0.0"
#define SVCNAME L"LGTVsvc"
#define SVCDISPLAYNAME L"LGTV Companion Service"
#define SERVICE_PORT "3000"
#define SERVICE_PORT_SSL "3001"

#define JSON_PREFS_NODE "LGTV Companion"
#define JSON_EVENT_RESTART_STRINGS "LocalEventLogRestartString"
Expand All @@ -54,6 +57,7 @@
#define JSON_IDLEBLANKDELAY "BlankWhenIdleDelay"
#define JSON_RDP_POWEROFF "PowerOffDuringRDP"
#define JSON_ADHERETOPOLOGY "AdhereDisplayTopology"
#define JSON_TOPOLOGYMODE "TopologyPreferPowerEfficient"

#define SERVICE_DEPENDENCIES L"Dhcp\0Dnscache\0LanmanServer\0\0"
#define SERVICE_ACCOUNT NULL //L"NT AUTHORITY\\LocalService"
Expand All @@ -77,8 +81,7 @@
#define SYSTEM_EVENT_USERIDLE 14
#define SYSTEM_EVENT_FORCESETHDMI 15
#define SYSTEM_EVENT_BOOT 16
#define SYSTEM_EVENT_UNBLANK 17
#define SYSTEM_EVENT_TOPOLOGY 18
#define SYSTEM_EVENT_TOPOLOGY 17

#define APP_CMDLINE_ON 1
#define APP_CMDLINE_OFF 2
Expand Down Expand Up @@ -120,8 +123,8 @@ struct PREFS {
int PowerOnTimeout = 40;
bool BlankWhenIdle = false;
int BlankScreenWhenIdleDelay = 10;
bool PowerOffDuringRDP = false;
bool DisplayIsCurrentlyRequestedPoweredOnByWindows = false;
bool TopologyPreferPowerEfficiency = true;
};

struct SESSIONPARAMETERS {
Expand All @@ -140,13 +143,16 @@ struct SESSIONPARAMETERS {
int BlankScreenWhenIdleDelay = 10;
bool SetHDMIInputOnResume = false;
int SetHDMIInputOnResumeToNumber = 1;
bool SSL = true;
};

class CSession {
public:
CSession(SESSIONPARAMETERS*);
~CSession();
void Run();
void RemoteHostConnected();
void RemoteHostDisconnected();
void Stop();
void SystemEvent(DWORD, int param = 0);
SESSIONPARAMETERS GetParams();
Expand All @@ -166,7 +172,7 @@ class CSession {
void TurnOnDisplay(bool SendWOL);
void TurnOffDisplay(bool forced, bool dimmed, bool blankscreen);
void SetDisplayHdmiInput(int HdmiInput);

bool bRemoteHostConnected = false;
SESSIONPARAMETERS Parameters;
};

Expand Down
Loading

0 comments on commit c320fc0

Please sign in to comment.