Skip to content

Commit

Permalink
Register the error callbacks earlier.
Browse files Browse the repository at this point in the history
  • Loading branch information
funkydude committed Jul 21, 2018
1 parent bd51d13 commit cb6bfc1
Showing 1 changed file with 75 additions and 82 deletions.
157 changes: 75 additions & 82 deletions core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

-----------------------------------------------------------------------
Expand Down

0 comments on commit cb6bfc1

Please sign in to comment.