[Pkg-mozext-commits] [firetray] 121/399: * another way to preserve unload eventListeners * cleaning

David Prévot taffit at alioth.debian.org
Tue Oct 29 18:23:26 UTC 2013


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch dfsg-clean
in repository firetray.

commit a050115a18d61046e4ac3dc536b4aebc135a993f
Author: foudfou <foudil.newbie+git at gmail.com>
Date:   Thu Dec 29 21:15:54 2011 +0100

    * another way to preserve unload eventListeners
    * cleaning
---
 src/chrome/content/overlay.js |   40 +++++++++++++++++++++++++++-------------
 testing/gtk_icon_example.c    |    2 +-
 testing/message-mail-new.png  |    1 +
 testing/newmail.png           |    1 -
 4 files changed, 29 insertions(+), 15 deletions(-)

diff --git a/src/chrome/content/overlay.js b/src/chrome/content/overlay.js
index 933e3e8..e41aebd 100644
--- a/src/chrome/content/overlay.js
+++ b/src/chrome/content/overlay.js
@@ -15,10 +15,9 @@ if ("undefined" == typeof(firetray)) {
 };
 
 firetray.Main = {
+  self: function() { return this; },
 
-  onLoad: function() {
-    window.removeEventListener('load', arguments.callee, true);
-
+  onLoad: function(win) {
     // initialization code
     this.strings = document.getElementById("firetray-strings");
 
@@ -33,28 +32,26 @@ firetray.Main = {
     }
 
     let init = firetray.Handler.initialized || firetray.Handler.init();
-    firetray.Handler.registerWindow(window);
+    firetray.Handler.registerWindow(win);
 
     // update unread messages count
     if (firetray.Handler.inMailApp && firetray.Messaging.initialized)
       firetray.Messaging.updateUnreadMsgCount();
 
     // prevent window closing.
-    window.addEventListener('close', firetray.Main.onClose, true);
-    // NOTE: each new window gets a new firetray.Main, and hence listens to pref
-    // changes
+    win.addEventListener('close', firetray.Main.onClose, true);
+    // NOTE: each new window gets a new firetray.Main, and hence listens to
+    // pref changes
 
     LOG('Firetray LOADED: ' + init);
     return true;
   },
 
-  onQuit: function(e) {
-    window.removeEventListener('unload', arguments.callee, true);
-
+  onQuit: function(win) {
     // Remove observer
     firetray.Utils.prefService.removeObserver("", firetray.Main);
 
-    firetray.Handler.unregisterWindow(window);
+    firetray.Handler.unregisterWindow(win);
 
     /* NOTE: don't firetray.Handler.initialized=false here, otherwise after a
      window close, a new window will create a new handler (and hence, a new
@@ -90,5 +87,22 @@ firetray.Main = {
 // should be sufficient for a delayed Startup (no need for window.setTimeout())
 // https://developer.mozilla.org/en/XUL_School/JavaScript_Object_Management.html
 // https://developer.mozilla.org/en/Extensions/Performance_best_practices_in_extensions#Removing_Event_Listeners
-window.addEventListener('load', firetray.Main.onLoad, false);
-window.addEventListener('unload', firetray.Main.onQuit, false);
+/* NOTE: this is tricky: it seems we need to keep some reference to 'firetray'
+   outside listeners. Otherwise the following will fail: open a new window
+   twice, and close them (CTRL-w). On the second close, onQuit fails because
+   globals ('firetray', 'Ci', ...) are undefined. THIS IS BECAUSE 'firetray'
+   GETS DEFINED IN commons.js !! I could achieve the "linkage" in two ways:
+   1. bind some method of firetray.Main to itself, or 2. use handlers instead
+   of an anonymous function in the listeners: window.addEventListener('load',
+   firetray.Main.onLoad, false); */
+var firetrayMain = firetray.Main.self.bind(firetray.Main);
+window.addEventListener(
+  'load', function (e) {
+    removeEventListener('load', arguments.callee, true);
+    firetrayMain().onLoad(this); },
+  false);
+window.addEventListener(
+  'unload', function (e) {
+    removeEventListener('unload', arguments.callee, true);
+    firetrayMain().onQuit(this); },
+  false);
diff --git a/testing/gtk_icon_example.c b/testing/gtk_icon_example.c
index 46c453b..f45d1fe 100644
--- a/testing/gtk_icon_example.c
+++ b/testing/gtk_icon_example.c
@@ -71,7 +71,7 @@ static void winShowHide(GtkMenuItem *item, gpointer window)
 SetIconText(GtkStatusIcon *tray_icon, const char *text, const char *color) {
 
   // build background from image
-  GdkPixbuf* special_icon = gdk_pixbuf_new_from_file("newmail.png", NULL); // GError **error);
+  GdkPixbuf* special_icon = gdk_pixbuf_new_from_file("message-mail-new.png", NULL); // GError **error);
   GdkPixbuf *dest = gdk_pixbuf_copy(special_icon);
   int w=gdk_pixbuf_get_width(special_icon);
   int h=gdk_pixbuf_get_height(special_icon);
diff --git a/testing/message-mail-new.png b/testing/message-mail-new.png
new file mode 120000
index 0000000..a822495
--- /dev/null
+++ b/testing/message-mail-new.png
@@ -0,0 +1 @@
+../src/chrome/skin/message-mail-new.png
\ No newline at end of file
diff --git a/testing/newmail.png b/testing/newmail.png
deleted file mode 120000
index 5253edf..0000000
--- a/testing/newmail.png
+++ /dev/null
@@ -1 +0,0 @@
-../src/chrome/skin/newmail.png
\ No newline at end of file

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/firetray.git



More information about the Pkg-mozext-commits mailing list