Unable to sync simple-storage for addon

I would like to make addon settings and other stored user data syncable.
Tried the following:

  1. Define a syncable pref:
    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);
  2. Reflect changes of the storage to this pref:
    simprefs.prefs[“syncy”] = JSON.stringify(store);
  3. Listen to changes on this pref for updating the storage:
    simprefs.on(‘syncy’, function() {
    store = JSON.parse(simprefs.prefs[“syncy”]);
    });

On about:config it looks fine:
services.sync.prefs.sync.extensions.test@myName.org.syncy;true
extensions.test@myName.org.syncy;{…}

But still syncing doesn’t work.
Also, when I open either a new temporary Firefox profile from the console with jpm run -b /usr/bin/firefox or another existing profile with firefox -P mySecondProfileName I get the following incomprehensible message in the console:

1461668786772 addons.xpi WARN Exception running bootstrap method startup on {fe272bd1-5f76-4ea4-8501-a05d35d823fc}: ReferenceError: invalid assignment left-hand side (resource://gre/modules/addons/XPIProvider.jsm -> jar:file:///home/mcl/.mozilla/firefox/c9wvycuh.syncy/extensions/%7Bfe272bd1-5f76-4ea4-8501-a05d35d823fc%7D.xpi!/bootstrap.js -> jar:file:///home/mcl/.mozilla/firefox/c9wvycuh.syncy/extensions/%7Bfe272bd1-5f76-4ea4-8501-a05d35d823fc%7D.xpi!/lib/ui.js:407:5) JS Stack trace: require@bootstrap.js:141:4 < @main.js:19:1 < require@bootstrap.js:141:4 < startup@bootstrap.js:28:2 < this.XPIProvider.callBootstrapMethod@XPIProvider.jsm:4658:9 < this.XPIProvider.startup@XPIProvider.jsm:2728:13 < callProvider@AddonManager.jsm:227:12 < _startProvider@AddonManager.jsm:833:5 < AddonManagerInternal.startup@AddonManager.jsm:1016:9 < this.AddonManagerPrivate.startup@AddonManager.jsm:2782:5 < amManager.prototype.observe@addonManager.js:58:7

Thanks a lot for any help

This is where the error happens. So in your ui.js file on line 407, in the 5th column. It seems you are assigning something that’s not yet defined or similar.

I can’t help you for your main problem, your setup seems correct.

Does the pref not get synced or do the changes not get through to your code (don’t appear in your simple-storage or aren’t in the pref value you get)?

Sorry, I think this warning in the console is related to a different addon (there is no ui.js in my test xpi).

Concerning the syncing:
Here is the main.js of my test addon:

(function() {

const
    addonid = require('sdk/self').id,
    simprefs = require('sdk/simple-prefs'),
    simstore = require('sdk/simple-storage'),
    service = require('sdk/preferences/service'),
    store = simstore.storage
;
**store.color** = store.color || '#ff0000';
if (simprefs.prefs["syncy"]) {
    **store.color = simprefs.prefs["syncy"];**
    simprefs.prefs["3"] = store.color;
}
**service.set**('services.sync.prefs.sync.extensions.' + addonid + '.syncy', true);
simprefs.on('syncy', function() {
    **store.color = simprefs.prefs["syncy"];**
    simprefs.prefs["3"] = store.color;
});
simprefs.on('1', function() {
    **store.color = simprefs.prefs["1"];**
    **simprefs.prefs["syncy"] = store.color;**
});

})();

In package.json:

"preferences": [ 
    { 
        "title": "Color 1", 
        "type": "color", 
        "value": "#000000", 
        "name": "1" 
    }, { 
        "title": "Color 3", 
        "type": "color", 
        "value": "#ffffff", 
        "name": "3"
    } 
]

Expected behavior:
When I change color 1 of simple-prefs (via Addon-Manager) this color is stored with simple-storage and also reflected to the synced pref (“syncy”).
When I open a window of a different Firefox profile (which is synced) then the storage should be overwritten with this synced pref and in addition (to make this overwriting visible) be reflected to pref “3”. Also the syncing of pref “syncy” should show up on about:config.

De facto behavior:
When in a FF window of profile A I change color “1” then pref “syncy” will be updated (as expected), color “3” will be updated (as expected) but when I shutdown the window of profile A and open a window of profile B (which is synced with A) this profile does not reflect (= sync) pref “syncy” (on about:config this pref does not reflect the value of profile A).