summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorChristian Dywan <christian@twotoasts.de>2018-11-22 07:34:53 +0200
committerGitHub <noreply@github.com>2018-11-22 07:34:53 +0200
commit154f0d21f1823a1616c7d460fc22946cd33569ce (patch)
treecde76a6e746b6cbfe2041431b524e2d1bb6f6b99 /core
parent3e0657b11b010944f4d14a642b3f1ab7e70e7761 (diff)
downloadmidori-git-154f0d21f1823a1616c7d460fc22946cd33569ce.tar.gz
Implement notifications for downloads and web (#175)
- Finished downloads when there's no active browser window - Web notifications with favicon if available for background tabs Notes: - The .desktop file is renamed to match the application ID. - Only one notification of each is allowed.
Diffstat (limited to 'core')
-rw-r--r--core/download-button.vala10
-rw-r--r--core/tab.vala23
2 files changed, 33 insertions, 0 deletions
diff --git a/core/download-button.vala b/core/download-button.vala
index 5056862a..94319792 100644
--- a/core/download-button.vala
+++ b/core/download-button.vala
@@ -168,6 +168,16 @@ namespace Midori {
item.notify["loading"].connect (update_buttons);
item.notify["error"].connect (update_buttons);
update_buttons ();
+
+ item.finished.connect (() => {
+ var app = (App)Application.get_default ();
+ if (item.error == null && app.active_window != null) {
+ var notification = new Notification (_("Transfer completed"));
+ notification.set_icon (item.icon);
+ notification.set_body (item.filename);
+ app.send_notification ("download-finished", notification);
+ }
+ });
}
void update_buttons () {
diff --git a/core/tab.vala b/core/tab.vala
index fe8cf0a7..10008cdc 100644
--- a/core/tab.vala
+++ b/core/tab.vala
@@ -329,10 +329,32 @@ namespace Midori {
return true;
}
+ public override bool show_notification (WebKit.Notification webkit_notification) {
+ // Don't show notifications for the visible tab
+ if (get_mapped ()) {
+ return false;
+ }
+
+ var notification = new Notification (webkit_notification.title);
+ if (favicon != null) {
+ var image = (Cairo.ImageSurface)favicon;
+ var pixbuf = Gdk.pixbuf_get_from_surface (image, 0, 0, image.get_width (), image.get_height ());
+ notification.set_icon ((Icon)pixbuf);
+ }
+ notification.set_body (webkit_notification.body);
+ // Use a per-host ID to avoid collisions, but neglect the tag
+ string hostname = new Soup.URI (uri).host;
+ Application.get_default ().send_notification ("web-%s".printf (hostname), notification);
+ return true;
+ }
+
public override bool permission_request (WebKit.PermissionRequest permission) {
if (permission is WebKit.GeolocationPermissionRequest) {
string hostname = new Soup.URI (uri).host;
message.label = _("%s wants to know your location.").printf (hostname);
+ } else if (permission is WebKit.NotificationPermissionRequest) {
+ permission.allow ();
+ return true;
} else {
message.label = permission.get_type ().name ();
}
@@ -340,6 +362,7 @@ namespace Midori {
confirm.show ();
confirm.clicked.connect (() => {
permission.allow ();
+ popover.hide ();
});
popover.closed.connect (() => {
permission.deny ();