Trigger identity event when the compose window first opens
Categories
(Thunderbird :: Add-Ons: Extensions API, enhancement)
Tracking
(Not tracked)
People
(Reporter: dreadnaut, Unassigned)
Details
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0
Steps to reproduce:
When the user opens a new compose window, Thunderbird will fill in the compose identity, but I don't think there is a way to be notified of this choice.
Actual results:
No event is raised.
Expected results:
Thunderbird could trigger the "compose-from-changed" event, so that any add-on listening on identity changes will be notified of the default selection.
In the specific case, I am working on BorderColors¹. I can update the identity color highlight when this changes thanks to #1642189, but this is only triggered when the user switches to a different identity. I have no way of setting the initial color for a new compose window.
[1] https://addons.thunderbird.net/en-GB/thunderbird/addon/bordercolors-d/
Comment 1•5 years ago
|
||
Could you not listen for the window.onCreated event?
I'm not sure how I would go from a newly created "messageCompose" window to the editor tab and then the compose identity. There is no "tabs" array when the windows.onCreated event is called. If I listen to tabs.onCreated, I can go up to the window to check its type, but still the editor is not in place, so getComposeDetails() causes gives an error "editor is null -- ext-compose.js:179".
There might be an easy way I'm overlooking here :)
Bumping this, as the issue is still open and I can't find a way around it. I cannot listen for windows.onCreated: when that event is triggered, the editor is not in place (even if the tab's status is "complete") so getComposeDetails() fails.
This snipped can be used to trigger the error:
browser.windows.onCreated.addListener(
newWindow => findIdentity(newWindow)
);
async function findIdentity(newWindow) {
if (newWindow.type == "messageCompose") {
const tabs = await browser.tabs.query({ windowId: newWindow.id });
console.log(`Trying to get the compose details for window ${newWindow.id}, tab ${tabs[0].id} (${tabs[0].status})`);
const details = await browser.compose.getComposeDetails(tabs[0].id);
console.log("New compose window with identity:", details.identityId);
}
}
The trace points to "getComposeDetails chrome://messenger/content/parent/ext-compose.js:185" (205 in tip)
function getComposeDetails(composeWindow, extension) {
let composeFields = composeWindow.GetComposeDetails();
let editor = composeWindow.GetCurrentEditor();
let details = {
// ... (other fields here)
// 🔥 fails here because editor is null
body: editor.outputToString("text/html", 0),
plainTextBody: editor.outputToString("text/plain", 0),
};
if (extension.hasPermission("accountsRead")) {
details.identityId = composeWindow.getCurrentIdentityKey();
}
return details;
}
Comment 4•5 years ago
|
||
The editor not being ready has been fixed in bug 1675012. As long as that has not landed, you can wait a little after the event has fired and before you call getComposeDetails:
https://thunderbird.topicbox.com/groups/addons/T877120d828ad8205-Meec3d6ea9d201ae6d48c11b8/error-in-getcomposedetails
Description
•