kewisch / quickmove-extension

Quick Folder Move Add-on for Thunderbird
86 stars 26 forks source link

Javascript access to quickmove popup #136

Closed sbliven closed 8 months ago

sbliven commented 11 months ago

I previously was able to trigger the quickmove popup from the console with window.quickmove.openFile(). Now with Thunderbird 15 / quickmove 2.7.0 I no longer have a top-level quickmove object. Is there a new way to access extensions programmatically in TB Supernova?

For context, I am using tbkeys to launch quickmove with a keystroke, something not supported by the built-in shortcut manager.

sbliven commented 8 months ago

Maybe this should be a feature request for the ability to launch the quickmove window from javascript.

kewisch commented 8 months ago

Yeah, it is now a WebExtension. You'll need to use ExtensionManager to grab the extensions context and then call https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/browserAction/openPopup .

Untested:

    let extension = ExtensionParent.GlobalManager.getExtension(ADDON_ID);
    let api = await extension.apiManager.asyncGetAPI("browserAction", extension, "addon_parent");
    api.browserAction.openPopup();

Making it simpler is probably out of scope, so I'll close this issue. Good luck :)

sbliven commented 3 months ago

Thanks for the help, @kewisch. I've been trying to make this work on and off but I've mostly given up now. I'll post my progress in case anyone comes across this thread.

I'm currently binding the following function:

let extension = ExtensionParent.GlobalManager.getExtension('quickmove@mozilla.kewis.ch');
let api = extension.apiManager.getAPI('browserAction', extension, 'addon_parent');
console.log(`api.browserAction = ${api.browserAction}`);
api.browserAction && api.browserAction.openPopup();

This logs api.browserAction = undefined to console. I suspect it might be undefined because I'm calling from outside a user action (tbkeys doesn't use the built-in shortcut manager, so its possible it doesn't count as user-triggered).