fix: default prefs
see https://www.zotero.org/support/dev/zotero_7_for_developers#default_preferences
This commit is contained in:
		
							parent
							
								
									e6aa4f1b6b
								
							
						
					
					
						commit
						623c3830f5
					
				
							
								
								
									
										38
									
								
								addon/bootstrap.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										38
									
								
								addon/bootstrap.js
									
									
									
									
										vendored
									
									
								
							@ -64,6 +64,11 @@ function install(data, reason) {}
 | 
				
			|||||||
async function startup({ id, version, resourceURI, rootURI }, reason) {
 | 
					async function startup({ id, version, resourceURI, rootURI }, reason) {
 | 
				
			||||||
  await waitForZotero();
 | 
					  await waitForZotero();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // String 'rootURI' introduced in Zotero 7
 | 
				
			||||||
 | 
					  if (!rootURI) {
 | 
				
			||||||
 | 
					    rootURI = resourceURI.spec;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (Zotero.platformMajorVersion >= 102) {
 | 
					  if (Zotero.platformMajorVersion >= 102) {
 | 
				
			||||||
    var aomStartup = Components.classes[
 | 
					    var aomStartup = Components.classes[
 | 
				
			||||||
      "@mozilla.org/addons/addon-manager-startup;1"
 | 
					      "@mozilla.org/addons/addon-manager-startup;1"
 | 
				
			||||||
@ -74,11 +79,10 @@ async function startup({ id, version, resourceURI, rootURI }, reason) {
 | 
				
			|||||||
      ["locale", "__addonRef__", "en-US", rootURI + "chrome/locale/en-US/"],
 | 
					      ["locale", "__addonRef__", "en-US", rootURI + "chrome/locale/en-US/"],
 | 
				
			||||||
      ["locale", "__addonRef__", "zh-CN", rootURI + "chrome/locale/zh-CN/"],
 | 
					      ["locale", "__addonRef__", "zh-CN", rootURI + "chrome/locale/zh-CN/"],
 | 
				
			||||||
    ]);
 | 
					    ]);
 | 
				
			||||||
  }
 | 
					  } else {
 | 
				
			||||||
 | 
					    if (reason == ADDON_INSTALL || reason == ADDON_ENABLE) {
 | 
				
			||||||
  // String 'rootURI' introduced in Zotero 7
 | 
					      setDefaultPrefs(rootURI);
 | 
				
			||||||
  if (!rootURI) {
 | 
					    }
 | 
				
			||||||
    rootURI = resourceURI.spec;
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Global variables for plugin code
 | 
					  // Global variables for plugin code
 | 
				
			||||||
@ -117,3 +121,27 @@ function shutdown({ id, version, resourceURI, rootURI }, reason) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function uninstall(data, 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);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user