From 23203fd7a1166d0e26ae9131d78105e3032fe5f9 Mon Sep 17 00:00:00 2001 From: Ivan K Date: Thu, 13 Mar 2025 00:10:18 +0300 Subject: [PATCH] feat: add createSystemButton function to ButtonFactory and flush cache button --- .../resources/view/podkop/podkop.js | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/luci-app-podkop/htdocs/luci-static/resources/view/podkop/podkop.js b/luci-app-podkop/htdocs/luci-static/resources/view/podkop/podkop.js index 4c12951..e0672d1 100644 --- a/luci-app-podkop/htdocs/luci-static/resources/view/podkop/podkop.js +++ b/luci-app-podkop/htdocs/luci-static/resources/view/podkop/podkop.js @@ -620,6 +620,27 @@ const ButtonFactory = { onClick: () => showConfigModal(config.command, config.title), style: config.style }); + }, + + createSystemButton: function (config) { + return this.createButton({ + label: config.label, + additionalClass: `cbi-button-${config.type || ''}`, + onClick: () => { + try { + const result = config.systemFunction(); + if (config.successMessage) { + ui.addNotification(null, E('p', {}, _(config.successMessage))); + } + return result; + } catch (e) { + if (config.errorMessage) { + ui.addNotification(null, E('p', {}, _(config.errorMessage) + ': ' + e.message)); + } + } + }, + style: config.style + }); } }; @@ -760,7 +781,13 @@ let createStatusSection = function (podkopStatus, singboxStatus, podkop, luci, s E('strong', {}, _('Sing-box: ')), singbox.stdout ? singbox.stdout.trim() : _('Unknown'), '\n', E('strong', {}, _('OpenWrt Version: ')), system.stdout ? system.stdout.split('\n')[1].trim() : _('Unknown'), '\n', E('strong', {}, _('Device Model: ')), system.stdout ? system.stdout.split('\n')[4].trim() : _('Unknown') - ]) + ]), + ButtonFactory.createSystemButton({ + label: _('Flush Cache'), + systemFunction: () => ui.menu.flushCache(), + successMessage: _('Cache has been flushed successfully!'), + errorMessage: _('Failed to flush cache') + }) ]) ]) ]);