chore: load config in addon.data

This commit is contained in:
windingwind 2024-11-29 10:55:23 +01:00
parent deb2cd0e07
commit d842292073
3 changed files with 21 additions and 18 deletions

View File

@ -1,3 +1,4 @@
import { config } from "../package.json";
import { ColumnOptions } from "zotero-plugin-toolkit/dist/helpers/virtualizedTable";
import { DialogHelper } from "zotero-plugin-toolkit/dist/helpers/dialog";
import hooks from "./hooks";
@ -6,6 +7,7 @@ import { createZToolkit } from "./utils/ztoolkit";
class Addon {
public data: {
alive: boolean;
config: typeof config;
// Env type, see build.js
env: "development" | "production";
ztoolkit: ZToolkit;
@ -27,6 +29,7 @@ class Addon {
constructor() {
this.data = {
alive: true,
config,
env: __env__,
ztoolkit: createZToolkit(),
};

View File

@ -5,7 +5,6 @@ import {
PromptExampleFactory,
UIExampleFactory,
} from "./modules/examples";
import { config } from "../package.json";
import { getString, initLocale } from "./utils/locale";
import { registerPrefsScripts } from "./modules/preferenceScript";
import { createZToolkit } from "./utils/ztoolkit";
@ -43,9 +42,11 @@ async function onMainWindowLoad(win: Window): Promise<void> {
addon.data.ztoolkit = createZToolkit();
// @ts-ignore This is a moz feature
win.MozXULElement.insertFTLIfNeeded(`${config.addonRef}-mainWindow.ftl`);
win.MozXULElement.insertFTLIfNeeded(
`${addon.data.config.addonRef}-mainWindow.ftl`,
);
const popupWin = new ztoolkit.ProgressWindow(config.addonName, {
const popupWin = new ztoolkit.ProgressWindow(addon.data.config.addonName, {
closeOnClick: true,
closeTime: -1,
})
@ -97,7 +98,7 @@ function onShutdown(): void {
addon.data.dialog?.window?.close();
// Remove addon object
addon.data.alive = false;
delete Zotero[config.addonInstance];
delete Zotero[addon.data.config.addonInstance];
}
/**

View File

@ -1,4 +1,3 @@
import { config } from "../../package.json";
import { getLocaleID, getString } from "../utils/locale";
function example(
@ -53,7 +52,7 @@ export class BasicExampleFactory {
@example
static exampleNotifierCallback() {
new ztoolkit.ProgressWindow(config.addonName)
new ztoolkit.ProgressWindow(addon.data.config.addonName)
.createLine({
text: "Open Tab Detected!",
type: "success",
@ -70,10 +69,10 @@ export class BasicExampleFactory {
@example
static registerPrefs() {
Zotero.PreferencePanes.register({
pluginID: config.addonID,
pluginID: addon.data.config.addonID,
src: rootURI + "content/preferences.xhtml",
label: getString("prefs-title"),
image: `chrome://${config.addonRef}/content/icons/favicon.png`,
image: `chrome://${addon.data.config.addonRef}/content/icons/favicon.png`,
});
}
}
@ -92,7 +91,7 @@ export class KeyExampleFactory {
}
});
new ztoolkit.ProgressWindow(config.addonName)
new ztoolkit.ProgressWindow(addon.data.config.addonName)
.createLine({
text: "Example Shortcuts: Alt+L/S/C",
type: "success",
@ -102,7 +101,7 @@ export class KeyExampleFactory {
@example
static exampleShortcutLargerCallback() {
new ztoolkit.ProgressWindow(config.addonName)
new ztoolkit.ProgressWindow(addon.data.config.addonName)
.createLine({
text: "Larger!",
type: "default",
@ -112,7 +111,7 @@ export class KeyExampleFactory {
@example
static exampleShortcutSmallerCallback() {
new ztoolkit.ProgressWindow(config.addonName)
new ztoolkit.ProgressWindow(addon.data.config.addonName)
.createLine({
text: "Smaller!",
type: "default",
@ -129,7 +128,7 @@ export class UIExampleFactory {
properties: {
type: "text/css",
rel: "stylesheet",
href: `chrome://${config.addonRef}/content/zoteroPane.css`,
href: `chrome://${addon.data.config.addonRef}/content/zoteroPane.css`,
},
});
doc.documentElement.appendChild(styles);
@ -138,7 +137,7 @@ export class UIExampleFactory {
@example
static registerRightClickMenuItem() {
const menuIcon = `chrome://${config.addonRef}/content/icons/favicon@0.5x.png`;
const menuIcon = `chrome://${addon.data.config.addonRef}/content/icons/favicon@0.5x.png`;
// item menuitem with icon
ztoolkit.Menu.register("item", {
tag: "menuitem",
@ -188,7 +187,7 @@ export class UIExampleFactory {
static async registerExtraColumn() {
const field = "test1";
await Zotero.ItemTreeManager.registerColumns({
pluginID: config.addonID,
pluginID: addon.data.config.addonID,
dataKey: field,
label: "text column",
dataProvider: (item: Zotero.Item, dataKey: string) => {
@ -202,7 +201,7 @@ export class UIExampleFactory {
static async registerExtraColumnWithCustomCell() {
const field = "test2";
await Zotero.ItemTreeManager.registerColumns({
pluginID: config.addonID,
pluginID: addon.data.config.addonID,
dataKey: field,
label: "custom column",
dataProvider: (item: Zotero.Item, dataKey: string) => {
@ -226,7 +225,7 @@ export class UIExampleFactory {
static registerItemPaneSection() {
Zotero.ItemPaneManager.registerSection({
paneID: "example",
pluginID: config.addonID,
pluginID: addon.data.config.addonID,
header: {
l10nID: getLocaleID("item-section-example1-head-text"),
icon: "chrome://zotero/skin/16/universal/book.svg",
@ -249,7 +248,7 @@ export class UIExampleFactory {
static async registerReaderItemPaneSection() {
Zotero.ItemPaneManager.registerSection({
paneID: "reader-example",
pluginID: config.addonID,
pluginID: addon.data.config.addonID,
header: {
l10nID: getLocaleID("item-section-example2-head-text"),
// Optional
@ -833,7 +832,7 @@ export class HelperExampleFactory {
@example
static progressWindowExample() {
new ztoolkit.ProgressWindow(config.addonName)
new ztoolkit.ProgressWindow(addon.data.config.addonName)
.createLine({
text: "ProgressWindow Example!",
type: "success",