Basic GUI client, login dialog, various comments fixes after copypaste.
Some checks failed
Linting and tests / Linting (push) Failing after 6s
Some checks failed
Linting and tests / Linting (push) Failing after 6s
This commit is contained in:
93
client/internal/services/features/accounts/accounts.go
Normal file
93
client/internal/services/features/accounts/accounts.go
Normal file
@@ -0,0 +1,93 @@
|
||||
package accounts
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
|
||||
"bunker/client/internal/application"
|
||||
"bunker/client/internal/services/core"
|
||||
"bunker/client/internal/services/features"
|
||||
|
||||
"fyne.io/fyne/v2/widget"
|
||||
)
|
||||
|
||||
var errAccounts = errors.New("accounts feature service")
|
||||
|
||||
type accounts struct {
|
||||
app *application.Application
|
||||
logger *slog.Logger
|
||||
db core.Database
|
||||
mainWindow core.MainWindow
|
||||
|
||||
loginDialogInstanceAddressEntry *widget.Entry
|
||||
loginDialogUsernameEntry *widget.Entry
|
||||
loginDialogPasswordEntry *widget.Entry
|
||||
}
|
||||
|
||||
// Initialize initializes service.
|
||||
func Initialize(app *application.Application) error {
|
||||
accts := &accounts{
|
||||
app: app,
|
||||
}
|
||||
|
||||
if err := app.RegisterService(accts); err != nil {
|
||||
return fmt.Errorf("%w: %w", errAccounts, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *accounts) Configure() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *accounts) ConnectDependencies() error {
|
||||
databaseRaw := a.app.Service(core.ServiceNameDatabase)
|
||||
if databaseRaw == nil {
|
||||
return fmt.Errorf("connect dependencies: get database service: %w", application.ErrServiceNotFound)
|
||||
}
|
||||
|
||||
database, valid := databaseRaw.(core.Database)
|
||||
if !valid {
|
||||
return fmt.Errorf("connect dependencies: type assert database service: %w", core.ErrDatabaseIsInvalid)
|
||||
}
|
||||
|
||||
a.db = database
|
||||
|
||||
mainWindowRaw := a.app.Service(core.ServiceNameMainWindow)
|
||||
if mainWindowRaw == nil {
|
||||
return fmt.Errorf("connect dependencies: get main window: %w", application.ErrServiceNotFound)
|
||||
}
|
||||
|
||||
mainWindow, valid := mainWindowRaw.(core.MainWindow)
|
||||
if !valid {
|
||||
return fmt.Errorf("connect dependencies: type assert main window: %w", core.ErrMainWindowIsInvalid)
|
||||
}
|
||||
|
||||
a.mainWindow = mainWindow
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *accounts) Initialize() error {
|
||||
a.logger = a.app.NewLogger("service", features.ServiceNameTasks)
|
||||
|
||||
a.logger.Info("Initializing...")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *accounts) Name() string {
|
||||
return features.ServiceNameTasks
|
||||
}
|
||||
|
||||
func (a *accounts) LaunchStartupTasks() error {
|
||||
a.loginDialogShow()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *accounts) Shutdown() error {
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user