fix: keep active page on config save, add Cyrillic preview support, fix grid sizing
- daemon.go: save/restore active page on config reload instead of always activating default_page (fixes page switch on save) - render.go: replace basicfont.Face7x13 with parseDisplayFace() for unicode/Cyrillic support in edit key preview - web.go: add SSE endpoint (GET /api/events) for real-time page_changed events and POST /api/activate-page API - app.js: persist active page via localStorage, listen for SSE page_changed events - styles.css, index.html: fix grid sizing (width 100%, minmax(0, 1fr), aspect-ratio on key buttons, max-width 525px)
This commit is contained in:
@@ -74,6 +74,7 @@ func Run(ctx context.Context, cfg *config.Config, opts RunOptions) error {
|
||||
|
||||
web.SetDecks(decks)
|
||||
web.SetPageManager(primaryPM)
|
||||
web.SetExtraPageManagers(pageMgrs[1:])
|
||||
|
||||
for _, pm := range pageMgrs {
|
||||
if err := pm.ActivatePage(cfg.DefaultPage); err != nil {
|
||||
@@ -104,14 +105,19 @@ func Run(ctx context.Context, cfg *config.Config, opts RunOptions) error {
|
||||
if a == nil {
|
||||
return
|
||||
}
|
||||
oldPage := primaryPM.ActivePageName()
|
||||
if err := ExecuteAction(a, primaryDeck, primaryPM); err != nil {
|
||||
slog.Error("execute action", "error", err)
|
||||
}
|
||||
if a.Type == "page" {
|
||||
asm.NotifyManualPage(a.Page)
|
||||
for _, pm := range pageMgrs[1:] {
|
||||
pm.ActivatePage(a.Page)
|
||||
newPage := primaryPM.ActivePageName()
|
||||
if newPage != oldPage {
|
||||
if a.Type == "page" {
|
||||
asm.NotifyManualPage(a.Page)
|
||||
}
|
||||
for _, pm := range pageMgrs[1:] {
|
||||
pm.ActivatePage(newPage)
|
||||
}
|
||||
web.BroadcastPageChange(newPage)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -191,6 +197,7 @@ func Run(ctx context.Context, cfg *config.Config, opts RunOptions) error {
|
||||
}
|
||||
pm.startPeriodicKeys()
|
||||
}
|
||||
web.BroadcastPageChange(page)
|
||||
}
|
||||
|
||||
case <-configTicker.C:
|
||||
@@ -214,7 +221,9 @@ func Run(ctx context.Context, cfg *config.Config, opts RunOptions) error {
|
||||
for _, d := range decks {
|
||||
d.SetBrightness(deviceBrightness(cfg, d.Serial()))
|
||||
}
|
||||
var activePages []string
|
||||
for _, pm := range pageMgrs {
|
||||
activePages = append(activePages, pm.ActivePageName())
|
||||
pm.stopPeriodicKeys()
|
||||
pm.defaultFont = cfg.Font
|
||||
pm.LoadPages(cfg.Pages)
|
||||
@@ -225,9 +234,18 @@ func Run(ctx context.Context, cfg *config.Config, opts RunOptions) error {
|
||||
detector = NewWindowDetector()
|
||||
windowCh, _ = detector.Start(ctx)
|
||||
}
|
||||
for _, pm := range pageMgrs {
|
||||
if err := pm.ActivatePage(cfg.DefaultPage); err != nil {
|
||||
slog.Warn("reload: activate default page", "error", err)
|
||||
for i, pm := range pageMgrs {
|
||||
page := cfg.DefaultPage
|
||||
if i < len(activePages) && activePages[i] != "" {
|
||||
for _, p := range cfg.Pages {
|
||||
if p.Name == activePages[i] {
|
||||
page = activePages[i]
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if err := pm.ActivatePage(page); err != nil {
|
||||
slog.Warn("reload: activate page", "error", err)
|
||||
}
|
||||
pm.startPeriodicKeys()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user