diff --git a/core/internal/config/hyprland_session_target.go b/core/internal/config/hyprland_session_target.go index c844d3be8..e5aa545e4 100644 --- a/core/internal/config/hyprland_session_target.go +++ b/core/internal/config/hyprland_session_target.go @@ -3,21 +3,32 @@ package config import ( "os" "path/filepath" + "slices" ) +// Mirrors Hyprland's shipped target. Before=graphical-session.target would cycle with the add-wants implicit After=dms.service. const hyprlandSessionTargetUnit = `[Unit] Description=Hyprland Session Target BindsTo=graphical-session.target +Wants=graphical-session-pre.target +After=graphical-session-pre.target +PropagatesStopTo=graphical-session.target +` + +var staleHyprlandSessionTargetUnits = []string{ + `[Unit] +Description=Hyprland Session Target +Requires=graphical-session.target +After=graphical-session.target +`, + `[Unit] +Description=Hyprland Session Target +BindsTo=graphical-session.target Before=graphical-session.target Wants=graphical-session-pre.target After=graphical-session-pre.target -` - -const legacyHyprlandSessionTargetUnit = `[Unit] -Description=Hyprland Session Target -Requires=graphical-session.target -After=graphical-session.target -` +`, +} // Only a missing or dankinstall-written unit is replaced; hand-written units are left alone. func EnsureHyprlandSessionTarget() (string, error) { @@ -30,10 +41,7 @@ func EnsureHyprlandSessionTarget() (string, error) { existing, err := os.ReadFile(targetPath) if err == nil { content := string(existing) - if content == hyprlandSessionTargetUnit { - return targetPath, nil - } - if content != legacyHyprlandSessionTargetUnit { + if content == hyprlandSessionTargetUnit || !slices.Contains(staleHyprlandSessionTargetUnits, content) { return targetPath, nil } } diff --git a/core/internal/config/hyprland_session_target_test.go b/core/internal/config/hyprland_session_target_test.go index 53e00f291..e42ddadd9 100644 --- a/core/internal/config/hyprland_session_target_test.go +++ b/core/internal/config/hyprland_session_target_test.go @@ -31,23 +31,25 @@ func TestEnsureHyprlandSessionTargetWritesMissing(t *testing.T) { } } -func TestEnsureHyprlandSessionTargetUpgradesLegacy(t *testing.T) { - home := t.TempDir() - t.Setenv("HOME", home) - path := targetPathFor(t, home) - if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil { - t.Fatal(err) - } - if err := os.WriteFile(path, []byte(legacyHyprlandSessionTargetUnit), 0o644); err != nil { - t.Fatal(err) - } +func TestEnsureHyprlandSessionTargetUpgradesStale(t *testing.T) { + for _, stale := range staleHyprlandSessionTargetUnits { + home := t.TempDir() + t.Setenv("HOME", home) + path := targetPathFor(t, home) + if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(path, []byte(stale), 0o644); err != nil { + t.Fatal(err) + } - if _, err := EnsureHyprlandSessionTarget(); err != nil { - t.Fatal(err) - } - data, _ := os.ReadFile(path) - if string(data) != hyprlandSessionTargetUnit { - t.Fatalf("legacy unit not upgraded:\n%s", data) + if _, err := EnsureHyprlandSessionTarget(); err != nil { + t.Fatal(err) + } + data, _ := os.ReadFile(path) + if string(data) != hyprlandSessionTargetUnit { + t.Fatalf("stale unit not upgraded:\n%s", data) + } } }