Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: persist device label and fallback to it when device id is not found #1736

Merged
merged 3 commits into from
Mar 31, 2025

Conversation

myandrienko
Copy link
Contributor

@myandrienko myandrienko commented Mar 25, 2025

Overview

Device ids reported by browser are not guaranteed to state the same in between browser sessions or device reconnects. Because of that persisting device preferences based on device id is not always reliable.

In this PR we add a fallback mode to usePeristedDevicePreferences hook: if persisted device id is not found, it will try to find device by its label.

We also now save up to three latest device preferences. That allows us to prefer devices that were recently used, even if the most recently used device is no longer available.

Implementation notes

usePeristedDevicePreferences hook is updated to fall back to device labels if device id is not found.

Using labels requires browser permission, so applying and persisting settings is now postponed until permission is granted (or, more precisely, until devices list observable is populated).

Applying and persisting is now merged into a single hook to simplify timing: we shouldn't persist settings until they are applied; we also should apply settings only once.

Every device preference can be an array of up to three preferences. We go through this array looking for a device that is currently available.

To preserve user data, we still support non-array preferences. They are migrated to an array format on write.

@myandrienko myandrienko requested a review from oliverlaz March 25, 2025 16:34
@myandrienko myandrienko merged commit 27536f7 into main Mar 31, 2025
13 checks passed
@myandrienko myandrienko deleted the persist-device-label branch March 31, 2025 15:06
myandrienko added a commit that referenced this pull request Apr 1, 2025
🚂 #1736 

I forgot to also apply enabled/disabled state when applying persisted
preference. Currently only device selection is applied.
myandrienko added a commit that referenced this pull request Apr 2, 2025
### Overview

🚂 #1736 #1741

Muted state was not applied from persisted settings in some cases. This
PR fixes that.

### Implementation notes

When applying muted state from persisted settings, we use the following
values (from top priority to lowest priority):

1. Muted state from the first persisted device that is currently
available
2. The latest user-selected user state
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants