From cb6bfc14ac744ba3a2a030a9fa9ea3f9e8c0deb9 Mon Sep 17 00:00:00 2001 From: funkydude Date: Sat, 21 Jul 2018 19:55:34 +0100 Subject: [PATCH] Register the error callbacks earlier. --- core.lua | 157 ++++++++++++++++++++++++++----------------------------- 1 file changed, 75 insertions(+), 82 deletions(-) diff --git a/core.lua b/core.lua index 6a9d3a5..a18889e 100644 --- a/core.lua +++ b/core.lua @@ -66,93 +66,86 @@ end -- Event handling -- -local eventFrame = CreateFrame("Frame", nil, InterfaceOptionsFramePanelContainer) -eventFrame:SetScript("OnEvent", function(self, event, ...) self[event](self, ...) end) -eventFrame:RegisterEvent("ADDON_LOADED") -eventFrame:RegisterEvent("PLAYER_LOGIN") -addon.frame = eventFrame - -function eventFrame:ADDON_LOADED(loadedAddon) - if loadedAddon ~= addonName then return end - self:UnregisterEvent("ADDON_LOADED") - - local ac = LibStub("AceComm-3.0", true) - if ac then ac:Embed(addon) end - local as = LibStub("AceSerializer-3.0", true) - if as then as:Embed(addon) end - - local popup = _G.StaticPopupDialogs - if type(popup) ~= "table" then popup = {} end - if type(popup.BugSackSendBugs) ~= "table" then - popup.BugSackSendBugs = { - text = L["Send all bugs from the currently viewed session (%d) in the sack to the player specified below."], - button1 = L["Send"], - button2 = CLOSE, - timeout = 0, - whileDead = true, - hideOnEscape = true, - hasEditBox = true, - OnAccept = function(self, data) - local recipient = self.editBox:GetText() - addon:SendBugsToUser(recipient, data) - end, - OnShow = function(self) - self.button1:Disable() - end, - EditBoxOnTextChanged = function(self) - local t = self:GetText() - if t:len() > 2 and not t:find("%s") then - self:GetParent().button1:Enable() - else - self:GetParent().button1:Disable() - end - end, - enterClicksFirstButton = true, - --OnCancel = function() show() end, -- Need to wrap it so we don't pass |self| as an error argument to show(). - preferredIndex = STATICPOPUP_NUMDIALOGS, - } - end - - if type(BugSackDB) ~= "table" then BugSackDB = {} end - local sv = BugSackDB - sv.profileKeys = nil - sv.profiles = nil - if type(sv.mute) ~= "boolean" then sv.mute = false end - if type(sv.auto) ~= "boolean" then sv.auto = false end - if type(sv.chatframe) ~= "boolean" then sv.chatframe = false end - if type(sv.soundMedia) ~= "string" then sv.soundMedia = "BugSack: Fatality" end - if type(sv.fontSize) ~= "string" then sv.fontSize = "GameFontHighlight" end - addon.db = sv - - self.ADDON_LOADED = nil -end - -function eventFrame:PLAYER_LOGIN() - self:UnregisterEvent("PLAYER_LOGIN") - - -- Make sure we grab any errors fired before bugsack loaded. - local session = addon:GetErrors(BugGrabber:GetSessionId()) - if #session > 0 then onError() end +do + local eventFrame = CreateFrame("Frame", nil, InterfaceOptionsFramePanelContainer) + eventFrame:SetScript("OnEvent", function(self, event, loadedAddon) + if loadedAddon ~= addonName then return end + self:UnregisterEvent("ADDON_LOADED") + + local ac = LibStub("AceComm-3.0", true) + if ac then ac:Embed(addon) end + local as = LibStub("AceSerializer-3.0", true) + if as then as:Embed(addon) end + + local popup = _G.StaticPopupDialogs + if type(popup) ~= "table" then popup = {} end + if type(popup.BugSackSendBugs) ~= "table" then + popup.BugSackSendBugs = { + text = L["Send all bugs from the currently viewed session (%d) in the sack to the player specified below."], + button1 = L["Send"], + button2 = CLOSE, + timeout = 0, + whileDead = true, + hideOnEscape = true, + hasEditBox = true, + OnAccept = function(self, data) + local recipient = self.editBox:GetText() + addon:SendBugsToUser(recipient, data) + end, + OnShow = function(self) + self.button1:Disable() + end, + EditBoxOnTextChanged = function(self) + local t = self:GetText() + if t:len() > 2 and not t:find("%s") then + self:GetParent().button1:Enable() + else + self:GetParent().button1:Disable() + end + end, + enterClicksFirstButton = true, + --OnCancel = function() show() end, -- Need to wrap it so we don't pass |self| as an error argument to show(). + preferredIndex = STATICPOPUP_NUMDIALOGS, + } + end - if addon.RegisterComm then - addon:RegisterComm("BugSack", "OnBugComm") - end + if type(BugSackDB) ~= "table" then BugSackDB = {} end + local sv = BugSackDB + sv.profileKeys = nil + sv.profiles = nil + if type(sv.mute) ~= "boolean" then sv.mute = false end + if type(sv.auto) ~= "boolean" then sv.auto = false end + if type(sv.chatframe) ~= "boolean" then sv.chatframe = false end + if type(sv.soundMedia) ~= "string" then sv.soundMedia = "BugSack: Fatality" end + if type(sv.fontSize) ~= "string" then sv.fontSize = "GameFontHighlight" end + addon.db = sv + + -- Make sure we grab any errors fired before bugsack loaded. + local session = addon:GetErrors(BugGrabber:GetSessionId()) + if #session > 0 then onError() end + + if addon.RegisterComm then + addon:RegisterComm("BugSack", "OnBugComm") + end - -- Set up our error event handler - BugGrabber.RegisterCallback(addon, "BugGrabber_BugGrabbed", onError) + -- Set up our error event handler + BugGrabber.RegisterCallback(addon, "BugGrabber_BugGrabbed", onError) - SlashCmdList.BugSack = function(msg) - msg = msg:lower() - if msg == "show" then - addon:OpenSack() - else - InterfaceOptionsFrame_OpenToCategory(addonName) - InterfaceOptionsFrame_OpenToCategory(addonName) + SlashCmdList.BugSack = function(msg) + msg = msg:lower() + if msg == "show" then + addon:OpenSack() + else + InterfaceOptionsFrame_OpenToCategory(addonName) + InterfaceOptionsFrame_OpenToCategory(addonName) + end end - end - SLASH_BugSack1 = "/bugsack" + SLASH_BugSack1 = "/bugsack" - self.PLAYER_LOGIN = nil + self:SetScript("OnEvent", nil) + end) + eventFrame:RegisterEvent("ADDON_LOADED") + addon.frame = eventFrame end -----------------------------------------------------------------------