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:
NeilClack
2026-06-26 22:51:32 -05:00
parent 6fd5ec919c
commit 2735af5fbb
15 changed files with 239 additions and 138 deletions
+41 -11
View File
@@ -100,7 +100,7 @@ func (p *AudioOptions) Init(ctx *PageCtx) error {
// Font
fm := fontManager.Get()
font, ok := fm.GetFont("Roboto-Regular")
font, ok := fm.GetFont("SpaceMonoNerdFont-Regular")
if !ok {
return fmt.Errorf("failed to get font: %w", sdl.GetError())
}
@@ -121,7 +121,12 @@ func (p *AudioOptions) Init(ctx *PageCtx) error {
return fmt.Errorf("base init failed: %w", err)
}
baseFontSize := p.Context.CfgPtr.StandardFontSize
config, err := db.GetConfig(p.Context.DbPtr)
if err != nil {
panic(err)
}
baseFontSize := config.StandardFontSize
titleScale := float32(64) / float32(baseFontSize)
p.ItemScale = float32(32) / float32(baseFontSize)
@@ -211,7 +216,11 @@ func (p *AudioOptions) seedAudioFiles() error {
// ── Audio status toggle ───────────────────────────────────────────────────────
func (p *AudioOptions) CreateAudioStatusItem() error {
on := p.Context.CfgPtr.AudioEnabled
config, err := db.GetConfig(p.Context.DbPtr)
if err != nil {
panic(err)
}
on := config.AudioEnabled
statusString := "Turn Audio On"
color := colors.Green
if on {
@@ -277,7 +286,11 @@ func (p *AudioOptions) CreateVolumePercentItem() error {
if p.volumePercent.ID != 0 {
gl.DeleteTextures(1, &p.volumePercent.ID)
}
pct := int(p.Context.CfgPtr.SavedVolume * 100)
config, err := db.GetConfig(p.Context.DbPtr)
if err != nil {
panic(err)
}
pct := int(config.SavedVolume * 100)
item, err := NewStringItem(fmt.Sprintf("%d%%", pct), p.font, colors.White)
if err != nil {
return fmt.Errorf("failed to create volume percent item: %v", err)
@@ -288,15 +301,19 @@ func (p *AudioOptions) CreateVolumePercentItem() error {
}
func (p *AudioOptions) UpdateVolume(level int) {
newVol := mixer.ConvertVolume(level) + p.Context.CfgPtr.SavedVolume
config, err := db.GetConfig(p.Context.DbPtr)
if err != nil {
panic(err)
}
newVol := mixer.ConvertVolume(level) + config.SavedVolume
if newVol < 0.0 || newVol > 1.0 {
return
}
if newVol > .99 {
newVol = 1.0
}
p.Context.CfgPtr.SavedVolume = newVol
p.Context.DbPtr.Save(&p.Context.CfgPtr)
config.SavedVolume = newVol
p.Context.DbPtr.Save(&config)
if err := mixer.SetAllSinkVolumes(newVol); err != nil {
logger.Error("Error setting allSinkVolumes: %v", err)
}
@@ -311,6 +328,11 @@ func (p *AudioOptions) UpdateVolume(level int) {
// ── Layout ────────────────────────────────────────────────────────────────────
func (p *AudioOptions) layout() {
config, err := db.GetConfig(p.Context.DbPtr)
if err != nil {
panic(err)
}
// Title
p.title.X = p.ScreenCenterX - p.title.W/2
p.title.Y = p.ScreenHeight - p.title.H - p.verticalMargin*2
@@ -320,7 +342,7 @@ func (p *AudioOptions) layout() {
p.prompt.Y = p.title.Y - p.verticalMargin - p.prompt.H
// Volume row
barH := int32(float32(p.Context.CfgPtr.StandardFontSize) * p.ItemScale)
barH := int32(float32(config.StandardFontSize) * p.ItemScale)
barW := int32(float32(p.ScreenWidth) * 0.30)
barX := p.ScreenCenterX - barW/2
barY := p.prompt.Y - p.verticalMargin*2 - barH
@@ -376,8 +398,12 @@ func (p *AudioOptions) updateCursorPosition() {
// ── Toggle ────────────────────────────────────────────────────────────────────
func (p *AudioOptions) ToggleAudio() {
p.Context.CfgPtr.AudioEnabled = !p.Context.CfgPtr.AudioEnabled
p.Context.DbPtr.Save(p.Context.CfgPtr)
config, err := db.GetConfig(p.Context.DbPtr)
if err != nil {
panic(err)
}
config.AudioEnabled = !config.AudioEnabled
p.Context.DbPtr.Save(config)
p.Context.RefreshConfig()
p.CreateAudioStatusItem()
p.layout()
@@ -447,7 +473,11 @@ func (p *AudioOptions) Update(dt float32) error {
// ── Render helpers ────────────────────────────────────────────────────────────
func (p *AudioOptions) renderVolumeBar() error {
vol := p.Context.CfgPtr.SavedVolume
config, err := db.GetConfig(p.Context.DbPtr)
if err != nil {
panic(err)
}
vol := config.SavedVolume
fillW := float32(p.volumeBarW) * float32(vol)
if fillW > 0 {