-
Notifications
You must be signed in to change notification settings - Fork 5
/
updater.go
45 lines (37 loc) · 1.01 KB
/
updater.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"fmt"
"hatt/variables"
"log"
"os"
"github.com/blang/semver"
"github.com/rhysd/go-github-selfupdate/selfupdate"
)
func (a *App) CheckForUpdate() selfupdate.Release {
latest, found, err := selfupdate.DetectLatest("FrenchGithubUser/Hatt")
if err != nil {
log.Println("Error occurred while detecting version:", err)
return selfupdate.Release{}
}
v := semver.MustParse(variables.CURRENT_VERSION)
fmt.Println(latest, found, v)
// if already on latest or if error
if !found || latest.Version.LTE(v) {
return selfupdate.Release{}
}
return *latest
}
func (a *App) SelfUpdate() bool {
latest, _, _ := selfupdate.DetectLatest("FrenchGithubUser/Hatt")
exe, err := os.Executable()
if err != nil {
log.Println("Could not locate executable path")
return false
}
if err := selfupdate.UpdateTo(latest.AssetURL, exe); err != nil {
log.Println("Error occurred while updating binary:", err)
return false
}
// log.Println("Successfully updated to version", latest.Version)
return true
}