natsufrank 564192f678
Some checks failed
Close inactive issues / close-issues (push) Has been cancelled
copy
2025-06-10 15:11:11 +08:00

28 lines
735 B
TypeScript

export function registerNotify(types: _ZoteroTypes.Notifier.Type[]) {
const callback = {
notify: async (...data: Parameters<_ZoteroTypes.Notifier.Notify>) => {
if (!addon?.data.alive) {
unregisterNotify(notifyID);
return;
}
addon.hooks.onNotify(...data);
},
};
// Register the callback in Zotero as an item observer
const notifyID = Zotero.Notifier.registerObserver(callback, types);
// Unregister callback when the window closes (important to avoid a memory leak)
window.addEventListener(
"unload",
(e: Event) => {
unregisterNotify(notifyID);
},
false
);
}
function unregisterNotify(notifyID: string) {
Zotero.Notifier.unregisterObserver(notifyID);
}