Fix device selection not persisting across restarts#151
Open
gratis-katze wants to merge 1 commit intoandyvorld:masterfrom
Open
Fix device selection not persisting across restarts#151gratis-katze wants to merge 1 commit intoandyvorld:masterfrom
gratis-katze wants to merge 1 commit intoandyvorld:masterfrom
Conversation
- Replace DeviceName.GetHashCode() with SHA256 in HidppDevice.cs; GetHashCode() is randomized per-process in .NET Core, causing the saved device ID to never match the newly computed one on restart. - Load previously selected device placeholders before subscribing to device messages to close a startup race condition. - In OnInitMessage, pre-check newly discovered devices that are already in SelectedDevices, as a belt-and-suspenders fix. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
After every PC restart, users must manually click "Rediscover Devices" and re-select their device. The battery icon either shows "Not Initialised" indefinitely or disappears entirely.
Root cause
Three issues combine to cause this:
1.
string.GetHashCode()is non-deterministic in .NET Core (primary cause)In
HidppDevice.cs, devices without HID++ feature0x0003fall back to:In .NET Core,
string.GetHashCode()is randomized per-process by design. The same device name produces a different hash on every launch, so the saved device ID never matches the newly computed one. The placeholder created byLoadPreviouslySelectedDevicesis never matched byOnInitMessage, which instead adds a second unchecked entry with the new hash — forcing the user to re-select every time.2. Startup race condition
LogiDeviceCollectionsubscribed to device messages before callingLoadPreviouslySelectedDevices(). AnInitMessagearriving in that narrow window would see an emptyDeviceslist and create an unchecked entry, after whichLoadPreviouslySelectedDeviceswould add a duplicate checked placeholder — causing aSingleOrDefaultexception on subsequent messages.3. New devices not respecting saved selections
When
OnInitMessagecreates a brand-new device entry (not found inDevices), it always setIsChecked = false, even if the device ID was inSelectedDevices.Fix
LGSTrayHID/HidppDevice.cs: ReplaceGetHashCode()withSHA256, which is deterministic across processes and restarts.LGSTrayUI/LogiDeviceCollection.cs: MoveLoadPreviouslySelectedDevices()before the subscriber setup to eliminate the race condition.LGSTrayUI/LogiDeviceCollection.cs: InOnInitMessage, pre-check newly discovered devices that are already inSelectedDevices.