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