change: config.addonInstance
This commit is contained in:
		
							parent
							
								
									c1ad9c5ee7
								
							
						
					
					
						commit
						7b9e139cb8
					
				
							
								
								
									
										19
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								README.md
									
									
									
									
									
								
							@ -97,7 +97,7 @@ See [`src/modules/preferenceScript.ts`](./src/modules/preferenceScript.ts)
 | 
			
		||||
 | 
			
		||||
### PromptExamples
 | 
			
		||||
 | 
			
		||||
An Obsidian-style prompt(popup command input) module. It accepts text command to run callback, with optional display in the popup. 
 | 
			
		||||
An Obsidian-style prompt(popup command input) module. It accepts text command to run callback, with optional display in the popup.
 | 
			
		||||
 | 
			
		||||
Activate with `Shift+P`.
 | 
			
		||||
 | 
			
		||||
@ -124,18 +124,21 @@ This is also how your plugin will be released and used by others.
 | 
			
		||||
- Enter the repo folder;
 | 
			
		||||
- Modify the settings in `./package.json`, including:
 | 
			
		||||
 | 
			
		||||
```
 | 
			
		||||
```json
 | 
			
		||||
{
 | 
			
		||||
  version,
 | 
			
		||||
  author,
 | 
			
		||||
  description,
 | 
			
		||||
  homepage,
 | 
			
		||||
  config {
 | 
			
		||||
    releasepage,
 | 
			
		||||
    updaterdf,
 | 
			
		||||
    addonName,
 | 
			
		||||
    addonID,
 | 
			
		||||
    addonRef
 | 
			
		||||
    releasepage, // URL to releases(`.xpi`)
 | 
			
		||||
    updaterdf, // URL to update.json
 | 
			
		||||
    addonName, // name to be displayed in the plugin manager
 | 
			
		||||
    addonID, // ID to avoid confliction. IMPORTANT!
 | 
			
		||||
    addonRef, // e.g. Element ID prefix
 | 
			
		||||
    addonInstance // the plugin's root instance: Zotero.${addonInstance}
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
> Be careful to set the addonID and addonRef to avoid confliction.
 | 
			
		||||
@ -145,7 +148,7 @@ This is also how your plugin will be released and used by others.
 | 
			
		||||
 | 
			
		||||
> What the difference between dev & prod?
 | 
			
		||||
>
 | 
			
		||||
> - This environment variable is stored in `Zotero.AddonTemplate.data.env`. The outputs to console is disabled in prod mode.
 | 
			
		||||
> - This environment variable is stored in `Zotero.${addonInstance}.data.env`. The outputs to console is disabled in prod mode.
 | 
			
		||||
> - You can decide what users cannot see/use based on this variable.
 | 
			
		||||
 | 
			
		||||
### Release
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										2
									
								
								addon/bootstrap.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								addon/bootstrap.js
									
									
									
									
										vendored
									
									
								
							@ -106,7 +106,7 @@ function shutdown({ id, version, resourceURI, rootURI }, reason) {
 | 
			
		||||
      Components.interfaces.nsISupports
 | 
			
		||||
    ).wrappedJSObject;
 | 
			
		||||
  }
 | 
			
		||||
  Zotero.AddonTemplate.hooks.onShutdown();
 | 
			
		||||
  Zotero.__addonInstance__.hooks.onShutdown();
 | 
			
		||||
 | 
			
		||||
  Cc["@mozilla.org/intl/stringbundle;1"]
 | 
			
		||||
    .getService(Components.interfaces.nsIStringBundleService)
 | 
			
		||||
 | 
			
		||||
@ -1,6 +1,6 @@
 | 
			
		||||
<vbox
 | 
			
		||||
  id="zotero-prefpane-__addonRef__"
 | 
			
		||||
  onload="Zotero.AddonTemplate.hooks.onPrefsEvent('load', {window})"
 | 
			
		||||
  onload="Zotero.__addonInstance__.hooks.onPrefsEvent('load', {window})"
 | 
			
		||||
>
 | 
			
		||||
  <groupbox>
 | 
			
		||||
    <label><html:h2>&zotero.__addonRef__.pref.title;</html:h2></label>
 | 
			
		||||
 | 
			
		||||
@ -6,6 +6,7 @@
 | 
			
		||||
    "addonName": "Zotero Addon Template",
 | 
			
		||||
    "addonID": "addontemplate@euclpts.com",
 | 
			
		||||
    "addonRef": "addontemplate",
 | 
			
		||||
    "addonInstance": "AddonTemplate",
 | 
			
		||||
    "releasepage": "https://github.com/windingwind/zotero-addon-template/releases/latest/download/zotero-addon-template.xpi",
 | 
			
		||||
    "updaterdf": "https://raw.githubusercontent.com/windingwind/zotero-addon-template/bootstrap/update.json"
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
@ -112,6 +112,21 @@ async function main() {
 | 
			
		||||
 | 
			
		||||
  console.log("[Build] Run esbuild OK");
 | 
			
		||||
 | 
			
		||||
  const replaceFrom = [
 | 
			
		||||
    /__author__/g,
 | 
			
		||||
    /__description__/g,
 | 
			
		||||
    /__homepage__/g,
 | 
			
		||||
    /__buildVersion__/g,
 | 
			
		||||
    /__buildTime__/g,
 | 
			
		||||
  ];
 | 
			
		||||
 | 
			
		||||
  const replaceTo = [author, description, homepage, version, buildTime];
 | 
			
		||||
 | 
			
		||||
  replaceFrom.push(
 | 
			
		||||
    ...Object.keys(config).map((k) => new RegExp(`__${k}__`, "g"))
 | 
			
		||||
  );
 | 
			
		||||
  replaceTo.push(...Object.values(config));
 | 
			
		||||
 | 
			
		||||
  const optionsAddon = {
 | 
			
		||||
    files: [
 | 
			
		||||
      path.join(buildDir, "**/*.rdf"),
 | 
			
		||||
@ -126,30 +141,8 @@ async function main() {
 | 
			
		||||
      "update.json",
 | 
			
		||||
      "update.rdf",
 | 
			
		||||
    ],
 | 
			
		||||
    from: [
 | 
			
		||||
      /__author__/g,
 | 
			
		||||
      /__description__/g,
 | 
			
		||||
      /__homepage__/g,
 | 
			
		||||
      /__releasepage__/g,
 | 
			
		||||
      /__updaterdf__/g,
 | 
			
		||||
      /__addonName__/g,
 | 
			
		||||
      /__addonID__/g,
 | 
			
		||||
      /__addonRef__/g,
 | 
			
		||||
      /__buildVersion__/g,
 | 
			
		||||
      /__buildTime__/g,
 | 
			
		||||
    ],
 | 
			
		||||
    to: [
 | 
			
		||||
      author,
 | 
			
		||||
      description,
 | 
			
		||||
      homepage,
 | 
			
		||||
      config.releasepage,
 | 
			
		||||
      config.updaterdf,
 | 
			
		||||
      config.addonName,
 | 
			
		||||
      config.addonID,
 | 
			
		||||
      config.addonRef,
 | 
			
		||||
      version,
 | 
			
		||||
      buildTime,
 | 
			
		||||
    ],
 | 
			
		||||
    from: replaceFrom,
 | 
			
		||||
    to: replaceTo,
 | 
			
		||||
    countMatches: true,
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -79,7 +79,7 @@ function onShutdown(): void {
 | 
			
		||||
  ztoolkit.unregisterAll();
 | 
			
		||||
  // Remove addon object
 | 
			
		||||
  addon.data.alive = false;
 | 
			
		||||
  delete Zotero.AddonTemplate;
 | 
			
		||||
  delete Zotero[config.addonInstance];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 | 
			
		||||
@ -4,7 +4,7 @@ import { config } from "../package.json";
 | 
			
		||||
 | 
			
		||||
const basicTool = new BasicTool();
 | 
			
		||||
 | 
			
		||||
if (!basicTool.getGlobal("Zotero").AddonTemplate) {
 | 
			
		||||
if (!basicTool.getGlobal("Zotero")[config.addonInstance]) {
 | 
			
		||||
  // Set global variables
 | 
			
		||||
  _globalThis.Zotero = basicTool.getGlobal("Zotero");
 | 
			
		||||
  _globalThis.ZoteroPane = basicTool.getGlobal("ZoteroPane");
 | 
			
		||||
@ -17,7 +17,7 @@ if (!basicTool.getGlobal("Zotero").AddonTemplate) {
 | 
			
		||||
  ztoolkit.basicOptions.log.disableConsole = addon.data.env === "production";
 | 
			
		||||
  ztoolkit.UI.basicOptions.ui.enableElementJSONLog =
 | 
			
		||||
    addon.data.env === "development";
 | 
			
		||||
  Zotero.AddonTemplate = addon;
 | 
			
		||||
  Zotero[config.addonInstance] = addon;
 | 
			
		||||
  // Trigger addon hook for initialization
 | 
			
		||||
  addon.hooks.onStartup();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -112,7 +112,7 @@ export class KeyExampleFactory {
 | 
			
		||||
          id: cmdSmallerId,
 | 
			
		||||
          document,
 | 
			
		||||
          _parentId: cmdsetId,
 | 
			
		||||
          oncommand: "Zotero.AddonTemplate.hooks.onShortcuts('smaller')",
 | 
			
		||||
          oncommand: `Zotero.${config.addonInstance}.hooks.onShortcuts('smaller')`,
 | 
			
		||||
        },
 | 
			
		||||
      },
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user