Fix missing config handling and auto-restart after setup
This commit is contained in:
@@ -2,8 +2,10 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -88,7 +90,7 @@ func main() {
|
||||
// Load config for server settings (optional)
|
||||
cfg, err := config.Load(*configPath)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
if errors.Is(err, fs.ErrNotExist) {
|
||||
// Use defaults if config file doesn't exist
|
||||
slog.Info("config file not found, using defaults", "path", *configPath)
|
||||
cfg = &config.Config{}
|
||||
|
||||
@@ -203,10 +203,11 @@ func (h *SetupHandler) SaveConnection(c *gin.Context) {
|
||||
}
|
||||
|
||||
// Always restart to properly initialize all services with the new connection
|
||||
restartRequired := h.restartSig == nil
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": true,
|
||||
"message": "Settings saved. Please restart the application to apply changes.",
|
||||
"restart_required": true,
|
||||
"message": "Settings saved.",
|
||||
"restart_required": restartRequired,
|
||||
})
|
||||
|
||||
// Signal restart after response is sent (if restart signal is configured)
|
||||
|
||||
@@ -158,6 +158,16 @@
|
||||
}, 1000); // Check every second
|
||||
}
|
||||
|
||||
async function requestRestartAndWait() {
|
||||
showStatus('Перезапуск приложения...', 'info');
|
||||
try {
|
||||
await fetch('/api/restart', { method: 'POST' });
|
||||
} catch (e) {
|
||||
// Ignore network errors here: restart may break connection immediately.
|
||||
}
|
||||
checkServerReady();
|
||||
}
|
||||
|
||||
document.getElementById('setup-form').addEventListener('submit', async function(e) {
|
||||
e.preventDefault();
|
||||
showStatus('Сохранение настроек...', 'info');
|
||||
@@ -176,9 +186,8 @@
|
||||
|
||||
// Check if restart is required
|
||||
if (data.restart_required) {
|
||||
// In normal mode, restart must be done manually
|
||||
setTimeout(() => {
|
||||
showStatus('⚠️ Пожалуйста, перезапустите приложение вручную для применения изменений', 'warning');
|
||||
requestRestartAndWait();
|
||||
}, 2000);
|
||||
} else {
|
||||
// In setup mode, auto-restart is happening
|
||||
|
||||
Reference in New Issue
Block a user