-
Notifications
You must be signed in to change notification settings - Fork 1
/
settings.go
103 lines (90 loc) · 2.34 KB
/
settings.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
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package cloud
import (
"fmt"
"fyne.io/cloud/internal/settings"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/widget"
)
func ShowSettings(a fyne.App, w fyne.Window) {
prov := a.CloudProvider()
if prov == nil {
showChoice(a, w)
return
}
config := widget.NewButton("Configure", func() {
go func() {
str, err := prov.(Configurable).Configure(a, w)
if err != nil {
dialog.ShowError(err, w)
} else {
if dis, ok := a.CloudProvider().(Disconnectable); ok {
dis.Disconnect()
}
settings.SetProviderConfig(str)
prov.(Configurable).SetConfig(str)
a.SetCloudProvider(prov) // we don't use setCloud here as we have a new config
}
}()
})
if _, ok := prov.(Configurable); !ok {
config.Hide()
}
current := widget.NewLabel(cloudText(prov))
ch := make(chan fyne.Settings)
a.Settings().AddChangeListener(ch)
go func() {
for range ch {
current.SetText(cloudText(prov))
}
}()
var d dialog.Dialog
d = dialog.NewCustomConfirm("Cloud configuration", "Change Provider", "Cancel",
container.NewBorder(nil, nil, nil, config, current),
func(change bool) {
if !change {
return
}
d.Hide()
showChoice(a, w)
}, w)
d.Show()
}
func showChoice(a fyne.App, w fyne.Window) {
var selected fyne.CloudProvider
ui := widget.NewList(func() int {
return len(providers)
},
func() fyne.CanvasObject {
return container.NewHBox(
widget.NewIcon(nil),
widget.NewLabel(""))
},
func(id widget.ListItemID, o fyne.CanvasObject) {
p := providers[id]
o.(*fyne.Container).Objects[0].(*widget.Icon).SetResource(p.ProviderIcon())
o.(*fyne.Container).Objects[1].(*widget.Label).SetText(p.ProviderName())
})
ui.OnSelected = func(id widget.ListItemID) {
selected = providers[id]
}
dialog.ShowCustomConfirm("Choose Cloud provider", "Enable", "Cancel",
container.NewVBox(widget.NewLabel("Choose one of the providers below to sync\nyour preferences to the cloud."), ui),
func(ok bool) {
if !ok || selected == nil {
return
}
chooseProvider(a, selected)
}, w)
}
func chooseProvider(a fyne.App, p fyne.CloudProvider) {
settings.SetCurrentProviderName(p.ProviderName())
setCloud(p, a)
}
func cloudText(p fyne.CloudProvider) string {
if p == nil {
return "No Cloud configured"
}
return fmt.Sprintf("Using %s cloud provider", p.ProviderName())
}