go_dreamfactory/cmd/ptt/ui/ui.go
2022-08-09 18:02:24 +08:00

53 lines
897 B
Go

package ui
import (
"go_dreamfactory/cmd/ptt/service"
"sync"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/theme"
)
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
}
func NewUI(
app fyne.App,
connService service.ConnService,
pttService service.PttService,
) *UIImpl {
app.Settings().SetTheme(theme.DarkTheme())
return &UIImpl{
app: app,
windows: make(map[string]fyne.Window),
winMux: &sync.Mutex{},
connService: connService,
pttService: pttService,
}
}
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()
}