forked from Shinonome/dots-hyprland
icons: add guess by icon search
This commit is contained in:
@@ -47,9 +47,18 @@ Singleton {
|
|||||||
.sort((a, b) => a.name.localeCompare(b.name))
|
.sort((a, b) => a.name.localeCompare(b.name))
|
||||||
|
|
||||||
readonly property var preppedNames: list.map(a => ({
|
readonly property var preppedNames: list.map(a => ({
|
||||||
name: Fuzzy.prepare(`${a.name} `),
|
name: Fuzzy.prepare(`${a.name} `),
|
||||||
entry: a
|
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<DesktopEntry> doesn't work
|
function fuzzyQuery(search: string): var { // Idk why list<DesktopEntry> doesn't work
|
||||||
if (root.sloppySearch) {
|
if (root.sloppySearch) {
|
||||||
@@ -76,6 +85,14 @@ Singleton {
|
|||||||
&& !iconName.includes("image-missing");
|
&& !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) {
|
function guessIcon(str) {
|
||||||
if (!str || str.length == 0) return "image-missing";
|
if (!str || str.length == 0) return "image-missing";
|
||||||
|
|
||||||
@@ -93,24 +110,37 @@ Singleton {
|
|||||||
if (replacedName != str) return replacedName;
|
if (replacedName != str) return replacedName;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If it gets detected normally, no need to guess
|
// Icon exists -> return as is
|
||||||
if (iconExists(str)) return str;
|
if (iconExists(str)) return str;
|
||||||
|
|
||||||
let guessStr = str;
|
|
||||||
// Guess: Take only app name of reverse domain name notation
|
// Simple guesses
|
||||||
guessStr = str.split('.').slice(-1)[0].toLowerCase();
|
const reverseDomainNameAppName = getReverseDomainNameAppName(str);
|
||||||
if (iconExists(guessStr)) return guessStr;
|
if (iconExists(reverseDomainNameAppName)) return reverseDomainNameAppName;
|
||||||
// Guess: normalize to kebab case
|
|
||||||
guessStr = str.toLowerCase().replace(/\s+/g, "-");
|
const kebabNormalizedGuess = getKebabNormalizedAppName(str);
|
||||||
if (iconExists(guessStr)) return guessStr;
|
if (iconExists(kebabNormalizedGuess)) return kebabNormalizedGuess;
|
||||||
// Guess: First fuzzy desktop entry match
|
|
||||||
const searchResults = root.fuzzyQuery(str);
|
|
||||||
if (searchResults.length > 0) {
|
// Search in desktop entries
|
||||||
const firstEntry = searchResults[0];
|
const iconSearchResults = Fuzzy.go(str, preppedIcons, {
|
||||||
guessStr = firstEntry.icon
|
all: true,
|
||||||
if (iconExists(guessStr)) return guessStr;
|
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
|
// Give up
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user