Skip to content

Commit

Permalink
Switch to menuet updater
Browse files Browse the repository at this point in the history
  • Loading branch information
caseymrm committed Jun 4, 2018
1 parent 1827226 commit 6dcc0a7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 31 deletions.
Binary file modified WhyAwake.app/Contents/MacOS/whyawake
Binary file not shown.
44 changes: 13 additions & 31 deletions whyawake.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package main

import (
"encoding/json"
"fmt"
"log"
"net/http"
"os/exec"
"strconv"
"strings"
"syscall"
Expand Down Expand Up @@ -156,44 +153,29 @@ func handleClick(clicked string) {
}

func checkUpdates() {
url := "https://api.github.com/repos/caseymrm/whyawake/releases"
version := "v0.4"
ticker := time.NewTicker(24 * time.Hour)
for ; true; <-ticker.C {
resp, err := http.Get(url)
if err != nil {
log.Printf("Could not check for updates: %v", err)
return
}
type Release struct {
TagName string `json:"tag_name"`
release := menuet.CheckForNewRelease("caseymrm/whyawake", version)
if release == nil {
continue
}
releases := make([]Release, 0)
dec := json.NewDecoder(resp.Body)
err = dec.Decode(&releases)
if err != nil {
log.Printf("Could not check for updates: %v", err)
return
}
if len(releases) == 0 {
log.Printf("Could not check for updates: no releases found")
return
}
if releases[0].TagName != version {
button := menuet.App().Alert(menuet.Alert{
MessageText: "New version of Why Awake? available",
InformativeText: fmt.Sprintf("Looks like %s of Why Awake? is now available- you're running %s", releases[0].TagName, version),
Buttons: []string{"Visit download page", "Remind me later"},
})
if button == 0 {
exec.Command("open", "https://github.com/caseymrm/whyawake/releases").Start()
button := menuet.App().Alert(menuet.Alert{
MessageText: "New version of Why Awake? available",
InformativeText: fmt.Sprintf("Looks like %s of Why Awake? is now available- you're running %s", release.TagName, version),
Buttons: []string{"Update now", "Remind me later"},
})
if button == 0 {
err := menuet.UpdateApp(release)
if err != nil {
log.Printf("Unable to update app: %v", err)
}

}
}
}

func main() {
menuet.CheckForRestart()
assertionsChannel := make(chan pmset.AssertionChange)
clickChannel := make(chan string)
pmset.SubscribeAssertionChanges(assertionsChannel)
Expand Down

0 comments on commit 6dcc0a7

Please sign in to comment.