mirror of
https://github.com/moparisthebest/FireTray
synced 2024-12-22 13:58:48 -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:
parent
ff7bcd4c91
commit
82fae974d1
@ -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":
|
||||
|
@ -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); }
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -121,6 +121,8 @@ function ctypes_library(aName, aABIs, aDefines, aGlobal) {
|
||||
}
|
||||
}
|
||||
|
||||
this.name = aName;
|
||||
|
||||
this.close = function() {
|
||||
F.LOG("Closing library " + aName);
|
||||
library.close();
|
||||
|
@ -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;
|
||||
},
|
||||
|
||||
|
@ -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;
|
||||
},
|
||||
|
||||
|
@ -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;
|
||||
},
|
||||
|
||||
|
@ -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;
|
||||
},
|
||||
|
||||
|
@ -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;
|
||||
},
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user