initial commit
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
package page
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"rhemawavetech.com/rhemawave/internal/download"
|
||||
)
|
||||
|
||||
type pageType int
|
||||
|
||||
const (
|
||||
HOME pageType = iota
|
||||
SCROLLER
|
||||
SETTINGS
|
||||
WIFI
|
||||
AUDIO
|
||||
PROCLAMATIONS
|
||||
LICENSE_KEY
|
||||
EMAIL_ADDRESS
|
||||
LOGS
|
||||
MESSAGE
|
||||
DOWNLOADING_ASSETS
|
||||
)
|
||||
|
||||
type PageCtx struct {
|
||||
DbPtr *gorm.DB
|
||||
W, H int32
|
||||
MessageChannel chan download.DownloadStatus
|
||||
DownloadDone chan struct{} // closed when downloads finish (success or failure)
|
||||
NavigateTo func(pageType)
|
||||
Msg string // Message to be displayed by MessagePage
|
||||
Inst string // Instructions to be displayed on MessagePage
|
||||
}
|
||||
|
||||
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 = &AudioOptions{}
|
||||
case PROCLAMATIONS:
|
||||
r.ActivePage = &ProclamationOptions{}
|
||||
case LICENSE_KEY:
|
||||
r.ActivePage = &LicenseKeyPage{}
|
||||
case EMAIL_ADDRESS:
|
||||
r.ActivePage = &EmailAddressPage{}
|
||||
case LOGS:
|
||||
r.ActivePage = &LogViewerPage{}
|
||||
case MESSAGE:
|
||||
r.ActivePage = &MessagePage{}
|
||||
case DOWNLOADING_ASSETS:
|
||||
r.ActivePage = &DownloadingAssets{}
|
||||
}
|
||||
|
||||
r.ActivePage.Init(&r.Context)
|
||||
}
|
||||
Reference in New Issue
Block a user