add background sync
This commit is contained in:
parent
250c5b5c5b
commit
6d1587e4ec
|
@ -1,5 +1,10 @@
|
|||
package component
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Logger struct {
|
||||
lines []string
|
||||
}
|
||||
|
@ -11,9 +16,22 @@ func NewLogger() *Logger {
|
|||
}
|
||||
|
||||
func (l *Logger) Log(line string) {
|
||||
l.lines = append(l.lines, line)
|
||||
l.lines = append(l.lines, fmt.Sprintf("%s: %s", time.Now().Format("15:04:05"), line))
|
||||
}
|
||||
|
||||
func (l *Logger) Lines() []string {
|
||||
return l.lines
|
||||
if len(l.lines) == 0 {
|
||||
return []string{}
|
||||
}
|
||||
|
||||
last := len(l.lines) - 1
|
||||
first := last - 50
|
||||
if first < 0 {
|
||||
first = 0
|
||||
}
|
||||
reverse := []string{}
|
||||
for i := last; i >= first; i-- {
|
||||
reverse = append(reverse, l.lines[i])
|
||||
}
|
||||
return reverse
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package runner
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"ewintr.nl/gte/cmd/android-app/component"
|
||||
"ewintr.nl/gte/cmd/android-app/screen"
|
||||
|
@ -66,6 +67,7 @@ func (r *Runner) Init() {
|
|||
func (r *Runner) Run() {
|
||||
go r.refresher()
|
||||
go r.processRequest()
|
||||
go r.backgroundSync()
|
||||
r.fyneWindow.ShowAndRun()
|
||||
}
|
||||
|
||||
|
@ -131,3 +133,11 @@ func (r *Runner) refresher() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Runner) backgroundSync() {
|
||||
ticker := time.NewTicker(time.Minute)
|
||||
for {
|
||||
<-ticker.C
|
||||
r.requests <- screen.SyncTasksRequest{}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,9 +17,7 @@ func NewLog() *Log {
|
|||
}
|
||||
|
||||
func (l *Log) Refresh(state State) {
|
||||
for i := l.lines.Length(); i < len(state.Logs); i++ {
|
||||
l.lines.Append(state.Logs[i])
|
||||
}
|
||||
l.lines.Set(state.Logs)
|
||||
}
|
||||
|
||||
func (l *Log) Content() fyne.CanvasObject {
|
||||
|
|
|
@ -35,11 +35,13 @@ func NewTasks(out chan interface{}) *Tasks {
|
|||
func (t *Tasks) Refresh(state State) {
|
||||
t.status.Set(state.Status)
|
||||
t.tasks = state.Tasks
|
||||
sort.Slice(t.tasks, func(i, j int) bool {
|
||||
return t.tasks[i].Action < t.tasks[j].Action
|
||||
})
|
||||
tls := []string{}
|
||||
for _, t := range t.tasks {
|
||||
tls = append(tls, t.Action)
|
||||
}
|
||||
sort.Strings(tls)
|
||||
t.taskLabels.Set(tls)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue