refactor: remove cached AppConfig pointer and read configuration directly from DB
Replace in-memory atomic AppConfig caching with direct DB queries via db.GetConfig across application and page layers. This simplifies state management and ensures all components always operate on the latest persisted configuration. Key changes: - Remove Application.Config atomic cache and refreshCache mechanism - Eliminate PageCtx.CfgPtr and pass DB handle instead - Replace all cfg reads with db.GetConfig(app.DB) - Update mixer, audio, UI pages, and initialization paths accordingly - Explicitly set AppConfig table name to avoid GORM pluralization issues - Reduce DB connection pooling (SetMaxIdleConns(1)) - Standardize application font to SpaceMonoNerdFont-Regular - Lower default audio volume (1.0 → 0.2) - Add Unicode checkmark glyph to font map Behavioral impact: - Configuration is no longer cached in memory - Every config access now hits the DB (more consistent, slightly more overhead)
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"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/keybinds"
|
||||
"rhemawavetech.com/rhemawave/internal/logger"
|
||||
@@ -39,6 +40,7 @@ type WiFiSetupPage struct {
|
||||
applicationFont *fontManager.FontEntry
|
||||
|
||||
// UI elements
|
||||
BaseFontSize int
|
||||
titleItem StringItem
|
||||
scanningStatusItem StringItem
|
||||
connectionStatusItem StringItem
|
||||
@@ -75,9 +77,9 @@ func (p *WiFiSetupPage) Init(ctx *PageCtx) error {
|
||||
}
|
||||
|
||||
fm := fontManager.Get()
|
||||
font, ok := fm.GetFont("Roboto-Regular")
|
||||
font, ok := fm.GetFont("SpaceMonoNerdFont-Regular")
|
||||
if !ok {
|
||||
return fmt.Errorf("could not find application font: Roboto-Regular")
|
||||
return fmt.Errorf("could not find application font: SpaceMonoNerdFont-Regular")
|
||||
}
|
||||
p.applicationFont = font
|
||||
|
||||
@@ -92,6 +94,12 @@ func (p *WiFiSetupPage) Init(ctx *PageCtx) error {
|
||||
return fmt.Errorf("failed to create scanning status item: %w", err)
|
||||
}
|
||||
|
||||
config, err := db.GetConfig(p.Context.DbPtr)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
p.BaseFontSize = config.StandardFontSize
|
||||
|
||||
p.connectResultCh = make(chan error, 1)
|
||||
p.ctx, p.cancel = context.WithCancel(context.Background())
|
||||
|
||||
@@ -310,7 +318,20 @@ func (p *WiFiSetupPage) rebuildNetworkList(nets []network.Network) {
|
||||
label += " ★"
|
||||
}
|
||||
if n.Security != network.SecurityOpen {
|
||||
label += " [" + string(n.Security) + "]"
|
||||
var secStr string
|
||||
switch n.Security {
|
||||
case network.SecurityWEP:
|
||||
secStr = "WEP"
|
||||
case network.SecurityWPA:
|
||||
secStr = "WPA"
|
||||
case network.SecurityWPA2:
|
||||
secStr = "WPA2"
|
||||
case network.SecurityWPA3:
|
||||
secStr = "WPA3"
|
||||
default:
|
||||
secStr = "Secured"
|
||||
}
|
||||
label += " [" + secStr + "]"
|
||||
}
|
||||
|
||||
c := colors.White
|
||||
@@ -417,8 +438,6 @@ func (p *WiFiSetupPage) rebuildPasswordErrorTexture() {
|
||||
// ─── Render ───────────────────────────────────────────────────────────────────
|
||||
|
||||
func (p *WiFiSetupPage) Render() error {
|
||||
baseFontSize := p.Context.CfgPtr.StandardFontSize
|
||||
|
||||
solidShader, _ := shaderManager.Get().Get("solid_color")
|
||||
textShader, _ := shaderManager.Get().Get("text")
|
||||
|
||||
@@ -435,7 +454,7 @@ func (p *WiFiSetupPage) Render() error {
|
||||
)
|
||||
|
||||
// Title — 48pt
|
||||
titleScale := float32(48) / float32(baseFontSize)
|
||||
titleScale := float32(48) / float32(p.BaseFontSize)
|
||||
titleW := float32(p.titleItem.W) * titleScale
|
||||
titleH := float32(p.titleItem.H) * titleScale
|
||||
titleX := float32(p.ScreenCenterX) - titleW/2
|
||||
@@ -449,7 +468,7 @@ func (p *WiFiSetupPage) Render() error {
|
||||
// Status message — 30pt (was 24pt, now 1.25x)
|
||||
statusY := titleY - titleH - vertMargin
|
||||
if p.status == wifiStatusScanning {
|
||||
scale := float32(30) / float32(baseFontSize)
|
||||
scale := float32(30) / float32(p.BaseFontSize)
|
||||
w := float32(p.scanningStatusItem.W) * scale
|
||||
h := float32(p.scanningStatusItem.H) * scale
|
||||
x := float32(p.ScreenCenterX) - w/2
|
||||
@@ -459,7 +478,7 @@ func (p *WiFiSetupPage) Render() error {
|
||||
white,
|
||||
)
|
||||
} else if p.connectionStatusItem.ID != 0 {
|
||||
scale := float32(30) / float32(baseFontSize)
|
||||
scale := float32(30) / float32(p.BaseFontSize)
|
||||
w := float32(p.connectionStatusItem.W) * scale
|
||||
h := float32(p.connectionStatusItem.H) * scale
|
||||
x := float32(p.ScreenCenterX) - w/2
|
||||
@@ -488,7 +507,7 @@ func (p *WiFiSetupPage) Render() error {
|
||||
)
|
||||
}
|
||||
|
||||
scale := float32(24) / float32(baseFontSize)
|
||||
scale := float32(24) / float32(p.BaseFontSize)
|
||||
tw := float32(item.Item.W) * scale
|
||||
th := float32(item.Item.H) * scale
|
||||
tx := listX + float32(listPad)
|
||||
@@ -502,7 +521,7 @@ func (p *WiFiSetupPage) Render() error {
|
||||
|
||||
// Password dialog
|
||||
if p.isEnteringPassword {
|
||||
if err := p.renderPasswordDialog(solidShader, textShader, float32(baseFontSize)); err != nil {
|
||||
if err := p.renderPasswordDialog(solidShader, textShader, float32(p.BaseFontSize)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user