Skip to content

Commit 680591e

Browse files
committed
UI: Implement a fallback to display when Options are disabled
With the lazy-loading approach, it's possible that players might disable the Options module (accidentally, usually) and then get script errors when AceConfig tries to load the UI tree. This is a pretty basic fallback UI which allows loading the options seamlessly in case they were accidentally disabled. Don't know if there are other cases where this might fail, but it's better than nothing.
1 parent f655276 commit 680591e

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

Core.lua

+32-7
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ local IsSpellKnown = _G.IsSpellKnown
111111
local CombatLogGetCurrentEventInfo = _G.CombatLogGetCurrentEventInfo
112112
local IsQuestFlaggedCompleted = _G.C_QuestLog.IsQuestFlaggedCompleted
113113
local C_Covenants = _G.C_Covenants
114+
local EnableAddOn = C_AddOns.EnableAddOn
115+
local IsAddOnLoadable = C_AddOns.IsAddOnLoadable
116+
local IsAddOnLoaded = C_AddOns.IsAddOnLoaded
114117
local LoadAddOn = _G.C_AddOns.LoadAddOn
115118

116119
local COMBATLOG_OBJECT_AFFILIATION_MINE = _G.COMBATLOG_OBJECT_AFFILIATION_MINE
@@ -347,6 +350,22 @@ do
347350
end
348351
end
349352

353+
local fallbackOptionsTable = {
354+
type = "group",
355+
name = L["Rarity"],
356+
width = "full",
357+
args = {
358+
enable = {
359+
name = L["Attempt to enable the Options module"],
360+
type = "execute",
361+
width = "full",
362+
func = function(info, val)
363+
EnableAddOn("Rarity_Options")
364+
end,
365+
},
366+
},
367+
}
368+
350369
function Rarity:LazyLoadOptions(which)
351370
local options = R[which]
352371
if type(options) == "table" then
@@ -355,21 +374,27 @@ function Rarity:LazyLoadOptions(which)
355374
end
356375

357376
Rarity.Profiling:StartTimer("RarityOptions: LoadAddon")
358-
LoadAddOn("Rarity_Options")
377+
local didLoad, errorMessage = LoadAddOn("Rarity_Options")
378+
if not didLoad then
379+
Rarity:Debug("Options failed to load? Reason: " .. errorMessage or "nil")
380+
return fallbackOptionsTable
381+
end
359382
Rarity.Profiling:EndTimer("RarityOptions: LoadAddon")
360383

361384
return R[which]
362385
end
363386

364387
function Rarity:TryShowOptionsUI()
365-
Rarity:LazyLoadOptions()
366-
if R.options then
367-
Rarity.Profiling:StartTimer("RarityOptions: OpenToCategory")
368-
Settings.OpenToCategory("Rarity")
369-
Rarity.Profiling:EndTimer("RarityOptions: OpenToCategory")
370-
else
388+
local canLoadOptions, reason = IsAddOnLoadable("Rarity_Options")
389+
if not canLoadOptions and reason == "DISABLED" then
371390
self:Print(L["The Rarity Options module has been disabled. Log out and enable it from your add-ons menu."])
391+
return
372392
end
393+
394+
Rarity:LazyLoadOptions()
395+
Rarity.Profiling:StartTimer("RarityOptions: OpenToCategory")
396+
Settings.OpenToCategory("Rarity")
397+
Rarity.Profiling:EndTimer("RarityOptions: OpenToCategory")
373398
end
374399

375400
function R:DelayedInit()

Locales.lua

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ local L
22
L = LibStub("AceLocale-3.0"):NewLocale("Rarity", "enUS", true)
33

44
-- L["AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"] = true
5+
L["Attempt to enable the Options module"] = true
56
L["Personalized Goblin S.C.R.A.Per"] = true
67
L["Bronze Goblin Waveshredder"] = true
78
L["Darkfuse Precipitant"] = true

0 commit comments

Comments
 (0)