diff options
author | fiaxh <git@lightrise.org> | 2019-11-26 18:42:18 +0100 |
---|---|---|
committer | fiaxh <git@lightrise.org> | 2019-11-26 18:47:30 +0100 |
commit | c4325473fba84db6d48bf2ca9e79214fef1cca2f (patch) | |
tree | 51b9dbb598628b44b1f09ae588db5588168ebfe7 | |
parent | b03da2af60e109921967fd38a2ba16bfb4df9f5d (diff) | |
download | dino-c4325473fba84db6d48bf2ca9e79214fef1cca2f.tar.gz dino-c4325473fba84db6d48bf2ca9e79214fef1cca2f.zip |
Don't require window object in notifications
fixes #658
-rw-r--r-- | libdino/src/entity/settings.vala | 5 | ||||
-rw-r--r-- | main/src/ui/application.vala | 7 | ||||
-rw-r--r-- | main/src/ui/notifications.vala | 21 |
3 files changed, 17 insertions, 16 deletions
diff --git a/libdino/src/entity/settings.vala b/libdino/src/entity/settings.vala index ef25fd23..bf1ebed4 100644 --- a/libdino/src/entity/settings.vala +++ b/libdino/src/entity/settings.vala @@ -18,11 +18,6 @@ public class Settings : Object { return val != null ? bool.parse(val) : def; } - private int col_to_int_or_default(string key, int def) { - string? val = db.settings.select({db.settings.value}).with(db.settings.key, "=", key)[db.settings.value]; - return val != null ? int.parse(val) : def; - } - private bool send_typing_; public bool send_typing { get { return send_typing_; } diff --git a/main/src/ui/application.vala b/main/src/ui/application.vala index 9a154a49..f031bf43 100644 --- a/main/src/ui/application.vala +++ b/main/src/ui/application.vala @@ -28,6 +28,11 @@ public class Dino.Ui.Application : Gtk.Application, Dino.Application { create_actions(); + startup.connect(() => { + notifications = new Notifications(stream_interactor); + notifications.start(); + }); + activate.connect(() => { if (window == null) { controller = new UnifiedWindowController(this, stream_interactor, db); @@ -36,8 +41,6 @@ public class Dino.Ui.Application : Gtk.Application, Dino.Application { controller.set_window(window); if ((get_flags() & ApplicationFlags.IS_SERVICE) == ApplicationFlags.IS_SERVICE) window.delete_event.connect(window.hide_on_delete); - notifications = new Notifications(stream_interactor, window); - notifications.start(); notifications.conversation_selected.connect((conversation) => window.on_conversation_selected(conversation)); } window.present(); diff --git a/main/src/ui/notifications.vala b/main/src/ui/notifications.vala index 2c576e14..7b45a46e 100644 --- a/main/src/ui/notifications.vala +++ b/main/src/ui/notifications.vala @@ -10,14 +10,12 @@ public class Notifications : Object { public signal void conversation_selected(Conversation conversation); private StreamInteractor stream_interactor; - private Gtk.Window window; private HashMap<Conversation, Notification> notifications = new HashMap<Conversation, Notification>(Conversation.hash_func, Conversation.equals_func); private Set<string>? active_conversation_ids = null; private Set<string>? active_ids = new HashSet<string>(); - public Notifications(StreamInteractor stream_interactor, Gtk.Window window) { + public Notifications(StreamInteractor stream_interactor) { this.stream_interactor = stream_interactor; - this.window = window; stream_interactor.get_module(ChatInteraction.IDENTITY).focused_in.connect((focused_conversation) => { if (active_conversation_ids == null) { @@ -81,13 +79,18 @@ public class Notifications : Object { Cairo.ImageSurface conversation_avatar = (yield Util.get_conversation_avatar_drawer(stream_interactor, conversation)).size(40, 40).draw_image_surface(); notifications[conversation].set_icon(get_pixbuf_icon(conversation_avatar)); } catch (Error e) { } - window.get_application().send_notification(conversation.id.to_string(), notifications[conversation]); - active_conversation_ids.add(conversation.id.to_string()); + GLib.Application.get_default().send_notification(conversation.id.to_string(), notifications[conversation]); + if (active_conversation_ids != null) { + active_conversation_ids.add(conversation.id.to_string()); + } // Don't set urgency hint in GNOME, produces "Window is active" notification var desktop_env = Environment.get_variable("XDG_CURRENT_DESKTOP"); if (desktop_env == null || !desktop_env.down().contains("gnome")) { - window.urgency_hint = true; + var app = (GLib.Application.get_default() as Application); + if (app.active_window != null) { + app.active_window.urgency_hint = true; + } } } @@ -101,7 +104,7 @@ public class Notifications : Object { notification.set_default_action_and_target_value("app.open-conversation", new Variant.int32(conversation.id)); notification.add_button_with_target_value(_("Accept"), "app.accept-subscription", conversation.id); notification.add_button_with_target_value(_("Deny"), "app.deny-subscription", conversation.id); - window.get_application().send_notification(conversation.id.to_string() + "-subscription", notification); + GLib.Application.get_default().send_notification(conversation.id.to_string() + "-subscription", notification); active_ids.add(conversation.id.to_string() + "-subscription"); } @@ -115,7 +118,7 @@ public class Notifications : Object { notification.set_body("Invalid TLS certificate"); break; } - window.get_application().send_notification(account.id.to_string() + "-connection-error", notification); + GLib.Application.get_default().send_notification(account.id.to_string() + "-connection-error", notification); } private async void on_invite_received(Account account, Jid room_jid, Jid from_jid, string? password, string? reason) { @@ -135,7 +138,7 @@ public class Notifications : Object { notification.set_default_action_and_target_value("app.open-muc-join", new Variant.int32(group_conversation.id)); notification.add_button_with_target_value(_("Deny"), "app.deny-invite", group_conversation.id); notification.add_button_with_target_value(_("Accept"), "app.open-muc-join", group_conversation.id); - window.get_application().send_notification(null, notification); + GLib.Application.get_default().send_notification(null, notification); } private Icon get_pixbuf_icon(Cairo.ImageSurface surface) throws Error { |