Update Database

Database is more usable now.
All pages have been updated to use the database, and share an application configuration.
Page Stack has been removed, no more pages hanging around in memory. Replaced with a 'Router' which uses an Enum to determine which page should be displayed, destroys the old page and initializes the new page all in one go. No more push, pop, rollback, etc. No more holding instances of pages.
Logger has been updated with proper timestamps and sorting now works as expected."
This commit is contained in:
NeilClack
2026-03-23 15:02:07 -05:00
parent f8fbfb721d
commit 17c088cc2f
28 changed files with 537 additions and 2276 deletions
+12 -32
View File
@@ -3,13 +3,11 @@ package page
import (
"fmt"
"regexp"
"strconv"
"github.com/go-gl/gl/v3.3-core/gl"
"github.com/go-gl/mathgl/mgl32"
"github.com/veandco/go-sdl2/sdl"
"rhemawavetech.com/rhemawave/internal/colors"
"rhemawavetech.com/rhemawave/internal/db"
"rhemawavetech.com/rhemawave/internal/fontManager"
"rhemawavetech.com/rhemawave/internal/shaderManager"
)
@@ -53,19 +51,15 @@ func isValidEmail(email string) bool {
}
// Init performs basic page initialization and creation of static assets.
func (p *EmailAddressPage) Init(app ApplicationInterface) error {
func (p *EmailAddressPage) Init(ctx *PageCtx) error {
if err := p.Base.Init(app); err != nil {
if err := p.Base.Init(ctx); err != nil {
return fmt.Errorf("failed base page initialization: %w", err)
}
p.title = "Your Email Address"
// Get application font from database
applicationFont, err := db.GetConfigValue("application_font")
if err != nil {
return fmt.Errorf("retrieving application_font from db: %w", err)
}
applicationFont := "Roboto-Regular"
fm := fontManager.Get()
textShader, ok := shaderManager.Get().Get("text")
@@ -87,10 +81,7 @@ func (p *EmailAddressPage) Init(app ApplicationInterface) error {
p.titleTextureHeight = titleHeight
// Load existing email address from database
emailAddress, err := db.GetConfigValue("email_address")
if err != nil {
return fmt.Errorf("retrieving email_address from db: %w", err)
}
emailAddress := ctx.CfgPtr.EmailAddress
if emailAddress != "" {
p.inputText = emailAddress
@@ -148,7 +139,7 @@ func (p *EmailAddressPage) HandleEvent(event *sdl.Event) error {
}
// Allow escape back to settings if coming from settings
sdl.StopTextInput()
p.App.UnwindToPage(&Settings{})
p.Context.NavigateTo(SETTINGS)
case sdl.K_RETURN:
// Validate email - check empty first, then format
if p.inputText == "" {
@@ -163,16 +154,15 @@ func (p *EmailAddressPage) HandleEvent(event *sdl.Event) error {
sdl.StopTextInput()
// Save email address to database
if err := db.SetConfigValue("email_address", p.inputText); err != nil {
return fmt.Errorf("failed to save email address: %w", err)
}
p.Base.Context.CfgPtr.EmailAddress = p.inputText
p.Base.Context.DbPtr.Save(p.Base.Context.CfgPtr)
p.Base.Context.RefreshConfig()
if p.isFirstTimeSetup {
// First-time setup: navigate to License Key page
p.App.PushPage(&LicenseKeyPage{})
p.Context.NavigateTo(LICENSE_KEY)
} else {
// Coming from settings: rewind back to settings
p.App.UnwindToPage(&Settings{})
p.Context.NavigateTo(SETTINGS)
}
case sdl.K_BACKSPACE:
if len(p.inputText) > 0 {
@@ -199,10 +189,7 @@ func (p *EmailAddressPage) HandleEvent(event *sdl.Event) error {
// Update updates animations and changing textures and other changes using `dt` which represents a time delta in float32.
func (p *EmailAddressPage) Update(dt float32) error {
// Get application font from database
applicationFont, err := db.GetConfigValue("application_font")
if err != nil {
return fmt.Errorf("retrieving application_font from db: %w", err)
}
applicationFont := "Roboto-Regular"
fm := fontManager.Get()
sm := shaderManager.Get()
@@ -266,14 +253,7 @@ func (p *EmailAddressPage) Update(dt float32) error {
// Render performs page drawing logic.
func (p *EmailAddressPage) Render() error {
// Get base font size from database
baseFontSizeStr, err := db.GetConfigValue("init_font_size")
if err != nil {
return fmt.Errorf("retrieving init_font_size from db: %w", err)
}
baseFontSize, err := strconv.Atoi(baseFontSizeStr)
if err != nil {
return fmt.Errorf("parsing init_font_size: %w", err)
}
baseFontSize := p.Base.Context.CfgPtr.StandardFontSize
sm := shaderManager.Get()