mirror of
https://github.com/moparisthebest/FireTray
synced 2024-11-15 21:35:01 -05:00
periodically clean prefs by removing removed accounts from excludedAccounts
This commit is contained in:
parent
edab0aab38
commit
756367230c
@ -23,14 +23,20 @@ const FLDRS_UNINTERESTING = {
|
|||||||
|
|
||||||
firetray.Messaging = {
|
firetray.Messaging = {
|
||||||
initialized: false,
|
initialized: false,
|
||||||
|
cleaningTimer: null,
|
||||||
|
|
||||||
init: function() {
|
init: function() {
|
||||||
if (this.initialized) {
|
if (this.initialized) {
|
||||||
firetray.WARN("Messaging already initialized");
|
firetray.LOG("Messaging already initialized");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
firetray.LOG("Enabling Messaging");
|
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;
|
let that = this;
|
||||||
MailServices.mailSession.AddFolderListener(that.mailSessionListener,
|
MailServices.mailSession.AddFolderListener(that.mailSessionListener,
|
||||||
that.mailSessionListener.notificationFlags);
|
that.mailSessionListener.notificationFlags);
|
||||||
@ -43,15 +49,48 @@ firetray.Messaging = {
|
|||||||
return;
|
return;
|
||||||
firetray.LOG("Disabling Messaging");
|
firetray.LOG("Disabling Messaging");
|
||||||
|
|
||||||
|
this.cleaningTimer.cancel();
|
||||||
|
|
||||||
MailServices.mailSession.RemoveFolderListener(this.mailSessionListener);
|
MailServices.mailSession.RemoveFolderListener(this.mailSessionListener);
|
||||||
firetray.Handler.setIconImageDefault();
|
firetray.Handler.setIconImageDefault();
|
||||||
|
|
||||||
this.initialized = false;
|
this.initialized = false;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/* removes removed accounts from excludedAccounts pref. NOTE: Can't be called
|
||||||
* http://mxr.mozilla.org/comm-central/source/mailnews/base/public/nsIFolderListener.idl
|
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: {
|
mailSessionListener: {
|
||||||
notificationFlags:
|
notificationFlags:
|
||||||
// Ci.nsIFolderListener.propertyChanged |
|
// Ci.nsIFolderListener.propertyChanged |
|
||||||
|
@ -8,6 +8,7 @@ var EXPORTED_SYMBOLS =
|
|||||||
"FIRETRAY_NOTIFICATION_NEWMAIL_ICON", "FIRETRAY_NOTIFICATION_CUSTOM_ICON",
|
"FIRETRAY_NOTIFICATION_NEWMAIL_ICON", "FIRETRAY_NOTIFICATION_CUSTOM_ICON",
|
||||||
"FIRETRAY_DELAY_BROWSER_STARTUP_MILLISECONDS",
|
"FIRETRAY_DELAY_BROWSER_STARTUP_MILLISECONDS",
|
||||||
"FIRETRAY_DELAY_NOWAIT_MILLISECONDS", "FIRETRAY_MESSAGE_COUNT_TYPE_UNREAD",
|
"FIRETRAY_DELAY_NOWAIT_MILLISECONDS", "FIRETRAY_MESSAGE_COUNT_TYPE_UNREAD",
|
||||||
|
"FIRETRAY_DELAY_PREF_CLEANING_MILLISECONDS",
|
||||||
"FIRETRAY_MESSAGE_COUNT_TYPE_NEW" ];
|
"FIRETRAY_MESSAGE_COUNT_TYPE_NEW" ];
|
||||||
|
|
||||||
const Cc = Components.classes;
|
const Cc = Components.classes;
|
||||||
@ -26,6 +27,7 @@ const FIRETRAY_NOTIFICATION_CUSTOM_ICON = 3;
|
|||||||
|
|
||||||
const FIRETRAY_DELAY_BROWSER_STARTUP_MILLISECONDS = 500;
|
const FIRETRAY_DELAY_BROWSER_STARTUP_MILLISECONDS = 500;
|
||||||
const FIRETRAY_DELAY_NOWAIT_MILLISECONDS = 0;
|
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_UNREAD = 0;
|
||||||
const FIRETRAY_MESSAGE_COUNT_TYPE_NEW = 1;
|
const FIRETRAY_MESSAGE_COUNT_TYPE_NEW = 1;
|
||||||
@ -174,6 +176,7 @@ firetray.Utils = {
|
|||||||
var timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
var timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
||||||
timer.initWithCallback({ notify: callback },
|
timer.initWithCallback({ notify: callback },
|
||||||
delay, timerType);
|
delay, timerType);
|
||||||
|
return timer;
|
||||||
},
|
},
|
||||||
|
|
||||||
tryCloseLibs: function(libs) {
|
tryCloseLibs: function(libs) {
|
||||||
|
Loading…
Reference in New Issue
Block a user