show sync status
This commit is contained in:
parent
b7587a0723
commit
15811821f3
4
Makefile
4
Makefile
|
@ -8,9 +8,9 @@ cli-install: test
|
|||
go build -o gte ./cmd/cli/main.go
|
||||
mv gte ${HOME}/bin
|
||||
|
||||
app-build:
|
||||
app-build: test
|
||||
cd cmd/android-app && fyne package -os android --icon ../../Icon.png --appID nl.ewintr.gte -name gte
|
||||
mv cmd/android-app/gte.apk .
|
||||
|
||||
app-run:
|
||||
app-run: test
|
||||
go run -tags mobile ./cmd/android-app/main.go
|
||||
|
|
|
@ -17,12 +17,15 @@ type Runner struct {
|
|||
logger *component.Logger
|
||||
tasks *component.Tasks
|
||||
screens []screen.Screen
|
||||
status string
|
||||
requests chan interface{}
|
||||
refresh chan bool
|
||||
}
|
||||
|
||||
func NewRunner() *Runner {
|
||||
return &Runner{
|
||||
requests: make(chan interface{}, 3),
|
||||
refresh: make(chan bool),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -57,12 +60,11 @@ func (r *Runner) Init() {
|
|||
r.fyneApp = fyneApp
|
||||
r.fyneWindow = w
|
||||
|
||||
r.refresh()
|
||||
|
||||
r.requests <- screen.SyncTasksRequest{}
|
||||
}
|
||||
|
||||
func (r *Runner) Run() {
|
||||
go r.refresher()
|
||||
go r.processRequest()
|
||||
r.fyneWindow.ShowAndRun()
|
||||
}
|
||||
|
@ -77,24 +79,29 @@ func (r *Runner) processRequest() {
|
|||
r.conf.Set(k, val)
|
||||
}
|
||||
case screen.SyncTasksRequest:
|
||||
r.status = "syncing..."
|
||||
r.refresh <- true
|
||||
count, err := r.tasks.Sync()
|
||||
if err != nil {
|
||||
r.logger.Log(err.Error())
|
||||
}
|
||||
r.logger.Log(fmt.Sprintf("fetched: %d", count))
|
||||
r.status = "synced"
|
||||
r.refresh <- true
|
||||
default:
|
||||
r.logger.Log("request unknown")
|
||||
}
|
||||
r.refresh()
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Runner) refresh() {
|
||||
func (r *Runner) refresher() {
|
||||
for range r.refresh {
|
||||
tasks, err := r.tasks.Today()
|
||||
if err != nil {
|
||||
r.logger.Log(err.Error())
|
||||
}
|
||||
state := screen.State{
|
||||
Status: r.status,
|
||||
Tasks: tasks,
|
||||
Config: r.conf.Fields(),
|
||||
Logs: r.logger.Lines(),
|
||||
|
@ -104,3 +111,4 @@ func (r *Runner) refresh() {
|
|||
s.Refresh(state)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,10 +24,12 @@ func NewTasks(out chan interface{}) *Tasks {
|
|||
}
|
||||
|
||||
func (t *Tasks) Refresh(state State) {
|
||||
t.status.Set(state.Status)
|
||||
t.tasks.Set(state.Tasks)
|
||||
}
|
||||
|
||||
func (t *Tasks) Content() fyne.CanvasObject {
|
||||
statusLabel := widget.NewLabelWithData(t.status)
|
||||
refreshButton := widget.NewButton("refresh", func() {
|
||||
t.out <- SyncTasksRequest{}
|
||||
})
|
||||
|
@ -42,7 +44,7 @@ func (t *Tasks) Content() fyne.CanvasObject {
|
|||
)
|
||||
|
||||
return container.NewBorder(
|
||||
refreshButton,
|
||||
container.NewHBox(refreshButton, statusLabel),
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
|
|
Loading…
Reference in New Issue