OnInitialize() is called once, during AddOn startup. Think of it as a very fancy wrapper for ADDON_LOADED, because, among other things, you do not need to weed out all the other AddOns to find yours.
OnEnable() and OnDisable() are called whenever your AddOn is enabled or disabled. In your defaults table, if you have a variable that flags the AddOn as enabled (call it enabled, or enabledAddOn, or Tony) "true", you can then, in OnInit, after setting up the SVs, call
Code:
self:SetEnabledState(self.db.profile.enabled)
If the value is true, then OnEnable() will run immediately after OnInit(), otherwise, OnDisable() will be called. In your options table, it would look like this:
Code:
enabled = {
order = 10,
type = "toggle",
name = ENABLE, -- use Blizzard's globalstring
get = function() return self.db.profile.enabled end,
set = function(_, value)
self.db.profile.enabled = value
if value then
self:OnEnable()
else
self:OnDisable()
end
end
}