1
0
mirror of https://github.com/moparisthebest/FireTray synced 2024-12-22 05:48:49 -05:00

ctypes libs are tracked by firetray.Handler.

(sub)modules using ctypes libs just need to declare opened libs, which will be
ultimately closed by the Handler. Not only is this fancier, but also useful in
situations where we want to init()/shutdown() modules without closing libs used
by others (ex: IMStatusIcon)
This commit is contained in:
foudfou 2012-08-07 23:37:32 +02:00
parent ff7bcd4c91
commit 82fae974d1
8 changed files with 29 additions and 18 deletions

View File

@ -36,6 +36,8 @@ firetray.Handler = {
windowsCount: 0,
visibleWindowsCount: 0,
observedTopics: {},
ctypesLibs: {}, // {"lib1": lib1, "lib2": lib2}
appId: (function(){return Services.appinfo.ID;})(),
appName: (function(){return Services.appinfo.name;})(),
@ -117,7 +119,7 @@ firetray.Handler = {
firetray.Messaging.shutdown();
firetray.StatusIcon.shutdown();
firetray.Window.shutdown();
// watchout order and sufficiency of lib closings (tryCloseLibs())
this.tryCloseLibs();
firetray.Utils.removeAllObservers(this);
@ -126,6 +128,24 @@ firetray.Handler = {
return true;
},
tryCloseLibs: function() {
try {
for (libName in this.ctypesLibs) {
let lib = this.ctypesLibs[libName];
if (lib.available())
lib.close();
};
} catch(x) { F.ERROR(x); }
},
subscribeLibsForClosing: function(libs) {
for (let i=0, len=libs.length; i<len; ++i) {
let lib = libs[i];
if (!this.ctypesLibs.hasOwnProperty(lib.name))
this.ctypesLibs[lib.name] = lib;
}
},
observe: function(subject, topic, data) {
switch (topic) {
case "sessionstore-windows-restored":

View File

@ -216,15 +216,6 @@ firetray.Utils = {
timer.initWithCallback({ notify: callback },
delay, timerType);
return timer;
},
tryCloseLibs: function(libs) {
try {
libs.forEach(function(lib) {
if (lib.available())
lib.close();
});
} catch(x) { F.ERROR(x); }
}
};

View File

@ -11,7 +11,7 @@
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
*
* The Original Code is Firetray
*
* The Initial Developer of the Original Code is
@ -121,6 +121,8 @@ function ctypes_library(aName, aABIs, aDefines, aGlobal) {
}
}
this.name = aName;
this.close = function() {
F.LOG("Closing library " + aName);
library.close();

View File

@ -8,6 +8,7 @@ const Cu = Components.utils;
Cu.import("resource://firetray/ctypes/linux/gtk.jsm");
Cu.import("resource://firetray/commons.js");
firetray.Handler.subscribeLibsForClosing([gtk]);
if ("undefined" == typeof(firetray.StatusIcon))
F.ERROR("This module MUST be imported from/after StatusIcon !");
@ -32,7 +33,6 @@ firetray.GtkIcons = {
},
shutdown: function() {
firetray.Utils.tryCloseLibs([gtk]);
this.initialized = false;
},

View File

@ -13,6 +13,7 @@ Cu.import("resource://firetray/ctypes/linux/gobject.jsm");
Cu.import("resource://firetray/ctypes/linux/gio.jsm");
Cu.import("resource://firetray/ctypes/linux/gtk.jsm");
Cu.import("resource://firetray/commons.js");
firetray.Handler.subscribeLibsForClosing([gobject, gio, gtk]);
if ("undefined" == typeof(firetray.Handler))
F.ERROR("This module MUST be imported from/after FiretrayHandler !");
@ -44,9 +45,6 @@ firetray.IMStatusIcon = {
shutdown: function() {
this.destroyIcons();
// FIXME: tryCloseLibs should be done by Handler only, submodules should
// just pass the imported ctypes modules to it
// firetray.Utils.tryCloseLibs([gobject, gio, gtk]);
this.initialized = false;
},

View File

@ -12,6 +12,7 @@ Cu.import("resource://gre/modules/ctypes.jsm");
Cu.import("resource://firetray/ctypes/linux/gobject.jsm");
Cu.import("resource://firetray/ctypes/linux/gtk.jsm");
Cu.import("resource://firetray/commons.js");
firetray.Handler.subscribeLibsForClosing([gobject, gtk]);
if ("undefined" == typeof(firetray.StatusIcon))
F.ERROR("This module MUST be imported from/after StatusIcon !");
@ -61,7 +62,6 @@ firetray.PopupMenu = {
shutdown: function() {
F.LOG("Disabling PopupMenu");
firetray.Utils.tryCloseLibs([gobject, gtk]);
this.initialized = false;
},

View File

@ -17,6 +17,7 @@ Cu.import("resource://firetray/ctypes/linux/gtk.jsm");
Cu.import("resource://firetray/ctypes/linux/pango.jsm");
Cu.import("resource://firetray/ctypes/linux/pangocairo.jsm");
Cu.import("resource://firetray/commons.js");
firetray.Handler.subscribeLibsForClosing([cairo, gobject, gdk, gio, gtk, pango, pangocairo]);
if ("undefined" == typeof(firetray.Handler))
F.ERROR("This module MUST be imported from/after FiretrayHandler !");
@ -63,7 +64,6 @@ firetray.StatusIcon = {
firetray.PopupMenu.shutdown();
// FIXME: should destroy/hide icon here
firetray.GtkIcons.shutdown();
firetray.Utils.tryCloseLibs([cairo, gobject, gdk, gio, gtk, pango, pangocairo]);
this.initialized = false;
},

View File

@ -23,6 +23,7 @@ Cu.import("resource://firetray/ctypes/linux/gtk.jsm");
Cu.import("resource://firetray/ctypes/linux/libc.jsm");
Cu.import("resource://firetray/ctypes/linux/x11.jsm");
Cu.import("resource://firetray/commons.js");
firetray.Handler.subscribeLibsForClosing([gobject, gdk, gtk, libc, x11, glib]);
if ("undefined" == typeof(firetray.Handler))
F.ERROR("This module MUST be imported from/after FiretrayHandler !");
@ -61,7 +62,6 @@ firetray.Window = {
},
shutdown: function() {
firetray.Utils.tryCloseLibs([gobject, gdk, gtk, libc, x11, glib]);
this.initialized = false;
},