Repository navigation
Expand file tree
/
Copy pathdataBible.go
More file actions
77 lines (70 loc) · 1.71 KB
/
Copy pathdataBible.go
File metadata and controls
77 lines (70 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"log"
"github.com/solafide-dev/gobible"
"github.com/solafide-dev/gobible/bible"
rt "github.com/wailsapp/wails/v2/pkg/runtime"
)
func (a *App) initBible() {
a.Bible = gobible.NewGoBible()
// Leverage august's ability to monitor filesystem changes
a.Data.Register("bibles", bible.Bible{})
rt.EventsOn(a.ctx, "data-mutate", func(d ...interface{}) {
data := d[0].(DataMutationEvent)
if data.DataType == "bibles" {
switch data.Type {
case "create":
// Load from store
store, err := a.Data.GetStore("bibles")
if err != nil {
rt.LogError(a.ctx, err.Error())
}
b, err := store.Get(data.Id)
if err != nil {
rt.LogError(a.ctx, err.Error())
}
bible := b.(bible.Bible)
err = a.Bible.LoadObject(bible)
if err != nil {
log.Println(err.Error())
}
case "update":
// Unload, then load from store
a.Bible.Unload(data.Id)
store, err := a.Data.GetStore("bibles")
if err != nil {
rt.LogError(a.ctx, err.Error())
}
b, err := store.Get(data.Id)
if err != nil {
rt.LogError(a.ctx, err.Error())
}
bible := b.(bible.Bible)
err = a.Bible.LoadObject(bible)
if err != nil {
log.Println(err.Error())
}
case "delete":
// Just unload
a.Bible.Unload(data.Id)
}
}
})
// Leverage August for data monitoring, and register bibles
bibleStore, err := a.Data.GetStore("bibles")
if err != nil {
rt.LogError(a.ctx, err.Error())
}
// Load our bibles
existingBibles, err := bibleStore.GetAll()
if err != nil {
rt.LogError(a.ctx, err.Error())
}
for _, b := range existingBibles {
bible := b.(bible.Bible)
err := a.Bible.LoadObject(bible)
if err != nil {
log.Println(err.Error())
}
}
}