Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions internal/app/app_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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) }
Expand Down
6 changes: 6 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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 {
Expand Down
19 changes: 19 additions & 0 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
7 changes: 4 additions & 3 deletions internal/settings/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ <h1 data-i18n="ui.title">TaskGlass</h1>
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; }

Expand Down Expand Up @@ -449,7 +450,7 @@ <h1 data-i18n="ui.title">TaskGlass</h1>
$("#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(); } });
Expand All @@ -465,13 +466,13 @@ <h1 data-i18n="ui.title">TaskGlass</h1>
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);
Expand Down