change: config.addonInstance

This commit is contained in:
xiangyu 2023-01-28 11:08:14 +08:00
parent c1ad9c5ee7
commit 7b9e139cb8
8 changed files with 35 additions and 38 deletions

View File

@ -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
View File

@ -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)

View File

@ -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>

View File

@ -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"
},

View File

@ -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,
};

View File

@ -79,7 +79,7 @@ function onShutdown(): void {
ztoolkit.unregisterAll();
// Remove addon object
addon.data.alive = false;
delete Zotero.AddonTemplate;
delete Zotero[config.addonInstance];
}
/**

View File

@ -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();
}

View File

@ -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')`,
},
},
});