From 0b6f5939cd8f5397c4f2d7906b2fc68eebc34f28 Mon Sep 17 00:00:00 2001
From: ReturnFI <151555003+ReturnFI@users.noreply.github.com>
Date: Mon, 15 Dec 2025 19:57:29 +0000
Subject: [PATCH] feat(webpanel): add restart button for Hysteria2 service with
fetch handling
---
core/scripts/webpanel/assets/js/index.js | 53 ++++++++++++++++++++++
core/scripts/webpanel/templates/index.html | 6 ++-
2 files changed, 58 insertions(+), 1 deletion(-)
diff --git a/core/scripts/webpanel/assets/js/index.js b/core/scripts/webpanel/assets/js/index.js
index a8ec42e..22f87ea 100644
--- a/core/scripts/webpanel/assets/js/index.js
+++ b/core/scripts/webpanel/assets/js/index.js
@@ -53,6 +53,15 @@ function updateServiceBox(serviceName, status) {
statusBox.classList.remove('bg-success');
statusBox.classList.add('bg-danger');
}
+
+ if (serviceName === 'hysteria2') {
+ const restartBtn = document.getElementById('restart-hysteria2-btn');
+ if (status === true) {
+ restartBtn.style.display = 'none';
+ } else {
+ restartBtn.style.display = 'block';
+ }
+ }
}
document.addEventListener('DOMContentLoaded', function () {
@@ -70,4 +79,48 @@ document.addEventListener('DOMContentLoaded', function () {
toggleIpBtn.querySelector('i').classList.toggle('fa-eye');
toggleIpBtn.querySelector('i').classList.toggle('fa-eye-slash');
});
+
+ const restartBtn = document.getElementById('restart-hysteria2-btn');
+ const restartUrl = document.querySelector('.content').dataset.restartHysteriaUrl;
+
+ restartBtn.addEventListener('click', function(e) {
+ e.preventDefault();
+
+ restartBtn.innerHTML = 'Restarting... ';
+ restartBtn.style.pointerEvents = 'none';
+
+ fetch(restartUrl, {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ }
+ })
+ .then(response => {
+ if (!response.ok) {
+ return response.json().then(err => { throw new Error(err.detail || 'Unknown error'); });
+ }
+ return response.json();
+ })
+ .then(data => {
+ Swal.fire({
+ icon: 'success',
+ title: 'Success',
+ text: data.detail,
+ timer: 2000,
+ showConfirmButton: false
+ });
+ setTimeout(updateServiceStatuses, 1000);
+ })
+ .catch(error => {
+ Swal.fire({
+ icon: 'error',
+ title: 'Error',
+ text: `Failed to restart Hysteria2: ${error.message}`
+ });
+ })
+ .finally(() => {
+ restartBtn.innerHTML = 'Restart Service ';
+ restartBtn.style.pointerEvents = 'auto';
+ });
+ });
});
\ No newline at end of file
diff --git a/core/scripts/webpanel/templates/index.html b/core/scripts/webpanel/templates/index.html
index 497b44b..0806813 100644
--- a/core/scripts/webpanel/templates/index.html
+++ b/core/scripts/webpanel/templates/index.html
@@ -15,7 +15,8 @@
+ data-services-status-url="{{ url_for('server_services_status_api') }}"
+ data-restart-hysteria-url="{{ url_for('restart_service') }}">