From 8603918771076004c09db0a7daa91beb8e76fc90 Mon Sep 17 00:00:00 2001 From: end-4 <97237370+end-4@users.noreply.github.com> Date: Sat, 19 Jul 2025 10:35:52 +0700 Subject: [PATCH] icons: add guess by icon search --- .config/quickshell/ii/services/AppSearch.qml | 64 ++++++++++++++------ 1 file changed, 47 insertions(+), 17 deletions(-) diff --git a/.config/quickshell/ii/services/AppSearch.qml b/.config/quickshell/ii/services/AppSearch.qml index a658d506e..6a0d4c059 100644 --- a/.config/quickshell/ii/services/AppSearch.qml +++ b/.config/quickshell/ii/services/AppSearch.qml @@ -47,9 +47,18 @@ Singleton { .sort((a, b) => a.name.localeCompare(b.name)) readonly property var preppedNames: list.map(a => ({ - name: Fuzzy.prepare(`${a.name} `), - entry: a - })) + name: Fuzzy.prepare(`${a.name} `), + entry: a + })) + + readonly property var preppedIcons: list.map(a => ({ + name: Fuzzy.prepare(`${a.icon} `), + entry: a + })) + + onPreppedIconsChanged: { + console.log(JSON.stringify(root.list.map(a => a.icon))) + } function fuzzyQuery(search: string): var { // Idk why list doesn't work if (root.sloppySearch) { @@ -76,6 +85,14 @@ Singleton { && !iconName.includes("image-missing"); } + function getReverseDomainNameAppName(str) { + return str.split('.').slice(-1)[0].toLowerCase() + } + + function getKebabNormalizedAppName(str) { + return str.toLowerCase().replace(/\s+/g, "-"); + } + function guessIcon(str) { if (!str || str.length == 0) return "image-missing"; @@ -93,24 +110,37 @@ Singleton { if (replacedName != str) return replacedName; } - // If it gets detected normally, no need to guess + // Icon exists -> return as is if (iconExists(str)) return str; - let guessStr = str; - // Guess: Take only app name of reverse domain name notation - guessStr = str.split('.').slice(-1)[0].toLowerCase(); - if (iconExists(guessStr)) return guessStr; - // Guess: normalize to kebab case - guessStr = str.toLowerCase().replace(/\s+/g, "-"); - if (iconExists(guessStr)) return guessStr; - // Guess: First fuzzy desktop entry match - const searchResults = root.fuzzyQuery(str); - if (searchResults.length > 0) { - const firstEntry = searchResults[0]; - guessStr = firstEntry.icon - if (iconExists(guessStr)) return guessStr; + + // Simple guesses + const reverseDomainNameAppName = getReverseDomainNameAppName(str); + if (iconExists(reverseDomainNameAppName)) return reverseDomainNameAppName; + + const kebabNormalizedGuess = getKebabNormalizedAppName(str); + if (iconExists(kebabNormalizedGuess)) return kebabNormalizedGuess; + + + // Search in desktop entries + const iconSearchResults = Fuzzy.go(str, preppedIcons, { + all: true, + key: "name" + }).map(r => { + return r.obj.entry + }); + if (iconSearchResults.length > 0) { + const guess = iconSearchResults[0].icon + if (iconExists(guess)) return guess; } + const nameSearchResults = root.fuzzyQuery(str); + if (nameSearchResults.length > 0) { + const guess = nameSearchResults[0].icon + if (iconExists(guess)) return guess; + } + + // Give up return str; }