diff --git a/ColorControl/ColorControl.csproj b/ColorControl/ColorControl.csproj index a87761b..870daa1 100644 --- a/ColorControl/ColorControl.csproj +++ b/ColorControl/ColorControl.csproj @@ -27,7 +27,7 @@ ColorControl Maassoft 0 - 1.5.1.0 + 1.5.2.0 false true true diff --git a/ColorControl/MainForm.cs b/ColorControl/MainForm.cs index 1f4c499..5c35278 100644 --- a/ColorControl/MainForm.cs +++ b/ColorControl/MainForm.cs @@ -1466,7 +1466,7 @@ namespace ColorControl { if (tcMain.SelectedTab == tabLG) { - if (cbxLgDevices.Items.Count == 0) + if (cbxLgDevices.Items.Count == 0 && _lgService != null) { var devices = _lgService.Devices; if (devices == null || !devices.Any()) @@ -1694,11 +1694,11 @@ namespace ColorControl _config.DisplaySettingsDelay = (int)edtDelayDisplaySettings.Value; } - private void ApplyNvPreset(NvPreset preset) + private bool ApplyNvPreset(NvPreset preset) { if (preset == null || _nvService == null) { - return; + return false; } try { @@ -1709,10 +1709,12 @@ namespace ColorControl } UpdateDisplayInfoItems(); + return true; } catch (Exception e) { MessageForms.ErrorOk($"Error applying NVIDIA-preset ({e.TargetSite.Name}): {e.Message}"); + return false; } } @@ -2030,6 +2032,10 @@ Do you want to continue?"; private void AfterInitialized() { + ApplyNvPresetOnStartup(); + } + + private void ApplyNvPresetOnStartup(int attempts = 5) { if (_config.NvPresetId_ApplyOnStartup != 0) { var preset = _presets.FirstOrDefault(p => p.id == _config.NvPresetId_ApplyOnStartup); @@ -2037,9 +2043,24 @@ Do you want to continue?"; { _config.NvPresetId_ApplyOnStartup = 0; } - else + else if (_nvService != null) { - ApplyNvPreset(preset); + if (_nvService.HasDisplaysAttached()) + { + ApplyNvPreset(preset); + } + else + { + attempts--; + if (attempts > 0) + { + System.Threading.Tasks.Task.Run(async () => + { + await System.Threading.Tasks.Task.Delay(2000); + BeginInvoke(new Action(() => ApplyNvPresetOnStartup(attempts))); + }); + } + } } } } diff --git a/ColorControl/NvService.cs b/ColorControl/NvService.cs index d72b156..0ead587 100644 --- a/ColorControl/NvService.cs +++ b/ColorControl/NvService.cs @@ -81,6 +81,18 @@ namespace ColorControl return _currentDisplay; } + public bool HasDisplaysAttached() + { + try + { + return DisplayDevice.GetGDIPrimaryDisplayDevice() != null; + } + catch (Exception) + { + return false; + } + } + private void SetCurrentDisplay(NvPreset preset) { if (preset.primaryDisplay) @@ -99,6 +111,11 @@ namespace ColorControl { var result = true; + if (!HasDisplaysAttached()) + { + return false; + } + SetCurrentDisplay(preset); var hdrEnabled = IsHDREnabled(); diff --git a/ColorControl/Properties/AssemblyInfo.cs b/ColorControl/Properties/AssemblyInfo.cs index e67e12c..7338364 100644 --- a/ColorControl/Properties/AssemblyInfo.cs +++ b/ColorControl/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // 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.1.0")] -[assembly: AssemblyFileVersion("1.5.1.0")] +[assembly: AssemblyVersion("1.5.2.0")] +[assembly: AssemblyFileVersion("1.5.2.0")]