fix: improve app restart after update
This commit is contained in:
@@ -187,12 +187,27 @@ func (u *Updater) DownloadAndInstall(progressCallback func(float64)) error {
|
||||
func (u *Updater) RestartApp() error {
|
||||
destPath := filepath.Join(InstallPath, AppName)
|
||||
|
||||
// Launch new app
|
||||
cmd := exec.Command("open", destPath)
|
||||
// Use shell to launch new app after this process exits
|
||||
// The sleep ensures the current app has time to exit
|
||||
script := fmt.Sprintf(`sleep 1 && open "%s"`, destPath)
|
||||
cmd := exec.Command("sh", "-c", script)
|
||||
cmd.Stdout = nil
|
||||
cmd.Stderr = nil
|
||||
cmd.Stdin = nil
|
||||
|
||||
// Detach the process so it continues after we exit
|
||||
if err := cmd.Start(); err != nil {
|
||||
return fmt.Errorf("failed to launch updated app: %w", err)
|
||||
}
|
||||
|
||||
// Release the process so it doesn't become a zombie
|
||||
go func() {
|
||||
_ = cmd.Wait()
|
||||
}()
|
||||
|
||||
// Give the shell time to start
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
// Exit current app
|
||||
os.Exit(0)
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user