diff --git a/LGSTrayHID/HidppDevice.cs b/LGSTrayHID/HidppDevice.cs index 8acca00..cbd3043 100644 --- a/LGSTrayHID/HidppDevice.cs +++ b/LGSTrayHID/HidppDevice.cs @@ -151,8 +151,10 @@ private async Task InitPopulateAsync() } else { - // Device does not have a serial identifier the device name as a hash identifier - Identifier = $"{DeviceName.GetHashCode():X04}"; + // Device does not have a serial identifier, use a stable hash of the device name + var hashBytes = System.Security.Cryptography.SHA256.HashData( + System.Text.Encoding.UTF8.GetBytes(DeviceName)); + Identifier = Convert.ToHexString(hashBytes, 0, 4); } #if DEBUG diff --git a/LGSTrayUI/LogiDeviceCollection.cs b/LGSTrayUI/LogiDeviceCollection.cs index 6c84597..2901d1d 100644 --- a/LGSTrayUI/LogiDeviceCollection.cs +++ b/LGSTrayUI/LogiDeviceCollection.cs @@ -29,6 +29,8 @@ ISubscriber subscriber _logiDeviceViewModelFactory = logiDeviceViewModelFactory; _subscriber = subscriber; + LoadPreviouslySelectedDevices(); + _subscriber.Subscribe(x => { if (x is InitMessage initMessage) @@ -40,8 +42,6 @@ ISubscriber subscriber OnUpdateMessage(updateMessage); } }); - - LoadPreviouslySelectedDevices(); } private void LoadPreviouslySelectedDevices() @@ -81,7 +81,12 @@ public void OnInitMessage(InitMessage initMessage) return; } - dev = _logiDeviceViewModelFactory.CreateViewModel((x) => x.UpdateState(initMessage)); + bool wasSelected = _userSettings.SelectedDevices?.Contains(initMessage.deviceId) ?? false; + dev = _logiDeviceViewModelFactory.CreateViewModel((x) => + { + x.UpdateState(initMessage); + x.IsChecked = wasSelected; + }); Application.Current.Dispatcher.BeginInvoke(() => Devices.Add(dev)); }