mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-30 00:12:50 -05:00
matugen: fix app checking
- double nil for flatpak + bin required to skip
This commit is contained in:
@@ -51,6 +51,7 @@ type Options struct {
|
||||
SyncModeWithPortal bool
|
||||
TerminalsAlwaysDark bool
|
||||
SkipTemplates string
|
||||
AppChecker utils.AppChecker
|
||||
}
|
||||
|
||||
type ColorsOutput struct {
|
||||
@@ -101,6 +102,9 @@ func Run(opts Options) error {
|
||||
if opts.IconTheme == "" {
|
||||
opts.IconTheme = "System Default"
|
||||
}
|
||||
if opts.AppChecker == nil {
|
||||
opts.AppChecker = utils.DefaultAppChecker{}
|
||||
}
|
||||
|
||||
if err := os.MkdirAll(opts.StateDir, 0755); err != nil {
|
||||
return fmt.Errorf("failed to create state dir: %w", err)
|
||||
@@ -353,10 +357,7 @@ func appendConfig(
|
||||
if _, err := os.Stat(configPath); err != nil {
|
||||
return
|
||||
}
|
||||
cmdExists := checkCmd == nil || utils.AnyCommandExists(checkCmd...)
|
||||
flatpakExists := checkFlatpaks == nil || utils.AnyFlatpakExists(checkFlatpaks...)
|
||||
|
||||
if !cmdExists && !flatpakExists {
|
||||
if !appExists(opts.AppChecker, checkCmd, checkFlatpaks) {
|
||||
return
|
||||
}
|
||||
data, err := os.ReadFile(configPath)
|
||||
@@ -372,10 +373,7 @@ func appendTerminalConfig(opts *Options, cfgFile *os.File, tmpDir string, checkC
|
||||
if _, err := os.Stat(configPath); err != nil {
|
||||
return
|
||||
}
|
||||
cmdExists := checkCmd == nil || utils.AnyCommandExists(checkCmd...)
|
||||
flatpakExists := checkFlatpaks == nil || utils.AnyFlatpakExists(checkFlatpaks...)
|
||||
|
||||
if !cmdExists && !flatpakExists {
|
||||
if !appExists(opts.AppChecker, checkCmd, checkFlatpaks) {
|
||||
return
|
||||
}
|
||||
data, err := os.ReadFile(configPath)
|
||||
@@ -428,6 +426,20 @@ func appendTerminalConfig(opts *Options, cfgFile *os.File, tmpDir string, checkC
|
||||
cfgFile.WriteString("\n")
|
||||
}
|
||||
|
||||
func appExists(checker utils.AppChecker, checkCmd []string, checkFlatpaks []string) bool {
|
||||
// Both nil is treated as "skip check" / unconditionally run
|
||||
if checkCmd == nil && checkFlatpaks == nil {
|
||||
return true
|
||||
}
|
||||
if checkCmd != nil && checker.AnyCommandExists(checkCmd...) {
|
||||
return true
|
||||
}
|
||||
if checkFlatpaks != nil && checker.AnyFlatpakExists(checkFlatpaks...) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func appendVSCodeConfig(cfgFile *os.File, name, extBaseDir, shellDir string) {
|
||||
pattern := filepath.Join(extBaseDir, "danklinux.dms-theme-*")
|
||||
matches, err := filepath.Glob(pattern)
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
mocks_utils "github.com/AvengeMedia/DankMaterialShell/core/internal/mocks/utils"
|
||||
)
|
||||
|
||||
func TestAppendConfigBinaryExists(t *testing.T) {
|
||||
@@ -28,7 +30,10 @@ func TestAppendConfigBinaryExists(t *testing.T) {
|
||||
}
|
||||
defer cfgFile.Close()
|
||||
|
||||
opts := &Options{ShellDir: shellDir}
|
||||
mockChecker := mocks_utils.NewMockAppChecker(t)
|
||||
mockChecker.EXPECT().AnyCommandExists("sh").Return(true)
|
||||
|
||||
opts := &Options{ShellDir: shellDir, AppChecker: mockChecker}
|
||||
|
||||
appendConfig(opts, cfgFile, []string{"sh"}, nil, "test.toml")
|
||||
|
||||
@@ -68,7 +73,11 @@ func TestAppendConfigBinaryDoesNotExist(t *testing.T) {
|
||||
}
|
||||
defer cfgFile.Close()
|
||||
|
||||
opts := &Options{ShellDir: shellDir}
|
||||
mockChecker := mocks_utils.NewMockAppChecker(t)
|
||||
mockChecker.EXPECT().AnyCommandExists("nonexistent-binary-12345").Return(false)
|
||||
mockChecker.EXPECT().AnyFlatpakExists().Return(false)
|
||||
|
||||
opts := &Options{ShellDir: shellDir, AppChecker: mockChecker}
|
||||
|
||||
appendConfig(opts, cfgFile, []string{"nonexistent-binary-12345"}, []string{}, "test.toml")
|
||||
|
||||
@@ -105,7 +114,10 @@ func TestAppendConfigFlatpakExists(t *testing.T) {
|
||||
}
|
||||
defer cfgFile.Close()
|
||||
|
||||
opts := &Options{ShellDir: shellDir}
|
||||
mockChecker := mocks_utils.NewMockAppChecker(t)
|
||||
mockChecker.EXPECT().AnyFlatpakExists("app.zen_browser.zen").Return(true)
|
||||
|
||||
opts := &Options{ShellDir: shellDir, AppChecker: mockChecker}
|
||||
|
||||
appendConfig(opts, cfgFile, nil, []string{"app.zen_browser.zen"}, "test.toml")
|
||||
|
||||
@@ -142,7 +154,11 @@ func TestAppendConfigFlatpakDoesNotExist(t *testing.T) {
|
||||
}
|
||||
defer cfgFile.Close()
|
||||
|
||||
opts := &Options{ShellDir: shellDir}
|
||||
mockChecker := mocks_utils.NewMockAppChecker(t)
|
||||
mockChecker.EXPECT().AnyCommandExists().Return(false)
|
||||
mockChecker.EXPECT().AnyFlatpakExists("com.nonexistent.flatpak").Return(false)
|
||||
|
||||
opts := &Options{ShellDir: shellDir, AppChecker: mockChecker}
|
||||
|
||||
appendConfig(opts, cfgFile, []string{}, []string{"com.nonexistent.flatpak"}, "test.toml")
|
||||
|
||||
@@ -179,7 +195,10 @@ func TestAppendConfigBothExist(t *testing.T) {
|
||||
}
|
||||
defer cfgFile.Close()
|
||||
|
||||
opts := &Options{ShellDir: shellDir}
|
||||
mockChecker := mocks_utils.NewMockAppChecker(t)
|
||||
mockChecker.EXPECT().AnyCommandExists("sh").Return(true)
|
||||
|
||||
opts := &Options{ShellDir: shellDir, AppChecker: mockChecker}
|
||||
|
||||
appendConfig(opts, cfgFile, []string{"sh"}, []string{"app.zen_browser.zen"}, "test.toml")
|
||||
|
||||
@@ -216,7 +235,11 @@ func TestAppendConfigNeitherExists(t *testing.T) {
|
||||
}
|
||||
defer cfgFile.Close()
|
||||
|
||||
opts := &Options{ShellDir: shellDir}
|
||||
mockChecker := mocks_utils.NewMockAppChecker(t)
|
||||
mockChecker.EXPECT().AnyCommandExists("nonexistent-binary-12345").Return(false)
|
||||
mockChecker.EXPECT().AnyFlatpakExists("com.nonexistent.flatpak").Return(false)
|
||||
|
||||
opts := &Options{ShellDir: shellDir, AppChecker: mockChecker}
|
||||
|
||||
appendConfig(opts, cfgFile, []string{"nonexistent-binary-12345"}, []string{"com.nonexistent.flatpak"}, "test.toml")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user