Skip to content
This repository has been archived by the owner on Nov 25, 2024. It is now read-only.

Commit

Permalink
Fix auto update on mac
Browse files Browse the repository at this point in the history
  • Loading branch information
achhabra2 committed Dec 16, 2021
1 parent 5cb4fe4 commit 3339b35
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
Binary file modified .DS_Store
Binary file not shown.
11 changes: 8 additions & 3 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
Binary file modified build/.DS_Store
Binary file not shown.
29 changes: 29 additions & 0 deletions internal/update/selfupdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package update

import (
"log"
"os"
"os/exec"
"path/filepath"

"github.com/blang/semver"
"github.com/rhysd/go-github-selfupdate/selfupdate"
Expand All @@ -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 {
Expand Down

0 comments on commit 3339b35

Please sign in to comment.