From 3339b358db24144ebb0e0201c24a641c7c2bfe48 Mon Sep 17 00:00:00 2001 From: Aman Chhabra <17457975+achhabra2@users.noreply.github.com> Date: Thu, 16 Dec 2021 14:21:56 -0800 Subject: [PATCH] Fix auto update on mac --- .DS_Store | Bin 8196 -> 8196 bytes app.go | 11 ++++++++--- build/.DS_Store | Bin 6148 -> 6148 bytes internal/update/selfupdate.go | 29 +++++++++++++++++++++++++++++ 4 files changed, 37 insertions(+), 3 deletions(-) diff --git a/.DS_Store b/.DS_Store index 39a44437539e21055149da43b54116d5b3023ba1..b83446e338789a1903192d3e4ccca39e261d1ac3 100644 GIT binary patch delta 24 fcmZp1XmQw}Cdh7NWTc~DVm_H)#C~&*;0!(hR6GWc delta 16 XcmZp1XmQw}CODZx#BFnq;0!(hFHZ$K diff --git a/app.go b/app.go index 0e75442..da82e51 100644 --- a/app.go +++ b/app.go @@ -328,14 +328,19 @@ func (b *App) UpdateCheckUI() { runtime.LogInfo(b.ctx, action) if action == "Yes" { runtime.LogInfo(b.ctx, "Update clicked") - updated := update.DoSelfUpdate() + var updated bool + if goruntime.GOOS == "darwin" { + updated = update.DoSelfUpdateMac() + } else { + updated = update.DoSelfUpdate() + } if updated { buttons = []string{"Ok"} - dialogOpts = runtime.MessageDialogOptions{Title: "Update Succeeded", Message: "Update Successfull. Please restart. ", Type: runtime.InfoDialog, Buttons: buttons, DefaultButton: "Ok"} + dialogOpts = runtime.MessageDialogOptions{Title: "Update Succeeded", Message: "Update Successfull. Please restart this app to take effect. ", Type: runtime.InfoDialog, Buttons: buttons, DefaultButton: "Ok"} runtime.MessageDialog(b.ctx, dialogOpts) } else { buttons = []string{"Ok"} - dialogOpts = runtime.MessageDialogOptions{Title: "Update Error", Message: "Update failed, try again later. ", Type: runtime.InfoDialog, Buttons: buttons, DefaultButton: "Ok"} + dialogOpts = runtime.MessageDialogOptions{Title: "Update Error", Message: "Update failed, please manually update from GitHub Releases. ", Type: runtime.InfoDialog, Buttons: buttons, DefaultButton: "Ok"} runtime.MessageDialog(b.ctx, dialogOpts) } } diff --git a/build/.DS_Store b/build/.DS_Store index 90c7aef2add84388f739c8612c4aa171250df30c..04f6d7ae90baca2ebaf76a78c453982871c6c031 100644 GIT binary patch delta 24 fcmZoMXffFEiG|(B$Vf-Q#C$RzoBd`B)-yr?Uc?6% delta 16 XcmZoMXffFEiDfc7o7-j!)-yr?G~Wfo diff --git a/internal/update/selfupdate.go b/internal/update/selfupdate.go index 22f6561..f9a6e11 100644 --- a/internal/update/selfupdate.go +++ b/internal/update/selfupdate.go @@ -2,6 +2,9 @@ package update import ( "log" + "os" + "os/exec" + "path/filepath" "github.com/blang/semver" "github.com/rhysd/go-github-selfupdate/selfupdate" @@ -27,6 +30,32 @@ func DoSelfUpdate() bool { } } +func DoSelfUpdateMac() bool { + latest, found, _ := selfupdate.DetectLatest("achhabra2/riftshare") + if found { + homeDir, _ := os.UserHomeDir() + downloadPath := filepath.Join(homeDir, "Downloads", "RiftShare.zip") + err := exec.Command("curl", "-L", latest.AssetURL, "-o", downloadPath).Run() + if err != nil { + log.Println("curl error:", err) + return false + } + err = exec.Command("ditto", "-xk", downloadPath, "/Applications/").Run() + if err != nil { + log.Println("ditto error:", err) + return false + } + err = exec.Command("rm", downloadPath).Run() + if err != nil { + log.Println("removing error:", err) + return false + } + return true + } else { + return false + } +} + func CheckForUpdate() (bool, string) { latest, found, err := selfupdate.DetectLatest("achhabra2/riftshare") if err != nil {