I would like to sync the settings of my Firefox addon using require('sdk/preferences/service')
.
Here my non-working trial: package.json:
{
"title": "Test",
"name": "test",
"author": "devname",
"version": "1.0.0",
"main": "lib/main.js",
"engines": {"firefox": ">=38.0a1","fennec": ">=38.0a1"},
"license": "MPL-2.0",
"id": "[email protected]",
"permissions": {"private-browsing": true},
"dependencies": ["addon-kit"],
"preferences": [{
"title": "Color 1",
"type": "color",
"value": "#000000",
"name": "1"
}]}
lib/main.js:
const
addonid = require('sdk/self').id,
simprefs = require('sdk/simple-prefs'),
simstore = require('sdk/simple-storage'),
service = require('sdk/preferences/service'),
store = simstore.storage
;
service.set('services.sync.prefs.sync.extensions.' + addonid + '.syncy', true);
simprefs.on('1', function() {
simprefs.prefs["syncy"] = simprefs.prefs["1"];
});
})();
So, when in the Addon-Manager I set pref 1 to color #777777 then pref syncy will get the same value (visible on the about:config page).
When I use 2 Firefox profiles and register with Mozilla for syncing and install this add-on on each of them I expect that changing this value on one profile will change it on the other (so the setting on about:config -> [email protected]) - but it doesn't.
What do I do wrong?
From Mozilla Wiki about conditions to synchronize add-ons between profiles:
Currently, Sync will synchronize add-ons that meet the following criteria:
- Is an extension or theme (i.e. not a plugin)
- Is installed in the profile directory
- Is installed explicitly by the user inside of Firefox
- Is installed from a trusted URI
I think problem in 4th condition. During development your addon can`t be trusted for Firefox. But in the same article, there is a hint of a possible variant of the bypass 4th condition:
Why is Functionality Limited to Add-ons from addons.mozilla.org?
First, this is only the default behavior. The services.sync.addons.trustedSourceHostnames preference is a comma-delimited list to allow other trusted hostnames.