Notification: add -i support
This commit is contained in:
parent
3d9ef8c2ed
commit
291d919b9f
2 changed files with 57 additions and 1 deletions
|
|
@ -9,3 +9,24 @@ for i in {1..8}; do
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "All notifications sent!"
|
echo "All notifications sent!"
|
||||||
|
|
||||||
|
# Additional tests for icon/image handling
|
||||||
|
if command -v notify-send >/dev/null 2>&1; then
|
||||||
|
echo "Sending icon/image tests..."
|
||||||
|
|
||||||
|
# 1) Themed icon name
|
||||||
|
notify-send -i dialog-information "Icon name test" "Should resolve from theme (dialog-information)"
|
||||||
|
|
||||||
|
# 2) Absolute path if a sample image exists
|
||||||
|
SAMPLE_IMG="/usr/share/pixmaps/debian-logo.png"
|
||||||
|
if [ -f "$SAMPLE_IMG" ]; then
|
||||||
|
notify-send -i "$SAMPLE_IMG" "Absolute path test" "Should show the provided image path"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 3) file:// URL form
|
||||||
|
if [ -f "$SAMPLE_IMG" ]; then
|
||||||
|
notify-send -i "file://$SAMPLE_IMG" "file:// URL test" "Should display after stripping scheme"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Icon/image tests sent!"
|
||||||
|
fi
|
||||||
|
|
|
||||||
|
|
@ -118,12 +118,13 @@ Singleton {
|
||||||
|
|
||||||
// Function to add notification to model
|
// Function to add notification to model
|
||||||
function addNotification(notification) {
|
function addNotification(notification) {
|
||||||
|
const resolvedImage = resolveNotificationImage(notification)
|
||||||
notificationModel.insert(0, {
|
notificationModel.insert(0, {
|
||||||
"rawNotification": notification,
|
"rawNotification": notification,
|
||||||
"summary": notification.summary,
|
"summary": notification.summary,
|
||||||
"body": notification.body,
|
"body": notification.body,
|
||||||
"appName": notification.appName,
|
"appName": notification.appName,
|
||||||
"image": notification.image,
|
"image": resolvedImage,
|
||||||
"appIcon": notification.appIcon,
|
"appIcon": notification.appIcon,
|
||||||
"urgency": notification.urgency,
|
"urgency": notification.urgency,
|
||||||
"timestamp": new Date()
|
"timestamp": new Date()
|
||||||
|
|
@ -139,6 +140,40 @@ Singleton {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Resolve an image path for a notification, supporting icon names and absolute paths
|
||||||
|
function resolveNotificationImage(notification) {
|
||||||
|
try {
|
||||||
|
// If an explicit image is already provided, prefer it
|
||||||
|
if (notification && notification.image && notification.image !== "") {
|
||||||
|
return notification.image
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback to appIcon which may be a name or a path (notify-send -i)
|
||||||
|
const icon = notification ? (notification.appIcon || "") : ""
|
||||||
|
if (!icon)
|
||||||
|
return ""
|
||||||
|
|
||||||
|
// Accept absolute file paths or file URLs directly
|
||||||
|
if (icon.startsWith("/")) {
|
||||||
|
return icon
|
||||||
|
}
|
||||||
|
if (icon.startsWith("file://")) {
|
||||||
|
// Strip the scheme for QML image source compatibility
|
||||||
|
return icon.substring("file://".length)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Resolve themed icon names to absolute paths
|
||||||
|
try {
|
||||||
|
const p = Icons.iconFromName(icon, "")
|
||||||
|
return p || ""
|
||||||
|
} catch (e2) {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Add a simplified copy into persistent history
|
// Add a simplified copy into persistent history
|
||||||
function addToHistory(notification) {
|
function addToHistory(notification) {
|
||||||
historyModel.insert(0, {
|
historyModel.insert(0, {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue