diff options
author | Christian Dywan <christian@twotoasts.de> | 2018-11-22 07:34:53 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-22 07:34:53 +0200 |
commit | 154f0d21f1823a1616c7d460fc22946cd33569ce (patch) | |
tree | cde76a6e746b6cbfe2041431b524e2d1bb6f6b99 | |
parent | 3e0657b11b010944f4d14a642b3f1ab7e70e7761 (diff) | |
download | midori-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.
-rw-r--r-- | core/download-button.vala | 10 | ||||
-rw-r--r-- | core/tab.vala | 23 | ||||
-rw-r--r-- | data/midori.appdata.xml.in | 2 | ||||
-rw-r--r-- | data/org.midori_browser.Midori.desktop.in (renamed from data/midori.desktop.in) | 0 | ||||
-rw-r--r-- | po/POTFILES.in | 2 | ||||
-rw-r--r-- | snap/snapcraft.yaml | 2 |
6 files changed, 36 insertions, 3 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 (); diff --git a/data/midori.appdata.xml.in b/data/midori.appdata.xml.in index 763a5228..95b5cca7 100644 --- a/data/midori.appdata.xml.in +++ b/data/midori.appdata.xml.in @@ -2,7 +2,7 @@ <!-- Copyright 2015-2018 Christian Dywan <christian@twotoasts.de> --> <component type="desktop"> <id>org.midori_browser.Midori</id> - <launchable type="desktop-id">midori.desktop</launchable> + <launchable type="desktop-id">org.midori_browser.Midori.desktop</launchable> <metadata_license>LGPL-2.1-or-later</metadata_license> <project_license>LGPL-2.1-or-later</project_license> <_name>Midori Web Browser</_name> diff --git a/data/midori.desktop.in b/data/org.midori_browser.Midori.desktop.in index ffd1df70..ffd1df70 100644 --- a/data/midori.desktop.in +++ b/data/org.midori_browser.Midori.desktop.in diff --git a/po/POTFILES.in b/po/POTFILES.in index d31844ed..1ed62a84 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -1,6 +1,6 @@ # List of source files containing translatable strings. -data/midori.desktop.in +data/org.midori_browser.Midori.desktop.in core/about.vala core/app.vala core/browser.vala diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 0c71d3e3..2d4d7cc2 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -44,7 +44,7 @@ apps: - network-bind - location-observe - network-status - desktop: share/applications/midori.desktop + desktop: share/applications/org.midori_browser.Midori.desktop environment: LD_LIBRARY_PATH: $SNAP/usr/lib/x86_64-linux-gnu/webkit2gtk-4.0/:$LD_LIBRARY_PATH # Work-around GPU crash https://bugs.webkit.org/show_bug.cgi?id=126122 |