mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-06-15 07:35:20 -04:00
fix(Hyprland): Respect legacy conf configs before migrating to lua
This commit is contained in:
@@ -11,6 +11,46 @@ import (
|
|||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestCleanupStrayHyprlandConfFile(t *testing.T) {
|
||||||
|
if os.Getenv("HYPRLAND_INSTANCE_SIGNATURE") == "" {
|
||||||
|
t.Setenv("HYPRLAND_INSTANCE_SIGNATURE", "test-signature")
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Run("leaves conf alone when no hyprland.lua present", func(t *testing.T) {
|
||||||
|
td := t.TempDir()
|
||||||
|
t.Setenv("HOME", td)
|
||||||
|
configDir := filepath.Join(td, ".config", "hypr")
|
||||||
|
require.NoError(t, os.MkdirAll(configDir, 0o755))
|
||||||
|
confPath := filepath.Join(configDir, "hyprland.conf")
|
||||||
|
require.NoError(t, os.WriteFile(confPath, []byte("# legacy user config\n"), 0o644))
|
||||||
|
|
||||||
|
CleanupStrayHyprlandConfFile(nil)
|
||||||
|
|
||||||
|
assert.FileExists(t, confPath, "must not touch hyprland.conf when user has not migrated")
|
||||||
|
assert.NoDirExists(t, filepath.Join(configDir, hyprlandBackupDirName))
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("moves stray conf into backup when hyprland.lua exists", func(t *testing.T) {
|
||||||
|
td := t.TempDir()
|
||||||
|
t.Setenv("HOME", td)
|
||||||
|
configDir := filepath.Join(td, ".config", "hypr")
|
||||||
|
require.NoError(t, os.MkdirAll(configDir, 0o755))
|
||||||
|
luaPath := filepath.Join(configDir, "hyprland.lua")
|
||||||
|
require.NoError(t, os.WriteFile(luaPath, []byte("-- dms managed\n"), 0o644))
|
||||||
|
confPath := filepath.Join(configDir, "hyprland.conf")
|
||||||
|
require.NoError(t, os.WriteFile(confPath, []byte("# autogen\n"), 0o644))
|
||||||
|
|
||||||
|
CleanupStrayHyprlandConfFile(nil)
|
||||||
|
|
||||||
|
assert.NoFileExists(t, confPath)
|
||||||
|
assert.FileExists(t, luaPath)
|
||||||
|
entries, err := os.ReadDir(filepath.Join(configDir, hyprlandBackupDirName))
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Len(t, entries, 1)
|
||||||
|
assert.FileExists(t, filepath.Join(configDir, hyprlandBackupDirName, entries[0].Name(), "hyprland.conf"))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestMergeNiriOutputSections(t *testing.T) {
|
func TestMergeNiriOutputSections(t *testing.T) {
|
||||||
cd := &ConfigDeployer{}
|
cd := &ConfigDeployer{}
|
||||||
|
|
||||||
|
|||||||
@@ -139,9 +139,10 @@ func readExistingHyprlandConfig(configDir string) (data string, sourcePath strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CleanupStrayHyprlandConfFile moves a stray ~/.config/hypr/hyprland.conf
|
// CleanupStrayHyprlandConfFile moves a stray ~/.config/hypr/hyprland.conf
|
||||||
// into .dms-backups/<timestamp>/ when running under Hyprland. Hyprland 0.55
|
// into .dms-backups/<timestamp>/ only when hyprland.lua also exists, which
|
||||||
// auto-generates hyprland.conf when launched without -c, so this is invoked
|
// proves Lua is the live config and the .conf is an autogen Hyprland 0.55
|
||||||
// from dms run startup to keep the active config tree single-file.
|
// produced when launched without -c. If only hyprland.conf exists, the user
|
||||||
|
// has not migrated and we must leave their config alone.
|
||||||
func CleanupStrayHyprlandConfFile(logFn func(format string, v ...any)) {
|
func CleanupStrayHyprlandConfFile(logFn func(format string, v ...any)) {
|
||||||
if os.Getenv("HYPRLAND_INSTANCE_SIGNATURE") == "" {
|
if os.Getenv("HYPRLAND_INSTANCE_SIGNATURE") == "" {
|
||||||
return
|
return
|
||||||
@@ -151,6 +152,10 @@ func CleanupStrayHyprlandConfFile(logFn func(format string, v ...any)) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
configDir := filepath.Join(home, ".config", "hypr")
|
configDir := filepath.Join(home, ".config", "hypr")
|
||||||
|
luaPath := filepath.Join(configDir, "hyprland.lua")
|
||||||
|
if _, err := os.Stat(luaPath); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
confPath := filepath.Join(configDir, "hyprland.conf")
|
confPath := filepath.Join(configDir, "hyprland.conf")
|
||||||
if _, err := os.Stat(confPath); err != nil {
|
if _, err := os.Stat(confPath); err != nil {
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user