refactor(daemon): share bar anchor names between run and cleanup
Introduce barAnchorTopRight/barAnchorBottomRight constants and a barAnchors slice so clearBarScriptsForSession's lastFailure cleanup loops over the same anchor set that runBarScripts executes, instead of duplicating "top-right"/"bottom-right" literals in both places.
- commit
- 67b1767f36b1b65436516f8cea8e948b76a990c6
- author
- brice · · 2026-07-20 09:53 UTC
- parent
- 8755162
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
1 file · +16 -4
M internal/usecase/daemon/bar_refresh.go +16 -4
| @@ -13,6 +13,17 @@ type barScriptExecutor interface { | |||
| 13 | 13 | run(ctx context.Context, command string, env []string, scriptCtx barScriptContext) (string, error) | |
| 14 | 14 | } | |
| 15 | 15 | ||
| 16 | + | // Anchor names, exported to bar scripts as VEV_ANCHOR and documented in | |
| 17 | + | // docs/configuration.md. barAnchors must list every anchor so cleanup in | |
| 18 | + | // clearBarScriptsForSession stays in sync with the anchors run in | |
| 19 | + | // runBarScripts. | |
| 20 | + | const ( | |
| 21 | + | barAnchorTopRight = "top-right" | |
| 22 | + | barAnchorBottomRight = "bottom-right" | |
| 23 | + | ) | |
| 24 | + | ||
| 25 | + | var barAnchors = []string{barAnchorTopRight, barAnchorBottomRight} | |
| 26 | + | ||
| 16 | 27 | type barScriptConfig struct { | |
| 17 | 28 | topRight string | |
| 18 | 29 | bottomRight string | |
| @@ -207,8 +218,9 @@ func (d *Daemon) clearBarScriptsForSession(id domain.SessionID) { | |||
| 207 | 218 | delete(d.barScripts.lastContext, id) | |
| 208 | 219 | delete(d.barScripts.running, id) | |
| 209 | 220 | delete(d.barScripts.pending, id) | |
| 210 | - | delete(d.barScripts.lastFailure, barScriptFailureKey{id: id, anchor: "top-right"}) | |
| 211 | - | delete(d.barScripts.lastFailure, barScriptFailureKey{id: id, anchor: "bottom-right"}) | |
| 221 | + | for _, anchor := range barAnchors { | |
| 222 | + | delete(d.barScripts.lastFailure, barScriptFailureKey{id: id, anchor: anchor}) | |
| 223 | + | } | |
| 212 | 224 | } | |
| 213 | 225 | ||
| 214 | 226 | // shouldLogBarFailure reports whether this failure differs from the last one | |
| @@ -329,8 +341,8 @@ func (d *Daemon) runBarScripts(sess *session, runner barScriptExecutor, cfg barS | |||
| 329 | 341 | if ctx == nil { | |
| 330 | 342 | ctx = context.Background() | |
| 331 | 343 | } | |
| 332 | - | top, topOK := d.runOneBarScript(ctx, runner, cfg.topRight, env, base, "top-right", sess) | |
| 333 | - | bottom, bottomOK := d.runOneBarScript(ctx, runner, cfg.bottomRight, env, base, "bottom-right", sess) | |
| 344 | + | top, topOK := d.runOneBarScript(ctx, runner, cfg.topRight, env, base, barAnchorTopRight, sess) | |
| 345 | + | bottom, bottomOK := d.runOneBarScript(ctx, runner, cfg.bottomRight, env, base, barAnchorBottomRight, sess) | |
| 334 | 346 | d.barScripts.mu.Lock() | |
| 335 | 347 | d.barScripts.initLocked() | |
| 336 | 348 | if !d.barScripts.running[sess.id] || d.barScripts.version != version { | |
| @@ -13,6 +13,17 @@ type barScriptExecutor interface { | |||||
| 13 | run(ctx context.Context, command string, env []string, scriptCtx barScriptContext) (string, error) | 13 | run(ctx context.Context, command string, env []string, scriptCtx barScriptContext) (string, error) | ||
| 14 | } | 14 | } | ||
| 15 | 15 | ||||
| 16 | + | // Anchor names, exported to bar scripts as VEV_ANCHOR and documented in | |||
| 17 | + | // docs/configuration.md. barAnchors must list every anchor so cleanup in | |||
| 18 | + | // clearBarScriptsForSession stays in sync with the anchors run in | |||
| 19 | + | // runBarScripts. | |||
| 20 | + | const ( | |||
| 21 | + | barAnchorTopRight = "top-right" | |||
| 22 | + | barAnchorBottomRight = "bottom-right" | |||
| 23 | + | ) | |||
| 24 | + | ||||
| 25 | + | var barAnchors = []string{barAnchorTopRight, barAnchorBottomRight} | |||
| 26 | + | ||||
| 16 | type barScriptConfig struct { | 27 | type barScriptConfig struct { | ||
| 17 | topRight string | 28 | topRight string | ||
| 18 | bottomRight string | 29 | bottomRight string | ||
| @@ -207,8 +218,9 @@ func (d *Daemon) clearBarScriptsForSession(id domain.SessionID) { | |||||
| 207 | delete(d.barScripts.lastContext, id) | 218 | delete(d.barScripts.lastContext, id) | ||
| 208 | delete(d.barScripts.running, id) | 219 | delete(d.barScripts.running, id) | ||
| 209 | delete(d.barScripts.pending, id) | 220 | delete(d.barScripts.pending, id) | ||
| 210 | - | delete(d.barScripts.lastFailure, barScriptFailureKey{id: id, anchor: "top-right"}) | 221 | + | for _, anchor := range barAnchors { |
| 211 | - | delete(d.barScripts.lastFailure, barScriptFailureKey{id: id, anchor: "bottom-right"}) | 222 | + | delete(d.barScripts.lastFailure, barScriptFailureKey{id: id, anchor: anchor}) |
| 223 | + | } | |||
| 212 | } | 224 | } | ||
| 213 | 225 | ||||
| 214 | // shouldLogBarFailure reports whether this failure differs from the last one | 226 | // shouldLogBarFailure reports whether this failure differs from the last one | ||
| @@ -329,8 +341,8 @@ func (d *Daemon) runBarScripts(sess *session, runner barScriptExecutor, cfg barS | |||||
| 329 | if ctx == nil { | 341 | if ctx == nil { | ||
| 330 | ctx = context.Background() | 342 | ctx = context.Background() | ||
| 331 | } | 343 | } | ||
| 332 | - | top, topOK := d.runOneBarScript(ctx, runner, cfg.topRight, env, base, "top-right", sess) | 344 | + | top, topOK := d.runOneBarScript(ctx, runner, cfg.topRight, env, base, barAnchorTopRight, sess) |
| 333 | - | bottom, bottomOK := d.runOneBarScript(ctx, runner, cfg.bottomRight, env, base, "bottom-right", sess) | 345 | + | bottom, bottomOK := d.runOneBarScript(ctx, runner, cfg.bottomRight, env, base, barAnchorBottomRight, sess) |
| 334 | d.barScripts.mu.Lock() | 346 | d.barScripts.mu.Lock() | ||
| 335 | d.barScripts.initLocked() | 347 | d.barScripts.initLocked() | ||
| 336 | if !d.barScripts.running[sess.id] || d.barScripts.version != version { | 348 | if !d.barScripts.running[sess.id] || d.barScripts.version != version { | ||