diff --git a/CHANGELOG.md b/CHANGELOG.md index d08d02d..5c1fc89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ Format based on [Keep a Changelog](https://keepachangelog.com/); versioning follows [SemVer](https://semver.org/). +## [Unreleased] + +### Fixed +- **Settings window showed "Cannot read properties of null".** With no per-app rules, 1.2.0 saved `"apps": null` to `config.json`, which the window could not read. `null` now loads as an empty list, is never written again, and the window tolerates it. + ## [1.2.0] - 2026-11-20 ### Fixed diff --git a/internal/app/app_windows.go b/internal/app/app_windows.go index 7cd95cf..4f6cb66 100644 --- a/internal/app/app_windows.go +++ b/internal/app/app_windows.go @@ -132,7 +132,7 @@ func (a *App) update(fn func(*config.Config)) { func (a *App) apply(fn func(*config.Config)) error { a.mu.Lock() next := a.cfg - next.Apps = append([]config.AppRule(nil), a.cfg.Apps...) + next.Apps = append([]config.AppRule{}, a.cfg.Apps...) fn(&next) if err := config.Save(a.CfgPath, next); err != nil { a.mu.Unlock() @@ -177,7 +177,7 @@ type host struct{ a *App } func (h host) Config() config.Config { return h.a.snapshot() } func (h host) Apply(c config.Config) error { next := c - next.Apps = append([]config.AppRule(nil), c.Apps...) + next.Apps = append([]config.AppRule{}, c.Apps...) return h.a.apply(func(cur *config.Config) { *cur = next }) } func (h host) AutostartEnabled() bool { return autostart.Enabled(h.a.exe) } diff --git a/internal/config/config.go b/internal/config/config.go index 7231f2c..29f65cf 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -464,6 +464,9 @@ func Parse(data []byte) (Config, error) { if err := c.Validate(); err != nil { return Config{}, fmt.Errorf("invalid config: %w", err) } + if c.Apps == nil { + c.Apps = []AppRule{} // "apps": null (written by 1.2.0) means no rules + } return c, nil } @@ -489,6 +492,9 @@ func Save(path string, c Config) error { if err := c.Validate(); err != nil { return err } + if c.Apps == nil { + c.Apps = []AppRule{} // never write "apps": null + } c.LegacyStartMenu, c.Surfaces.LegacySurfaceStartMenu, c.Surfaces.LegacyExplorer = nil, nil, nil // dropped for good on the first save data, err := json.MarshalIndent(c, "", " ") if err != nil { diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 2626e32..b034995 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -272,3 +272,22 @@ func TestOldStartMenuRuleStillLoads(t *testing.T) { t.Fatal("maximized must be off by default") } } + +func TestNullAppsBecomesEmptyAndIsNeverWrittenAsNull(t *testing.T) { + c, err := Parse([]byte(`{"version":1,"apps":null}`)) + if err != nil { + t.Fatal(err) + } + if c.Apps == nil { + t.Fatal("apps: null must load as an empty list") + } + c.Apps = nil + path := filepath.Join(t.TempDir(), "config.json") + if err := Save(path, c); err != nil { + t.Fatal(err) + } + data, _ := os.ReadFile(path) + if strings.Contains(string(data), `"apps": null`) { + t.Fatalf("saved null apps:\n%s", data) + } +} diff --git a/internal/settings/index.html b/internal/settings/index.html index d5d2871..8a8af7a 100644 --- a/internal/settings/index.html +++ b/internal/settings/index.html @@ -247,6 +247,7 @@