-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice.go
46 lines (36 loc) · 848 Bytes
/
service.go
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
package renlite
import (
"sync"
"fyne.io/fyne/v2"
)
var once sync.Once
type service struct {
widgets map[string]fyne.CanvasObject
layouts map[string]fyne.Container
data map[string]interface{}
state map[string]string
}
var srv *service
func getSrv() *service {
once.Do(func() { // <-- atomic, does not allow repeating
srv = &service{
widgets: make(map[string]fyne.CanvasObject),
layouts: make(map[string]fyne.Container),
data: make(map[string]interface{}),
state: make(map[string]string),
} // <-- thread safe
})
return srv
}
func GetWidget(id string) fyne.CanvasObject {
return getSrv().widgets[id]
}
func GetLayout(id string) fyne.Container {
return getSrv().layouts[id]
}
func GetData(id string) interface{} {
return getSrv().data[id]
}
func GetState(id string) string {
return getSrv().state[id]
}