Skip to content

Commit

Permalink
don't delay ScanFrames on init fixes #7
Browse files Browse the repository at this point in the history
  • Loading branch information
mrbuds committed Oct 22, 2019
1 parent abdfb24 commit ced13f9
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions LibGetFrame-1.0.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local MAJOR_VERSION = "LibGetFrame-1.0"
local MINOR_VERSION = 7
local MINOR_VERSION = 8
if not LibStub then error(MAJOR_VERSION .. " requires LibStub.") end
local lib = LibStub:NewLibrary(MAJOR_VERSION, MINOR_VERSION)
if not lib then return end
Expand Down Expand Up @@ -86,11 +86,16 @@ local function ScanFrames(depth, frame, ...)
ScanFrames(depth, ...)
end

local function ScanForUnitFrames()
C_Timer.After(1, function()
local function ScanForUnitFrames(noDelay)
if noDelay then
wipe(GetFramesCache)
ScanFrames(0, UIParent)
end)
else
C_Timer.After(1, function()
wipe(GetFramesCache)
ScanFrames(0, UIParent)
end)
end
end

local function isFrameFiltered(name, ignoredFrames)
Expand Down Expand Up @@ -150,19 +155,19 @@ local defaultOptions = {
}

local GetFramesCacheListener
lib.Init = function()
lib.Init = function(noDelay)
GetFramesCacheListener = CreateFrame("Frame")
GetFramesCacheListener:RegisterEvent("PLAYER_REGEN_DISABLED")
GetFramesCacheListener:RegisterEvent("PLAYER_REGEN_ENABLED")
GetFramesCacheListener:RegisterEvent("PLAYER_ENTERING_WORLD")
GetFramesCacheListener:RegisterEvent("GROUP_ROSTER_UPDATE")
GetFramesCacheListener:SetScript("OnEvent", ScanForUnitFrames)

ScanForUnitFrames()
ScanForUnitFrames(noDelay)
end

function lib.GetUnitFrame(target, opt)
if not GetFramesCacheListener then lib.Init() end
if not GetFramesCacheListener then lib.Init(true) end
opt = opt or {}
setmetatable(opt, { __index = defaultOptions })

Expand Down

0 comments on commit ced13f9

Please sign in to comment.