Skip to content

Commit

Permalink
Merge branch 'master' into shrink-apps
Browse files Browse the repository at this point in the history
  • Loading branch information
danirabbit authored Aug 29, 2023
2 parents b294e79 + 40545f6 commit 9be02fa
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 234 deletions.
1 change: 0 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ shared_module(
'src/Services/NotificationsMonitor.vala',
'src/Services/Notification.vala',
'src/Services/Session.vala',
'src/Services/Interfaces.vala',
gresource,
config_vala,
dependencies: [
Expand Down
40 changes: 22 additions & 18 deletions src/Indicator.vala
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,20 @@
*/

public class Notifications.Indicator : Wingpanel.Indicator {
private const string[] EXCEPTIONS = { "NetworkManager", "gnome-settings-daemon", "gnome-power-panel" };
private const string CHILD_SCHEMA_ID = "io.elementary.notifications.applications";
private const string CHILD_PATH = "/io/elementary/notifications/applications/%s/";
private const string REMEMBER_KEY = "remember";

private Gee.HashMap<string, Settings> app_settings_cache;
private GLib.Settings notify_settings;

private Gtk.Grid? main_box = null;
private Gtk.ModelButton clear_all_btn;
private Gtk.Spinner? dynamic_icon = null;
private NotificationsList nlist;

private List<Notification> previous_session = null;
private NotificationsMonitor monitor;

public Indicator () {
Object (
Expand All @@ -42,6 +44,8 @@ public class Notifications.Indicator : Wingpanel.Indicator {

notify_settings = new GLib.Settings ("io.elementary.notifications");
app_settings_cache = new Gee.HashMap<string, Settings> ();

monitor = new NotificationsMonitor ();
}

public override Gtk.Widget get_display_widget () {
Expand All @@ -60,9 +64,15 @@ public class Notifications.Indicator : Wingpanel.Indicator {

nlist = new NotificationsList ();

var monitor = NotificationMonitor.get_instance ();
monitor.notification_received.connect (on_notification_received);
monitor.notification_closed.connect (on_notification_closed);
monitor.init.begin ((obj, res) => {
try {
((NotificationsMonitor) obj).init.end (res);
} catch (Error e) {
critical ("Unable to monitor notifications bus: %s", e.message);
}
});

notify_settings.changed["do-not-disturb"].connect (() => {
set_display_icon_name ();
Expand Down Expand Up @@ -162,12 +172,8 @@ public class Notifications.Indicator : Wingpanel.Indicator {

private void on_notification_received (DBusMessage message, uint32 id) {
var notification = new Notification.from_message (message, id);
if (notification.is_transient || notification.app_name in EXCEPTIONS) {
return;
}

string app_id = notification.desktop_id.replace (Notification.DESKTOP_ID_EXT, "");

Settings? app_settings = app_settings_cache.get (app_id);

var schema = SettingsSchemaSource.get_default ().lookup (CHILD_SCHEMA_ID, true);
Expand All @@ -187,18 +193,16 @@ public class Notifications.Indicator : Wingpanel.Indicator {
clear_all_btn.sensitive = nlist.app_entries.size > 0;
}

private void on_notification_closed (uint32 id, uint32 reason) {
// If notification bubble was dismissed by user do not keep in list
if (reason == Notification.CloseReason.DISMISSED ||
reason == Notification.CloseReason.CLOSE_NOTIFICATION_CALL) {

foreach (var app_entry in nlist.app_entries.values) {
foreach (var item in app_entry.app_notifications) {
if (item.notification.id == id) {
item.clear ();
return;
}
}
private void on_notification_closed (uint32 id, Notification.CloseReason reason) {
SearchFunc<NotificationEntry, uint32> find_entry = (e, i) => {
return i == e.notification.id ? 0 : i > e.notification.id ? 1 : -1;
};

foreach (var app_entry in nlist.app_entries.values) {
unowned var node = app_entry.app_notifications.search (id, find_entry);
if (node != null) {
node.data.clear ();
return;
}
}
}
Expand Down
21 changes: 0 additions & 21 deletions src/Services/Interfaces.vala

This file was deleted.

25 changes: 0 additions & 25 deletions src/Services/Notification.vala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public class Notifications.Notification : Object {

public const string DESKTOP_ID_EXT = ".desktop";

public bool is_transient = false;
public string app_name;
public string summary;
public string message_body;
Expand Down Expand Up @@ -139,30 +138,6 @@ public class Notifications.Notification : Object {
desktop_id = FALLBACK_DESKTOP_ID;
app_info = new DesktopAppInfo (desktop_id);
}

var transient_hint = hints.lookup_value ("transient", VariantType.BOOLEAN);
is_transient = hints.lookup_value (X_CANONICAL_PRIVATE_KEY, null) != null || (transient_hint != null && transient_hint.get_boolean ());
}

public bool run_default_action () {
if (DEFAULT_ACTION in actions) {
app_info.launch_action (DEFAULT_ACTION, new GLib.AppLaunchContext ());

var notifications_iface = NotificationMonitor.get_instance ().notifications_iface;
if (notifications_iface != null) {
notifications_iface.action_invoked (id, DEFAULT_ACTION);
}

return true;
} else {
try {
app_info.launch (null, null);
} catch (Error e) {
critical ("Unable to launch app: %s", e.message);
}
}

return false;
}

private string get_string (Variant tuple, int column) {
Expand Down
Loading

0 comments on commit 9be02fa

Please sign in to comment.