feat(theming): apply updates overlay theme_overrides.__active
This commit is contained in:
@@ -140,6 +140,52 @@ func Apply(cfg config.Config, themeID string) error {
|
||||
return fmt.Errorf("write %s: %w", tc.DestRel, err)
|
||||
}
|
||||
}
|
||||
_ = cfg // overlay update lands in Task 3
|
||||
_ = cfg // overlay carries config state; overlay file update below
|
||||
if err := updateOverlayActive(th.ID); err != nil {
|
||||
return fmt.Errorf("update overlay: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// updateOverlayActive rewrites ~/.config/archduino/overlay.yaml so that
|
||||
// theme_overrides.__active reflects the selected theme, preserving all
|
||||
// other keys via a generic map round-trip.
|
||||
func updateOverlayActive(themeID string) error {
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
path := filepath.Join(home, ".config", "archduino", "overlay.yaml")
|
||||
|
||||
var root map[string]any
|
||||
if data, err := os.ReadFile(path); err == nil {
|
||||
if err := yaml.Unmarshal(data, &root); err != nil {
|
||||
return fmt.Errorf("parse overlay: %w", err)
|
||||
}
|
||||
}
|
||||
if root == nil {
|
||||
root = map[string]any{}
|
||||
}
|
||||
|
||||
if _, ok := root["version"]; !ok {
|
||||
root["version"] = 1
|
||||
}
|
||||
|
||||
var overrides map[string]any
|
||||
if raw, ok := root["theme_overrides"]; ok {
|
||||
if m, ok := raw.(map[string]any); ok {
|
||||
overrides = m
|
||||
}
|
||||
}
|
||||
if overrides == nil {
|
||||
overrides = map[string]any{}
|
||||
}
|
||||
overrides["__active"] = themeID
|
||||
root["theme_overrides"] = overrides
|
||||
|
||||
out, err := yaml.Marshal(root)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return platform.WriteUserFile(path, out, 0o644)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user