diff --git a/cmd/qfs/main.go b/cmd/qfs/main.go index 79b126f..b24ddd7 100644 --- a/cmd/qfs/main.go +++ b/cmd/qfs/main.go @@ -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{} diff --git a/internal/handlers/setup.go b/internal/handlers/setup.go index d2e71a5..5f9f7b3 100644 --- a/internal/handlers/setup.go +++ b/internal/handlers/setup.go @@ -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) diff --git a/web/templates/setup.html b/web/templates/setup.html index 003f7fb..0139288 100644 --- a/web/templates/setup.html +++ b/web/templates/setup.html @@ -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