From 82fae974d1d94cad06a18203efc08d2c0d881717 Mon Sep 17 00:00:00 2001 From: foudfou Date: Tue, 7 Aug 2012 23:37:32 +0200 Subject: [PATCH] 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) --- src/modules/FiretrayHandler.jsm | 22 +++++++++++++++++++++- src/modules/commons.js | 9 --------- src/modules/ctypes/ctypes-utils.jsm | 4 +++- src/modules/linux/FiretrayGtkIcons.jsm | 2 +- src/modules/linux/FiretrayIMStatusIcon.jsm | 4 +--- src/modules/linux/FiretrayPopupMenu.jsm | 2 +- src/modules/linux/FiretrayStatusIcon.jsm | 2 +- src/modules/linux/FiretrayWindow.jsm | 2 +- 8 files changed, 29 insertions(+), 18 deletions(-) diff --git a/src/modules/FiretrayHandler.jsm b/src/modules/FiretrayHandler.jsm index 5e83931..4cdee21 100644 --- a/src/modules/FiretrayHandler.jsm +++ b/src/modules/FiretrayHandler.jsm @@ -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