From a0f0a96b4f7c329203400e6ef011b5da3791eded Mon Sep 17 00:00:00 2001 From: hius07 <62179190+hius07@users.noreply.github.com> Date: Fri, 30 May 2025 14:57:58 +0300 Subject: [PATCH] Profiles auto-exec "On showing folder": add "path is (not) equal" conditions (#13873) --- plugins/profiles.koplugin/main.lua | 32 +++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/plugins/profiles.koplugin/main.lua b/plugins/profiles.koplugin/main.lua index f06bb304d..af61e7dcc 100644 --- a/plugins/profiles.koplugin/main.lua +++ b/plugins/profiles.koplugin/main.lua @@ -617,21 +617,23 @@ function Profiles:genAutoExecPathChangedMenuItem(text, event, profile_name, sepa local conditions = { { _("if folder path contains"), "has" }, { _("if folder path does not contain"), "has_not" }, + { _("if folder path is equal"), "is_equal" }, + { _("if folder path is not equal"), "is_not_equal" }, } local sub_item_table = {} for i, mode in ipairs(conditions) do + local condition = mode[2] sub_item_table[i] = { text_func = function() - local txt = conditions[i][1] - local value = util.tableGetValue(self.autoexec, event, profile_name, conditions[i][2]) + local txt = mode[1] + local value = util.tableGetValue(self.autoexec, event, profile_name, condition) return value and txt .. ": " .. value or txt end, no_refresh_on_check = true, checked_func = function() - return util.tableGetValue(self.autoexec, event, profile_name, conditions[i][2]) + return util.tableGetValue(self.autoexec, event, profile_name, condition) end, callback = function(touchmenu_instance) - local condition = conditions[i][2] local dialog local buttons = {{ { @@ -672,6 +674,10 @@ function Profiles:genAutoExecPathChangedMenuItem(text, event, profile_name, sepa UIManager:show(dialog) dialog:onShowKeyboard() end, + hold_callback = function(touchmenu_instance) + util.tableRemoveValue(self.autoexec, event, profile_name, condition) + touchmenu_instance:updateItems() + end, } end return sub_item_table @@ -985,11 +991,19 @@ function Profiles:onPathChanged(path) -- global end for profile_name, conditions in pairs(self.autoexec[event]) do local do_execute - if conditions.has then - do_execute = is_match(path, conditions.has) - end - if do_execute == nil and conditions.has_not then - do_execute = not is_match(path, conditions.has_not) + for condition, trigger in pairs(conditions) do + if condition == "has" then + do_execute = is_match(path, trigger) + elseif condition == "has_not" then + do_execute = not is_match(path, trigger) + elseif condition == "is_equal" then + do_execute = path == trigger + elseif condition == "is_not_equal" then + do_execute = path ~= trigger + end + if do_execute then + break + end end if do_execute then self:executeAutoExec(profile_name)