Skip to content

Commit

Permalink
Cleaner notifications (#49)
Browse files Browse the repository at this point in the history
* Cleaner notifications

* Honor sticky; stale import

* Update AppSettingsPage.qml

clarifying
  • Loading branch information
b100dian authored Oct 20, 2024
1 parent 803e792 commit a218183
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 248 deletions.
238 changes: 0 additions & 238 deletions qml/components/HydrogenNotifier.qml

This file was deleted.

52 changes: 45 additions & 7 deletions qml/harbour-hydrogen.qml
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,36 @@ import Sailfish.WebView 1.0
import Sailfish.WebEngine 1.0
import Nemo.DBus 2.0
import Nemo.Configuration 1.0
import Nemo.Notifications 1.0
import io.thp.pyotherside 1.5
import "cover"
import "components"

ApplicationWindow {
id: app
cover: Component { HydrogenCover {} }

allowedOrientations: Orientation.All
property int notificationCount: 0
property int oldUnreadCount: 0
property var openingArgument
property bool isSettingsAvailable: true

property int notificationCount: 0
property int oldUnreadCount: 0
onNotificationCountChanged: {
if (oldUnreadCount < notificationCount && Qt.application.state !== Qt.ApplicationActive) {
notifier.quickNumberedNotification( "New Messages", notificationCount )
if (oldUnreadCount < notificationCount && appConfig.showNotifications) {
var tryToBeSilent = Qt.application.state == Qt.ApplicationActive;
var message = notificationComponent.createObject(null, {
'previewSummary': tryToBeSilent ? null: qsTr("New hydrogen message."),
'isTransient': !appConfig.stickyNotifications,
'urgency': tryToBeSilent ? Notification.Low : Notification.Normal,
'itemCount': notificationCount,
'replacesId': appConfig.lastNotificationId
})
message.publish()
appConfig.lastNotificationId = message.replacesId
}
oldUnreadCount = notificationCount
}

HydrogenNotifier { id: notifier }

/* Array of objects: {name: "Name", count: 5}
These messages will be shown on the cover with an optional
Expand Down Expand Up @@ -164,6 +172,35 @@ ApplicationWindow {
}
}

Component {
id: notificationComponent;
Notification {
appName: "Hydrogen"
appIcon: "image://theme/harbour-hydrogen"
summary: qsTr("New messages")
category: "im.received"
remoteActions: [
{
// invoked when the user clicks the notification item
"name": "default",
"displayName": qsTr("Open Conversation"),
"icon": "icon-lock-chat",
"service": dbuslistener.service,
"path": dbuslistener.path,
"iface": dbuslistener.iface,
"method": "fromNotification"
},
{
// invoked when the user clicks the app notification group
"name": "app",
"service": dbuslistener.service,
"path": dbuslistener.path,
"iface": dbuslistener.iface,
"method": "activate",
}]
}
}

// application settings:
property alias appConfig: appConfig
property alias wvConfig: wvConfig
Expand All @@ -178,6 +215,7 @@ ApplicationWindow {
property bool showNotifications: true
property bool stickyNotifications: false
property bool showFunFacts: true
property int lastNotificationId: 42
}
ConfigurationGroup {
id: wvConfig
Expand Down
6 changes: 3 additions & 3 deletions qml/pages/AppSettingsPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ Page {
enabled: notifysw.checked
checked: appConfig.stickyNotifications
text: qsTr("Sticky notifications")
description: qsTr("If enabled, the app will update a single " +
"notification (as opposed to sending a new " +
"one each time).")
description: qsTr("If enabled, when the app has a notification " +
"it will also be present in the events view. " +
"Otherwise it is transient.")
onClicked: appConfig.stickyNotifications =
!appConfig.stickyNotifications
}
Expand Down

0 comments on commit a218183

Please sign in to comment.