diff --git a/pkg/display/display.go b/pkg/display/display.go index b6cf51ae..6dcc5a07 100644 --- a/pkg/display/display.go +++ b/pkg/display/display.go @@ -1120,9 +1120,12 @@ func (s *Service) GetWindowInfo(name string) (*window.WindowInfo, error) { func (s *Service) ListWindowInfos() []window.WindowInfo { r := s.Core().QUERY(window.QueryWindowList{}) if !r.OK { - return nil + return []window.WindowInfo{} } list, _ := r.Value.([]window.WindowInfo) + if list == nil { + return []window.WindowInfo{} + } return list } @@ -1340,7 +1343,7 @@ func (s *Service) ResetWindowState() error { func (s *Service) GetSavedWindowStates() map[string]window.WindowState { ws := s.windowService() if ws == nil { - return nil + return map[string]window.WindowState{} } result := make(map[string]window.WindowState) for _, name := range ws.Manager().State().ListStates() { @@ -1424,9 +1427,12 @@ func (s *Service) RestoreLayout(name string) error { func (s *Service) ListLayouts() []window.LayoutInfo { r := s.Core().QUERY(window.QueryLayoutList{}) if !r.OK { - return nil + return []window.LayoutInfo{} } layouts, _ := r.Value.([]window.LayoutInfo) + if layouts == nil { + return []window.LayoutInfo{} + } return layouts } diff --git a/pkg/display/display_test.go b/pkg/display/display_test.go index b367cd7a..7877d05e 100644 --- a/pkg/display/display_test.go +++ b/pkg/display/display_test.go @@ -760,6 +760,21 @@ func TestGetSavedWindowStates_Good(t *testing.T) { assert.NotNil(t, states) } +func TestDisplay_PublicCollections_AreNilSafe(t *testing.T) { + svc, _ := newTestDisplayService(t) + + infos := svc.ListWindowInfos() + layouts := svc.ListLayouts() + states := svc.GetSavedWindowStates() + + require.NotNil(t, infos) + require.NotNil(t, layouts) + require.NotNil(t, states) + assert.Empty(t, infos) + assert.Empty(t, layouts) + assert.Empty(t, states) +} + func TestHandleIPCEvents_WindowOpened_Good(t *testing.T) { c := newTestConclave(t)