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

Use storage.sync API to sync preferences across computers #30

Closed
Natim opened this issue Feb 1, 2018 · 6 comments
Closed

Use storage.sync API to sync preferences across computers #30

Natim opened this issue Feb 1, 2018 · 6 comments

Comments

@Natim
Copy link

Natim commented Feb 1, 2018

Today I switched computer and Temporary Containers was automatically installed in the new computer (thanks to Sync) but I was a bit puzzle to see that my preferences (Automatic Mode off) was not taken into account.

@Natim
Copy link
Author

Natim commented Feb 1, 2018

Following a discussion about privacy it would make sense to add an opt-in preferences to enable synchronization preferences across devices. uBlock Origin is an example of that feature.

@stoically
Copy link
Owner

stoically commented Feb 2, 2018

When activating "sync feature" the decision has to be made how to handle the initial sync

  • (A) If there's something in storage.sync just use it (already existing preferences are lost). If there's nothing in storage.sync overwrite it with what is currently in storage.local. Communicate to the user: "Your current preferences might get overwritten by preferences that are already synced"
  • (B) Just overwrite storage.sync with what's currently in storage.local. Communicate to the user: "Your current preferences will be stored to Sync"

Since it's entirely possible that Firefox Sync is not yet activated in Firefox or currently not connected when activating "sync feature", I see no reliable way of making sure that (B) will work because in case of conflict the Server always wins - if Firefox Sync got implemented like chrome (couldn't find other info on that) - and in that case it would overwrite what got written from storage.local to storage.sync with whatever comes from the Firefox Sync server. So I'd say (A) is the way to go.

Another edge-case:

  • If you have two (or more) devices running the Add-on at the same time and change a preference in one, that preference won't get loaded into the other already running Add-ons. If you then happen to change a preference on another device (without restarting the browser), you'll overwrite the preference from the first device.

    This could potentially be made less worse by always refreshing the preferences from storage.sync before giving the possibility to edit them (Icon Popup #32 would give other means of editing preferences besides the Add-on preferences itself) or by always accessing storage.sync instead of "caching" the preferences in the storage object.

@glasserc
Copy link

glasserc commented Feb 2, 2018

The current implementation uses "client wins" on synchronization of everything except for crypto keys. Of course, "server wins" and "client wins" are kind of misnomers, because all changes originate from clients. "Server wins" is really more like "first-to-server wins", and "client wins" is more like "last-to-server wins". Anyhow, we use the second of these.

All of the above solutions eventually require losing one device's set of preferences in favor of the others. Maybe it's possible to do slightly better and merge the synced data with the data stored locally. For instance, you might use a variant of B where you only migrate from storage.local to storage.sync once per device, probably by storing a flag in storage.local saying "I've already been migrated".

To mitigate the concern of race conditions with preference changes being made on two devices separately, I'd recommend only using storage.sync (as you suggest). If you have a preferences panel where you've generated HTML based on preferences, you can add a listener to storage.onChanged to update the HTML when new preferences come in.

@stoically
Copy link
Owner

stoically commented Feb 7, 2018

Anyhow, we use the second of these.

Good to know, thanks for the explanation!

All of the above solutions eventually require losing one device's set of preferences in favor of the others. Maybe it's possible to do slightly better and merge the synced data with the data stored locally.

Yeah, I guess that's why e.g. uBlock really just provides a separate "Import / Export Interface" with enabled cloud-syncing. Nothing happens automatically.

Losing preferences without you knowing why is like the worst UX that possibly can happen. So I'm personally also in favour of only providing an additional interface to "Import / Export" preferences to avoid that under any circumstances. That requires more work, of course, but I feel like it's the right thing to do.

you can add a listener to storage.onChanged

Ah, didn't know about this one, that could come in handy for that case, yeah.

@stoically
Copy link
Owner

Closing, since making this a good implementation would require a fair amount of work, for imho not enough value in return. A workaround is using the Export/Import introduced in #86. I'd be open for a PR though, if someone wants to tackle it.

@stoically
Copy link
Owner

Starting with v1.0beta7 it's possible to export/import to/from Firefox Sync.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants