One-shot event handlers: use EventUtil.RegisterOnceFrameEventAndCallback instead of self-unregistering frames

This commit is contained in:
Brues
2026-11-03 01:07:02 -06:00
parent d143e91f81
commit 70bfc1c443
7 changed files with 10 additions and 59 deletions
+1 -4
View File
@@ -935,14 +935,11 @@ pfUI_profiles["Adapta"].new_module_positions = pfUI_profiles["Modern"].new_modul
-- overwrite core profiles in userdata
local profile_loader = CreateFrame("Frame")
profile_loader:RegisterEvent("VARIABLES_LOADED")
profile_loader:SetScript("OnEvent", function()
EventUtil.RegisterOnceFrameEventAndCallback("VARIABLES_LOADED", function()
pfUI_profiles["Modern"] = modern
pfUI_profiles["Nostalgia"] = nostalgia
pfUI_profiles["Legacy"] = legacy
pfUI_profiles["Adapta"] = adapta
pfUI_profiles["Light"] = light
pfUI_profiles["Slim"] = slim
this:UnregisterAllEvents()
end)
+1 -7
View File
@@ -139,8 +139,7 @@ function libthrottle:ResetAllToDefaults()
end
-- Initialize - set defaults if config doesn't exist
libthrottle:SetScript("OnEvent", function()
if event == "PLAYER_ENTERING_WORLD" then
EventUtil.RegisterOnceFrameEventAndCallback("PLAYER_ENTERING_WORLD", function()
if not _G.pfUI_throttle then
_G.pfUI_throttle = {}
end
@@ -155,12 +154,7 @@ libthrottle:SetScript("OnEvent", function()
-- Set defaults for custom fields if missing
if not _G.pfUI_throttle.tooltip_cursor_custom then _G.pfUI_throttle.tooltip_cursor_custom = "10" end
if not _G.pfUI_throttle.chat_tab_custom then _G.pfUI_throttle.chat_tab_custom = "10" end
this:UnregisterEvent("PLAYER_ENTERING_WORLD")
end
end)
libthrottle:RegisterEvent("PLAYER_ENTERING_WORLD")
-- Export to pfUI namespace for easier access
pfUI.throttle = libthrottle
+1 -5
View File
@@ -1,7 +1,5 @@
pfUI:RegisterModule("chatcopy", function ()
local f = CreateFrame("Frame")
f:RegisterEvent("PLAYER_ENTERING_WORLD")
f:SetScript("OnEvent", function()
EventUtil.RegisterOnceFrameEventAndCallback("PLAYER_ENTERING_WORLD", function()
if not pfUI.chat then return end
local button = CreateFrame("Button", "pfChatCopyButton", pfUI.chat.left.panelTop)
@@ -99,7 +97,5 @@ pfUI:RegisterModule("chatcopy", function ()
frame.scroll = scroll
end
this:UnregisterAllEvents()
end)
end)
+1 -5
View File
@@ -801,11 +801,7 @@ pfUI:RegisterModule("thirdparty-vanilla", function()
HookAddon("SortBags", function()
if C.thirdparty.sortbags.enable == "0" then return end
local sort = CreateFrame("Frame", nil)
sort:RegisterEvent("PLAYER_ENTERING_WORLD")
sort:SetScript("OnEvent", function()
this:UnregisterAllEvents()
EventUtil.RegisterOnceFrameEventAndCallback("PLAYER_ENTERING_WORLD", function()
pfUI.thirdparty.RegisterBagSort("SortBags",
function()
SortBags()
+1 -5
View File
@@ -142,11 +142,7 @@ pfUI:RegisterModule("thirdparty", function()
HookAddon("MrPlow", function()
if C.thirdparty.mrplow.enable == "0" then return end
local sort = CreateFrame("Frame", nil)
sort:RegisterEvent("PLAYER_ENTERING_WORLD")
sort:SetScript("OnEvent", function()
this:UnregisterAllEvents()
EventUtil.RegisterOnceFrameEventAndCallback("PLAYER_ENTERING_WORLD", function()
local MrPlowL = AceLibrary and AceLibrary("AceLocale-2.2"):new("MrPlow")
if not (MrPlowL and MrPlowL["Bank"]) then return end
+1 -27
View File
@@ -180,33 +180,7 @@ pfUI:RegisterModule("unitxp", function ()
CreateTargetIndicators()
-- Also try on PLAYER_ENTERING_WORLD in case target frame wasn't ready
local initFrame = CreateFrame("Frame")
initFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
initFrame:RegisterEvent("PLAYER_LOGOUT")
initFrame:SetScript("OnEvent", function()
-- Handle shutdown to prevent crash 132
if event == "PLAYER_LOGOUT" then
this:UnregisterAllEvents()
this:SetScript("OnEvent", nil)
-- Stop indicator OnUpdate scripts
if pfUI.uf and pfUI.uf.target then
if pfUI.uf.target.behindIndicator then
pfUI.uf.target.behindIndicator:SetScript("OnUpdate", nil)
end
if pfUI.uf.target.distanceIndicator then
pfUI.uf.target.distanceIndicator:SetScript("OnUpdate", nil)
end
-- free-frame mode polls from its own scanner frame, not the indicator
if pfUI.uf.target.distanceScanner then
pfUI.uf.target.distanceScanner:SetScript("OnUpdate", nil)
end
end
return
end
CreateTargetIndicators()
this:UnregisterAllEvents()
end)
EventUtil.RegisterOnceFrameEventAndCallback("PLAYER_ENTERING_WORLD", CreateTargetIndicators)
-- OS Notification Support
if C.unitframes.unitxp_notify == "1" then
+4 -6
View File
@@ -5,10 +5,9 @@ pfUI:RegisterSkin("Mailbox", function ()
-- Compatibility
local StationeryBackgroundLeft, StationeryBackgroundRight
do -- SendMailFrame
local skin = CreateFrame("Frame")
skin:SetScript("OnEvent", function()
this:UnregisterEvent("MAIL_SHOW")
if not this._Mail then
local mailLoaded
EventUtil.RegisterOnceFrameEventAndCallback("MAIL_SHOW", function()
if not mailLoaded then
StripTextures(SendMailPackageButton)
SkinButton(SendMailPackageButton, nil, nil, nil, nil, true)
@@ -26,10 +25,9 @@ pfUI:RegisterSkin("Mailbox", function ()
end)
end
end)
skin:RegisterEvent("MAIL_SHOW")
HookAddon("Mail", function()
skin._Mail = true
mailLoaded = true
for i = 1, 21 do
local button = _G["MailAttachment"..i]
StripTextures(button)