Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions LGSTrayHID/HidppDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions LGSTrayUI/LogiDeviceCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ ISubscriber<IPCMessage> subscriber
_logiDeviceViewModelFactory = logiDeviceViewModelFactory;
_subscriber = subscriber;

LoadPreviouslySelectedDevices();

_subscriber.Subscribe(x =>
{
if (x is InitMessage initMessage)
Expand All @@ -40,8 +42,6 @@ ISubscriber<IPCMessage> subscriber
OnUpdateMessage(updateMessage);
}
});

LoadPreviouslySelectedDevices();
}

private void LoadPreviouslySelectedDevices()
Expand Down Expand Up @@ -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));
}
Expand Down