-
-
Notifications
You must be signed in to change notification settings - Fork 77
Introduce NotificationsManager #2237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 9 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
ece7592
ScreenshotManager: avoid making it static
lenemter 38577d7
Avoid making DBusAccelerator static
lenemter 7576880
Introduce NotificationsManager
lenemter e7c96b3
Fix lint
lenemter d1c6aee
Merge branch 'main' into lenemter/notifications-manager
lenemter 5147fa4
Fix lint
lenemter 9f733ca
Merge branch 'main' into lenemter/notifications-manager
lenemter 98988a9
Put icon on top
lenemter 6331acc
Use async
lenemter a348cec
Remove NotificationData
lenemter 5d265f2
Remove NotificationData
lenemter cd6250d
Improve error logging
lenemter 1416bf5
Fix typos in error messages
lenemter 37cd466
Merge branch 'main' into lenemter/notifications-manager
lenemter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| /* | ||
| * SPDX-License-Identifier: GPL-3.0-or-later | ||
| * SPDX-FileCopyrightText: 2016 Rico Tzschichholz | ||
| * 2025 elementary, Inc. (https://elementary.io) | ||
| */ | ||
|
|
||
| /** | ||
| * Gala.NotificationsManager can be used to send notifications to org.freedesktop.Notifications | ||
| */ | ||
| public class Gala.NotificationsManager : GLib.Object { | ||
| [DBus (name = "org.freedesktop.Notifications")] | ||
| private interface DBusNotifications : GLib.Object { | ||
| public abstract async uint32 notify (string app_name, uint32 replaces_id, string app_icon, string summary, | ||
| string body, string[] actions, HashTable<string, Variant> hints, int32 expire_timeout) throws DBusError, IOError; | ||
| } | ||
|
|
||
| private const int EXPIRE_TIMEOUT = 2000; | ||
|
|
||
| /** | ||
| * Data structure to hold notification data. Component name is used to correctly replace notifications. | ||
| */ | ||
| [Compact] | ||
| public class NotificationData { | ||
| public string component_name; | ||
| public string icon; | ||
| public string summary; | ||
| public string body; | ||
| public GLib.HashTable<string, Variant> hints; | ||
|
|
||
| public NotificationData ( | ||
| string _component_name, | ||
| string _icon, | ||
| string _summary, | ||
| string _body, | ||
| GLib.HashTable<string, Variant> _hints | ||
| ) { | ||
| component_name = _component_name; | ||
| icon = _icon; | ||
| summary = _summary; | ||
| body = _body; | ||
| hints = _hints; | ||
| } | ||
| } | ||
|
|
||
| private DBusNotifications? notifications = null; | ||
| private GLib.HashTable<string, uint32> replaces_id_table = new GLib.HashTable<string, uint32> (str_hash, str_equal); | ||
|
|
||
| construct { | ||
| try { | ||
| Bus.watch_name (BusType.SESSION, "org.freedesktop.Notifications", BusNameWatcherFlags.NONE, on_watch, on_unwatch); | ||
| } catch (IOError e) { | ||
| warning (e.message); | ||
| } | ||
| } | ||
|
|
||
| private void on_watch (DBusConnection conn) { | ||
| conn.get_proxy.begin<DBusNotifications> ( | ||
| "org.freedesktop.Notifications", "/org/freedesktop/Notifications", DBusProxyFlags.NONE, null, | ||
| (obj, res) => { | ||
| try { | ||
| notifications = ((DBusConnection) obj).get_proxy.end<DBusNotifications> (res); | ||
| } catch (Error e) { | ||
| warning (e.message); | ||
| notifications = null; | ||
| } | ||
| } | ||
| ); | ||
| } | ||
|
|
||
| private void on_unwatch (DBusConnection conn) { | ||
| notifications = null; | ||
| } | ||
|
|
||
| public async void send (owned NotificationData notification_data) { | ||
| if (notifications == null) { | ||
| return; | ||
| } | ||
|
|
||
| uint32? replaces_id = replaces_id_table.get (notification_data.component_name); | ||
| if (replaces_id == null) { | ||
| replaces_id = 0; | ||
| } | ||
|
|
||
| try { | ||
| var notification_id = yield notifications.notify ( | ||
| "gala-feedback", | ||
| replaces_id, | ||
| notification_data.icon, | ||
| notification_data.summary, | ||
| notification_data.body, | ||
| {}, | ||
| notification_data.hints, | ||
| EXPIRE_TIMEOUT | ||
| ); | ||
|
|
||
| replaces_id_table.insert (notification_data.component_name, notification_id); | ||
| } catch (Error e) { | ||
| critical (e.message); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.