Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firefox SDK simple-storage and Firefox Sync

I'm currently converting a Chrome extension into a Firefox add-on and would appreciate to replicate the chrome.storage.sync feature.

However, I cannot manage to find whether the data stored by a Firefox add-on using simple-storage will be automatically synced whenever a user of the add-on is signed into Firefox Sync.

Given that all the pieces of data stored via the latter method can be found in the user profile, I presume it will... as long as the add-on is available at https://addons.mozilla.org ?

Any information on the topic would be greatly appreciated.

like image 310
flo Avatar asked Dec 25 '22 10:12

flo


1 Answers

simple-storage is not synced. But you can sync it with little effort.

The trick it to store the storage object, it is serializable by definition, as a string preference and tell to the sync service to synchronize it.

Lets name that preference syncstorage and mark it as synchronizable.

var self = require("sdk/self");
var prefs = require("sdk/preferences/service");
prefs.set("services.sync.prefs.sync.extensions." + self.id + ".syncstorage", true);

When storing something to simple-storage reflect the change to syncstorage.

var sp = require("sdk/simple-prefs");
var ss = require("sdk/simple-storage");
sp.prefs["syncstorage"] = JSON.stringify(ss.storage);

For the opposite effect watch syncstorage for changes

sp.on("syncstorage", function(prefname){
  ss.storage = JSON.parse(sp.prefs["syncstorage"]);
})

Last but not least, It would nice and perhaps mandatory to sync only with the explicit consent of the user.

like image 196
paa Avatar answered Jan 26 '23 01:01

paa