diff --git a/lib/config.js b/lib/config.js new file mode 100644 index 0000000..34dff93 --- /dev/null +++ b/lib/config.js @@ -0,0 +1,39 @@ +/*jslint vars: true, white: true, plusplus: true, todo: true */ +"use strict"; +var addonPrefs = require("sdk/simple-prefs").prefs; + +(function() { + var ps = require("sdk/preferences/service"); + var addonId = require("sdk/self").id; + var simpleprefs = ps.keys("extensions." + addonId); + var prefix = "services.sync.prefs.sync.extensions." + addonId + "."; + + simpleprefs.forEach(function(prefname){ + var pref = prefix + prefname; + if (!ps.has(pref)) { ps.set(pref, true); } + }); +}()); + +var defaultConfig = { + //TODO +}; + +function Configuration() { + var config = null; + try { + config = JSON.parse(addonPrefs.configJSON); + } catch (ignore) { } + if (!config) { + config = JSON.stringify(defaultConfig); + addonPrefs.configJSON = config; + config = JSON.parse(config); + } + this.config = config; +} + +Configuration.prototype = { + //TODO +}; + +exports.Configuration = Configuration; + diff --git a/lib/controller.js b/lib/controller.js index 7cdcedc..7bf78df 100644 --- a/lib/controller.js +++ b/lib/controller.js @@ -1,7 +1,8 @@ -/*jslint white: true, todo: true */ +/*jslint vars: true, white: true, plusplus: true, todo: true */ "use strict"; var util = require("./util"); +var Configuration = require("./config").Configuration; var Ci = require("chrome").Ci; var topics = [ @@ -18,6 +19,7 @@ function Controller() { topics.forEach(function(topic) { me.observerService.addObserver(me, topic, false); }); + this.config = new Configuration(); this[" is valid "] = true; } @@ -51,6 +53,7 @@ Controller.prototype = { topics.forEach(function(topic) { me.observerService.removeObserver(me, topic); }); + delete this.config; delete this[" is valid "]; return true; } diff --git a/package.json b/package.json index 50b516b..4c74806 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,13 @@ "id": "jid1-dnyWGmNL0bAoQQ", "description": "an add-on providing (most of?) Privoxy's functionality", "author": "Anthropohedron", + "preferences": [{ + "name": "configJSON", + "title": "Configuration", + "description": "Configuration object serialized to JSON", + "type": "string", + "value": "null" + }], "license": "GPL 2.0", "version": "0.1" } diff --git a/test/test-config.js b/test/test-config.js new file mode 100644 index 0000000..33f788a --- /dev/null +++ b/test/test-config.js @@ -0,0 +1,9 @@ +var Configuration = require("./config").Configuration; + +exports["test config instantiate"] = function(assert) { + var config = new Configuration(); + assert.ok(config, "Configuration instantiated"); +} + +require("sdk/test").run(exports); +