diff options
| author | AlexanderCurl <alexc@alexc.hu> | 2026-04-18 17:46:06 +0100 |
|---|---|---|
| committer | AlexanderCurl <alexc@alexc.hu> | 2026-04-18 17:46:06 +0100 |
| commit | 70ca3fef77ee8bdc6e3ac28589a6fa08c024cc69 (patch) | |
| tree | ab1123d4067c1b086dd6faa7ee4ea643236b565a /raveos-hyprland-theme/theme-data/DankMaterialShell/core/internal/keybinds/discovery.go | |
| parent | 5d94c0a7d44a2255b81815a52a7056a94a39842d (diff) | |
| download | RaveOS-PKGBUILD-70ca3fef77ee8bdc6e3ac28589a6fa08c024cc69.tar.gz RaveOS-PKGBUILD-70ca3fef77ee8bdc6e3ac28589a6fa08c024cc69.zip | |
Replaced file structures for themes in the correct format
Diffstat (limited to 'raveos-hyprland-theme/theme-data/DankMaterialShell/core/internal/keybinds/discovery.go')
| -rw-r--r-- | raveos-hyprland-theme/theme-data/DankMaterialShell/core/internal/keybinds/discovery.go | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/raveos-hyprland-theme/theme-data/DankMaterialShell/core/internal/keybinds/discovery.go b/raveos-hyprland-theme/theme-data/DankMaterialShell/core/internal/keybinds/discovery.go new file mode 100644 index 0000000..4990975 --- /dev/null +++ b/raveos-hyprland-theme/theme-data/DankMaterialShell/core/internal/keybinds/discovery.go @@ -0,0 +1,107 @@ +package keybinds + +import ( + "fmt" + "os" + "path/filepath" + "strings" + + "github.com/AvengeMedia/DankMaterialShell/core/internal/utils" +) + +type DiscoveryConfig struct { + SearchPaths []string +} + +func DefaultDiscoveryConfig() *DiscoveryConfig { + var searchPaths []string + + configDir, err := os.UserConfigDir() + if err == nil && configDir != "" { + searchPaths = append(searchPaths, filepath.Join(configDir, "DankMaterialShell", "cheatsheets")) + } + + configDirs := os.Getenv("XDG_CONFIG_DIRS") + if configDirs != "" { + for dir := range strings.SplitSeq(configDirs, ":") { + if dir != "" { + searchPaths = append(searchPaths, filepath.Join(dir, "DankMaterialShell", "cheatsheets")) + } + } + } + + return &DiscoveryConfig{ + SearchPaths: searchPaths, + } +} + +func (d *DiscoveryConfig) FindJSONFiles() ([]string, error) { + var files []string + + for _, searchPath := range d.SearchPaths { + expandedPath, err := utils.ExpandPath(searchPath) + if err != nil { + continue + } + + if _, err := os.Stat(expandedPath); os.IsNotExist(err) { + continue + } + + entries, err := os.ReadDir(expandedPath) + if err != nil { + continue + } + + for _, entry := range entries { + if entry.IsDir() { + continue + } + + if !strings.HasSuffix(entry.Name(), ".json") { + continue + } + + fullPath := filepath.Join(expandedPath, entry.Name()) + files = append(files, fullPath) + } + } + + return files, nil +} + +type JSONProviderFactory func(filePath string) (Provider, error) + +var jsonProviderFactory JSONProviderFactory + +func SetJSONProviderFactory(factory JSONProviderFactory) { + jsonProviderFactory = factory +} + +func AutoDiscoverProviders(registry *Registry, config *DiscoveryConfig) error { + if config == nil { + config = DefaultDiscoveryConfig() + } + + if jsonProviderFactory == nil { + return nil + } + + files, err := config.FindJSONFiles() + if err != nil { + return fmt.Errorf("failed to discover JSON files: %w", err) + } + + for _, file := range files { + provider, err := jsonProviderFactory(file) + if err != nil { + continue + } + + if err := registry.Register(provider); err != nil { + continue + } + } + + return nil +} |