new option: mute notifications
This commit is contained in:
parent
1b105158ba
commit
1b72375dd7
3 changed files with 52 additions and 6 deletions
|
@ -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) {
|
public DesktopFile (string name, string url, string icon, bool stay_open) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.url = url.replace ("%", "%%");
|
this.url = url.replace ("%", "%%");
|
||||||
|
|
|
@ -37,6 +37,7 @@ namespace Webpin {
|
||||||
Gtk.Spinner spinner;
|
Gtk.Spinner spinner;
|
||||||
|
|
||||||
public DesktopFile desktop_file { get; private set; }
|
public DesktopFile desktop_file { get; private set; }
|
||||||
|
private Notification desktop_notification;
|
||||||
|
|
||||||
public WebWindow (DesktopFile desktop_file) {
|
public WebWindow (DesktopFile desktop_file) {
|
||||||
this.desktop_file = desktop_file;
|
this.desktop_file = desktop_file;
|
||||||
|
@ -45,6 +46,8 @@ namespace Webpin {
|
||||||
set_wmclass (desktop_file.url, desktop_file.url);
|
set_wmclass (desktop_file.url, desktop_file.url);
|
||||||
web_app = new WebApp (desktop_file.url);
|
web_app = new WebApp (desktop_file.url);
|
||||||
|
|
||||||
|
desktop_notification = new Notification ("");
|
||||||
|
|
||||||
var headerbar = new Gtk.HeaderBar ();
|
var headerbar = new Gtk.HeaderBar ();
|
||||||
headerbar.title = desktop_file.name;
|
headerbar.title = desktop_file.name;
|
||||||
headerbar.show_close_button = true;
|
headerbar.show_close_button = true;
|
||||||
|
@ -63,6 +66,31 @@ namespace Webpin {
|
||||||
});
|
});
|
||||||
headerbar.pack_start (stay_open);
|
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);
|
this.set_titlebar (headerbar);
|
||||||
|
|
||||||
var width = desktop_file.info.get_string ("WebpinWindowWidth");
|
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 (() => {
|
web_app.request_begin.connect (() => {
|
||||||
spinner.active = true;
|
spinner.active = true;
|
||||||
});
|
});
|
||||||
|
|
|
@ -37,11 +37,11 @@ namespace Webpin {
|
||||||
private WebKit.CookieManager cookie_manager;
|
private WebKit.CookieManager cookie_manager;
|
||||||
private Gtk.Box container;
|
private Gtk.Box container;
|
||||||
Granite.Widgets.Toast app_notification;
|
Granite.Widgets.Toast app_notification;
|
||||||
Notification desktop_notification;
|
|
||||||
|
|
||||||
public signal void external_request (WebKit.NavigationAction action);
|
public signal void external_request (WebKit.NavigationAction action);
|
||||||
public signal void request_begin ();
|
public signal void request_begin ();
|
||||||
public signal void request_finished ();
|
public signal void request_finished ();
|
||||||
|
public signal void desktop_notification (string title, string body);
|
||||||
|
|
||||||
|
|
||||||
public WebApp (string app_url) {
|
public WebApp (string app_url) {
|
||||||
|
@ -76,7 +76,6 @@ namespace Webpin {
|
||||||
container.valign = Gtk.Align.FILL;
|
container.valign = Gtk.Align.FILL;
|
||||||
|
|
||||||
app_notification = new Granite.Widgets.Toast ("");
|
app_notification = new Granite.Widgets.Toast ("");
|
||||||
desktop_notification = new Notification ("");
|
|
||||||
|
|
||||||
//overlay trick to make snapshot work even with the spinner
|
//overlay trick to make snapshot work even with the spinner
|
||||||
var overlay = new Gtk.Overlay ();
|
var overlay = new Gtk.Overlay ();
|
||||||
|
@ -135,9 +134,7 @@ namespace Webpin {
|
||||||
});
|
});
|
||||||
|
|
||||||
app_view.show_notification.connect ((notification) => {
|
app_view.show_notification.connect ((notification) => {
|
||||||
desktop_notification.set_title (notification.title);
|
desktop_notification (notification.title, notification.body);
|
||||||
desktop_notification.set_body (notification.body);
|
|
||||||
WebpinApp.instance.send_notification (null, desktop_notification);
|
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue