61 lines
1.1 KiB
Go
61 lines
1.1 KiB
Go
package ui
|
|
|
|
import (
|
|
"go_dreamfactory/cmd/v2/service"
|
|
"go_dreamfactory/cmd/v2/service/observer"
|
|
"sync"
|
|
|
|
"go_dreamfactory/cmd/v2/theme"
|
|
|
|
"fyne.io/fyne/v2"
|
|
)
|
|
|
|
type UI interface {
|
|
AddWindow(name string, w fyne.Window)
|
|
Run()
|
|
Stop()
|
|
}
|
|
|
|
type UIImpl struct {
|
|
app fyne.App
|
|
windows map[string]fyne.Window
|
|
winMux *sync.Mutex
|
|
connService service.ConnService
|
|
pttService service.PttService
|
|
configService service.ConfigService
|
|
obs observer.Observer
|
|
}
|
|
|
|
func NewUI(
|
|
app fyne.App,
|
|
configService service.ConfigService,
|
|
connService service.ConnService,
|
|
pttService service.PttService,
|
|
obs observer.Observer,
|
|
) *UIImpl {
|
|
app.Settings().SetTheme(&theme.MyTheme{})
|
|
return &UIImpl{
|
|
app: app,
|
|
windows: make(map[string]fyne.Window),
|
|
winMux: &sync.Mutex{},
|
|
configService: configService,
|
|
connService: connService,
|
|
pttService: pttService,
|
|
obs: obs,
|
|
}
|
|
}
|
|
|
|
func (ui *UIImpl) AddWindow(name string, w fyne.Window) {
|
|
ui.winMux.Lock()
|
|
defer ui.winMux.Unlock()
|
|
ui.windows[name] = w
|
|
}
|
|
|
|
func (ui *UIImpl) Run() {
|
|
ui.app.Run()
|
|
}
|
|
|
|
func (ui *UIImpl) Stop() {
|
|
ui.app.Quit()
|
|
}
|