api: run lurker on addon event if config exists

This commit is contained in:
shagu
2019-03-31 14:59:20 +02:00
parent 0a376bc251
commit 497a053e60
+8
View File
@@ -340,9 +340,17 @@ end
function pfUI.api.HookAddonOrVariable(addon, func) function pfUI.api.HookAddonOrVariable(addon, func)
local lurker = CreateFrame("Frame", nil) local lurker = CreateFrame("Frame", nil)
lurker.func = func lurker.func = func
lurker:RegisterEvent("ADDON_LOADED")
lurker:RegisterEvent("VARIABLES_LOADED") lurker:RegisterEvent("VARIABLES_LOADED")
lurker:RegisterEvent("PLAYER_ENTERING_WORLD") lurker:RegisterEvent("PLAYER_ENTERING_WORLD")
lurker:SetScript("OnEvent",function() lurker:SetScript("OnEvent",function()
-- only run when config is available
if event == "ADDON_LOADED" and not this.foundConfig then
return
elseif event == "VARIABLES_LOADED" then
this.foundConfig = true
end
if IsAddOnLoaded(addon) or _G[addon] then if IsAddOnLoaded(addon) or _G[addon] then
this:func() this:func()
this:UnregisterAllEvents() this:UnregisterAllEvents()