Skip to content

Commit

Permalink
chore: load config in addon.data
Browse files Browse the repository at this point in the history
  • Loading branch information
windingwind committed Nov 29, 2024
1 parent deb2cd0 commit d842292
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
3 changes: 3 additions & 0 deletions src/addon.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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;
Expand All @@ -27,6 +29,7 @@ class Addon {
constructor() {
this.data = {
alive: true,
config,
env: __env__,
ztoolkit: createZToolkit(),
};
Expand Down
9 changes: 5 additions & 4 deletions src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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,
})
Expand Down Expand Up @@ -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];
}

/**
Expand Down
27 changes: 13 additions & 14 deletions src/modules/examples.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { config } from "../../package.json";
import { getLocaleID, getString } from "../utils/locale";

function example(
Expand Down Expand Up @@ -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",
Expand All @@ -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`,
});
}
}
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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);
Expand All @@ -138,7 +137,7 @@ export class UIExampleFactory {

@example
static registerRightClickMenuItem() {
const menuIcon = `chrome://${config.addonRef}/content/icons/[email protected]`;
const menuIcon = `chrome://${addon.data.config.addonRef}/content/icons/[email protected]`;
// item menuitem with icon
ztoolkit.Menu.register("item", {
tag: "menuitem",
Expand Down Expand Up @@ -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) => {
Expand All @@ -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) => {
Expand All @@ -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",
Expand All @@ -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
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit d842292

Please sign in to comment.