From bc3b08ca5d8aa24733d3214e8cf95a554eca9df0 Mon Sep 17 00:00:00 2001 From: Snider Date: Fri, 17 Apr 2026 17:40:11 +0100 Subject: [PATCH] Harden theme IPC payload handling --- pkg/display/api.go | 23 +++++++++++++++++++---- pkg/display/api_test.go | 3 +-- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/pkg/display/api.go b/pkg/display/api.go index 0d0e77c4..f02f3cd4 100644 --- a/pkg/display/api.go +++ b/pkg/display/api.go @@ -2,6 +2,7 @@ package display import ( "context" + "fmt" core "dappco.re/go/core" coreerr "dappco.re/go/core/log" @@ -507,22 +508,36 @@ func (s *Service) SetTheme(theme string) error { func (s *Service) GetTheme() *Theme { r := s.Core().QUERY(environment.QueryTheme{}) - if !r.OK { + info, ok := themeInfoFromQueryResult(s, "display.GetTheme", r) + if !ok { return nil } - info, _ := r.Value.(environment.ThemeInfo) return &Theme{IsDark: info.IsDark} } func (s *Service) GetSystemTheme() string { r := s.Core().QUERY(environment.QueryTheme{}) - if !r.OK { + info, ok := themeInfoFromQueryResult(s, "display.GetSystemTheme", r) + if !ok { return "" } - info, _ := r.Value.(environment.ThemeInfo) return info.Theme } +func themeInfoFromQueryResult(s *Service, method string, r core.Result) (environment.ThemeInfo, bool) { + if !r.OK { + return environment.ThemeInfo{}, false + } + info, ok := r.Value.(environment.ThemeInfo) + if ok { + return info, true + } + if s != nil && s.Core() != nil { + s.Core().LogWarn(fmt.Errorf("query=environment.QueryTheme value_type=%T", r.Value), method, "malformed theme query payload") + } + return environment.ThemeInfo{}, false +} + func (s *Service) sendNotification(opts notification.NotificationOptions) error { result := s.Core().Action("notification.send").Run(context.Background(), core.NewOptions( core.Option{Key: "task", Value: notification.TaskSend{Options: opts}}, diff --git a/pkg/display/api_test.go b/pkg/display/api_test.go index e42c71f6..2e803248 100644 --- a/pkg/display/api_test.go +++ b/pkg/display/api_test.go @@ -291,8 +291,7 @@ func TestDisplayAPI_GetTheme_Bad(t *testing.T) { }) theme := svc.GetTheme() - require.NotNil(t, theme) - assert.False(t, theme.IsDark) + assert.Nil(t, theme) assert.Empty(t, svc.GetSystemTheme()) }