Fx60 compatibility: Update pref handling

- getStringPref/setStringPref are now used for strings instead of
  getComplexValue/setComplexValue
- Remove nsIPrefBranch2 reference
- If there was a pref failure during initialization, nothing was logged
  to the terminal
This commit is contained in:
Dan Stillman 2018-02-24 05:05:30 -05:00
parent b7b9a2063b
commit c1f195ebeb

View File

@ -2242,13 +2242,22 @@ Zotero.Prefs = new function(){
case branch.PREF_BOOL: case branch.PREF_BOOL:
return branch.getBoolPref(pref); return branch.getBoolPref(pref);
case branch.PREF_STRING: case branch.PREF_STRING:
return '' + branch.getComplexValue(pref, Components.interfaces.nsISupportsString); // Pre-Fx59
if (!branch.getStringPref) {
return '' + branch.getComplexValue(pref, Components.interfaces.nsISupportsString);
}
return branch.getStringPref(pref);
case branch.PREF_INT: case branch.PREF_INT:
return branch.getIntPref(pref); return branch.getIntPref(pref);
} }
} }
catch (e){ catch (e) {
throw ("Invalid preference '" + pref + "'"); // If debug system isn't yet initialized, log proper error
if (Zotero.Debug.enabled === undefined) {
dump(e + "\n\n");
}
Zotero.logError(e);
throw new Error(`Error getting preference '${pref}'`);
} }
} }
@ -2269,10 +2278,14 @@ Zotero.Prefs = new function(){
case branch.PREF_BOOL: case branch.PREF_BOOL:
return branch.setBoolPref(pref, value); return branch.setBoolPref(pref, value);
case branch.PREF_STRING: case branch.PREF_STRING:
let str = Cc["@mozilla.org/supports-string;1"] // Pre-Fx59
.createInstance(Ci.nsISupportsString); if (!branch.setStringPref) {
str.data = value; let str = Cc["@mozilla.org/supports-string;1"]
return branch.setComplexValue(pref, Ci.nsISupportsString, str); .createInstance(Ci.nsISupportsString);
str.data = value;
return branch.setComplexValue(pref, Ci.nsISupportsString, str);
}
return branch.setStringPref(pref, value);
case branch.PREF_INT: case branch.PREF_INT:
return branch.setIntPref(pref, value); return branch.setIntPref(pref, value);
@ -2284,7 +2297,14 @@ Zotero.Prefs = new function(){
} }
if (typeof value == 'string') { if (typeof value == 'string') {
Zotero.debug("Creating string pref '" + pref + "'"); Zotero.debug("Creating string pref '" + pref + "'");
return branch.setCharPref(pref, value); // Pre-Fx59
if (!branch.setStringPref) {
let str = Cc["@mozilla.org/supports-string;1"]
.createInstance(Ci.nsISupportsString);
str.data = value;
return branch.setComplexValue(pref, Ci.nsISupportsString, str);
}
return branch.setStringPref(pref, value);
} }
if (parseInt(value) == value) { if (parseInt(value) == value) {
Zotero.debug("Creating integer pref '" + pref + "'"); Zotero.debug("Creating integer pref '" + pref + "'");
@ -2294,8 +2314,12 @@ Zotero.Prefs = new function(){
} }
} }
catch (e) { catch (e) {
// If debug system isn't yet initialized, log proper error
if (Zotero.Debug.enabled === undefined) {
dump(e + "\n\n");
}
Zotero.logError(e); Zotero.logError(e);
throw new Error("Invalid preference '" + pref + "'"); throw new Error(`Error setting preference '${pref}'`);
} }
} }
@ -2414,7 +2438,6 @@ Zotero.Prefs = new function(){
// Methods to register a preferences observer // Methods to register a preferences observer
// //
function register(){ function register(){
this.prefBranch.QueryInterface(Components.interfaces.nsIPrefBranch2);
this.prefBranch.addObserver("", this, false); this.prefBranch.addObserver("", this, false);
// Register pre-set handlers // Register pre-set handlers