Is it possible to programmatically set a simple-prefs
value?
Or should I be using preferences/service
which contains set(name, value)?
This is the simple-prefs
I would like to set:
{
"name": "pathToFile",
"title": "Path to file?",
"type": "directory",
"value": ""
},
White it isn't obvious from the documentation, but simple-prefs.prefs
is actually a Branch
, which in turn is a full Javascript proxy around the underlying XPCOM preference service.
So it is possible to just set any preference to a Number
(Integer
), Boolean
or String
, e.g.
const {prefs} = require("simple-prefs");
console.log("before", prefs.pref1, prefs["pref2"]);
prefs.pref1 = "some string";
prefs["pref2"] = 2;
console.log("after", prefs.pref1, prefs["pref2"]);