Skip to content

Commit

Permalink
skeleton of configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthropohedron committed Apr 8, 2015
1 parent 481823a commit e6a0bc2
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
39 changes: 39 additions & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
@@ -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;

5 changes: 4 additions & 1 deletion lib/controller.js
Original file line number Diff line number Diff line change
@@ -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 = [
Expand All @@ -18,6 +19,7 @@ function Controller() {
topics.forEach(function(topic) {
me.observerService.addObserver(me, topic, false);
});
this.config = new Configuration();
this[" is valid "] = true;
}

Expand Down Expand Up @@ -51,6 +53,7 @@ Controller.prototype = {
topics.forEach(function(topic) {
me.observerService.removeObserver(me, topic);
});
delete this.config;
delete this[" is valid "];
return true;
}
Expand Down
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
9 changes: 9 additions & 0 deletions test/test-config.js
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit e6a0bc2

Please sign in to comment.