annotate Modules/FailSafe.lua @ 6:f10c8a083d2a

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