1
0
mirror of https://github.com/moparisthebest/FireTray synced 2024-11-17 22:35:02 -05:00

cleaner observer for accountmanager.accounts

We also need to start observing the mail.accountmanager.accounts pref *after*
it's fully built.
This commit is contained in:
foudfou 2013-11-03 02:09:07 +01:00
parent 6d2bd81053
commit 088f7f56e4
2 changed files with 28 additions and 4 deletions

View File

@ -239,6 +239,10 @@ firetray.Handler = {
Ci.nsITimer.TYPE_ONE_SHOT, function() {
firetray.Handler.appStarted = true;
log.info("*** appStarted ***");
if (firetray.Handler.inMailApp) {
firetray.Messaging.addPrefObserver();
}
});
},

View File

@ -23,6 +23,8 @@ const FLDRS_UNINTERESTING = {
Virtual: Ci.nsMsgFolderFlags.Virtual
};
const ACCOUNTS_PREF_BRANCH = "mail.accountmanager.accounts";
let log = firetray.Logging.getLogger("firetray.Messaging");
@ -38,9 +40,9 @@ firetray.Messaging = {
}
log.debug("Enabling Messaging");
// includes IM accounts
Services.prefs.addObserver("mail.accountmanager.accounts",
firetray.Messaging.cleanExcludedAccounts, false);
/* addPrefObserver() called after appStarted because it's hazardous to
clean our excludedAccounts while mail.accountmanager.accounts is being
built dynamically at startup */
let that = this;
MailServices.mailSession.AddFolderListener(that.mailSessionListener,
@ -55,11 +57,29 @@ firetray.Messaging = {
MailServices.mailSession.RemoveFolderListener(this.mailSessionListener);
Services.prefs.removeObserver("mail.accountmanager.accounts", this);
this.removePrefObserver();
this.initialized = false;
},
addPrefObserver: function() {
// includes IM accounts
Services.prefs.addObserver(ACCOUNTS_PREF_BRANCH, this, false);
log.debug("PrefObserver added");
},
removePrefObserver: function() {
Services.prefs.removeObserver(ACCOUNTS_PREF_BRANCH, this);
},
/* could also use a PrefListener, but let's keep it simple for now */
observe: function(subject, topic, data) {
if (topic === "nsPref:changed" &&
data === ACCOUNTS_PREF_BRANCH) {
log.debug(ACCOUNTS_PREF_BRANCH+"="+subject.QueryInterface(Ci.nsIPrefBranch).getCharPref(ACCOUNTS_PREF_BRANCH));
this.cleanExcludedAccounts();
}
},
/* removes removed accounts from excludedAccounts pref. NOTE: Can't be called
at shutdown because MailServices.accounts no longer available */
cleanExcludedAccounts: function() {