A simple solution would be to move the contents of your LSMLaunch.lua file into a callback function that gets called when your addon's active profile changes (or is loaded at login). Add this in your main file:
Lua Code:
function BasicUI:OnInitialize()
self.db = LibStub("AceDB-3.0"):New("BasicDB", defaults, true)
self.db.RegisterCallback(self, "OnProfileChanged", "OnProfileChanged")
self.db.RegisterCallback(self, "OnProfileCopied", "OnProfileChanged")
self.db.RegisterCallback(self, "OnProfileReset", "OnProfileChanged")
end
And then modify your LSMLaunch.lua file like so:
Lua Code:
local BasicUI = LibStub("AceAddon-3.0"):GetAddon("BasicUI")
local LSM = LibStub("LibSharedMedia-3.0")
local cfg
function BasicUI:OnProfileChanged()
cfg = BasicUI.db.profile
-- Load All SharedMedia
-- Font Media
cfg.media.fontNormal = LSM:Fetch("font", cfg.media.fontNormal)
cfg.media.fontBold = LSM:Fetch("font", cfg.media.fontBold)
cfg.media.fontItalic = LSM:Fetch("font", cfg.media.fontItalic)
cfg.media.fontBoldItalic = LSM:Fetch("font", cfg.media.fontBoldItalic)
cfg.media.fontNumber = LSM:Fetch("font", cfg.media.fontNumber)
-- Minimap Media
cfg.minimap.border = LSM:Fetch("border", cfg.minimap.border)
-- Skins Media
cfg.skin.border = LSM:Fetch("border", cfg.skin.border)
cfg.skin.statusbar = LSM:Fetch("statusbar", cfg.skin.statusbar)
-- Buff Media
cfg.buff.border = LSM:Fetch("border", cfg.buff.border)
-- Castbar Media
cfg.castbar.border = LSM:Fetch("border", cfg.castbar.border)
cfg.castbar.background = LSM:Fetch("background", cfg.castbar.background)
cfg.castbar.statusbar = LSM:Fetch("statusbar", cfg.castbar.statusbar)
-- Chat Media
cfg.chat.border = LSM:Fetch("border", cfg.chat.border)
cfg.chat.background = LSM:Fetch("background", cfg.chat.background)
cfg.chat.editboxborder = LSM:Fetch("border", cfg.chat.editboxborder)
cfg.chat.editboxbackground = LSM:Fetch("background", cfg.chat.editboxbackground)
cfg.chat.sound = LSM:Fetch("sound", cfg.chat.sound)
-- Datatext Media
cfg.datatext.border = LSM:Fetch("border", cfg.datatext.border)
cfg.datatext.background = LSM:Fetch("background", cfg.datatext.background)
-- Nameplates Media
cfg.nameplates.border = LSM:Fetch("border", cfg.nameplates.border)
cfg.nameplates.background = LSM:Fetch("background", cfg.nameplates.background)
cfg.nameplates.statusbar = LSM:Fetch("statusbar", cfg.nameplates.statusbar)
-- Powerbar Media
cfg.powerbar.background = LSM:Fetch("background", cfg.powerbar.background)
cfg.powerbar.statusbar = LSM:Fetch("statusbar", cfg.powerbar.statusbar)
-- Tooltip Media
cfg.tooltip.border = LSM:Fetch("border", cfg.tooltip.border)
cfg.tooltip.background = LSM:Fetch("background", cfg.tooltip.background)
cfg.tooltip.statusbar = LSM:Fetch("statusbar", cfg.tooltip.statusbar)
end)
However, there is a major flaw in your reasoning here. Presumably you are trying to convert names like "Arial Narrow" into file paths like "Fonts\\ARIALN__.ttf" for use in your addon, but with the code you are using, you are actually modifying what is saved in your addon's DB, so after the first time this code runs, "Arial Narrow" is no longer the value in the DB -- "Fonts\\ARIALN__.ttf" is -- and since LSM:Fetch requires a font name, not a file path, you will end up changing all of your fonts to whatever LSM's default font for your locale is, eg. "Fonts\\FRIZQT__ttf.".
What you should actually be doing, if you want to use LibSharedMedia, is storing the font name -- eg. "Arial Narrow" -- in your DB, and then look up the actual file path only when you're actually applying the font to a fontstring, eg:
Lua Code:
local fontPath = LSM:Fetch("font", cfg.media.fontNormal)
MY_FONT_STRING:SetFont(fontPath, 18, "OUTLINE")
Obviously, if you're setting the font on 20 fontstrings in the same chunk of code, you should only look up the font path once, and reuse the variable.
Finally, based on the contents of your
defaults table you appear to be embedding part or all of
Postal in your addon, which is a copyright no-no since that addon is not licensed under terms which allow you to redistribute it. Either get permission from Xinhuan to embed his addon, or write your own mailbox modules, or just recommend Postal as a companion to your UI.