Skip to content

Commit cd69863

Browse files
committed
Fixed TSM detection logic.
1 parent e3d9148 commit cd69863

File tree

2 files changed

+43
-14
lines changed

2 files changed

+43
-14
lines changed

LibMagicUtil-1.0.toc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Lib## Interface: 120001, 50503, 38000, 20505, 11508
1+
## Interface: 120001, 50503, 38000, 20505, 11508
22
## X-Curse-Project-ID: 18625
33
## LoadOnDemand: 1
44
## Title: Lib: MagicUtil-1.0
@@ -10,5 +10,6 @@ Lib## Interface: 120001, 50503, 38000, 20505, 11508
1010
## X-License: GPLv3
1111

1212
LibStub.lua
13+
bootstrap.lua
1314
LibMagicUtil-1.0\lib.xml
1415

LibMagicUtil-1.0/LibMagicUtil-1.0.lua

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ After embedding you will be able to use the following methods:
2525

2626
local MAJOR = "LibMagicUtil-1.0"
2727
local MINOR = tonumber("@project-date-integer@") or tonumber(date("%Y%m%d%H%M%S"))
28-
28+
-- Standalone addon sets this flag via bootstrap.lua (loaded from .toc before lib.xml).
29+
-- Embedded copies don't run bootstrap.lua, so the flag is nil for them.
30+
-- Bumping MINOR ensures the standalone copy always wins over embedded copies.
31+
if LIBMAGICUTIL_STANDALONE then
32+
MINOR = MINOR + 1
33+
end
2934
local lib = LibStub:NewLibrary(MAJOR, MINOR)
3035
local media = LibStub("LibSharedMedia-3.0")
3136
local L = LibStub("AceLocale-3.0"):GetLocale("LibMagicUtil-1.0", false)
@@ -256,19 +261,42 @@ function lib:InterfaceOptionsFrame_OpenToCategory(categoryIDOrFrame)
256261
end
257262
end
258263

259-
-- Returns the currently visible mail frame. Checks for TSM's mail frame first
260-
-- (which replaces the default MailFrame), then falls back to the default MailFrame.
264+
-- Returns the active mail frame and whether it's TSM.
265+
-- Second return value is true if the returned frame is TSM's mail frame.
266+
-- Finds TSM's mail window by looking for the MailsScrollTable element
267+
-- (unique to TSM's mail UI) and walking up to the top-level parent.
268+
local cachedTSMMailFrame
269+
local function FindTSMMailFrame()
270+
if cachedTSMMailFrame then
271+
return cachedTSMMailFrame
272+
end
273+
-- Find MailsScrollTable, then walk up to the LargeApplicationFrame
274+
local frame = EnumerateFrames()
275+
while frame do
276+
local name = frame:GetName()
277+
if name and type(name) == "string" and name:match("^TSM_FRAME:MailsScrollTable:") then
278+
-- Walk up the parent chain to find the top-level TSM frame
279+
local parent = frame:GetParent()
280+
while parent and parent ~= UIParent do
281+
local parentName = parent:GetName()
282+
if parentName and type(parentName) == "string" and parentName:match("^TSM_FRAME:LargeApplicationFrame:") then
283+
cachedTSMMailFrame = parent
284+
return parent
285+
end
286+
parent = parent:GetParent()
287+
end
288+
end
289+
frame = EnumerateFrames(frame)
290+
end
291+
return nil
292+
end
293+
261294
function lib:GetMailFrame()
262-
for i = 1, #UISpecialFrames do
263-
local name = UISpecialFrames[i]
264-
if name:match("^TSM_FRAME:LargeApplicationFrame:") then
265-
local frame = _G[name]
266-
if frame and frame:IsShown() then
267-
return frame
268-
end
269-
end
270-
end
271-
return MailFrame
295+
local tsmFrame = FindTSMMailFrame()
296+
if tsmFrame and tsmFrame:IsShown() then
297+
return tsmFrame, true
298+
end
299+
return MailFrame, false
272300
end
273301

274302
-- Config template for a frame background

0 commit comments

Comments
 (0)