I am working on a small extension for personal consumption and practice. What I would like to do is provide some information every time Firefox starts using a modal dialog. I know this is generally frowned upon, but this is mostly for know-how. I have a few question regarding some things---I feel like there are better ways to do them. Kindly share your wisdom:
I have created a small dialog XUL, and I have an event listener registered to the load event of the main window. To actually display the dialog, I use:
window.openDialog("chrome://myext/content/prompt.xul", "dialogname", "chrome,dialog,modal,centerscreen,resizable", params).focus();
Problem 1: I can never get the start up dialog to be on the center screen (even if I have centerscreen
enabled), it starts top left---it would be nice to have it in the middle---something like Firefox's password-on-startup request. How can I achieve that?
- I would like the modal window to open only once per session, even if there are multiple instances of Firefox. What I have done to accomplish that is, once the dialog runs, I set an extension preference, and I check that before opening another dialog on the "load" event of any new window.
Problem 2: To make sure I somehow don't have preferences set from a previous session, I try to check if this is the first window opened, and if so, I reset the preferences. Just to be safe, I also reset them on the unload event of the last window that closes. To discover the first/last load and unload, I use the nsIWindowWatcher
service, and see if I can traverse the returned enumerator:
var ww = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
.getService(Components.interfaces.nsIWindowWatcher);
var en = ww.getWindowEnumerator();
var win1 = en.getNext();
//if there is no more en.getNext(), then this is the 1st window
There has to be a better way to do this, no? Some event which only fires once per session (not per window) for example?
- If the dialog box is 开发者_开发技巧cancelled, I want Firefox to close down. Right now, I accomplish that through a simple
window.close()
associated with the cancel button of the dialog. However, since the original load (which triggered the modal dialog) is called after the page finishes loading, I can see a small glimpse of the homepage before it closes due towindow.close()
---this is not elegant. Is there an event similar to "before_page_load"? What is the proper way to accomplish this goal.
Once again, this is mostly for personal use, so kindly ignore the usability factor of a startup modal dialog.
You probably need to observe the final-ui-startup
notification, which happens before the main window opens. You do this by registering a component to observe the profile-after-change
notification, then during that notification, add yourself to observe the final-ui-startup
notification. When your component subsequently receives that notification, it can then open your modal dialog and subsequently quit the application if necessary.
精彩评论