From 70ca3fef77ee8bdc6e3ac28589a6fa08c024cc69 Mon Sep 17 00:00:00 2001 From: AlexanderCurl Date: Sat, 18 Apr 2026 17:46:06 +0100 Subject: Replaced file structures for themes in the correct format --- .../core/internal/plugins/search.go | 91 ++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 raveos-hyprland-theme/theme-data/DankMaterialShell/core/internal/plugins/search.go (limited to 'raveos-hyprland-theme/theme-data/DankMaterialShell/core/internal/plugins/search.go') diff --git a/raveos-hyprland-theme/theme-data/DankMaterialShell/core/internal/plugins/search.go b/raveos-hyprland-theme/theme-data/DankMaterialShell/core/internal/plugins/search.go new file mode 100644 index 0000000..833158f --- /dev/null +++ b/raveos-hyprland-theme/theme-data/DankMaterialShell/core/internal/plugins/search.go @@ -0,0 +1,91 @@ +package plugins + +import ( + "sort" + "strings" + + "github.com/AvengeMedia/DankMaterialShell/core/internal/utils" +) + +func FuzzySearch(query string, plugins []Plugin) []Plugin { + if query == "" { + return plugins + } + + queryLower := strings.ToLower(query) + return utils.Filter(plugins, func(p Plugin) bool { + return fuzzyMatch(queryLower, strings.ToLower(p.Name)) || + fuzzyMatch(queryLower, strings.ToLower(p.Category)) || + fuzzyMatch(queryLower, strings.ToLower(p.Description)) || + fuzzyMatch(queryLower, strings.ToLower(p.Author)) + }) +} + +func fuzzyMatch(query, text string) bool { + queryIdx := 0 + for _, char := range text { + if queryIdx < len(query) && char == rune(query[queryIdx]) { + queryIdx++ + } + } + return queryIdx == len(query) +} + +func FilterByCategory(category string, plugins []Plugin) []Plugin { + if category == "" { + return plugins + } + categoryLower := strings.ToLower(category) + return utils.Filter(plugins, func(p Plugin) bool { + return strings.ToLower(p.Category) == categoryLower + }) +} + +func FilterByCompositor(compositor string, plugins []Plugin) []Plugin { + if compositor == "" { + return plugins + } + compositorLower := strings.ToLower(compositor) + return utils.Filter(plugins, func(p Plugin) bool { + return utils.Any(p.Compositors, func(c string) bool { + return strings.ToLower(c) == compositorLower + }) + }) +} + +func FilterByCapability(capability string, plugins []Plugin) []Plugin { + if capability == "" { + return plugins + } + capabilityLower := strings.ToLower(capability) + return utils.Filter(plugins, func(p Plugin) bool { + return utils.Any(p.Capabilities, func(c string) bool { + return strings.ToLower(c) == capabilityLower + }) + }) +} + +func SortByFirstParty(plugins []Plugin) []Plugin { + sort.SliceStable(plugins, func(i, j int) bool { + if plugins[i].Featured != plugins[j].Featured { + return plugins[i].Featured + } + isFirstPartyI := strings.HasPrefix(plugins[i].Repo, "https://github.com/AvengeMedia") + isFirstPartyJ := strings.HasPrefix(plugins[j].Repo, "https://github.com/AvengeMedia") + if isFirstPartyI != isFirstPartyJ { + return isFirstPartyI + } + return false + }) + return plugins +} + +func FindByIDOrName(idOrName string, plugins []Plugin) *Plugin { + if p, found := utils.Find(plugins, func(p Plugin) bool { return p.ID == idOrName }); found { + return &p + } + if p, found := utils.Find(plugins, func(p Plugin) bool { return p.Name == idOrName }); found { + return &p + } + return nil +} -- cgit v1.3