Firefox SDK简单存储和Firefox同步 [英] Firefox SDK simple-storage and Firefox Sync

查看:181
本文介绍了Firefox SDK简单存储和Firefox同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在将Chrome扩展程序转换成Firefox加载项,并希望能够复制chrome.storage.sync功能。



但是,我无法管理使用简单存储将在附加组件的用户登录到 Firefox Sync



考虑到通过后一种方法存储的所有数据段在用户个人资料中找到,我认为它会...只要附加功能在 https:// addons .mozilla.org



关于这个主题的任何信息将不胜感激。

解决方案

simple-storage 未同步。但是您可以轻松地同步它。



存储存储对象的技巧,它可以被序列化定义为字符串首选项,并告诉同步服务进行同步。



让我们指定首选项 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆