-
-
Notifications
You must be signed in to change notification settings - Fork 5
Add Notification Portal v2 backend #266
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
Open
lenemter
wants to merge
6
commits into
main
Choose a base branch
from
lenemter/add-portal-backend
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
90fcca8
Add Notification Portal v2 backend
lenemter 50d7d2e
Cleanup
lenemter 76fd1b9
Merge branch 'main' into lenemter/add-portal-backend
lenemter 2f8cea2
Reduce diff, fix merge
lenemter da04b03
Reduce diff
lenemter 17c1549
Merge branch 'main' into lenemter/add-portal-backend
danirabbit 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 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,106 @@ | ||
| /* | ||
| * Copyright 2025 elementary, Inc. (https://elementary.io) | ||
| * SPDX-License-Identifier: GPL-3.0-or-later | ||
| */ | ||
|
|
||
|
|
||
| // TEST CALL FOR DSPY: | ||
| // 'io.elementary.mail.desktop' | ||
| // 'new-mail' | ||
| // {'title': <'New mail from John Doe'>, 'body': <'You have a new mail from John Doe. Click to read it.'>, 'priority': <'high'>} | ||
|
|
||
| [DBus (name = "io.elementary.notifications.PortalProxy")] | ||
| public class Notifications.PortalProxy : Object { | ||
| private const string ID_FORMAT = "%s:%s"; | ||
|
|
||
| public signal void action_invoked (string app_id, string id, string action_name, Variant[] parameters); | ||
|
|
||
| public HashTable<string, Variant> supported_options { get; construct; } | ||
| public uint version { get; default = 2; } | ||
|
|
||
| [DBus (visible = false)] | ||
| public DBusConnection connection { private get; construct; } | ||
|
|
||
| private uint server_id; | ||
| private Gee.Map<string, Bubble?> bubbles; | ||
|
|
||
| public PortalProxy (DBusConnection connection) { | ||
| Object (connection: connection); | ||
| } | ||
|
|
||
| ~PortalProxy () { | ||
| connection.unregister_object (server_id); | ||
| } | ||
|
|
||
| construct { | ||
| try { | ||
| server_id = connection.register_object ("/io/elementary/notifications/PortalProxy", this); | ||
| } catch (Error e) { | ||
| critical (e.message); | ||
| } | ||
|
|
||
| supported_options = new HashTable<string, Variant> (str_hash, str_equal); | ||
| bubbles = new Gee.HashMap<string, Bubble?> (); | ||
| } | ||
|
|
||
| public void add_notification (string app_id, string id, HashTable<string, Variant> data) throws Error { | ||
| if (!("title" in data)) { | ||
| throw new DBusError.FAILED ("Can't show notification without title"); | ||
| } | ||
|
|
||
| unowned var title = data["title"].get_string (); | ||
|
|
||
| unowned string body = ""; | ||
| if ("body-markup" in data) { | ||
| body = data["body-markup"].get_string (); | ||
| } else if ("body" in data) { | ||
| body = data["body"].get_string (); | ||
| } | ||
|
|
||
| var app_icon = app_id; | ||
| var hints = new HashTable<string, Variant> (str_hash, str_equal); | ||
|
|
||
| var notification = new Notification (app_id, app_icon, title, body, hints) { | ||
| buttons = new GenericArray<Notification.Button?> (0) | ||
| }; | ||
|
|
||
| if (!Application.settings.get_boolean ("do-not-disturb") || notification.priority == GLib.NotificationPriority.URGENT) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably we can check this condition earlier in this method so that the following code is less nested? |
||
| var app_settings = new Settings.with_path ( | ||
| "io.elementary.notifications.applications", | ||
| Application.settings.path.concat ("applications", "/", notification.app_id, "/") | ||
| ); | ||
|
|
||
| if (app_settings.get_boolean ("bubbles")) { | ||
| var full_id = ID_FORMAT.printf (app_id, id); | ||
|
|
||
| if (bubbles.has_key (full_id) && bubbles[full_id] != null) { | ||
| bubbles[full_id].notification = notification; | ||
| } else { | ||
| bubbles[full_id] = new Bubble (notification); | ||
| bubbles[full_id].close_request.connect (() => { | ||
| bubbles[full_id] = null; | ||
| return Gdk.EVENT_PROPAGATE; | ||
| }); | ||
| } | ||
|
|
||
| bubbles[full_id].present (); | ||
| } | ||
|
|
||
| if (app_settings.get_boolean ("sounds")) { | ||
| var sound = notification.priority != URGENT ? "dialog-information" : "dialog-warning"; | ||
|
|
||
| Application.play_sound (sound); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public void remove_notification (string app_id, string id) throws Error { | ||
| var full_id = ID_FORMAT.printf (app_id, id); | ||
|
|
||
| if (!bubbles.has_key (full_id)) { | ||
| throw new DBusError.FAILED ("Provided id %s not found", id); | ||
| } | ||
|
|
||
| bubbles[full_id].close (); | ||
| } | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we should unregister only when we successfully registered in the constructor.