Skip to content

Commit

Permalink
fix bug when no Nvidia hardware is found
Browse files Browse the repository at this point in the history
  • Loading branch information
Maassoft committed Nov 22, 2020
1 parent d00595f commit aa371d7
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 21 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.3.1.0</ApplicationVersion>
<ApplicationVersion>1.3.2.0</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<PublishWizardCompleted>true</PublishWizardCompleted>
<BootstrapperEnabled>true</BootstrapperEnabled>
Expand Down
28 changes: 12 additions & 16 deletions ColorControl/LgService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,30 +86,26 @@ public void SaveConfig()
File.WriteAllText(_configFilename, json);
}

public void RefreshDevices(Action callBack = null)
public async Task RefreshDevices(bool connect = true)
{
Utils.GetPnpDevices(LgDeviceSearchKey).ContinueWith((task) =>
var devices = await Utils.GetPnpDevices(LgDeviceSearchKey);
SetDevices(devices);
if (connect && SelectedDevice != null)
{
SetDevicesTask(task);
callBack?.Invoke();
if (callBack == null && SelectedDevice != null)
if (Config.PowerOnAfterStartup && _allowPowerOn)
{
if (Config.PowerOnAfterStartup && _allowPowerOn)
{
WakeAndConnectToSelectedDevice(0);
}
else
{
ConnectToSelectedDevice();
}
WakeAndConnectToSelectedDevice(0);
}
else
{
ConnectToSelectedDevice();
}
}
);
}

private void SetDevicesTask(Task<List<PnpDev>> task)
private void SetDevices(List<PnpDev> devices)
{
Devices = task.Result;
Devices = devices;
if (Devices?.Count > 0)
{
var preferredDevice = Devices.FirstOrDefault(x => x.MacAddress != null && x.MacAddress.Equals(Config.PreferredMacAddress)) ?? Devices[0];
Expand Down
2 changes: 1 addition & 1 deletion ColorControl/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1419,7 +1419,7 @@ private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
var devices = _lgService.Devices;
if (devices == null || !devices.Any())
{
_lgService.RefreshDevices(() => BeginInvoke(new Action(FillLgDevices)));
_lgService.RefreshDevices(false).ContinueWith((task) => BeginInvoke(new Action(FillLgDevices)));
}
else
{
Expand Down
7 changes: 6 additions & 1 deletion ColorControl/NvService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public struct NV_GPU_DITHER_CONTROL_V1
};

private Display _currentDisplay;
private bool _initialized = false;

public NvService()
{
Expand Down Expand Up @@ -193,11 +194,15 @@ public Display[] GetDisplays()
protected override void Initialize()
{
NVIDIA.Initialize();
_initialized = true;
}

protected override void Uninitialize()
{
NVIDIA.Unload();
if (_initialized)
{
NVIDIA.Unload();
}
}
}
}
18 changes: 18 additions & 0 deletions ColorControl/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ static class Program
[STAThread]
static void Main(string[] args)
{
var currentDomain = AppDomain.CurrentDomain;
// Handler for unhandled exceptions.
currentDomain.UnhandledException += GlobalUnhandledExceptionHandler;
// Handler for exceptions in threads behind forms.
Application.ThreadException += GlobalThreadExceptionHandler;

var startUpParams = StartUpParams.Parse(args);

if (startUpParams.ActivateChromeFontFix || startUpParams.DeactivateChromeFontFix)
Expand Down Expand Up @@ -51,5 +57,17 @@ static void Main(string[] args)
}
}
}

private static void GlobalUnhandledExceptionHandler(object sender, UnhandledExceptionEventArgs e)
{
var ex = (Exception)e.ExceptionObject;
MessageBox.Show("Unhandled exception: " + ex.ToLogString(Environment.StackTrace), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

private static void GlobalThreadExceptionHandler(object sender, System.Threading.ThreadExceptionEventArgs e)
{
var ex = e.Exception;
MessageBox.Show("Exception in thread: " + ex.ToLogString(Environment.StackTrace), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
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.3.1.0")]
[assembly: AssemblyFileVersion("1.3.1.0")]
[assembly: AssemblyVersion("1.3.2.0")]
[assembly: AssemblyFileVersion("1.3.2.0")]

0 comments on commit aa371d7

Please sign in to comment.