diff --git a/ColorControl/ColorControl.csproj b/ColorControl/ColorControl.csproj index 870daa1..9f482d1 100644 --- a/ColorControl/ColorControl.csproj +++ b/ColorControl/ColorControl.csproj @@ -27,7 +27,7 @@ ColorControl Maassoft 0 - 1.5.2.0 + 1.5.3.0 false true true diff --git a/ColorControl/LgService.cs b/ColorControl/LgService.cs index 2501075..187f7fe 100644 --- a/ColorControl/LgService.cs +++ b/ColorControl/LgService.cs @@ -21,7 +21,7 @@ class LgService private static readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger(); - public string FriendlyScreenName { get; private set; } + //public string FriendlyScreenName { get; private set; } public List Devices { get; private set; } public PnpDev SelectedDevice @@ -53,16 +53,16 @@ public LgService(string dataDir, bool allowPowerOn) LoadConfig(); LoadRemoteControlButtons(); - foreach (var screen in Screen.AllScreens) - { - var name = screen.DeviceFriendlyName(); - if (name.Contains("LG")) - { - FriendlyScreenName = name; - } - } + //foreach (var screen in Screen.AllScreens) + //{ + // var name = screen.DeviceFriendlyName(); + // if (name.Contains("LG")) + // { + // FriendlyScreenName = name; + // } + //} - RefreshDevices(); + RefreshDevices(afterStartUp: true); } ~LgService() @@ -167,10 +167,23 @@ public void SaveRemoteControlButtons() File.WriteAllText(_rcButtonsFilename, json); } - public async Task RefreshDevices(bool connect = true) + public async Task RefreshDevices(bool connect = true, bool afterStartUp = false) { var devices = await Utils.GetPnpDevices(Config.DeviceSearchKey); SetDevices(devices); + + if (afterStartUp && SelectedDevice == null && Config.PowerOnAfterStartup && !string.IsNullOrEmpty(Config.PreferredMacAddress)) + { + Logger.Debug("No device has been found, trying to wake it first..."); + + WakeSelectedDevice(Config.PreferredMacAddress); + + await Task.Delay(4000); + await RefreshDevices(); + + return; + } + if (connect && SelectedDevice != null) { if (Config.PowerOnAfterStartup && _allowPowerOn) @@ -374,11 +387,12 @@ internal async Task PowerOff() return true; } - internal void WakeSelectedDevice() + internal void WakeSelectedDevice(string macAddress = null) { - if (SelectedDevice != null) + macAddress = macAddress == null ? SelectedDevice?.MacAddress : macAddress; + if (macAddress != null) { - WOL.WakeFunction(SelectedDevice.MacAddress); + WOL.WakeFunction(macAddress); _justWokeUp = true; } else diff --git a/ColorControl/MainForm.cs b/ColorControl/MainForm.cs index 5c35278..9bfae5e 100644 --- a/ColorControl/MainForm.cs +++ b/ColorControl/MainForm.cs @@ -178,7 +178,7 @@ public MainForm(StartUpParams startUpParams) } catch (Exception e) { - Debug.WriteLine(e); + Logger.Error("Error initializing LgService: " + e.ToLogString()); } InitInfo(); diff --git a/ColorControl/Properties/AssemblyInfo.cs b/ColorControl/Properties/AssemblyInfo.cs index 7338364..fe2ca0f 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.2.0")] -[assembly: AssemblyFileVersion("1.5.2.0")] +[assembly: AssemblyVersion("1.5.3.0")] +[assembly: AssemblyFileVersion("1.5.3.0")] diff --git a/ColorControl/Utils.cs b/ColorControl/Utils.cs index a7a8363..549d8d2 100644 --- a/ColorControl/Utils.cs +++ b/ColorControl/Utils.cs @@ -236,10 +236,10 @@ public static string GetDeviceProperty(PnpObject device, string propertyName) object objValue; string value = null; - foreach (var key in device.Properties.Keys) - { - Debug.WriteLine(key); - } + //foreach (var key in device.Properties.Keys) + //{ + // Debug.WriteLine(key); + //} if (device.Properties.TryGetValue(propertyName, out objValue)) {