The very basic client app, not adapted for mobiles.
This commit is contained in:
109
client/internal/services/core/mainwindow/mainwindow.go
Normal file
109
client/internal/services/core/mainwindow/mainwindow.go
Normal file
@@ -0,0 +1,109 @@
|
||||
package mainwindow
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"os"
|
||||
|
||||
"bunker/client/internal/application"
|
||||
"bunker/client/internal/services/core"
|
||||
"bunker/client/internal/services/core/mainwindow/models"
|
||||
"bunker/commons"
|
||||
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/lang"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
)
|
||||
|
||||
var _ = core.MainWindow(&mainWindow{})
|
||||
|
||||
type mainWindow struct {
|
||||
app *application.Application
|
||||
window fyne.Window
|
||||
options core.Options
|
||||
tabs *container.AppTabs
|
||||
sysInfoHandlers map[string]*models.SysInfoHandler
|
||||
}
|
||||
|
||||
// Initialize инициализирует сервис.
|
||||
func Initialize(app *application.Application) error {
|
||||
mainW := &mainWindow{
|
||||
app: app,
|
||||
}
|
||||
|
||||
if err := app.RegisterService(mainW); err != nil {
|
||||
return fmt.Errorf("%w: %w", core.ErrMainWindow, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *mainWindow) Configure() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *mainWindow) ConnectDependencies() error {
|
||||
optionsRaw := m.app.Service(core.ServiceNameOptions)
|
||||
if optionsRaw == nil {
|
||||
return fmt.Errorf("connect dependencies: get options service: %w", application.ErrServiceNotFound)
|
||||
}
|
||||
|
||||
options, valid := optionsRaw.(core.Options)
|
||||
if !valid {
|
||||
return fmt.Errorf("connect dependencies: type assert options service: %w", core.ErrOptionsIsInvalid)
|
||||
}
|
||||
|
||||
m.options = options
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *mainWindow) Initialize() error {
|
||||
m.sysInfoHandlers = make(map[string]*models.SysInfoHandler)
|
||||
|
||||
m.window = m.app.Fyne().NewWindow(lang.L("window.title"))
|
||||
// ToDo: сохранение и восстановление размеров окна.
|
||||
//nolint:mnd
|
||||
m.window.Resize(fyne.NewSize(800, 650))
|
||||
|
||||
m.initializeMenu()
|
||||
|
||||
m.window.SetCloseIntercept(m.stopApp)
|
||||
|
||||
welcomeLabel := widget.NewLabel(lang.L("window.lorem_ipsum.text"))
|
||||
welcomeLabel.Wrapping = fyne.TextWrapWord
|
||||
|
||||
m.tabs = container.NewAppTabs(
|
||||
container.NewTabItem(lang.L("window.lorem_ipsum.tab_name"), welcomeLabel),
|
||||
)
|
||||
m.window.SetContent(m.tabs)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *mainWindow) MainWindow() fyne.Window {
|
||||
return m.window
|
||||
}
|
||||
|
||||
func (m *mainWindow) Name() string {
|
||||
return core.ServiceNameMainWindow
|
||||
}
|
||||
|
||||
func (m *mainWindow) LaunchStartupTasks() error {
|
||||
m.window.Show()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *mainWindow) Shutdown() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *mainWindow) stopApp() {
|
||||
if err := m.app.Shutdown(); err != nil {
|
||||
slog.Error("Failed to stop Bunker!", "error", err.Error())
|
||||
|
||||
os.Exit(commons.ExitCodeAppStopFailed)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user