Skip to content

Commit

Permalink
fix crash on startup when no displays are active, set thread executio…
Browse files Browse the repository at this point in the history
…n state when powering off tv on standby
  • Loading branch information
Maassoft committed Jan 30, 2021
1 parent 04d52d6 commit d2aacbb
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
2 changes: 1 addition & 1 deletion ColorControl/ColorControl.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<ProductName>ColorControl</ProductName>
<PublisherName>Maassoft</PublisherName>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.5.0.0</ApplicationVersion>
<ApplicationVersion>1.5.1.0</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<PublishWizardCompleted>true</PublishWizardCompleted>
<BootstrapperEnabled>true</BootstrapperEnabled>
Expand Down
26 changes: 23 additions & 3 deletions ColorControl/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down Expand Up @@ -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());
Expand Down
4 changes: 2 additions & 2 deletions ColorControl/NvService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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();
}
}

Expand Down
4 changes: 2 additions & 2 deletions ColorControl/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]

0 comments on commit d2aacbb

Please sign in to comment.