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:
@@ -2,12 +2,10 @@ package page
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/go-gl/gl/v3.3-core/gl"
|
||||
"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"
|
||||
)
|
||||
@@ -26,11 +24,11 @@ type Settings struct {
|
||||
}
|
||||
|
||||
type Option struct {
|
||||
page Page
|
||||
label StringItem
|
||||
target pageType
|
||||
label StringItem
|
||||
}
|
||||
|
||||
func (p *Settings) Init(app ApplicationInterface) error {
|
||||
func (p *Settings) Init(ctx *PageCtx) error {
|
||||
var err error
|
||||
p.verticalMargin = int32(20)
|
||||
|
||||
@@ -54,7 +52,7 @@ func (p *Settings) Init(app ApplicationInterface) error {
|
||||
}
|
||||
|
||||
// Initialize base
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -76,8 +74,8 @@ func (p *Settings) Init(app ApplicationInterface) error {
|
||||
return fmt.Errorf("creating proclamations label: %w", err)
|
||||
}
|
||||
p.options = append(p.options, Option{
|
||||
page: &ProclamationOptions{},
|
||||
label: proclamationsLabel,
|
||||
target: PROCLAMATIONS,
|
||||
label: proclamationsLabel,
|
||||
})
|
||||
|
||||
wifiLabel, err := NewStringItem("WiFi Setup", font, colors.White)
|
||||
@@ -85,8 +83,8 @@ func (p *Settings) Init(app ApplicationInterface) error {
|
||||
return fmt.Errorf("creating wifi label: %w", err)
|
||||
}
|
||||
p.options = append(p.options, Option{
|
||||
page: &WiFiSetupPage{},
|
||||
label: wifiLabel,
|
||||
target: WIFI,
|
||||
label: wifiLabel,
|
||||
})
|
||||
|
||||
audioLabel, err := NewStringItem("Audio Device", font, colors.White)
|
||||
@@ -94,8 +92,8 @@ func (p *Settings) Init(app ApplicationInterface) error {
|
||||
return fmt.Errorf("creating audio label: %w", err)
|
||||
}
|
||||
p.options = append(p.options, Option{
|
||||
page: &AudioDevices{},
|
||||
label: audioLabel,
|
||||
target: AUDIO,
|
||||
label: audioLabel,
|
||||
})
|
||||
|
||||
emailLabel, err := NewStringItem("Email Address", font, colors.White)
|
||||
@@ -103,8 +101,8 @@ func (p *Settings) Init(app ApplicationInterface) error {
|
||||
return fmt.Errorf("creating email label: %w", err)
|
||||
}
|
||||
p.options = append(p.options, Option{
|
||||
page: &EmailAddressPage{},
|
||||
label: emailLabel,
|
||||
target: EMAIL_ADDRESS,
|
||||
label: emailLabel,
|
||||
})
|
||||
|
||||
licenseKeyLabel, err := NewStringItem("License Key", font, colors.White)
|
||||
@@ -112,8 +110,8 @@ func (p *Settings) Init(app ApplicationInterface) error {
|
||||
return fmt.Errorf("creating license key label: %w", err)
|
||||
}
|
||||
p.options = append(p.options, Option{
|
||||
page: &LicenseKeyPage{},
|
||||
label: licenseKeyLabel,
|
||||
target: LICENSE_KEY,
|
||||
label: licenseKeyLabel,
|
||||
})
|
||||
|
||||
logsLabel, err := NewStringItem("Logs", font, colors.White)
|
||||
@@ -121,8 +119,8 @@ func (p *Settings) Init(app ApplicationInterface) error {
|
||||
return fmt.Errorf("creating logs label: %w", err)
|
||||
}
|
||||
p.options = append(p.options, Option{
|
||||
page: &LogViewerPage{},
|
||||
label: logsLabel,
|
||||
target: LOGS,
|
||||
label: logsLabel,
|
||||
})
|
||||
|
||||
updateLabel, err := NewStringItem("Check for Updates", font, colors.White)
|
||||
@@ -130,19 +128,12 @@ func (p *Settings) Init(app ApplicationInterface) error {
|
||||
return fmt.Errorf("creating update label: %w", err)
|
||||
}
|
||||
p.options = append(p.options, Option{
|
||||
page: &UpdateCheckPage{},
|
||||
label: updateLabel,
|
||||
target: CHECK_UPDATES,
|
||||
label: updateLabel,
|
||||
})
|
||||
|
||||
// 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.Context.CfgPtr.StandardFontSize
|
||||
|
||||
// Calculate scales
|
||||
titleScale := float32(64) / float32(baseFontSize)
|
||||
@@ -208,10 +199,10 @@ func (p *Settings) HandleEvent(event *sdl.Event) error {
|
||||
case sdl.K_RETURN:
|
||||
if p.highlightIndex >= 0 && p.highlightIndex < len(p.options) {
|
||||
selectedOption := p.options[p.highlightIndex]
|
||||
p.App.SwitchPage(selectedOption.page)
|
||||
p.Context.NavigateTo(selectedOption.target)
|
||||
}
|
||||
case sdl.K_BACKSPACE:
|
||||
p.App.SwitchPage(&Welcome{})
|
||||
p.Context.NavigateTo(HOME)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user