-
Notifications
You must be signed in to change notification settings - Fork 376
/
main.go
106 lines (84 loc) · 2.14 KB
/
main.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
104
105
106
package gui
import (
"context"
"fmt"
"sync"
"fyne.io/fyne/v2"
"go.uber.org/zap"
assets "berty.tech/berty/v2/go/pkg/assets"
"berty.tech/berty/v2/go/pkg/errcode"
"berty.tech/berty/v2/go/pkg/messengertypes"
"berty.tech/weshnet/pkg/lifecycle"
"berty.tech/weshnet/pkg/protocoltypes"
)
// Opts ...
type Opts struct {
MessengerClient messengertypes.MessengerServiceClient
ProtocolClient protocoltypes.ProtocolServiceClient
Logger *zap.Logger
GroupInvitation string
DisplayName string
LifecycleManager *lifecycle.Manager
AppChan chan fyne.App
}
// Main ...
func Main(ctx context.Context, opts *Opts) error {
assets.Noop() // embed assets
if opts.MessengerClient == nil {
return errcode.ErrMissingInput.Wrap(fmt.Errorf("missing messenger client"))
}
if opts.ProtocolClient == nil {
return errcode.ErrMissingInput.Wrap(fmt.Errorf("missing protocol client"))
}
if opts.AppChan == nil {
return errcode.ErrMissingInput.Wrap(fmt.Errorf("missing window chan"))
}
ctx, cancel := context.WithCancel(ctx)
defer cancel()
a := <-opts.AppChan
w := a.NewWindow("bergy")
wg := &sync.WaitGroup{}
wg.Add(1)
w.SetOnClosed(func() { wg.Done() })
store, err := newMsgrStore(ctx, opts.MessengerClient, opts.Logger)
if err != nil {
return err
}
mc := msgrContext{
ctx: ctx,
client: opts.MessengerClient,
protocolClient: opts.ProtocolClient,
logger: opts.Logger,
store: store,
window: w,
app: a,
}
wfr := newAppRootWidget(&mc)
if wfr.err != nil {
return wfr.err
}
w.SetContent(wfr.object)
w.Resize(fyne.NewSize(600, 600))
w.Show()
w.SetMaster()
wg.Wait()
return wfr.clean()
}
// CONTEXT
type msgrContext struct {
client messengertypes.MessengerServiceClient
protocolClient protocoltypes.ProtocolServiceClient
logger *zap.Logger
ctx context.Context
store *msgrStore
window fyne.Window
app fyne.App
}
// WIDGET FACTORY
type widgetFactoryReturn struct {
object fyne.CanvasObject
clean func() error
err error
}
type wfr = widgetFactoryReturn
type widgetFactory = func(mc *msgrContext) wfr