annotate Modules/FailSafe.lua @ 79:136aa3dd4dda

The keep free space will now cause the opener to partially loot mail when you are near the keep free space requirement, rather than skipping the entire mail. The config has been changed to reflect this.
author Zerotorescue
date Thu, 16 Sep 2010 17:20:34 +0200
parents f01e0184a275
children
rev   line source
Zerotorescue@5 1 local MailOpener = LibStub("AceAddon-3.0"):GetAddon("MailOpener");
Zerotorescue@31 2 local mod = MailOpener:NewModule("FailSafe", "AceEvent-3.0", "AceTimer-3.0");
Zerotorescue@70 3 local L = LibStub("AceLocale-3.0"):GetLocale("MailOpener");
Zerotorescue@5 4
Zerotorescue@68 5 mod.moduleDescription = L["Prevents the mail opening from completely stopping when the opening of a single mail gets stuck."];
Zerotorescue@31 6 mod.moduleRequired = false;
Zerotorescue@5 7
Zerotorescue@31 8 function mod:OnInitialize()
Zerotorescue@5 9 local defaults = {
Zerotorescue@5 10 profile = {
Zerotorescue@5 11 timeout = 20,
Zerotorescue@5 12 },
Zerotorescue@5 13 };
Zerotorescue@5 14
Zerotorescue@5 15 -- Register our saved variables NameSpace
Zerotorescue@5 16 self.db = MailOpener.db:RegisterNamespace("FailSafe", defaults);
Zerotorescue@5 17 end
Zerotorescue@5 18
Zerotorescue@31 19 function mod:OnEnable()
Zerotorescue@5 20 self:Debug("OnEnable");
Zerotorescue@5 21
Zerotorescue@5 22 self:RegisterEvent("MAIL_SHOW");
Zerotorescue@31 23
Zerotorescue@31 24 -- If we were toggling this module on while the mailbox is opened we must register all events again
Zerotorescue@31 25 if MailFrame:IsVisible() then
Zerotorescue@31 26 self:MAIL_SHOW();
Zerotorescue@31 27 end
Zerotorescue@5 28 end
Zerotorescue@5 29
Zerotorescue@5 30 -- Even though Ace can unregister our events it's neater to do it manually too
Zerotorescue@31 31 function mod:OnDisable()
Zerotorescue@5 32 self:Debug("OnDisable");
Zerotorescue@5 33
Zerotorescue@5 34 self:UnregisterEvent("MAIL_SHOW");
Zerotorescue@42 35
Zerotorescue@42 36 -- If we were toggling this module off while the mailbox is opened we must unregister all events
Zerotorescue@42 37 if MailFrame:IsVisible() then
Zerotorescue@42 38 self:MAIL_CLOSED();
Zerotorescue@42 39 end
Zerotorescue@5 40 end
Zerotorescue@5 41
Zerotorescue@31 42 function mod:MAIL_SHOW()
Zerotorescue@5 43 self:Debug("MAIL_SHOW");
Zerotorescue@5 44
Zerotorescue@5 45 self:RegisterEvent("MAIL_CLOSED");
Zerotorescue@5 46
Zerotorescue@5 47 self:RegisterMessage("MO_OPENING_MAIL");
Zerotorescue@5 48 self:RegisterMessage("MO_MAIL_EMPTIED");
Zerotorescue@5 49 end
Zerotorescue@5 50
Zerotorescue@31 51 function mod:MAIL_CLOSED()
Zerotorescue@5 52 self:Debug("MAIL_CLOSED");
Zerotorescue@5 53
Zerotorescue@5 54 self:UnregisterEvent("MAIL_CLOSED");
Zerotorescue@5 55
Zerotorescue@5 56 self:UnregisterMessage("MO_OPENING_MAIL");
Zerotorescue@5 57 self:UnregisterMessage("MO_OPENING_MAIL_FINISHED");
Zerotorescue@5 58
Zerotorescue@6 59 self:CancelTimer(self.tmrTimeout, true);
Zerotorescue@5 60 end
Zerotorescue@5 61
Zerotorescue@31 62 function mod:MO_OPENING_MAIL()
Zerotorescue@5 63 -- Single mail being opened
Zerotorescue@5 64
Zerotorescue@11 65 self:CancelTimer(self.tmrTimeout, true); -- insurance
Zerotorescue@5 66 self.tmrTimeout = self:ScheduleTimer("Continue", self.db.profile.timeout);
Zerotorescue@5 67 end
Zerotorescue@5 68
Zerotorescue@31 69 function mod:MO_MAIL_EMPTIED()
Zerotorescue@5 70 -- Single mail has been opened
Zerotorescue@5 71
Zerotorescue@6 72 self:CancelTimer(self.tmrTimeout, true);
Zerotorescue@5 73 end
Zerotorescue@5 74
Zerotorescue@31 75 function mod:Continue()
Zerotorescue@5 76 MailOpener:GetModule("OpenAll"):Continue();
Zerotorescue@5 77
Zerotorescue@68 78 MailOpener:Print(L["(FailSafe) Mail opening timeout, continuing with the next mail."]);
Zerotorescue@5 79 end
Zerotorescue@5 80
Zerotorescue@31 81 function mod:GetOptionsGroup()
Zerotorescue@5 82 local configGroup = {
Zerotorescue@31 83 order = 0,
Zerotorescue@31 84 type = "modulesSubGroup",
Zerotorescue@68 85 name = L["FailSafe"],
Zerotorescue@68 86 desc = L["Change settings for the FailSafe module."],
Zerotorescue@5 87 args = {
Zerotorescue@5 88 General = {
Zerotorescue@5 89 order = 10,
Zerotorescue@5 90 type = "group",
Zerotorescue@5 91 inline = true,
Zerotorescue@68 92 name = L["General"],
Zerotorescue@5 93 args = {
Zerotorescue@5 94 description = {
Zerotorescue@5 95 order = 10,
Zerotorescue@5 96 type = "description",
Zerotorescue@5 97 name = function()
Zerotorescue@68 98 local descText = L["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";
Zerotorescue@5 99
Zerotorescue@5 100 if self:IsEnabled() then
Zerotorescue@68 101 descText = descText .. L["Status: %s"]:format(L["|cff00ff00Enabled|r"]);
Zerotorescue@5 102 else
Zerotorescue@68 103 descText = descText .. L["Status: %s"]:format(L["|cffff0000Disabled|r"]);
Zerotorescue@5 104 end
Zerotorescue@31 105
Zerotorescue@31 106 return descText;
Zerotorescue@5 107 end,
Zerotorescue@5 108 },
Zerotorescue@5 109 disable = {
Zerotorescue@5 110 order = 20,
Zerotorescue@5 111 type = "execute",
Zerotorescue@5 112 name = function()
Zerotorescue@5 113 if self:IsEnabled() then
Zerotorescue@68 114 return L["Disable Module"];
Zerotorescue@5 115 else
Zerotorescue@68 116 return L["Enable Module"];
Zerotorescue@5 117 end
Zerotorescue@5 118 end,
Zerotorescue@68 119 desc = L["Click here to completely toggle this module on or off."],
Zerotorescue@5 120 width = "double",
Zerotorescue@5 121 func = function()
Zerotorescue@5 122 if self:IsEnabled() then
Zerotorescue@5 123 self:Disable();
Zerotorescue@5 124
Zerotorescue@5 125 MailOpener.db.profile.modules[self:GetName()] = false;
Zerotorescue@5 126 else
Zerotorescue@5 127 self:Enable();
Zerotorescue@5 128
Zerotorescue@5 129 MailOpener.db.profile.modules[self:GetName()] = true;
Zerotorescue@5 130 end
Zerotorescue@5 131 end,
Zerotorescue@5 132 },
Zerotorescue@5 133 },
Zerotorescue@5 134 },
Zerotorescue@5 135 SingleMailTimeout = {
Zerotorescue@5 136 order = 20,
Zerotorescue@5 137 type = "group",
Zerotorescue@5 138 inline = true,
Zerotorescue@68 139 name = L["Single Mail Opening Timeout"],
Zerotorescue@5 140 args = {
Zerotorescue@5 141 description = {
Zerotorescue@5 142 order = 10,
Zerotorescue@5 143 type = "description",
Zerotorescue@68 144 name = L["Change how long FailSafe should wait before skipping the last mail and continuing with the next. This will prevent mail opening getting stuck forever because a single mail is frozen for whatever reason."],
Zerotorescue@5 145 },
Zerotorescue@5 146 timeout = {
Zerotorescue@5 147 order = 20,
Zerotorescue@5 148 type = "range",
Zerotorescue@5 149 width = "double",
Zerotorescue@5 150 min = 1,
Zerotorescue@5 151 max = 60,
Zerotorescue@5 152 step = 0.5,
Zerotorescue@68 153 name = L["Single Mail Timeout"],
Zerotorescue@68 154 desc = L["Change how long FailSafe should wait before skipping the last mail and continuing 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."],
Zerotorescue@5 155 get = function() return self.db.profile.timeout; end,
Zerotorescue@5 156 set = function(i, v) self.db.profile.timeout = v; end,
Zerotorescue@5 157 },
Zerotorescue@5 158 },
Zerotorescue@5 159 },
Zerotorescue@5 160 },
Zerotorescue@5 161 };
Zerotorescue@5 162
Zerotorescue@5 163 return configGroup;
Zerotorescue@5 164 end
Zerotorescue@5 165
Zerotorescue@31 166 function mod:Debug(t)
Zerotorescue@5 167 return MailOpener:Debug("|cffff0000FailSafe|r:" .. t);
Zerotorescue@5 168 end