Skip to content
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

Bubble: minor refactor #202

Merged
merged 3 commits into from
Jun 28, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
replace contents in notification setter
DRY the content creation code by handling it in the setter for the
notification property.

Signed-off-by: Gustavo Marques <pushstarttocontinue@outlook.com>
  • Loading branch information
Marukesu committed Jun 27, 2023
commit 8cb9676aab0ef20899aab2d1cb95b7ff871d17f0
72 changes: 32 additions & 40 deletions src/Bubble.vala
Original file line number Diff line number Diff line change
@@ -6,65 +6,57 @@
public class Notifications.Bubble : AbstractBubble {
public signal void action_invoked (string action_key);

public Notifications.Notification notification { get; construct; }

private Gtk.GestureMultiPress press_gesture;
private bool _has_default;
public Notification notification {
get {
return _notification;
}

public Bubble (Notification notification) {
Object (notification: notification);
}
set {
_notification = value;
timeout = 0;

construct {
var contents = new Contents (notification);
for (int i = 0; i < notification.actions.length; i += 2) {
if (notification.actions[i] == "default") {
_has_default = true;
break;
}
}

content_area.add (contents);
var contents = new Contents (value);
contents.action_invoked.connect ((a) => action_invoked (a));
contents.show_all ();

switch (notification.priority) {
case GLib.NotificationPriority.HIGH:
case GLib.NotificationPriority.URGENT:
content_area.get_style_context ().add_class ("urgent");
break;
default:
if (value.priority >= NotificationPriority.HIGH) {
contents.get_style_context ().add_class ("urgent");
} else {
timeout = 4000;
break;
}

for (int i = 0; i < notification.actions.length; i += 2) {
if (notification.actions[i] == "default") {
_has_default = true;
break;
}

content_area.add (contents);
content_area.visible_child = contents;
}
}

private Notification _notification;
private Gtk.GestureMultiPress press_gesture;
private bool _has_default;

contents.action_invoked.connect ((action_key) => {
action_invoked (action_key);
close ();
});
public Bubble (Notification notification) {
Object (notification: notification);
}

construct {
press_gesture = new Gtk.GestureMultiPress (this) {
propagation_phase = BUBBLE
};
press_gesture.released.connect (released);
}

public void replace (Notifications.Notification new_notification) {
var new_contents = new Contents (new_notification);
new_contents.show_all ();

new_contents.action_invoked.connect ((action_key) => {
action_invoked (action_key);
close ();
});

content_area.add (new_contents);
content_area.visible_child = new_contents;
action_invoked.connect (close);
}

private void released () {
if (_has_default) {
action_invoked ("default");
close ();
} else if (notification.app_info != null) {
notification.app_info.launch_uris_async.begin (null, null, null, (obj, res) => {
try {
2 changes: 1 addition & 1 deletion src/DBus.vala
Original file line number Diff line number Diff line change
@@ -135,7 +135,7 @@ public class Notifications.Server : Object {

if (app_settings.get_boolean ("bubbles")) {
if (bubbles.has_key (id) && bubbles[id] != null) {
bubbles[id].replace (notification);
bubbles[id].notification = notification;
} else {
bubbles[id] = new Bubble (notification);