From 7eee2c15d9e2db6712ed41346c2d74c6c2689c22 Mon Sep 17 00:00:00 2001 From: hius07 <62179190+hius07@users.noreply.github.com> Date: Mon, 20 Apr 2026 07:58:30 +0300 Subject: [PATCH] Profiles: keep settings in the base class (#15270) --- plugins/profiles.koplugin/main.lua | 45 ++++++++++++++---------------- 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/plugins/profiles.koplugin/main.lua b/plugins/profiles.koplugin/main.lua index bf2edde6a..2c4f96a05 100644 --- a/plugins/profiles.koplugin/main.lua +++ b/plugins/profiles.koplugin/main.lua @@ -22,43 +22,41 @@ local autostart_done local Profiles = WidgetContainer:extend{ name = "profiles", prefix = "profile_exec_", - profiles_file = DataStorage:getSettingsDir() .. "/profiles.lua", - profiles = nil, - data = nil, - updated = false, + settings_file = DataStorage:getSettingsDir() .. "/profiles.lua", + data = nil, -- direct access to the settings table + updated = nil, } function Profiles:init() Dispatcher:init() self.autoexec = G_reader_settings:readSetting("profiles_autoexec", {}) self.ui.menu:registerToMainMenu(self) - self:onDispatcherRegisterActions() + self:onDispatcherRegisterActions() -- will call loadSettings() self:onStart() end -function Profiles:loadProfiles() - if self.profiles then - return - end - self.profiles = LuaSettings:open(self.profiles_file) - self.data = self.profiles.data - -- ensure profile name - for k, v in pairs(self.data) do - if not v.settings then - v.settings = {} +function Profiles:loadSettings() + if not Profiles.settings then + Profiles.settings = LuaSettings:open(self.settings_file) + if not next(Profiles.settings.data) then + self.updated = true -- first run, force flush end - if not v.settings.name then - v.settings.name = k - self.updated = true + -- ensure profile name + for k, v in pairs(Profiles.settings.data) do + v.settings = v.settings or {} + if not v.settings.name then + v.settings.name = k + self.updated = true + end end end - self:onFlushSettings() + self.data = Profiles.settings.data end function Profiles:onFlushSettings() - if self.profiles and self.updated then - self.profiles:flush() - self.updated = false + if self.updated then + Profiles.settings:flush() + self.updated = nil end end @@ -72,7 +70,7 @@ local function dispatcherUnregisterProfile(name) end function Profiles:onDispatcherRegisterActions() - self:loadProfiles() + self:loadSettings() for k, v in pairs(self.data) do if v.settings.registered then dispatcherRegisterProfile(k) @@ -90,7 +88,6 @@ function Profiles:addToMainMenu(menu_items) end function Profiles:getSubMenuItems() - self:loadProfiles() local sub_item_table = { { text = _("New"),