Skip to content

Commit

Permalink
add update checks
Browse files Browse the repository at this point in the history
  • Loading branch information
arguablykomodo committed Jun 2, 2019
1 parent 9f75176 commit f7af0cc
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 1 deletion.
19 changes: 19 additions & 0 deletions fallback.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,30 @@ package main
import (
"fmt"
"strconv"

"github.com/skratchdot/open-golang/open"
)

func createFallbackUI() {
fmt.Println(header)

shouldUpdate, newTag, err := checkForUpdate()
if err != nil {
fmt.Println(err.Error())
fmt.Scanln()
panic(err)
}

if shouldUpdate {
var choice string
fmt.Printf("There is a new shadowfox-updater version available (%s -> %s)\nDo you want to update? [y/n]", tag, newTag)
fmt.Scanln(&choice)
wantToUpdate := (choice == "y" || choice == "Y")
if wantToUpdate {
open.Start("https://github.com/SrKomodo/shadowfox-updater/#installing")
}
}

var choice string
paths, names, err := getProfilePaths()
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ require (
github.com/gen2brain/dlgs v0.0.0-20180629122906-342edb4c68c1
github.com/go-ini/ini v1.42.0
github.com/mitchellh/go-homedir v1.1.0
github.com/skratchdot/open-golang v0.0.0-20190402232053-79abb63cd66e
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ github.com/go-ini/ini v1.42.0 h1:TWr1wGj35+UiWHlBA8er89seFXxzwFn11spilrrj+38=
github.com/go-ini/ini v1.42.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/skratchdot/open-golang v0.0.0-20190402232053-79abb63cd66e h1:VAzdS5Nw68fbf5RZ8RDVlUvPXNU6Z3jtPCK/qvm4FoQ=
github.com/skratchdot/open-golang v0.0.0-20190402232053-79abb63cd66e/go.mod h1:sUM3LWHvSMaG192sy56D9F7CNvL7jUJVXoqM1QKLnog=
1 change: 0 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"os"
)

var tag string
var header = "Shadowfox updater " + tag

func main() {
Expand Down
22 changes: 22 additions & 0 deletions ui.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
package main

import (
"fmt"

"github.com/gen2brain/dlgs"
"github.com/skratchdot/open-golang/open"
)

func createUI() error {
shouldUpdate, newTag, err := checkForUpdate()
if err != nil {
_, err := dlgs.Error(header, err.Error())
if err != nil {
return err
}
}

if shouldUpdate {
wantToUpdate, err := dlgs.Question(header, fmt.Sprintf("There is a new shadowfox-updater version available (%s -> %s)\nDo you want to update?", tag, newTag), true)
if err != nil {
return err
}
if wantToUpdate {
open.Start("https://github.com/SrKomodo/shadowfox-updater/#installing")
return nil
}
}

paths, names, err := getProfilePaths()
if err != nil {
_, err := dlgs.Error(header, err.Error())
Expand Down
27 changes: 27 additions & 0 deletions version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package main

import (
"io/ioutil"
"net/http"
"regexp"
)

var tag string

func checkForUpdate() (bool, string, error) {
resp, err := http.Get("https://api.github.com/repos/SrKomodo/shadowfox-updater/releases/latest")
if err != nil {
return false, "", err
}

defer resp.Body.Close()
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
return false, "", err
}

regex := regexp.MustCompile(`"tag_name":"(.+?)"`)
newTag := string(regex.FindSubmatch(data)[1])

return newTag != tag, newTag, nil
}

0 comments on commit f7af0cc

Please sign in to comment.