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
+5 -15
View File
@@ -4,7 +4,6 @@ import (
"fmt"
"os"
"path/filepath"
"strconv"
"strings"
"sync"
@@ -35,7 +34,7 @@ var (
// InitFontManager initializes the FontManager singleton.
// It must be called once at startup after ShaderManager has been initialized.
func InitFontManager() error {
func InitFontManager(cfg *db.AppConfig) error {
fontManagerOnce.Do(func() {
// Dependency check: Ensure ShaderManager is ready
@@ -49,13 +48,8 @@ func InitFontManager() error {
Fonts: make(map[string]*FontEntry),
}
assetsDir, err := db.GetConfigValue("assets_dir")
if err != nil {
initErr = fmt.Errorf("could not get assets_dir from config: %w", err)
return
}
fontPath := filepath.Join(assetsDir, "fonts")
if err := fm.loadFonts(fontPath); err != nil {
fontPath := filepath.Join(cfg.AssetsDir, "fonts")
if err := fm.loadFonts(fontPath, cfg); err != nil {
initErr = fmt.Errorf("could not load fonts from '%s': %w", fontPath, err)
return
}
@@ -136,7 +130,7 @@ type Glyph struct {
}
// loadFonts scans the fonts directory, loads all .ttf/.otf files, and creates a font map for each.
func (fm *FontManager) loadFonts(fontDir string) error {
func (fm *FontManager) loadFonts(fontDir string, cfg *db.AppConfig) error {
files, err := os.ReadDir(fontDir)
if err != nil {
return fmt.Errorf("could not read font directory '%s': %w", fontDir, err)
@@ -149,11 +143,7 @@ func (fm *FontManager) loadFonts(fontDir string) error {
fileName := file.Name()
if strings.HasSuffix(strings.ToLower(fileName), ".ttf") || strings.HasSuffix(strings.ToLower(fileName), ".otf") {
fontPath := filepath.Join(fontDir, fileName)
baseFontSizeStr, err := db.GetConfigValue("init_font_size")
if err != nil {
return fmt.Errorf("could not get standard_font_size from config: %w", err)
}
baseFontSize, err := strconv.Atoi(baseFontSizeStr)
baseFontSize := cfg.StandardFontSize
if err != nil {
return fmt.Errorf("could not convert init_font_size to int: %w", err)
}