From 934649773bfc79b01a0e5e3040896bb1b41657b7 Mon Sep 17 00:00:00 2001 From: diiinesh Date: Sat, 10 Aug 2024 19:02:33 +0200 Subject: [PATCH] Set up such that custom module is called in zotero client --- addon/bootstrap.js | 3 +- package.json | 6 ++-- src/hooks.ts | 81 +++--------------------------------------- src/modules/new_tab.ts | 9 +++++ 4 files changed, 18 insertions(+), 81 deletions(-) create mode 100644 src/modules/new_tab.ts diff --git a/addon/bootstrap.js b/addon/bootstrap.js index 03c5493..c569087 100644 --- a/addon/bootstrap.js +++ b/addon/bootstrap.js @@ -42,6 +42,7 @@ async function startup({ id, version, resourceURI, rootURI }, reason) { `${rootURI}/chrome/content/scripts/__addonRef__.js`, ctx, ); + Zotero.__addonInstance__.hooks.onStartup(); } @@ -77,4 +78,4 @@ function shutdown({ id, version, resourceURI, rootURI }, reason) { } } -function uninstall(data, reason) {} +function uninstall(data, reason) {} \ No newline at end of file diff --git a/package.json b/package.json index fed0d1a..acebc36 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ }, "repository": { "type": "git", - "url": "git+https://github.com/diiinesh/Zotero_new_tab" + "url": "git+https://github.com/diiinesh/Zotero_new_tab.git" }, "author": "diiinesh", "bugs": { @@ -28,6 +28,7 @@ "update-deps": "npm update --save" }, "dependencies": { + "zotero-plugin-scaffold": "^0.0.34", "zotero-plugin-toolkit": "^2.3.31" }, "devDependencies": { @@ -37,7 +38,6 @@ "prettier": "^3.2.5", "typescript": "^5.4.5", "typescript-eslint": "^8.0.0-alpha.20", - "zotero-plugin-scaffold": "^0.0.26", "zotero-types": "^2.0.0" }, "prettier": { @@ -55,4 +55,4 @@ } ] } -} \ No newline at end of file +} diff --git a/src/hooks.ts b/src/hooks.ts index 1a96fd7..b711364 100644 --- a/src/hooks.ts +++ b/src/hooks.ts @@ -1,10 +1,4 @@ -import { - BasicExampleFactory, - HelperExampleFactory, - KeyExampleFactory, - PromptExampleFactory, - UIExampleFactory, -} from "./modules/examples"; +import { NewTabModule } from "./modules/new_tab"; import { config } from "../package.json"; import { getString, initLocale } from "./utils/locale"; import { registerPrefsScripts } from "./modules/preferenceScript"; @@ -17,21 +11,9 @@ async function onStartup() { Zotero.uiReadyPromise, ]); - initLocale(); + initLocale(); - BasicExampleFactory.registerPrefs(); - - BasicExampleFactory.registerNotifier(); - - KeyExampleFactory.registerShortcuts(); - - await UIExampleFactory.registerExtraColumn(); - - await UIExampleFactory.registerExtraColumnWithCustomCell(); - - UIExampleFactory.registerItemPaneSection(); - - UIExampleFactory.registerReaderItemPaneSection(); + const newTab = new NewTabModule(); await onMainWindowLoad(window); } @@ -40,9 +22,6 @@ async function onMainWindowLoad(win: Window): Promise { // Create ztoolkit for every window addon.data.ztoolkit = createZToolkit(); - // @ts-ignore This is a moz feature - window.MozXULElement.insertFTLIfNeeded(`${config.addonRef}-mainWindow.ftl`); - const popupWin = new ztoolkit.ProgressWindow(config.addonName, { closeOnClick: true, closeTime: -1, @@ -60,22 +39,6 @@ async function onMainWindowLoad(win: Window): Promise { text: `[30%] ${getString("startup-begin")}`, }); - UIExampleFactory.registerStyleSheet(); - - UIExampleFactory.registerRightClickMenuItem(); - - UIExampleFactory.registerRightClickMenuPopup(); - - UIExampleFactory.registerWindowMenuWithSeparator(); - - await UIExampleFactory.registerCustomItemBoxRow(); - - PromptExampleFactory.registerNormalCommandExample(); - - PromptExampleFactory.registerAnonymousCommandExample(); - - PromptExampleFactory.registerConditionalCommandExample(); - await Zotero.Promise.delay(1000); popupWin.changeLine({ @@ -83,8 +46,6 @@ async function onMainWindowLoad(win: Window): Promise { text: `[100%] ${getString("startup-finish")}`, }); popupWin.startCloseTimer(5000); - - addon.hooks.onDialogEvents("dialogExample"); } async function onMainWindowUnload(win: Window): Promise { @@ -93,11 +54,6 @@ async function onMainWindowUnload(win: Window): Promise { } function onShutdown(): void { - ztoolkit.unregisterAll(); - addon.data.dialog?.window?.close(); - // Remove addon object - addon.data.alive = false; - delete Zotero[config.addonInstance]; } /** @@ -140,38 +96,9 @@ async function onPrefsEvent(type: string, data: { [key: string]: any }) { } function onShortcuts(type: string) { - switch (type) { - case "larger": - KeyExampleFactory.exampleShortcutLargerCallback(); - break; - case "smaller": - KeyExampleFactory.exampleShortcutSmallerCallback(); - break; - default: - break; - } } function onDialogEvents(type: string) { - switch (type) { - case "dialogExample": - HelperExampleFactory.dialogExample(); - break; - case "clipboardExample": - HelperExampleFactory.clipboardExample(); - break; - case "filePickerExample": - HelperExampleFactory.filePickerExample(); - break; - case "progressWindowExample": - HelperExampleFactory.progressWindowExample(); - break; - case "vtableExample": - HelperExampleFactory.vtableExample(); - break; - default: - break; - } } // Add your hooks here. For element click, etc. @@ -187,4 +114,4 @@ export default { onPrefsEvent, onShortcuts, onDialogEvents, -}; +}; \ No newline at end of file diff --git a/src/modules/new_tab.ts b/src/modules/new_tab.ts new file mode 100644 index 0000000..b6e8c1a --- /dev/null +++ b/src/modules/new_tab.ts @@ -0,0 +1,9 @@ +export class NewTabModule { + constructor() { + this.init(); + } + + private init() { + Zotero.debug("Initialization of NewTabModule!"); + } +} \ No newline at end of file