Restart Button when on DEBUG mode (#211)

Feature for #210
This commit is contained in:
CaliBrain
2025-08-06 17:17:32 -04:00
committed by GitHub
parent 340aa3aeee
commit 86c642d874
3 changed files with 63 additions and 0 deletions
+9
View File
@@ -153,6 +153,15 @@ if DEBUG:
logger.error_trace(f"Debug endpoint error: {e}")
return jsonify({"error": str(e)}), 500
if DEBUG:
@app.route('/api/restart', methods=['GET'])
@login_required
def restart() -> Union[Response, Tuple[Response, int]]:
"""
Restart the application
"""
os._exit(0)
@app.route('/api/search', methods=['GET'])
@login_required
def api_search() -> Union[Response, Tuple[Response, int]]:
+49
View File
@@ -32,6 +32,11 @@ document.addEventListener('DOMContentLoaded', () => {
form: document.getElementById('debug-form'),
button: document.getElementById('debug-button'),
spinner: document.getElementById('debug-spinner')
},
restart: {
form: document.getElementById('restart-form'),
button: document.getElementById('restart-button'),
spinner: document.getElementById('restart-spinner')
}
};
@@ -753,6 +758,49 @@ document.addEventListener('DOMContentLoaded', () => {
}
};
// Restart Functions
const restart = {
init() {
if (!elements.restart.form) return;
elements.restart.form.addEventListener('submit', (e) => {
e.preventDefault(); // Prevent default form submission
if (elements.restart.button.disabled) {
return; // Prevent multiple submissions
}
// Show confirmation dialog
UIkit.modal.confirm('Are you sure you want to restart the application? This will interrupt any ongoing downloads.').then(() => {
// User confirmed, proceed with restart
elements.restart.spinner.classList.remove('uk-hidden');
elements.restart.button.disabled = true;
// Show restarting message
UIkit.notification({
message: 'Application restarting...',
status: 'warning',
pos: 'top-center',
timeout: 5000
});
// Make the restart request - this will kill the server
fetch(elements.restart.form.action)
.catch(() => {
// Expected to fail when server shuts down
});
// Wait a bit then refresh the page to reconnect to the restarted server
setTimeout(() => {
window.location.reload();
}, 3000);
}, () => {
// User cancelled, do nothing
});
});
}
};
// Event Listeners
function setupEventListeners() {
// Search events
@@ -830,6 +878,7 @@ document.addEventListener('DOMContentLoaded', () => {
setupEventListeners();
theme.init(); // Initialize theme management
debug.init(); // Initialize debug functionality
restart.init(); // Initialize restart functionality
status.fetch();
setInterval(() => status.fetch(), REFRESH_INTERVAL);
}
+5
View File
@@ -22,6 +22,11 @@
<h1 class="uk-heading-medium" style="color: white;">Book Search & Download</h1>
<div class="uk-margin-right">
{% if debug %}
<form action="/api/restart" method="get" style="display: inline;" id="restart-form">
<button class="uk-button uk-button-danger uk-margin-small-right" id="restart-button" type="submit">
RESTART <span uk-spinner="ratio: 0.8" class="uk-hidden" id="restart-spinner"></span>
</button>
</form>
<form action="/debug" method="get" style="display: inline;" id="debug-form">
<button class="uk-button uk-button-danger uk-margin-small-right" id="debug-button" type="submit">
DEBUG <span uk-spinner="ratio: 0.8" class="uk-hidden" id="debug-spinner"></span>