Firefox SDK简单存储和Firefox同步 [英] Firefox SDK simple-storage and Firefox Sync
问题描述
我目前正在将Chrome扩展程序转换成Firefox加载项,并希望能够复制chrome.storage.sync功能。
但是,我无法管理使用简单存储将在附加组件的用户登录到 Firefox Sync 。
考虑到通过后一种方法存储的所有数据段在用户个人资料中找到,我认为它会...只要附加功能在 https:// addons .mozilla.org ?
关于这个主题的任何信息将不胜感激。
存储存储
对象的技巧,它可以被序列化定义为字符串首选项,并告诉同步服务进行同步。
让我们指定首选项 syncstorage
和将其标记为可同步。
var self = require(sdk / self);
var prefs = require(sdk / preferences / service);
prefs.set(services.sync.prefs.sync.extensions。+ self.id +.syncstorage,true);
将某些内容存储到 simple-storage
更改为 syncstorage
。
$ b
var sp = require(sdk / simple-prefs);
var ss = require(sdk / simple-storage);
sp.prefs [syncstorage] = JSON.stringify(ss.storage);
对于相反的效果,更改 syncstorage
$ b
sp.on(syncstorage,function(prefname){
ss。 storage = JSON.parse(sp.prefs [syncstorage]);
})
最后但并非最不重要的,这将是很好的,也许是强制性的同步只有用户的明确同意。
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.
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.
这篇关于Firefox SDK简单存储和Firefox同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!