From 5230edf051fdf73ce7dcd5968987fa9342c24d70 Mon Sep 17 00:00:00 2001 From: zxlhhyccc Date: Sun, 1 Feb 2026 13:20:26 +0800 Subject: [PATCH] luci-app-ssr-plus: Restore default CBI save & apply behavior. --- .../model/cbi/shadowsocksr/client-config.lua | 141 +--- .../luasrc/model/cbi/shadowsocksr/servers.lua | 33 +- .../view/shadowsocksr/optimize_cbi_ui.htm | 24 + .../luasrc/view/shadowsocksr/server_list.htm | 55 ++ luci-app-ssr-plus/po/templates/ssr-plus.pot | 686 +++++++++-------- luci-app-ssr-plus/po/zh_Hans/ssr-plus.po | 689 +++++++++--------- 6 files changed, 791 insertions(+), 837 deletions(-) create mode 100644 luci-app-ssr-plus/luasrc/view/shadowsocksr/optimize_cbi_ui.htm diff --git a/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/client-config.lua b/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/client-config.lua index b05e9662059..f65a3007803 100644 --- a/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/client-config.lua +++ b/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/client-config.lua @@ -22,122 +22,31 @@ local function is_installed(e) return luci.model.ipkg.installed(e) end --- 判断系统是否 JS 版 LuCI -local function is_js_luci() - return luci.sys.call('[ -f "/www/luci-static/resources/uci.js" ]') == 0 -end - --- 显示提示条 -local function showMsg_Redirect(redirectUrl, delay) - local message = translate("Applying configuration changes… %ds") - luci.http.write([[ - - ]]) -end - --- 兼容新旧版本 LuCI -local function set_apply_on_parse(map) - if not map then - return - end - - if is_js_luci() then - -- JS 版 LuCI:显示提示条并延迟跳转 - map.apply_on_parse = false - map.on_after_apply = function(self) - luci.http.prepare_content("text/html") - showMsg_Redirect(self.redirect or luci.dispatcher.build_url() , 3000) - end +-- 默认的保存并应用行为 +local function apply_redirect(m) + local tmp_uci_file = "/etc/config/" .. "shadowsocksr" .. "_redirect" + if m.redirect and m.redirect ~= "" then + if nixio.fs.access(tmp_uci_file) then + local redirect + for line in io.lines(tmp_uci_file) do + redirect = line:match("option%s+url%s+['\"]([^'\"]+)['\"]") + if redirect and redirect ~= "" then break end + end + if redirect and redirect ~= "" then + luci.sys.call("/bin/rm -f " .. tmp_uci_file) + luci.http.redirect(redirect) + end + else + nixio.fs.writefile(tmp_uci_file, "config redirect\n") + end + m.on_after_save = function(self) + local redirect = self.redirect + if redirect and redirect ~= "" then + uci:set("shadowsocksr" .. "_redirect", "@redirect[0]", "url", redirect) + end + end else - -- Lua 版 LuCI:直接跳转 - map.apply_on_parse = true - map.on_after_apply = function(self) - luci.http.redirect(self.redirect) - end - end - - -- 保持原渲染流程 - map.render = function(self, ...) - getmetatable(self).__index.render(self, ...) -- 保持原渲染流程 + luci.sys.call("/bin/rm -f " .. tmp_uci_file) end end @@ -263,7 +172,7 @@ if m.uci:get("shadowsocksr", sid) ~= "servers" then return end -- 保存&应用成功后跳转到节点列表 -set_apply_on_parse(m) +apply_redirect(m) -- [[ Servers Setting ]]-- s = m:section(NamedSection, sid, "servers") diff --git a/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/servers.lua b/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/servers.lua index 5303655a377..13b02077610 100644 --- a/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/servers.lua +++ b/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/servers.lua @@ -4,6 +4,7 @@ require "luci.sys" require "nixio.fs" require "luci.dispatcher" require "luci.model.uci" +local cbi = require "luci.cbi" local uci = require "luci.model.uci".cursor() local m, s, o, node @@ -14,31 +15,6 @@ local function is_finded(e) return luci.sys.exec(string.format('type -t -p "%s" 2>/dev/null', e)) ~= "" end --- 优化 CBI UI(新版 LuCI 专用) -local function optimize_cbi_ui() - luci.http.write([[ - - ]]) -end - local has_xray = is_finded("xray") local has_hysteria2 = is_finded("hysteria") @@ -242,6 +218,7 @@ s = m:section(TypedSection, "servers") s.anonymous = true s.addremove = true s.template = "cbi/tblsection" +s:append(cbi.Template("shadowsocksr" .. "/optimize_cbi_ui")) s.sortable = true s.extedit = luci.dispatcher.build_url("admin", "services", "shadowsocksr", "servers", "%s") function s.create(...) @@ -251,12 +228,6 @@ function s.create(...) return end end -s.render = function(self, ...) - Map.render(self, ...) - if type(optimize_cbi_ui) == "function" then - optimize_cbi_ui() - end -end o = s:option(DummyValue, "type", translate("Type")) function o.cfgvalue(self, section) diff --git a/luci-app-ssr-plus/luasrc/view/shadowsocksr/optimize_cbi_ui.htm b/luci-app-ssr-plus/luasrc/view/shadowsocksr/optimize_cbi_ui.htm new file mode 100644 index 00000000000..579d03835b1 --- /dev/null +++ b/luci-app-ssr-plus/luasrc/view/shadowsocksr/optimize_cbi_ui.htm @@ -0,0 +1,24 @@ + diff --git a/luci-app-ssr-plus/luasrc/view/shadowsocksr/server_list.htm b/luci-app-ssr-plus/luasrc/view/shadowsocksr/server_list.htm index 3e5cfc96fff..d40da9c67cd 100644 --- a/luci-app-ssr-plus/luasrc/view/shadowsocksr/server_list.htm +++ b/luci-app-ssr-plus/luasrc/view/shadowsocksr/server_list.htm @@ -2,6 +2,61 @@ Copyright 2018-2019 Lienol Licensed to the public under the Apache License 2.0. -%> +<% +require "luci.sys" +function is_js_luci() + return luci.sys.call('[ -f "/www/luci-static/resources/uci.js" ]') == 0 +end +-%> +<% if is_js_luci() then -%> + +<%- else %> + +<%- end %> +