From 5281f733c882c2a383a882fc89516c19246f2aa1 Mon Sep 17 00:00:00 2001 From: AnderCMD Date: Fri, 20 Nov 2026 10:40:42 -0600 Subject: [PATCH] fix: settings window failed on "apps": null With no per-app rules the app saved "apps": null (nil slice), and the settings page crashed reading cfg.apps.length. Normalise nil to an empty list when loading and saving, keep copies non-nil, and make the page tolerate null from older config files. Co-Authored-By: Claude Sonnet 5.5 --- CHANGELOG.md | 5 +++++ internal/app/app_windows.go | 4 ++-- internal/config/config.go | 6 ++++++ internal/config/config_test.go | 19 +++++++++++++++++++ internal/settings/index.html | 7 ++++--- 5 files changed, 36 insertions(+), 5 deletions(-) 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 @@

TaskGlass

if (!r.ok) throw new Error(j.error || r.statusText); return j; } +const norm = c => { c.apps = c.apps || []; return c; }; // older versions wrote "apps": null const getPath = (o, p) => p.split(".").reduce((x, k) => x?.[k], o); function setPath(o, p, v) { const ks = p.split("."); const last = ks.pop(); ks.reduce((x, k) => x[k], o)[last] = v; } @@ -449,7 +450,7 @@

TaskGlass

$("#revert").onclick = () => { cfg = JSON.parse(savedCfg); auto = savedAuto; applyI18n(); onChange(); }; $("#reset").onclick = async () => { if (!confirm(t("ui.resetConfirm"))) return; - cfg = await api("/api/defaults", {}); applyI18n(); onChange(); + cfg = norm(await api("/api/defaults", {})); applyI18n(); onChange(); }; $("#save").onclick = save; addEventListener("keydown", e => { if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === "s") { e.preventDefault(); if (!$("#save").disabled) save(); } }); @@ -465,13 +466,13 @@

TaskGlass

cfg.apps = cfg.apps.filter(r => r.exe && r.exe.trim()); const res = await api("/api/config", cfg); if (auto !== savedAuto) { const r = await api("/api/autostart", { on: auto }); auto = r.autostart; } - cfg = res.config; savedCfg = JSON.stringify(cfg); savedAuto = auto; + cfg = norm(res.config); savedCfg = JSON.stringify(cfg); savedAuto = auto; applyI18n(); onChange(); toast(t("ui.saved")); } catch (e) { toast(t("ui.saveFailed", e.message), true); } } async function init() { meta = await api("/api/state"); - cfg = meta.config; savedCfg = JSON.stringify(cfg); auto = savedAuto = meta.autostart; + cfg = norm(meta.config); savedCfg = JSON.stringify(cfg); auto = savedAuto = meta.autostart; $("#ver").textContent = meta.version; $("#cfgPath").textContent = meta.configPath; bindStatic(); applyI18n(); showTab(TABS.includes(tab) ? tab : "general"); onChange(); history.replaceState(null, "", location.pathname);