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 fin
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.