Skip to content

Commit

Permalink
hydrate persisted features
Browse files Browse the repository at this point in the history
Signed-off-by: Allen Faure <[email protected]>
  • Loading branch information
emptyrivers committed Jan 30, 2024
1 parent 9e1fcfa commit 8cbc64c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
16 changes: 14 additions & 2 deletions WeakAuras/Features.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ end

---@param id string
function Features:Enable(id)
if self.__feats[id] then
if self:Exists(id) and not self.__feats[id].enabled then
self.__feats[id].enabled = true
if self.__feats[id].persist then
Private.db.features[id] = true
Expand All @@ -41,7 +41,7 @@ end

---@param id string
function Features:Disable(id)
if self.__feats[id] then
if self:Exists(id) and self.__feats[id].enabled then
self.__feats[id].enabled = false
if self.__feats[id].persist then
Private.db.features[id] = false
Expand All @@ -50,6 +50,18 @@ function Features:Disable(id)
end
end

-- enable persisted features from the db
function Features:Hydrate()
for id, enabled in (Private.db.features) do
if not self:Exists(id) then
Private.db.features[id] = nil
end
if enabled then
self:Enable(id)
end
end
end

---@param feature feature
function Features:Register(feature)
if not self.__feats[feature.id] then
Expand Down
1 change: 1 addition & 0 deletions WeakAuras/WeakAuras.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1171,6 +1171,7 @@ function Private.Login(initialTime, takeNewSnapshots)
Private.Pause();

db.features = db.features or {}
Private.Features:Hydrate()
if db.history then
local histRepo = WeakAuras.LoadFromArchive("Repository", "history")
local migrationRepo = WeakAuras.LoadFromArchive("Repository", "migration")
Expand Down

0 comments on commit 8cbc64c

Please sign in to comment.