file uri
This commit is contained in:
parent
25413a6b00
commit
5bbea05305
|
@ -4,6 +4,7 @@ import (
|
||||||
"ewintr.nl/gte/cmd/android-app/component"
|
"ewintr.nl/gte/cmd/android-app/component"
|
||||||
"ewintr.nl/gte/cmd/android-app/runner"
|
"ewintr.nl/gte/cmd/android-app/runner"
|
||||||
"fyne.io/fyne/v2/app"
|
"fyne.io/fyne/v2/app"
|
||||||
|
"fyne.io/fyne/v2/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -13,7 +14,12 @@ func main() {
|
||||||
conf.Load()
|
conf.Load()
|
||||||
logger := component.NewLogger()
|
logger := component.NewLogger()
|
||||||
|
|
||||||
r := runner.NewRunner(conf, logger)
|
tasksURI, err := storage.Child(fyneApp.Storage().RootURI(), "tasks.json")
|
||||||
|
if err != nil {
|
||||||
|
logger.Log(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
r := runner.NewRunner(conf, tasksURI, logger)
|
||||||
tabs := r.Init()
|
tabs := r.Init()
|
||||||
w.SetContent(tabs)
|
w.SetContent(tabs)
|
||||||
go r.Run()
|
go r.Run()
|
||||||
|
|
|
@ -27,15 +27,17 @@ type Runner struct {
|
||||||
status string
|
status string
|
||||||
requests chan interface{}
|
requests chan interface{}
|
||||||
refresh chan bool
|
refresh chan bool
|
||||||
|
fileURI fyne.URI
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRunner(conf *component.Configuration, logger *component.Logger) *Runner {
|
func NewRunner(conf *component.Configuration, fileURI fyne.URI, logger *component.Logger) *Runner {
|
||||||
return &Runner{
|
return &Runner{
|
||||||
status: "init",
|
status: "init",
|
||||||
conf: conf,
|
conf: conf,
|
||||||
logger: logger,
|
logger: logger,
|
||||||
requests: make(chan interface{}),
|
requests: make(chan interface{}),
|
||||||
refresh: make(chan bool),
|
refresh: make(chan bool),
|
||||||
|
fileURI: fileURI,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +51,7 @@ func (r *Runner) Init() fyne.CanvasObject {
|
||||||
configTab := container.NewTabItem("config", configScreen.Content())
|
configTab := container.NewTabItem("config", configScreen.Content())
|
||||||
r.screens = append(r.screens, configScreen)
|
r.screens = append(r.screens, configScreen)
|
||||||
|
|
||||||
stored, err := load()
|
stored, err := load(r.fileURI)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
r.logger.Log(err.Error())
|
r.logger.Log(err.Error())
|
||||||
}
|
}
|
||||||
|
@ -101,7 +103,7 @@ func (r *Runner) processRequest() {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
r.logger.Log("saving all")
|
r.logger.Log("saving all")
|
||||||
if err := save(all); err != nil {
|
if err := save(r.fileURI, all); err != nil {
|
||||||
r.logger.Log(err.Error())
|
r.logger.Log(err.Error())
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -157,15 +159,14 @@ func (r *Runner) backgroundSync() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func load() ([]*task.Task, error) {
|
func load(fu fyne.URI) ([]*task.Task, error) {
|
||||||
uri := storage.NewFileURI("tasks.json")
|
fr, err := storage.Reader(fu)
|
||||||
fr, err := storage.Reader(uri)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []*task.Task{}, err
|
return []*task.Task{}, err
|
||||||
}
|
}
|
||||||
defer fr.Close()
|
defer fr.Close()
|
||||||
|
|
||||||
exists, err := storage.Exists(uri)
|
exists, err := storage.Exists(fu)
|
||||||
if !exists {
|
if !exists {
|
||||||
return []*task.Task{}, fmt.Errorf("uri does not exist")
|
return []*task.Task{}, fmt.Errorf("uri does not exist")
|
||||||
}
|
}
|
||||||
|
@ -185,9 +186,8 @@ func load() ([]*task.Task, error) {
|
||||||
return storedTasks, nil
|
return storedTasks, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func save(tasks []*task.Task) error {
|
func save(fu fyne.URI, tasks []*task.Task) error {
|
||||||
uri := storage.NewFileURI("tasks.json")
|
fw, err := storage.Writer(fu)
|
||||||
fw, err := storage.Writer(uri)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue