[Thunderbird] Adding and removing UI elements in restartles

Talk about add-ons and extension development.
Post Reply
omarce91
Posts: 14
Joined: May 16th, 2011, 12:48 pm

[Thunderbird] Adding and removing UI elements in restartles

Post by omarce91 »

Hi guys

I develop a restartless addon for Thunderbird. I need to add some UI elements in compose window when the addon is activated.

What I did so far is:

- at startup, add an observer on windows via nsIWindowWatcher
- at shutdown, remove window observer, and set a variable X to true
- when this observer observes domwindowopened event, add a
eventlistener to the opened window for "compose-window-init" event (when
it observes domwindowclosed, it removes the eventlistener)
- when this compose-window-init event is fired, check the
document.location of the window, if it corresponds to a message
composer:

* add the UI elements,
* or remove UI elements and remove eventListener, if X is set to true

This works well (UI is added to compose message when addon is
activated, and removed when deactivated) except the following : when
addon is deactivated then activated again, the first compose message is
not provided with the UI elements. The UI is added to the other one, but
not to the first.

Any idea on why and how to solve this ?

Thx
[I post this also on mozillacommunity and stackoverflow]
TB version: 3.6
Noitidart
Posts: 1168
Joined: September 16th, 2007, 8:01 am

Re: [Thunderbird] Adding and removing UI elements in restart

Post by Noitidart »

Instead of nsIWindowWatcher use nsIWindowsMediator windowListener its the recommended way. Heres a bootstrap template for firefox which shows a bunch of different techniques https://github.com/Noitidart/Bootstrap-Full-Skeleton
omarce91
Posts: 14
Joined: May 16th, 2011, 12:48 pm

Re: [Thunderbird] Adding and removing UI elements in restart

Post by omarce91 »

Hi,
Thanks a lot Noitidart, the skeleton is very impressive.

Indeed I found by myself what was wrong.
Some windows are already open even if not displayed.
It is then needed to go throught all wndows (with nsIWindowWatcher or nwIWindowMediator getEnumerator method) and add or del the UI depending on the called method (startup/shutdown).
The windowlistener is needed anyway to be notified when a new window is opened, and to add the UI.
TB version: 3.6
Noitidart
Posts: 1168
Joined: September 16th, 2007, 8:01 am

Re: [Thunderbird] Adding and removing UI elements in restart

Post by Noitidart »

omarce91 wrote:Hi,
Thanks a lot Noitidart, the skeleton is very impressive.

Indeed I found by myself what was wrong.
Some windows are already open even if not displayed.
It is then needed to go throught all wndows (with nsIWindowWatcher or nwIWindowMediator getEnumerator method) and add or del the UI depending on the called method (startup/shutdown).
The windowlistener is needed anyway to be notified when a new window is opened, and to add the UI.

So glad to have helped!! :) That skeleton does look a little daunting at first so thanks for taking the time to read it and solve your issue :)
Post Reply