# HG changeset patch # User Zerotorescue # Date 1283885869 -7200 # Node ID 1ba07a64bf142a7c74230d45f3c546bc973d88aa # Parent 2dd6005d41f37c0f23c07b730f2e9bf24ebbb7e3 Added a ?FailSafe? module which will safe you from mail failing to open. The opening of a single mail may get stuck when other things occur such as mail being send at the exact same time. This module will continue with the next mail after a set timeout (default set to 20 seconds). diff -r 2dd6005d41f3 -r 1ba07a64bf14 Core.lua --- a/Core.lua Tue Sep 07 17:49:39 2010 +0200 +++ b/Core.lua Tue Sep 07 20:57:49 2010 +0200 @@ -24,6 +24,7 @@ }, modules = { Collected = true, + FailSafe = true, }, notifications = { welcome = false, diff -r 2dd6005d41f3 -r 1ba07a64bf14 MailOpener.toc --- a/MailOpener.toc Tue Sep 07 17:49:39 2010 +0200 +++ b/MailOpener.toc Tue Sep 07 20:57:49 2010 +0200 @@ -15,4 +15,5 @@ Modules\Collected.lua Modules\Config.lua +Modules\FailSafe.lua Modules\OpenAll.lua \ No newline at end of file diff -r 2dd6005d41f3 -r 1ba07a64bf14 Modules/FailSafe.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Modules/FailSafe.lua Tue Sep 07 20:57:49 2010 +0200 @@ -0,0 +1,159 @@ +local MailOpener = LibStub("AceAddon-3.0"):GetAddon("MailOpener"); +local FailSafe = MailOpener:NewModule("FailSafe", "AceEvent-3.0", "AceTimer-3.0"); + +--[[ +Module name: FailSafe +Description: Prevents the mail opening from stopping when the execution of a single mail opening function fails (e.g. because of mail functions throttling). +Required: No. +]] + +function FailSafe:OnInitialize() + local defaults = { + profile = { + timeout = 20, + }, + }; + + -- Register our saved variables NameSpace + self.db = MailOpener.db:RegisterNamespace("FailSafe", defaults); +end + +function FailSafe:OnEnable() + self:Debug("OnEnable"); + + self:RegisterEvent("MAIL_SHOW"); +end + +-- Even though Ace can unregister our events it's neater to do it manually too +function FailSafe:OnDisable() + self:Debug("OnDisable"); + + self:UnregisterEvent("MAIL_SHOW"); + + self:Stop(); +end + +function FailSafe:MAIL_SHOW() + self:Debug("MAIL_SHOW"); + + self:RegisterEvent("MAIL_CLOSED"); + + self:RegisterMessage("MO_OPENING_MAIL"); + self:RegisterMessage("MO_MAIL_EMPTIED"); +end + +function FailSafe:MAIL_CLOSED() + self:Debug("MAIL_CLOSED"); + + self:UnregisterEvent("MAIL_CLOSED"); + + self:UnregisterMessage("MO_OPENING_MAIL"); + self:UnregisterMessage("MO_OPENING_MAIL_FINISHED"); + + self:CancelTimer(self.tmrTimeout); +end + +function FailSafe:MO_OPENING_MAIL() + -- Single mail being opened + + self.tmrTimeout = self:ScheduleTimer("Continue", self.db.profile.timeout); +end + +function FailSafe:MO_MAIL_EMPTIED() + -- Single mail has been opened + + self:CancelTimer(self.tmrTimeout); +end + +function FailSafe:Continue() + MailOpener:GetModule("OpenAll"):Continue(); + + print("|cff15ff00Mail Opener|r (FailSafe): Mail opening timeout, continueing with the next mail."); +end + +function FailSafe:GetOptionsGroup() + local configGroup = { + order = 450, + type = "group", + name = "FailSafe", + desc = "Change settings for the FailSafe module.", + args = { + General = { + order = 10, + type = "group", + inline = true, + name = "General", + args = { + description = { + order = 10, + type = "description", + name = function() + local default = "With this button you can completely toggle this module |cff00ff00on|r or |cffff0000off|r. This setting will be remembered and the module will be automatically toggled |cff00ff00on|r or |cffff0000off|r upon logon as it was last set.\n\n"; + + if self:IsEnabled() then + return default .. "Status: |cff00ff00Enabled|r"; + else + return default .. "Status: |cffff0000Disabled|r"; + end + end, + }, + disable = { + order = 20, + type = "execute", + name = function() + if self:IsEnabled() then + return "Disable Module"; + else + return "Enable Module"; + end + end, + desc = "Click here to completely toggle this module on or off.", + width = "double", + func = function() + if self:IsEnabled() then + self:Disable(); + + MailOpener.db.profile.modules[self:GetName()] = false; + else + self:Enable(); + + MailOpener.db.profile.modules[self:GetName()] = true; + end + end, + }, + }, + }, + SingleMailTimeout = { + order = 20, + type = "group", + inline = true, + name = "Single Mail Opening Timeout", + args = { + description = { + order = 10, + type = "description", + name = "Change how long FailSafe should wait before skipping the last mail and continueing with the next. This will prevent mail opening getting stuck forever because a single mail is frozen for whatever reason.", + }, + timeout = { + order = 20, + type = "range", + width = "double", + min = 1, + max = 60, + step = 0.5, + name = "Single Mail Timeout", + desc = "Change how long FailSafe should wait before skipping the last mail and continueing with the next. This should prevent mail opening getting stuck because a single mail is stuck for whatever reason.\n\nDefault value is 20 seconds.", + get = function() return self.db.profile.timeout; end, + set = function(i, v) self.db.profile.timeout = v; end, + }, + }, + }, + }, + }; + + return configGroup; +end + +function FailSafe:Debug(t) + return MailOpener:Debug("|cffff0000FailSafe|r:" .. t); +end \ No newline at end of file diff -r 2dd6005d41f3 -r 1ba07a64bf14 Modules/OpenAll.lua --- a/Modules/OpenAll.lua Tue Sep 07 17:49:39 2010 +0200 +++ b/Modules/OpenAll.lua Tue Sep 07 20:57:49 2010 +0200 @@ -759,7 +759,7 @@ max = 60, step = 0.5, name = "Continued Mail Opening Interval", - desc = "Change the interval at which Mail Opener tries to continue opening mail after opening the mailbox. Please note that this setting does not reduce the game's normal 60 seconds wait time for mail.\n\nThe default value is 5 seconds", + desc = "Change the interval at which Mail Opener tries to continue opening mail after opening the mailbox. Please note that this setting does not reduce the game's normal 60 seconds wait time for mail.\n\nThe default value is 5 seconds.", get = function() return MailOpener.db.profile.general.waitTime; end, set = function(i, v) MailOpener.db.profile.general.waitTime = v; end, disabled = function() return (not MailOpener.db.profile.general.continueOpening); end,