periodically clean prefs by removing removed accounts from excludedAccounts

This commit is contained in:
foudfou 2012-03-20 22:06:19 +01:00
parent edab0aab38
commit 756367230c
2 changed files with 46 additions and 4 deletions

View File

@ -23,14 +23,20 @@ const FLDRS_UNINTERESTING = {
firetray.Messaging = {
initialized: false,
cleaningTimer: null,
init: function() {
if (this.initialized) {
firetray.WARN("Messaging already initialized");
firetray.LOG("Messaging already initialized");
return;
}
firetray.LOG("Enabling Messaging");
// there is no means to detect account-removed event
this.cleaningTimer = firetray.Utils.timer(firetray.Messaging.cleanExcludedAccounts,
FIRETRAY_DELAY_PREF_CLEANING_MILLISECONDS, Ci.nsITimer.TYPE_REPEATING_SLACK);
firetray.WARN(this.cleaningTimer+"="+FIRETRAY_DELAY_PREF_CLEANING_MILLISECONDS);
let that = this;
MailServices.mailSession.AddFolderListener(that.mailSessionListener,
that.mailSessionListener.notificationFlags);
@ -43,15 +49,48 @@ firetray.Messaging = {
return;
firetray.LOG("Disabling Messaging");
this.cleaningTimer.cancel();
MailServices.mailSession.RemoveFolderListener(this.mailSessionListener);
firetray.Handler.setIconImageDefault();
this.initialized = false;
},
/**
* http://mxr.mozilla.org/comm-central/source/mailnews/base/public/nsIFolderListener.idl
*/
/* removes removed accounts from excludedAccounts pref. NOTE: Can't be called
at shutdown because MailServices.accounts no longer available */
cleanExcludedAccounts: function() {
try {
firetray.LOG("* cleaning *");
let mailAccounts = firetray.Utils.getObjPref('mail_accounts');
let excludedAccounts = mailAccounts["excludedAccounts"];
// build current list of account server keys
let accounts = MailServices.accounts.accounts;
let accountServerKeys = [];
for (let i=0, len=accounts.Count(); i<len; ++i) {
let account = accounts.QueryElementAt(i, Ci.nsIMsgAccount);
let accountServer = account.incomingServer;
accountServerKeys[i] = accountServer;
}
let newExcludedAccounts = [], cleaningNeeded = 0;
for (let excludedAccount in excludedAccounts) {
if (accountServerKeys.indexOf(excludedAccount) >= 0)
newExcludedAccounts.push(excludedAccount);
else
cleaningNeeded += 1;
}
if (cleaningNeeded) {
firetray.LOG("cleaning excluded accounts");
let prefObj = {"serverTypes":mailAccounts["serverTypes"], "excludedAccounts":newExcludedAccounts};
firetray.Utils.setObjPref('mail_accounts', prefObj);
}
} catch(x) { firetray.ERROR(x); }
},
/* http://mxr.mozilla.org/comm-central/source/mailnews/base/public/nsIFolderListener.idl */
mailSessionListener: {
notificationFlags:
// Ci.nsIFolderListener.propertyChanged |

View File

@ -8,6 +8,7 @@ var EXPORTED_SYMBOLS =
"FIRETRAY_NOTIFICATION_NEWMAIL_ICON", "FIRETRAY_NOTIFICATION_CUSTOM_ICON",
"FIRETRAY_DELAY_BROWSER_STARTUP_MILLISECONDS",
"FIRETRAY_DELAY_NOWAIT_MILLISECONDS", "FIRETRAY_MESSAGE_COUNT_TYPE_UNREAD",
"FIRETRAY_DELAY_PREF_CLEANING_MILLISECONDS",
"FIRETRAY_MESSAGE_COUNT_TYPE_NEW" ];
const Cc = Components.classes;
@ -26,6 +27,7 @@ const FIRETRAY_NOTIFICATION_CUSTOM_ICON = 3;
const FIRETRAY_DELAY_BROWSER_STARTUP_MILLISECONDS = 500;
const FIRETRAY_DELAY_NOWAIT_MILLISECONDS = 0;
const FIRETRAY_DELAY_PREF_CLEANING_MILLISECONDS = 15*60*1000;
const FIRETRAY_MESSAGE_COUNT_TYPE_UNREAD = 0;
const FIRETRAY_MESSAGE_COUNT_TYPE_NEW = 1;
@ -174,6 +176,7 @@ firetray.Utils = {
var timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
timer.initWithCallback({ notify: callback },
delay, timerType);
return timer;
},
tryCloseLibs: function(libs) {