Skip to content

Commit

Permalink
fix: default prefs
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangyu committed Jan 18, 2023
1 parent e6aa4f1 commit 623c383
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions addon/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ function install(data, reason) {}
async function startup({ id, version, resourceURI, rootURI }, reason) {
await waitForZotero();

// String 'rootURI' introduced in Zotero 7
if (!rootURI) {
rootURI = resourceURI.spec;
}

if (Zotero.platformMajorVersion >= 102) {
var aomStartup = Components.classes[
"@mozilla.org/addons/addon-manager-startup;1"
Expand All @@ -74,11 +79,10 @@ async function startup({ id, version, resourceURI, rootURI }, reason) {
["locale", "__addonRef__", "en-US", rootURI + "chrome/locale/en-US/"],
["locale", "__addonRef__", "zh-CN", rootURI + "chrome/locale/zh-CN/"],
]);
}

// String 'rootURI' introduced in Zotero 7
if (!rootURI) {
rootURI = resourceURI.spec;
} else {
if (reason == ADDON_INSTALL || reason == ADDON_ENABLE) {
setDefaultPrefs(rootURI);
}
}

// Global variables for plugin code
Expand Down Expand Up @@ -117,3 +121,27 @@ function shutdown({ id, version, resourceURI, rootURI }, reason) {
}

function uninstall(data, reason) {}

// Loads default preferences from defaults/preferences/prefs.js in Zotero 6
function setDefaultPrefs(rootURI) {
var branch = Services.prefs.getDefaultBranch("");
var obj = {
pref(pref, value) {
switch (typeof value) {
case "boolean":
branch.setBoolPref(pref, value);
break;
case "string":
branch.setStringPref(pref, value);
break;
case "number":
branch.setIntPref(pref, value);
break;
default:
Zotero.logError(`Invalid type '${typeof value}' for pref '${pref}'`);
}
},
};
Zotero.getMainWindow().console.log(rootURI + "prefs.js");
Services.scriptloader.loadSubScript(rootURI + "prefs.js", obj);
}
File renamed without changes.

0 comments on commit 623c383

Please sign in to comment.