From 70bfc1c443035aab7a4c3e7859063ca4a265037f Mon Sep 17 00:00:00 2001 From: Brues <5278969+brues-code@users.noreply.github.com> Date: Mon, 2 Nov 2026 21:16:30 -0600 Subject: [PATCH] One-shot event handlers: use EventUtil.RegisterOnceFrameEventAndCallback instead of self-unregistering frames --- env/profiles.lua | 5 +---- libs/libthrottle.lua | 8 +------- modules/chatcopy.lua | 6 +----- modules/thirdparty-vanilla.lua | 6 +----- modules/thirdparty.lua | 6 +----- modules/unitxp.lua | 28 +--------------------------- skins/blizzard/mail.lua | 10 ++++------ 7 files changed, 10 insertions(+), 59 deletions(-) diff --git a/env/profiles.lua b/env/profiles.lua index cea27159..60b5a18f 100644 --- a/env/profiles.lua +++ b/env/profiles.lua @@ -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) \ No newline at end of file diff --git a/libs/libthrottle.lua b/libs/libthrottle.lua index 393d8a34..f78118bf 100644 --- a/libs/libthrottle.lua +++ b/libs/libthrottle.lua @@ -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 diff --git a/modules/chatcopy.lua b/modules/chatcopy.lua index 3acd8458..bc5a35f5 100644 --- a/modules/chatcopy.lua +++ b/modules/chatcopy.lua @@ -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) diff --git a/modules/thirdparty-vanilla.lua b/modules/thirdparty-vanilla.lua index 6ac19c44..abf3d8cb 100644 --- a/modules/thirdparty-vanilla.lua +++ b/modules/thirdparty-vanilla.lua @@ -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() diff --git a/modules/thirdparty.lua b/modules/thirdparty.lua index c7fbaaa4..33a6d3dd 100644 --- a/modules/thirdparty.lua +++ b/modules/thirdparty.lua @@ -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 diff --git a/modules/unitxp.lua b/modules/unitxp.lua index e6fa254d..104812a1 100644 --- a/modules/unitxp.lua +++ b/modules/unitxp.lua @@ -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 diff --git a/skins/blizzard/mail.lua b/skins/blizzard/mail.lua index 6001232f..64547e62 100644 --- a/skins/blizzard/mail.lua +++ b/skins/blizzard/mail.lua @@ -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)