-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathupdate.go
More file actions
58 lines (47 loc) · 1.04 KB
/
update.go
File metadata and controls
58 lines (47 loc) · 1.04 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"time"
"github.com/ActiveState/cli/internal/errs"
"github.com/ActiveState/cli/internal/logging"
"github.com/ActiveState/cli/pkg/platform/model"
"github.com/getlantern/systray"
"golang.org/x/net/context"
)
const (
updateCheckInterval = time.Hour
)
func superviseUpdate(mdl *model.SvcModel, notice *updateNotice) func() {
done := make(chan struct{})
go func() {
for {
notice.show(needsUpdate(mdl))
select {
case <-time.After(updateCheckInterval):
case <-done:
return
}
}
}()
return func() { close(done) }
}
func needsUpdate(mdl *model.SvcModel) bool {
availableUpdate, err := mdl.CheckUpdate(context.Background())
if err != nil {
logging.Errorf("Cannot determine the latest state version: %s", errs.Join(err, ","))
return false
}
return availableUpdate != nil
}
type updateNotice struct {
item *systray.MenuItem
}
func (n *updateNotice) show(show bool) {
switch show {
case true:
n.item.Show()
systray.SetIcon(iconUpdateFile)
case false:
n.item.Hide()
systray.SetIcon(iconFile)
}
}