Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add add-on installation hooks #2523

Merged
merged 3 commits into from
May 29, 2023
Merged

Add add-on installation hooks #2523

merged 3 commits into from
May 29, 2023

Conversation

abdnh
Copy link
Contributor

@abdnh abdnh commented May 26, 2023

A follow-up to #2518

This adds the addons_manager_will_install_addon and addons_manager_did_install_addon hooks. My main use case is to prevent update errors caused by the add-on holding a DB connection to some file in the add-on folder. Example usage:

def on_addon_manager_will_install_addon(manager, module):
    if module == manager.addonFromModule(__name__):
        db.close()


def on_addon_manager_did_install_addon(manager, module):
    if module == manager.addonFromModule(__name__):
        db.init()


gui_hooks.addon_manager_will_install_addon.append(
    on_addon_manager_will_install_addon
)

gui_hooks.addon_manager_did_install_addon.append(
    on_addon_manager_did_install_addon
)

Another common source of installation errors are open .pyd files coming from bundled dependencies. The AnkiHub add-on for example patches AddonManager.deleteAddon twice to work around similar errors. (I probably have a bunch of more add-ons suffering from this issue too).

dc066bb fixes a crash in .deleteAddon() when run from the update routine and OSError is thrown there.

abdnh and others added 3 commits May 26, 2023 04:33
deleteAddon() is run in the background in the update routine so it
shouldn't containg any GUI code.
@dae
Copy link
Member

dae commented May 29, 2023

Thanks Abdo!

@dae dae merged commit c87f624 into ankitects:main May 29, 2023
@abdnh abdnh deleted the addon-install-hooks branch May 29, 2023 09:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants