Show Start/Stop/Restart Podman progress in a log modal
Same pattern already used for container update checking (P.openLogModal) — these can take a while (storage checks, container stop grace periods, ...) and are exactly the actions someone reaches for when something's actually wrong, so a button that just sits there disabled with no feedback until it's done isn't good enough. "Refresh Status" stays inline (quick, read-only, no modal needed). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -57,19 +57,12 @@
|
||||
});
|
||||
}
|
||||
|
||||
// --- Podman service status/start/restart ----------------------------------
|
||||
// --- Podman service status/start/stop/restart ------------------------------
|
||||
|
||||
function renderServiceResult(data) {
|
||||
function renderServiceChip(data) {
|
||||
const chip = P.el('settings-service-chip');
|
||||
chip.className = 'podman-chip ' + (data.running ? 'podman-chip-good' : 'podman-chip-bad');
|
||||
chip.innerHTML = '<span class="d"></span>' + (data.running ? 'Running' : 'Not running');
|
||||
|
||||
const log = P.el('settings-service-log');
|
||||
if (data.output) {
|
||||
log.style.display = '';
|
||||
log.textContent = data.output;
|
||||
log.scrollTop = log.scrollHeight;
|
||||
}
|
||||
}
|
||||
|
||||
function serviceButtons() {
|
||||
@@ -77,10 +70,17 @@
|
||||
.map(function (id) { return P.el(id); });
|
||||
}
|
||||
|
||||
// "Refresh Status" is quick and read-only — shown inline, no modal needed.
|
||||
function refreshServiceStatus() {
|
||||
const buttons = serviceButtons();
|
||||
buttons.forEach(function (b) { b.disabled = true; });
|
||||
return P.get('settings', 'service_status').then(renderServiceResult).catch(function (err) {
|
||||
return P.get('settings', 'service_status').then(function (data) {
|
||||
renderServiceChip(data);
|
||||
const log = P.el('settings-service-log');
|
||||
log.style.display = '';
|
||||
log.textContent = data.output || '';
|
||||
log.scrollTop = log.scrollHeight;
|
||||
}).catch(function (err) {
|
||||
P.el('settings-service-chip').className = 'podman-chip podman-chip-bad';
|
||||
P.el('settings-service-chip').innerHTML = '<span class="d"></span>Unknown';
|
||||
P.el('settings-service-log').style.display = '';
|
||||
@@ -90,14 +90,22 @@
|
||||
});
|
||||
}
|
||||
|
||||
function runServiceAction(action) {
|
||||
// Start/Stop/Restart can take a while (storage checks, container
|
||||
// stop grace periods, ...) and are exactly the actions someone reaches
|
||||
// for when something's actually wrong — a small log modal (same pattern
|
||||
// as container update checking) shows what's happening instead of
|
||||
// leaving the button just spinning with no feedback.
|
||||
function runServiceAction(action, title) {
|
||||
const buttons = serviceButtons();
|
||||
buttons.forEach(function (b) { b.disabled = true; });
|
||||
P.el('settings-service-log').style.display = '';
|
||||
P.el('settings-service-log').textContent = 'Working…';
|
||||
return P.post('settings', action, {}).then(renderServiceResult).catch(function (err) {
|
||||
P.el('settings-service-log').style.display = '';
|
||||
P.el('settings-service-log').textContent = err.message;
|
||||
const modal = P.openLogModal(title);
|
||||
return P.post('settings', action, {}).then(function (data) {
|
||||
renderServiceChip(data);
|
||||
(data.output || '').split('\n').forEach(function (line) { modal.log(line); });
|
||||
modal.done();
|
||||
}).catch(function (err) {
|
||||
modal.log('Error: ' + err.message);
|
||||
modal.done('Close');
|
||||
}).finally(function () {
|
||||
buttons.forEach(function (b) { b.disabled = false; });
|
||||
});
|
||||
@@ -209,14 +217,14 @@
|
||||
});
|
||||
|
||||
P.el('settings-service-status-btn').addEventListener('click', refreshServiceStatus);
|
||||
P.el('settings-service-start-btn').addEventListener('click', function () { runServiceAction('service_start'); });
|
||||
P.el('settings-service-start-btn').addEventListener('click', function () { runServiceAction('service_start', 'Starting Podman'); });
|
||||
P.el('settings-service-stop-btn').addEventListener('click', function () {
|
||||
if (!confirm('Stop podman? All running containers will be stopped first (each with its own configured grace period).')) return;
|
||||
runServiceAction('service_stop');
|
||||
runServiceAction('service_stop', 'Stopping Podman');
|
||||
});
|
||||
P.el('settings-service-restart-btn').addEventListener('click', function () {
|
||||
if (!confirm('Restart podman? All running containers will be stopped and podman.sock will be unavailable until it comes back up.')) return;
|
||||
runServiceAction('service_restart');
|
||||
runServiceAction('service_restart', 'Restarting Podman');
|
||||
});
|
||||
P.el('settings-format-disk-btn').addEventListener('click', openFormatDiskModal);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user