add background sync
This commit is contained in:
parent
250c5b5c5b
commit
6d1587e4ec
|
@ -1,5 +1,10 @@
|
||||||
package component
|
package component
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
type Logger struct {
|
type Logger struct {
|
||||||
lines []string
|
lines []string
|
||||||
}
|
}
|
||||||
|
@ -11,9 +16,22 @@ func NewLogger() *Logger {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *Logger) Log(line string) {
|
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 {
|
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 (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
"ewintr.nl/gte/cmd/android-app/component"
|
"ewintr.nl/gte/cmd/android-app/component"
|
||||||
"ewintr.nl/gte/cmd/android-app/screen"
|
"ewintr.nl/gte/cmd/android-app/screen"
|
||||||
|
@ -66,6 +67,7 @@ func (r *Runner) Init() {
|
||||||
func (r *Runner) Run() {
|
func (r *Runner) Run() {
|
||||||
go r.refresher()
|
go r.refresher()
|
||||||
go r.processRequest()
|
go r.processRequest()
|
||||||
|
go r.backgroundSync()
|
||||||
r.fyneWindow.ShowAndRun()
|
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) {
|
func (l *Log) Refresh(state State) {
|
||||||
for i := l.lines.Length(); i < len(state.Logs); i++ {
|
l.lines.Set(state.Logs)
|
||||||
l.lines.Append(state.Logs[i])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *Log) Content() fyne.CanvasObject {
|
func (l *Log) Content() fyne.CanvasObject {
|
||||||
|
|
|
@ -35,11 +35,13 @@ func NewTasks(out chan interface{}) *Tasks {
|
||||||
func (t *Tasks) Refresh(state State) {
|
func (t *Tasks) Refresh(state State) {
|
||||||
t.status.Set(state.Status)
|
t.status.Set(state.Status)
|
||||||
t.tasks = state.Tasks
|
t.tasks = state.Tasks
|
||||||
|
sort.Slice(t.tasks, func(i, j int) bool {
|
||||||
|
return t.tasks[i].Action < t.tasks[j].Action
|
||||||
|
})
|
||||||
tls := []string{}
|
tls := []string{}
|
||||||
for _, t := range t.tasks {
|
for _, t := range t.tasks {
|
||||||
tls = append(tls, t.Action)
|
tls = append(tls, t.Action)
|
||||||
}
|
}
|
||||||
sort.Strings(tls)
|
|
||||||
t.taskLabels.Set(tls)
|
t.taskLabels.Set(tls)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue