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 {
|
func (u *Updater) RestartApp() error {
|
||||||
destPath := filepath.Join(InstallPath, AppName)
|
destPath := filepath.Join(InstallPath, AppName)
|
||||||
|
|
||||||
// Launch new app
|
// Use shell to launch new app after this process exits
|
||||||
cmd := exec.Command("open", destPath)
|
// 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 {
|
if err := cmd.Start(); err != nil {
|
||||||
return fmt.Errorf("failed to launch updated app: %w", err)
|
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
|
// Exit current app
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
Reference in New Issue
Block a user