@@ -11,7 +11,6 @@ import (
1111 "path/filepath"
1212 "runtime"
1313 "strings"
14- "sync"
1514
1615 "github.com/wailsapp/wails/v3/pkg/application"
1716)
@@ -22,8 +21,8 @@ const (
2221)
2322
2423type Updater struct {
25- app * application.App
26- lock sync. Mutex
24+ app * application.App
25+ newExePath string
2726}
2827
2928type ReleaseInfo struct {
@@ -85,6 +84,9 @@ func (u *Updater) CheckForUpdates() UpdateCheckResult {
8584// DoUpdate downloads the new version side-by-side and launches it
8685func (u * Updater ) DoUpdate (version string ) error {
8786 // 1. Fetch release info
87+ // url := fmt.Sprintf("https://api.github.com/repos/%s/%s/releases/tags/%s", RepoOwner, RepoName, version)
88+ // Actually we need to fetch the release info to get the assets.
89+ // The previous code was:
8890 url := fmt .Sprintf ("https://api.github.com/repos/%s/%s/releases/tags/%s" , RepoOwner , RepoName , version )
8991 resp , err := http .Get (url )
9092 if err != nil {
@@ -160,14 +162,24 @@ func (u *Updater) DoUpdate(version string) error {
160162 }
161163
162164 // 5. Launch new executable and quit
163- u .app .Event .Emit ("update:progress" , map [string ]interface {}{"status" : "installing " , "percent" : 100 })
165+ u .app .Event .Emit ("update:progress" , map [string ]interface {}{"status" : "ready " , "percent" : 100 })
164166
165- cmd := exec .Command (newExePath )
167+ // Store path for restart
168+ u .newExePath = newExePath
169+ return nil
170+ }
171+
172+ // RestartApp launches the new executable and quits the current one
173+ func (u * Updater ) RestartApp () error {
174+ if u .newExePath == "" {
175+ return fmt .Errorf ("no update ready to install" )
176+ }
177+
178+ cmd := exec .Command (u .newExePath )
166179 if err := cmd .Start (); err != nil {
167180 return fmt .Errorf ("failed to start new version: %w" , err )
168181 }
169182
170- // Quit current app
171183 u .app .Quit ()
172184 return nil
173185}
0 commit comments