mirror of
https://github.com/zoriya/noctalia-shell.git
synced 2026-06-08 04:42:11 +00:00
Launcher: let users use app name & app command/exec
This commit is contained in:
@@ -59,10 +59,43 @@ Item {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const allApps = DesktopEntries.applications.values || []
|
const allApps = DesktopEntries.applications.values || []
|
||||||
entries = allApps.filter(app => app && !app.noDisplay)
|
entries = allApps.filter(app => app && !app.noDisplay).map(app => {
|
||||||
|
// Add executable name property for search
|
||||||
|
app.executableName = getExecutableName(app)
|
||||||
|
return app
|
||||||
|
})
|
||||||
Logger.log("ApplicationsPlugin", `Loaded ${entries.length} applications`)
|
Logger.log("ApplicationsPlugin", `Loaded ${entries.length} applications`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getExecutableName(app) {
|
||||||
|
if (!app)
|
||||||
|
return ""
|
||||||
|
|
||||||
|
// Try to get executable name from command array
|
||||||
|
if (app.command && Array.isArray(app.command) && app.command.length > 0) {
|
||||||
|
const cmd = app.command[0]
|
||||||
|
// Extract just the executable name from the full path
|
||||||
|
const parts = cmd.split('/')
|
||||||
|
const executable = parts[parts.length - 1]
|
||||||
|
// Remove any arguments or parameters
|
||||||
|
return executable.split(' ')[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try to get from exec property if available
|
||||||
|
if (app.exec) {
|
||||||
|
const parts = app.exec.split('/')
|
||||||
|
const executable = parts[parts.length - 1]
|
||||||
|
return executable.split(' ')[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback to app id (desktop file name without .desktop)
|
||||||
|
if (app.id) {
|
||||||
|
return app.id.replace('.desktop', '')
|
||||||
|
}
|
||||||
|
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
function getResults(query) {
|
function getResults(query) {
|
||||||
if (!entries || entries.length === 0)
|
if (!entries || entries.length === 0)
|
||||||
return []
|
return []
|
||||||
@@ -99,7 +132,7 @@ Item {
|
|||||||
// Use fuzzy search if available, fallback to simple search
|
// Use fuzzy search if available, fallback to simple search
|
||||||
if (typeof Fuzzysort !== 'undefined') {
|
if (typeof Fuzzysort !== 'undefined') {
|
||||||
const fuzzyResults = Fuzzysort.go(query, entries, {
|
const fuzzyResults = Fuzzysort.go(query, entries, {
|
||||||
"keys": ["name", "comment", "genericName"],
|
"keys": ["name", "comment", "genericName", "executableName"],
|
||||||
"threshold": -1000,
|
"threshold": -1000,
|
||||||
"limit": 20
|
"limit": 20
|
||||||
})
|
})
|
||||||
@@ -123,17 +156,31 @@ Item {
|
|||||||
const name = (app.name || "").toLowerCase()
|
const name = (app.name || "").toLowerCase()
|
||||||
const comment = (app.comment || "").toLowerCase()
|
const comment = (app.comment || "").toLowerCase()
|
||||||
const generic = (app.genericName || "").toLowerCase()
|
const generic = (app.genericName || "").toLowerCase()
|
||||||
return name.includes(searchTerm) || comment.includes(searchTerm) || generic.includes(searchTerm)
|
const executable = getExecutableName(app).toLowerCase()
|
||||||
|
return name.includes(searchTerm) || comment.includes(searchTerm) || generic.includes(searchTerm) || executable.includes(searchTerm)
|
||||||
}).sort((a, b) => {
|
}).sort((a, b) => {
|
||||||
// Prioritize name matches
|
// Prioritize name matches, then executable matches
|
||||||
const aName = a.name.toLowerCase()
|
const aName = a.name.toLowerCase()
|
||||||
const bName = b.name.toLowerCase()
|
const bName = b.name.toLowerCase()
|
||||||
|
const aExecutable = getExecutableName(a).toLowerCase()
|
||||||
|
const bExecutable = getExecutableName(b).toLowerCase()
|
||||||
const aStarts = aName.startsWith(searchTerm)
|
const aStarts = aName.startsWith(searchTerm)
|
||||||
const bStarts = bName.startsWith(searchTerm)
|
const bStarts = bName.startsWith(searchTerm)
|
||||||
|
const aExecStarts = aExecutable.startsWith(searchTerm)
|
||||||
|
const bExecStarts = bExecutable.startsWith(searchTerm)
|
||||||
|
|
||||||
|
// Prioritize name matches first
|
||||||
if (aStarts && !bStarts)
|
if (aStarts && !bStarts)
|
||||||
return -1
|
return -1
|
||||||
if (!aStarts && bStarts)
|
if (!aStarts && bStarts)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
// Then prioritize executable matches
|
||||||
|
if (aExecStarts && !bExecStarts)
|
||||||
|
return -1
|
||||||
|
if (!aExecStarts && bExecStarts)
|
||||||
|
return 1
|
||||||
|
|
||||||
return aName.localeCompare(bName)
|
return aName.localeCompare(bName)
|
||||||
}).slice(0, 20).map(app => createResultEntry(app))
|
}).slice(0, 20).map(app => createResultEntry(app))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user