mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-07-03 20:16:33 +02:00
Added export and import for settings
This commit is contained in:
parent
41d9b7073f
commit
d531abb2de
10 changed files with 149 additions and 9 deletions
|
@ -44,21 +44,40 @@
|
|||
settingDefinition.on = function on(callback){
|
||||
scope.on(name, callback);
|
||||
};
|
||||
settingDefinition.get = function getValue(){
|
||||
return settings[name];
|
||||
};
|
||||
settingDefinition.set = function setValue(newValue){
|
||||
settingDefinition.invalid = function invalid(newValue){
|
||||
if (settingDefinition.fixed){
|
||||
logging.warning("Trying to set the fixed setting", name, ":", newValue);
|
||||
return "fixed";
|
||||
}
|
||||
else if ((typeof newValue) !== (typeof settingDefinition.defaultValue)){
|
||||
logging.warning("Wrong type provided for setting", name, ":", newValue);
|
||||
return "wrongType";
|
||||
}
|
||||
else if (
|
||||
settingDefinition.options &&
|
||||
!settingDefinition.options.includes(newValue)
|
||||
){
|
||||
logging.warning("Provided value outside specified options for ", name, ":", newValue);
|
||||
return "noOption";
|
||||
}
|
||||
return false;
|
||||
};
|
||||
settingDefinition.get = function getValue(){
|
||||
return settings[name];
|
||||
};
|
||||
settingDefinition.set = function setValue(newValue){
|
||||
logging.verbose("New value for %s:", name, newValue);
|
||||
var invalid = settingDefinition.invalid(newValue);
|
||||
if (invalid){
|
||||
if (invalid === "fixed"){
|
||||
logging.warning("Trying to set the fixed setting", name, ":", newValue);
|
||||
}
|
||||
else if (invalid === "wrongType"){
|
||||
logging.warning("Wrong type provided for setting", name, ":", newValue);
|
||||
}
|
||||
else if (invalid === "noOption"){
|
||||
logging.warning("Provided value outside specified options for ", name, ":", newValue);
|
||||
}
|
||||
else {
|
||||
logging.warning("Unknown invalid state:", invalid);
|
||||
}
|
||||
}
|
||||
else {
|
||||
settings[name] = newValue;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue