feat: implement application restart functionality and update UI reload options

This commit is contained in:
Lyz Coote
2026-02-18 13:16:33 +01:00
parent be2c3b749c
commit af7d8a0792
6 changed files with 76 additions and 15 deletions

27
app.go
View File

@@ -4,8 +4,10 @@ package main
import (
"context"
"fmt"
"log"
"os"
"os/exec"
"strings"
"sync"
"time"
@@ -141,6 +143,31 @@ func (a *App) QuitApp() {
os.Exit(133)
}
// RestartApp performs a full application restart, including the Go backend.
// It schedules a new process via PowerShell with a short delay to ensure the
// single-instance lock is released before the new instance starts, then exits.
func (a *App) RestartApp() error {
exe, err := os.Executable()
if err != nil {
Log("RestartApp: failed to get executable path:", err)
return err
}
// Escape single quotes in the path for PowerShell string literal
safePath := strings.ReplaceAll(exe, "'", "''")
script := fmt.Sprintf(`Start-Sleep -Seconds 1; Start-Process '%s'`, safePath)
cmd := exec.Command("powershell", "-WindowStyle", "Hidden", "-Command", script)
if err := cmd.Start(); err != nil {
Log("RestartApp: failed to schedule restart:", err)
return err
}
Log("RestartApp: scheduled restart, quitting current instance...")
runtime.Quit(a.ctx)
return nil
}
// =============================================================================
// Configuration Management
// =============================================================================