Unload event for Zotero 7 preference pane

Skip to first unread message

David Hoff-Vanoni

Dec 31, 2023, 2:11:15 AM12/31/23
to zotero-dev
I'm working on a plugin that uses Zotero 7's new preference pane functionality. Within my preference pane code, I'm using `Zotero.Prefs.registerObserver` to observe changes to a preference value. However, I don't know of a way to determine when my pane is unloaded so that I can call `Zotero.Prefs.unregisterObserver`. Because of this, duplicate pref observers continue to get added as I open and close the Zotero preferences window.

I've been trying to implement a workaround using MutationObserver, but I haven't had any luck yet.

Would it be possible to add an `unload` event that's sent to the preference pane similar to how `load` is currently?


David Hoff-Vanoni

Dec 31, 2023, 3:00:38 AM12/31/23
to zotero-dev
It looks like I'm able to get something working using the following in my preference pane code:

window.addEventListener('unload', doMyUnloading);

This seems to handle both of the following scenarios:
  • the preferences window is closed 
  • my plugin's preference pane is unloaded when the plugin is disabled

Is this a reasonable solution, or is there a chance I could be missing something?
Reply all
Reply to author
0 new messages