Skip to content

Commit

Permalink
Set up such that custom module is called in zotero client
Browse files Browse the repository at this point in the history
  • Loading branch information
diiinesh committed Aug 10, 2024
1 parent 7028eca commit 9346497
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 81 deletions.
3 changes: 2 additions & 1 deletion addon/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ async function startup({ id, version, resourceURI, rootURI }, reason) {
`${rootURI}/chrome/content/scripts/__addonRef__.js`,
ctx,
);

Zotero.__addonInstance__.hooks.onStartup();
}

Expand Down Expand Up @@ -77,4 +78,4 @@ function shutdown({ id, version, resourceURI, rootURI }, reason) {
}
}

function uninstall(data, reason) {}
function uninstall(data, reason) {}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -28,6 +28,7 @@
"update-deps": "npm update --save"
},
"dependencies": {
"zotero-plugin-scaffold": "^0.0.34",
"zotero-plugin-toolkit": "^2.3.31"
},
"devDependencies": {
Expand All @@ -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": {
Expand All @@ -55,4 +55,4 @@
}
]
}
}
}
81 changes: 4 additions & 77 deletions src/hooks.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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);
}
Expand All @@ -40,9 +22,6 @@ async function onMainWindowLoad(win: Window): Promise<void> {
// 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,
Expand All @@ -60,31 +39,13 @@ async function onMainWindowLoad(win: Window): Promise<void> {
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({
progress: 100,
text: `[100%] ${getString("startup-finish")}`,
});
popupWin.startCloseTimer(5000);

addon.hooks.onDialogEvents("dialogExample");
}

async function onMainWindowUnload(win: Window): Promise<void> {
Expand All @@ -93,11 +54,6 @@ async function onMainWindowUnload(win: Window): Promise<void> {
}

function onShutdown(): void {
ztoolkit.unregisterAll();
addon.data.dialog?.window?.close();
// Remove addon object
addon.data.alive = false;
delete Zotero[config.addonInstance];
}

/**
Expand Down Expand Up @@ -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.
Expand All @@ -187,4 +114,4 @@ export default {
onPrefsEvent,
onShortcuts,
onDialogEvents,
};
};
9 changes: 9 additions & 0 deletions src/modules/new_tab.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export class NewTabModule {
constructor() {
this.init();
}

private init() {
Zotero.debug("Initialization of NewTabModule!");
}
}

0 comments on commit 9346497

Please sign in to comment.