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
|
||||
}
|
53
client/internal/services/features/accounts/login_dialog.go
Normal file
53
client/internal/services/features/accounts/login_dialog.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package accounts
|
||||
|
||||
import (
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/dialog"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
)
|
||||
|
||||
func (a *accounts) loginDialogLogin() {
|
||||
a.logger.Info(
|
||||
"Trying to log in...",
|
||||
"instance", a.loginDialogInstanceAddressEntry.Text,
|
||||
"username", a.loginDialogUsernameEntry.Text,
|
||||
"password", a.loginDialogPasswordEntry.Text,
|
||||
)
|
||||
}
|
||||
|
||||
func (a *accounts) loginDialogShow() {
|
||||
if a.loginDialogInstanceAddressEntry == nil {
|
||||
a.loginDialogInstanceAddressEntry = widget.NewEntry()
|
||||
a.loginDialogInstanceAddressEntry.SetText("http://localhost:53400")
|
||||
}
|
||||
|
||||
if a.loginDialogUsernameEntry == nil {
|
||||
a.loginDialogUsernameEntry = widget.NewEntry()
|
||||
a.loginDialogUsernameEntry.SetPlaceHolder("username")
|
||||
}
|
||||
|
||||
if a.loginDialogPasswordEntry == nil {
|
||||
a.loginDialogPasswordEntry = widget.NewEntry()
|
||||
} else {
|
||||
a.loginDialogPasswordEntry.SetText("")
|
||||
}
|
||||
|
||||
loginForm := widget.NewForm(
|
||||
widget.NewFormItem("Instance address:", a.loginDialogInstanceAddressEntry),
|
||||
widget.NewFormItem("Login:", a.loginDialogUsernameEntry),
|
||||
widget.NewFormItem("Password:", a.loginDialogPasswordEntry),
|
||||
)
|
||||
|
||||
loginButton := widget.NewButton("Log in", a.loginDialogLogin)
|
||||
|
||||
loginDialogContent := container.NewBorder(nil, loginButton, nil, nil, loginForm)
|
||||
|
||||
dialog := dialog.NewCustomWithoutButtons(
|
||||
"Login to Bunker instance",
|
||||
loginDialogContent,
|
||||
a.mainWindow.MainWindow(),
|
||||
)
|
||||
dialog.Resize(dialog.MinSize().AddWidthHeight(200, 0))
|
||||
|
||||
dialog.Show()
|
||||
}
|
Reference in New Issue
Block a user