Mercurial > wow > mailopener
comparison Modules/FailSafe.lua @ 5:1ba07a64bf14
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).
| author | Zerotorescue |
|---|---|
| date | Tue, 07 Sep 2010 20:57:49 +0200 |
| parents | |
| children | f10c8a083d2a |
comparison
equal
deleted
inserted
replaced
| 4:2dd6005d41f3 | 5:1ba07a64bf14 |
|---|---|
| 1 local MailOpener = LibStub("AceAddon-3.0"):GetAddon("MailOpener"); | |
| 2 local FailSafe = MailOpener:NewModule("FailSafe", "AceEvent-3.0", "AceTimer-3.0"); | |
| 3 | |
| 4 --[[ | |
| 5 Module name: FailSafe | |
| 6 Description: Prevents the mail opening from stopping when the execution of a single mail opening function fails (e.g. because of mail functions throttling). | |
| 7 Required: No. | |
| 8 ]] | |
| 9 | |
| 10 function FailSafe:OnInitialize() | |
| 11 local defaults = { | |
| 12 profile = { | |
| 13 timeout = 20, | |
| 14 }, | |
| 15 }; | |
| 16 | |
| 17 -- Register our saved variables NameSpace | |
| 18 self.db = MailOpener.db:RegisterNamespace("FailSafe", defaults); | |
| 19 end | |
| 20 | |
| 21 function FailSafe:OnEnable() | |
| 22 self:Debug("OnEnable"); | |
| 23 | |
| 24 self:RegisterEvent("MAIL_SHOW"); | |
| 25 end | |
| 26 | |
| 27 -- Even though Ace can unregister our events it's neater to do it manually too | |
| 28 function FailSafe:OnDisable() | |
| 29 self:Debug("OnDisable"); | |
| 30 | |
| 31 self:UnregisterEvent("MAIL_SHOW"); | |
| 32 | |
| 33 self:Stop(); | |
| 34 end | |
| 35 | |
| 36 function FailSafe:MAIL_SHOW() | |
| 37 self:Debug("MAIL_SHOW"); | |
| 38 | |
| 39 self:RegisterEvent("MAIL_CLOSED"); | |
| 40 | |
| 41 self:RegisterMessage("MO_OPENING_MAIL"); | |
| 42 self:RegisterMessage("MO_MAIL_EMPTIED"); | |
| 43 end | |
| 44 | |
| 45 function FailSafe:MAIL_CLOSED() | |
| 46 self:Debug("MAIL_CLOSED"); | |
| 47 | |
| 48 self:UnregisterEvent("MAIL_CLOSED"); | |
| 49 | |
| 50 self:UnregisterMessage("MO_OPENING_MAIL"); | |
| 51 self:UnregisterMessage("MO_OPENING_MAIL_FINISHED"); | |
| 52 | |
| 53 self:CancelTimer(self.tmrTimeout); | |
| 54 end | |
| 55 | |
| 56 function FailSafe:MO_OPENING_MAIL() | |
| 57 -- Single mail being opened | |
| 58 | |
| 59 self.tmrTimeout = self:ScheduleTimer("Continue", self.db.profile.timeout); | |
| 60 end | |
| 61 | |
| 62 function FailSafe:MO_MAIL_EMPTIED() | |
| 63 -- Single mail has been opened | |
| 64 | |
| 65 self:CancelTimer(self.tmrTimeout); | |
| 66 end | |
| 67 | |
| 68 function FailSafe:Continue() | |
| 69 MailOpener:GetModule("OpenAll"):Continue(); | |
| 70 | |
| 71 print("|cff15ff00Mail Opener|r (FailSafe): Mail opening timeout, continueing with the next mail."); | |
| 72 end | |
| 73 | |
| 74 function FailSafe:GetOptionsGroup() | |
| 75 local configGroup = { | |
| 76 order = 450, | |
| 77 type = "group", | |
| 78 name = "FailSafe", | |
| 79 desc = "Change settings for the FailSafe module.", | |
| 80 args = { | |
| 81 General = { | |
| 82 order = 10, | |
| 83 type = "group", | |
| 84 inline = true, | |
| 85 name = "General", | |
| 86 args = { | |
| 87 description = { | |
| 88 order = 10, | |
| 89 type = "description", | |
| 90 name = function() | |
| 91 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"; | |
| 92 | |
| 93 if self:IsEnabled() then | |
| 94 return default .. "Status: |cff00ff00Enabled|r"; | |
| 95 else | |
| 96 return default .. "Status: |cffff0000Disabled|r"; | |
| 97 end | |
| 98 end, | |
| 99 }, | |
| 100 disable = { | |
| 101 order = 20, | |
| 102 type = "execute", | |
| 103 name = function() | |
| 104 if self:IsEnabled() then | |
| 105 return "Disable Module"; | |
| 106 else | |
| 107 return "Enable Module"; | |
| 108 end | |
| 109 end, | |
| 110 desc = "Click here to completely toggle this module on or off.", | |
| 111 width = "double", | |
| 112 func = function() | |
| 113 if self:IsEnabled() then | |
| 114 self:Disable(); | |
| 115 | |
| 116 MailOpener.db.profile.modules[self:GetName()] = false; | |
| 117 else | |
| 118 self:Enable(); | |
| 119 | |
| 120 MailOpener.db.profile.modules[self:GetName()] = true; | |
| 121 end | |
| 122 end, | |
| 123 }, | |
| 124 }, | |
| 125 }, | |
| 126 SingleMailTimeout = { | |
| 127 order = 20, | |
| 128 type = "group", | |
| 129 inline = true, | |
| 130 name = "Single Mail Opening Timeout", | |
| 131 args = { | |
| 132 description = { | |
| 133 order = 10, | |
| 134 type = "description", | |
| 135 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.", | |
| 136 }, | |
| 137 timeout = { | |
| 138 order = 20, | |
| 139 type = "range", | |
| 140 width = "double", | |
| 141 min = 1, | |
| 142 max = 60, | |
| 143 step = 0.5, | |
| 144 name = "Single Mail Timeout", | |
| 145 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.", | |
| 146 get = function() return self.db.profile.timeout; end, | |
| 147 set = function(i, v) self.db.profile.timeout = v; end, | |
| 148 }, | |
| 149 }, | |
| 150 }, | |
| 151 }, | |
| 152 }; | |
| 153 | |
| 154 return configGroup; | |
| 155 end | |
| 156 | |
| 157 function FailSafe:Debug(t) | |
| 158 return MailOpener:Debug("|cffff0000FailSafe|r:" .. t); | |
| 159 end |
