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