From d2aacbb8e04b5e86ccd73b8b697d4ffeede12c26 Mon Sep 17 00:00:00 2001 From: Vincent Maas Date: Sat, 30 Jan 2021 15:23:06 +0100 Subject: [PATCH] fix crash on startup when no displays are active, set thread execution state when powering off tv on standby --- ColorControl/ColorControl.csproj | 2 +- ColorControl/MainForm.cs | 26 ++++++++++++++++++++++--- ColorControl/NvService.cs | 4 ++-- ColorControl/Properties/AssemblyInfo.cs | 4 ++-- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/ColorControl/ColorControl.csproj b/ColorControl/ColorControl.csproj index d14bb41..a87761b 100644 --- a/ColorControl/ColorControl.csproj +++ b/ColorControl/ColorControl.csproj @@ -27,7 +27,7 @@ ColorControl Maassoft 0 - 1.5.0.0 + 1.5.1.0 false true true diff --git a/ColorControl/MainForm.cs b/ColorControl/MainForm.cs index 1be470c..1f4c499 100644 --- a/ColorControl/MainForm.cs +++ b/ColorControl/MainForm.cs @@ -225,7 +225,18 @@ private void PowerModeChanged(object sender, PowerModeChangedEventArgs e) if (_lgService.Config.PowerOffOnStandby) { - _lgService.PowerOff(); + NativeMethods.SetThreadExecutionState(NativeConstants.ES_CONTINUOUS | NativeConstants.ES_SYSTEM_REQUIRED | NativeConstants.ES_AWAYMODE_REQUIRED); + try + { + Logger.Debug("Powering off tv..."); + var task = _lgService.PowerOff(); + Utils.WaitForTask(task); + Logger.Debug("Done powering off tv"); + } + finally + { + NativeMethods.SetThreadExecutionState(NativeConstants.ES_CONTINUOUS); + } } } @@ -369,9 +380,18 @@ private void UpdateDisplayInfoItems() return; } - var text = "ColorControl"; + Display[] displays; + try + { + displays = _nvService.GetDisplays(); + } + catch (Exception e) + { + Logger.Error("Error while getting displays: " + e.ToLogString()); + return; + } - var displays = _nvService.GetDisplays(); + var text = TS_TASKNAME; foreach (var display in displays) { var id = Math.Abs((int)display.Handle.MemoryAddress.ToInt64()); diff --git a/ColorControl/NvService.cs b/ColorControl/NvService.cs index 3b33fe0..d72b156 100644 --- a/ColorControl/NvService.cs +++ b/ColorControl/NvService.cs @@ -106,7 +106,7 @@ public bool ApplyPreset(NvPreset preset, Config config) var newHdrEnabled = preset.applyHDR && (preset.HDREnabled || (preset.toggleHDR && !hdrEnabled)); var applyHdr = preset.applyHDR && (preset.toggleHDR || preset.HDREnabled != hdrEnabled); - if (preset.applyColorData && ColorDataDiffers(preset.colorData)) + if (preset.applyColorData && (ColorDataDiffers(preset.colorData) || (!newHdrEnabled && preset.applyColorData && preset.colorData.Colorimetry != ColorDataColorimetry.Auto))) { var display = GetCurrentDisplay(); if (hdrEnabled) @@ -192,7 +192,7 @@ private void SetHDRState(Display display, bool enabled, ColorData colorData = nu else if (enabled) { // Currectly there seems to be a bug that after enabling HDR via NVAPI, some settings are only applied upon opening the Display Settings... - OpenDisplaySettings(); + ////OpenDisplaySettings(); } } diff --git a/ColorControl/Properties/AssemblyInfo.cs b/ColorControl/Properties/AssemblyInfo.cs index 19c03da..e67e12c 100644 --- a/ColorControl/Properties/AssemblyInfo.cs +++ b/ColorControl/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.5.0.0")] -[assembly: AssemblyFileVersion("1.5.0.0")] +[assembly: AssemblyVersion("1.5.1.0")] +[assembly: AssemblyFileVersion("1.5.1.0")]