From 1b72375dd7b451a7b25c5135accaf1c22610d9f9 Mon Sep 17 00:00:00 2001 From: Artem Anufrij Date: Thu, 7 Sep 2017 20:01:06 +0200 Subject: [PATCH] new option: mute notifications --- src/Objects/DesktopFile.vala | 13 ++++++++++++ src/WebWindow.vala | 38 +++++++++++++++++++++++++++++++++++- src/Widgets/WebApp.vala | 7 ++----- 3 files changed, 52 insertions(+), 6 deletions(-) diff --git a/src/Objects/DesktopFile.vala b/src/Objects/DesktopFile.vala index 322ffbf..1db111c 100644 --- a/src/Objects/DesktopFile.vala +++ b/src/Objects/DesktopFile.vala @@ -63,6 +63,19 @@ namespace Webpin { } } + public bool mute_notifications { + get { + this.file = new GLib.KeyFile(); + try { + file.load_from_file (info.filename, KeyFileFlags.NONE); + return file.get_string ("Desktop Entry", "WebpinMuteNotifications") == "true"; + } catch (Error e) { + warning (e.message); + } + return false; + } + } + public DesktopFile (string name, string url, string icon, bool stay_open) { this.name = name; this.url = url.replace ("%", "%%"); diff --git a/src/WebWindow.vala b/src/WebWindow.vala index eccc2e4..ff676fe 100644 --- a/src/WebWindow.vala +++ b/src/WebWindow.vala @@ -37,6 +37,7 @@ namespace Webpin { Gtk.Spinner spinner; public DesktopFile desktop_file { get; private set; } + private Notification desktop_notification; public WebWindow (DesktopFile desktop_file) { this.desktop_file = desktop_file; @@ -45,6 +46,8 @@ namespace Webpin { set_wmclass (desktop_file.url, desktop_file.url); web_app = new WebApp (desktop_file.url); + desktop_notification = new Notification (""); + var headerbar = new Gtk.HeaderBar (); headerbar.title = desktop_file.name; headerbar.show_close_button = true; @@ -52,7 +55,7 @@ namespace Webpin { spinner = new Gtk.Spinner (); spinner.set_size_request (16, 16); headerbar.pack_end (spinner); - + var stay_open = new Gtk.ToggleButton (); stay_open.active = desktop_file.hide_on_close; stay_open.tooltip_text = _("Run in background when closed"); @@ -63,6 +66,31 @@ namespace Webpin { }); headerbar.pack_start (stay_open); + var mute_notifications = new Gtk.ToggleButton (); + mute_notifications.active = desktop_file.mute_notifications; + if (mute_notifications.active) { + mute_notifications.image = new Gtk.Image.from_icon_name ("notification-disabled-symbolic", Gtk.IconSize.MENU); + mute_notifications.tooltip_text = _("Unmute notifications"); + } else { + mute_notifications.image = new Gtk.Image.from_icon_name ("notification-symbolic", Gtk.IconSize.MENU); + mute_notifications.tooltip_text = _("Mute notifications"); + } + mute_notifications.toggled.connect (() => { + desktop_file.edit_propertie ("WebpinMuteNotifications", mute_notifications.active.to_string ()); + desktop_file.save_to_file (); + if (mute_notifications.active) { + mute_notifications.image = new Gtk.Image.from_icon_name ("notification-disabled-symbolic", Gtk.IconSize.MENU); + mute_notifications.tooltip_text = _("Unmute notifications"); + } else { + mute_notifications.image = new Gtk.Image.from_icon_name ("notification-symbolic", Gtk.IconSize.MENU); + mute_notifications.tooltip_text = _("Mute notifications"); + desktop_notification.set_title (desktop_file.name); + desktop_notification.set_body (_("Desktop notifications are enabled")); + WebpinApp.instance.send_notification (null, desktop_notification); + } + }); + headerbar.pack_start (mute_notifications); + this.set_titlebar (headerbar); var width = desktop_file.info.get_string ("WebpinWindowWidth"); @@ -101,6 +129,14 @@ namespace Webpin { } }); + web_app.desktop_notification.connect ((title, body) => { + if (!desktop_file.mute_notifications) { + desktop_notification.set_title (title); + desktop_notification.set_body (body); + WebpinApp.instance.send_notification (null, desktop_notification); + } + }); + web_app.request_begin.connect (() => { spinner.active = true; }); diff --git a/src/Widgets/WebApp.vala b/src/Widgets/WebApp.vala index 143272f..e128e18 100644 --- a/src/Widgets/WebApp.vala +++ b/src/Widgets/WebApp.vala @@ -37,11 +37,11 @@ namespace Webpin { private WebKit.CookieManager cookie_manager; private Gtk.Box container; Granite.Widgets.Toast app_notification; - Notification desktop_notification; public signal void external_request (WebKit.NavigationAction action); public signal void request_begin (); public signal void request_finished (); + public signal void desktop_notification (string title, string body); public WebApp (string app_url) { @@ -76,7 +76,6 @@ namespace Webpin { container.valign = Gtk.Align.FILL; app_notification = new Granite.Widgets.Toast (""); - desktop_notification = new Notification (""); //overlay trick to make snapshot work even with the spinner var overlay = new Gtk.Overlay (); @@ -135,9 +134,7 @@ namespace Webpin { }); app_view.show_notification.connect ((notification) => { - desktop_notification.set_title (notification.title); - desktop_notification.set_body (notification.body); - WebpinApp.instance.send_notification (null, desktop_notification); + desktop_notification (notification.title, notification.body); return false; });