Notification: show resolved app name instead of id (possibly fixes #230)

This commit is contained in:
Ly-sec
2025-09-08 15:38:29 +02:00
parent 59ef26af1c
commit d05255c15b
2 changed files with 41 additions and 3 deletions

View File

@@ -147,7 +147,7 @@ Singleton {
// Inject missing default setting (metaData) from BarWidgetRegistry
const keys = Object.keys(BarWidgetRegistry.widgetMetadata[widget.id])
for (let i=0; i<keys.length; i++) {
for (var i = 0; i < keys.length; i++) {
const k = keys[i]
if (k === "id" || k === "allowUserSettings") {
continue

View File

@@ -117,14 +117,50 @@ Singleton {
}
}
// Function to resolve app name from notification
function resolveAppName(notification) {
try {
const appName = notification.appName || ""
// If it's already a clean name (no dots or reverse domain notation), use it
if (!appName.includes(".") || appName.length < 10) {
return appName
}
// Try to find a desktop entry for this app ID
const desktopEntries = DesktopEntries.byId(appName)
if (desktopEntries && desktopEntries.length > 0) {
const entry = desktopEntries[0]
// Prefer name over genericName, fallback to original appName
return entry.name || entry.genericName || appName
}
// If no desktop entry found, try to clean up the app ID
// Convert "org.gnome.Nautilus" to "Nautilus"
const parts = appName.split(".")
if (parts.length > 1) {
// Take the last part and capitalize it
const lastPart = parts[parts.length - 1]
return lastPart.charAt(0).toUpperCase() + lastPart.slice(1)
}
return appName
} catch (e) {
// Fallback to original app name on any error
return notification.appName || ""
}
}
// Function to add notification to model
function addNotification(notification) {
const resolvedImage = resolveNotificationImage(notification)
const resolvedAppName = resolveAppName(notification)
notificationModel.insert(0, {
"rawNotification": notification,
"summary": notification.summary,
"body": notification.body,
"appName": notification.appName,
"appName": resolvedAppName,
"image": resolvedImage,
"appIcon": notification.appIcon,
"urgency": notification.urgency,
@@ -177,10 +213,12 @@ Singleton {
// Add a simplified copy into persistent history
function addToHistory(notification) {
const resolvedAppName = resolveAppName(notification)
historyModel.insert(0, {
"summary": notification.summary,
"body": notification.body,
"appName": notification.appName,
"appName": resolvedAppName,
"urgency": notification.urgency,
"timestamp": new Date()
})