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."
76 lines
1.2 KiB
Go
76 lines
1.2 KiB
Go
package page
|
|
|
|
import (
|
|
"gorm.io/gorm"
|
|
"rhemawavetech.com/rhemawave/internal/db"
|
|
)
|
|
|
|
type pageType int
|
|
|
|
const (
|
|
HOME pageType = iota
|
|
SCROLLER
|
|
SETTINGS
|
|
WIFI
|
|
AUDIO
|
|
PROCLAMATIONS
|
|
LICENSE_KEY
|
|
EMAIL_ADDRESS
|
|
LOGS
|
|
CHECK_UPDATES
|
|
ERROR
|
|
)
|
|
|
|
type PageCtx struct {
|
|
CfgPtr *db.AppConfig
|
|
DbPtr *gorm.DB
|
|
W, H int32
|
|
RefreshConfig func()
|
|
NavigateTo func(pageType)
|
|
}
|
|
|
|
type Router struct {
|
|
ActivePage Page
|
|
Context PageCtx
|
|
}
|
|
|
|
func NewRouter(pgCtx PageCtx) *Router {
|
|
r := &Router{
|
|
Context: pgCtx,
|
|
}
|
|
r.Context.NavigateTo = r.NavigateTo
|
|
r.NavigateTo(HOME)
|
|
return r
|
|
}
|
|
|
|
func (r *Router) NavigateTo(p pageType) {
|
|
if r.ActivePage != nil {
|
|
r.ActivePage.Destroy()
|
|
}
|
|
|
|
switch p {
|
|
case HOME:
|
|
r.ActivePage = &Home{}
|
|
case SCROLLER:
|
|
r.ActivePage = &ScrollerPage{}
|
|
case SETTINGS:
|
|
r.ActivePage = &Settings{}
|
|
case WIFI:
|
|
r.ActivePage = &WiFiSetupPage{}
|
|
case AUDIO:
|
|
r.ActivePage = &AudioDevices{}
|
|
case PROCLAMATIONS:
|
|
r.ActivePage = &ProclamationOptions{}
|
|
case LICENSE_KEY:
|
|
r.ActivePage = &LicenseKeyPage{}
|
|
case EMAIL_ADDRESS:
|
|
r.ActivePage = &EmailAddressPage{}
|
|
case LOGS:
|
|
r.ActivePage = &LogViewerPage{}
|
|
case CHECK_UPDATES:
|
|
r.ActivePage = &UpdateCheckPage{}
|
|
}
|
|
|
|
r.ActivePage.Init(&r.Context)
|
|
}
|