mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-04-14 17:52:10 -04:00
Add headless mode support with command-line flags (#2182)
* Add support for headless mode. Allow dankinstall run with command-line flags. * Fix https://github.com/AvengeMedia/DankMaterialShell/pull/2182#discussion_r3056146219 * Fix https://github.com/AvengeMedia/DankMaterialShell/pull/2182#discussion_r3056146253 * Fix https://github.com/AvengeMedia/DankMaterialShell/pull/2182#discussion_r3056146271 * Fix https://github.com/AvengeMedia/DankMaterialShell/pull/2182#discussion_r3056146296 * Fix https://github.com/AvengeMedia/DankMaterialShell/pull/2182#discussion_r3056146348 * FIx https://github.com/AvengeMedia/DankMaterialShell/pull/2182#discussion_r3056146328 * Update headless mode instructions * Add log dir config. Use DANKINSTALL_LOG env var, fallback to /var/tmp * Fix https://github.com/AvengeMedia/DankMaterialShell/pull/2182#discussion_r3056737552 * Fix https://github.com/AvengeMedia/DankMaterialShell/pull/2182#discussion_r3056737572 * Fix https://github.com/AvengeMedia/DankMaterialShell/pull/2182#discussion_r3056737592 * Add explanations for headless validating rules and log file location * Fix https://github.com/AvengeMedia/DankMaterialShell/pull/2182#discussion_r3058087146 and https://github.com/AvengeMedia/DankMaterialShell/pull/2182#discussion_r3058087234 * Fix https://github.com/AvengeMedia/DankMaterialShell/pull/2182#discussion_r3058087271 * Fix https://github.com/AvengeMedia/DankMaterialShell/pull/2182#discussion_r3058310408 * Enhance configuration deployment logic to support missing files and add corresponding unit tests * Fix https://github.com/AvengeMedia/DankMaterialShell/pull/2182#discussion_r3058310495 * Reworked the log channel handling logic to simplify the code and added the `drainLogChan` function to prevent blocking (https://github.com/AvengeMedia/DankMaterialShell/pull/2182#discussion_r3058609491) * Added dependency-checking functionality to ensure installation requirements are met, and optimized the pre-installation logic for AUR packages * feat: output log messages to stdout during installation * Revert dependency-checking functionality due to official fix * Revert compositor provider workaround due to upstream fix
This commit is contained in:
@@ -62,12 +62,31 @@ func (cd *ConfigDeployer) DeployConfigurationsSelectiveWithReinstalls(ctx contex
|
||||
func (cd *ConfigDeployer) deployConfigurationsInternal(ctx context.Context, wm deps.WindowManager, terminal deps.Terminal, installedDeps []deps.Dependency, replaceConfigs map[string]bool, reinstallItems map[string]bool, useSystemd bool) ([]DeploymentResult, error) {
|
||||
var results []DeploymentResult
|
||||
|
||||
// Primary config file paths used to detect fresh installs.
|
||||
configPrimaryPaths := map[string]string{
|
||||
"Niri": filepath.Join(os.Getenv("HOME"), ".config", "niri", "config.kdl"),
|
||||
"Hyprland": filepath.Join(os.Getenv("HOME"), ".config", "hypr", "hyprland.conf"),
|
||||
"Ghostty": filepath.Join(os.Getenv("HOME"), ".config", "ghostty", "config"),
|
||||
"Kitty": filepath.Join(os.Getenv("HOME"), ".config", "kitty", "kitty.conf"),
|
||||
"Alacritty": filepath.Join(os.Getenv("HOME"), ".config", "alacritty", "alacritty.toml"),
|
||||
}
|
||||
|
||||
shouldReplaceConfig := func(configType string) bool {
|
||||
if replaceConfigs == nil {
|
||||
return true
|
||||
}
|
||||
replace, exists := replaceConfigs[configType]
|
||||
return !exists || replace
|
||||
if !exists || replace {
|
||||
return true
|
||||
}
|
||||
// Config is explicitly set to "don't replace" — but still deploy
|
||||
// if the config file doesn't exist yet (fresh install scenario).
|
||||
if primaryPath, ok := configPrimaryPaths[configType]; ok {
|
||||
if _, err := os.Stat(primaryPath); os.IsNotExist(err) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
switch wm {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
@@ -624,3 +625,168 @@ func TestAlacrittyConfigDeployment(t *testing.T) {
|
||||
assert.Contains(t, string(newContent), "decorations = \"None\"")
|
||||
})
|
||||
}
|
||||
|
||||
func TestShouldReplaceConfigDeployIfMissing(t *testing.T) {
|
||||
allFalse := map[string]bool{
|
||||
"Niri": false,
|
||||
"Hyprland": false,
|
||||
"Ghostty": false,
|
||||
"Kitty": false,
|
||||
"Alacritty": false,
|
||||
}
|
||||
|
||||
t.Run("replaceConfigs nil deploys config", func(t *testing.T) {
|
||||
tempDir, err := os.MkdirTemp("", "dankinstall-replace-nil-test")
|
||||
require.NoError(t, err)
|
||||
defer os.RemoveAll(tempDir)
|
||||
|
||||
originalHome := os.Getenv("HOME")
|
||||
os.Setenv("HOME", tempDir)
|
||||
defer os.Setenv("HOME", originalHome)
|
||||
|
||||
logChan := make(chan string, 100)
|
||||
cd := NewConfigDeployer(logChan)
|
||||
|
||||
results, err := cd.DeployConfigurationsSelectiveWithReinstalls(
|
||||
context.Background(),
|
||||
deps.WindowManagerNiri,
|
||||
deps.TerminalGhostty,
|
||||
nil, // installedDeps
|
||||
nil, // replaceConfigs
|
||||
nil, // reinstallItems
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
// With replaceConfigs=nil, all configs should be deployed
|
||||
hasDeployed := false
|
||||
for _, r := range results {
|
||||
if r.Deployed {
|
||||
hasDeployed = true
|
||||
break
|
||||
}
|
||||
}
|
||||
assert.True(t, hasDeployed, "expected at least one config to be deployed when replaceConfigs is nil")
|
||||
})
|
||||
|
||||
t.Run("replaceConfigs all false and config missing deploys config", func(t *testing.T) {
|
||||
tempDir, err := os.MkdirTemp("", "dankinstall-replace-missing-test")
|
||||
require.NoError(t, err)
|
||||
defer os.RemoveAll(tempDir)
|
||||
|
||||
originalHome := os.Getenv("HOME")
|
||||
os.Setenv("HOME", tempDir)
|
||||
defer os.Setenv("HOME", originalHome)
|
||||
|
||||
logChan := make(chan string, 100)
|
||||
cd := NewConfigDeployer(logChan)
|
||||
|
||||
results, err := cd.DeployConfigurationsSelectiveWithReinstalls(
|
||||
context.Background(),
|
||||
deps.WindowManagerNiri,
|
||||
deps.TerminalGhostty,
|
||||
nil, // installedDeps
|
||||
allFalse, // replaceConfigs — all false
|
||||
nil, // reinstallItems
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Config files don't exist on disk, so they should still be deployed
|
||||
hasDeployed := false
|
||||
for _, r := range results {
|
||||
if r.Deployed {
|
||||
hasDeployed = true
|
||||
break
|
||||
}
|
||||
}
|
||||
assert.True(t, hasDeployed, "expected configs to be deployed when files are missing, even with replaceConfigs all false")
|
||||
})
|
||||
|
||||
t.Run("replaceConfigs false and config exists skips config", func(t *testing.T) {
|
||||
tempDir, err := os.MkdirTemp("", "dankinstall-replace-exists-test")
|
||||
require.NoError(t, err)
|
||||
defer os.RemoveAll(tempDir)
|
||||
|
||||
originalHome := os.Getenv("HOME")
|
||||
os.Setenv("HOME", tempDir)
|
||||
defer os.Setenv("HOME", originalHome)
|
||||
|
||||
// Create the Ghostty primary config file so shouldReplaceConfig returns false
|
||||
ghosttyPath := filepath.Join(tempDir, ".config", "ghostty", "config")
|
||||
err = os.MkdirAll(filepath.Dir(ghosttyPath), 0o755)
|
||||
require.NoError(t, err)
|
||||
err = os.WriteFile(ghosttyPath, []byte("# existing ghostty config\n"), 0o644)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Also create the Niri primary config file
|
||||
niriPath := filepath.Join(tempDir, ".config", "niri", "config.kdl")
|
||||
err = os.MkdirAll(filepath.Dir(niriPath), 0o755)
|
||||
require.NoError(t, err)
|
||||
err = os.WriteFile(niriPath, []byte("// existing niri config\n"), 0o644)
|
||||
require.NoError(t, err)
|
||||
|
||||
logChan := make(chan string, 100)
|
||||
cd := NewConfigDeployer(logChan)
|
||||
|
||||
results, err := cd.DeployConfigurationsSelectiveWithReinstalls(
|
||||
context.Background(),
|
||||
deps.WindowManagerNiri,
|
||||
deps.TerminalGhostty,
|
||||
nil, // installedDeps
|
||||
allFalse, // replaceConfigs — all false
|
||||
nil, // reinstallItems
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Both Niri and Ghostty config files exist, so with all false they should be skipped
|
||||
for _, r := range results {
|
||||
assert.Fail(t, "expected no configs to be deployed", "got deployed config: %s", r.ConfigType)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("replaceConfigs true and config exists deploys config", func(t *testing.T) {
|
||||
tempDir, err := os.MkdirTemp("", "dankinstall-replace-true-test")
|
||||
require.NoError(t, err)
|
||||
defer os.RemoveAll(tempDir)
|
||||
|
||||
originalHome := os.Getenv("HOME")
|
||||
os.Setenv("HOME", tempDir)
|
||||
defer os.Setenv("HOME", originalHome)
|
||||
|
||||
// Create the Ghostty primary config file
|
||||
ghosttyPath := filepath.Join(tempDir, ".config", "ghostty", "config")
|
||||
err = os.MkdirAll(filepath.Dir(ghosttyPath), 0o755)
|
||||
require.NoError(t, err)
|
||||
err = os.WriteFile(ghosttyPath, []byte("# existing ghostty config\n"), 0o644)
|
||||
require.NoError(t, err)
|
||||
|
||||
logChan := make(chan string, 100)
|
||||
cd := NewConfigDeployer(logChan)
|
||||
|
||||
replaceConfigs := map[string]bool{
|
||||
"Niri": false,
|
||||
"Hyprland": false,
|
||||
"Ghostty": true, // explicitly true
|
||||
"Kitty": false,
|
||||
"Alacritty": false,
|
||||
}
|
||||
|
||||
results, err := cd.DeployConfigurationsSelectiveWithReinstalls(
|
||||
context.Background(),
|
||||
deps.WindowManagerNiri,
|
||||
deps.TerminalGhostty,
|
||||
nil, // installedDeps
|
||||
replaceConfigs, // Ghostty=true, rest=false
|
||||
nil, // reinstallItems
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Ghostty should be deployed because replaceConfigs["Ghostty"]=true
|
||||
foundGhostty := false
|
||||
for _, r := range results {
|
||||
if r.ConfigType == "Ghostty" && r.Deployed {
|
||||
foundGhostty = true
|
||||
}
|
||||
}
|
||||
assert.True(t, foundGhostty, "expected Ghostty config to be deployed when replaceConfigs is true")
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user