new option: mute notifications

This commit is contained in:
Artem Anufrij 2017-09-07 20:01:06 +02:00
parent 1b105158ba
commit 1b72375dd7
3 changed files with 52 additions and 6 deletions

View file

@ -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 ("%", "%%");

View file

@ -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;
});

View file

@ -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;
});