Fix: Notification

This commit is contained in:
Artem Anufrij 2018-02-22 19:33:38 +01:00
parent e2816f9a5d
commit 2fed86ac36
2 changed files with 58 additions and 48 deletions

View file

@ -40,7 +40,8 @@ namespace Webpin {
Terminal=false Terminal=false
Type=Application Type=Application
Categories=Network; Categories=Network;
X-GNOME-FullName=webpin X-GNOME-Gettext-Domain=com.github.artemanufrij.webpin
X-GNOME-UsesNotifications=true
StartupWMClass=Webpin StartupWMClass=Webpin
X-Webpin-PrimaryColor=rgba (222,222,222,1)"""; X-Webpin-PrimaryColor=rgba (222,222,222,1)""";

View file

@ -63,7 +63,10 @@ namespace Webpin.Widgets {
cookie_manager.set_persistent_storage (cookie_db + "cookies.db", WebKit.CookiePersistentStorage.SQLITE); cookie_manager.set_persistent_storage (cookie_db + "cookies.db", WebKit.CookiePersistentStorage.SQLITE);
web_view = new WebKit.WebView.with_context (WebKit.WebContext.get_default ()) { web_view = new WebKit.WebView.with_context (WebKit.WebContext.get_default ()) {
settings = new WebKit.Settings () { enable_webgl = true } settings = new WebKit.Settings () {
enable_webgl = true,
user_agent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.167 Safari/537.36"
}
}; };
web_view.load_uri (desktop_file.url); web_view.load_uri (desktop_file.url);
@ -106,59 +109,65 @@ namespace Webpin.Widgets {
} }
container.pack_start (icon, true, true, 0); container.pack_start (icon, true, true, 0);
web_view.create.connect ((action) => { web_view.create.connect (
app_notification.title = _("Open request in an external application…"); (action) => {
app_notification.send_notification (); app_notification.title = _ ("Open request in an external application…");
app_notification.send_notification ();
external_request (action); external_request (action);
return new WebKit.WebView (); return new WebKit.WebView ();
}); });
web_view.load_changed.connect ((load_event) => { web_view.load_changed.connect (
request_begin (); (load_event) => {
if (load_event == WebKit.LoadEvent.FINISHED) { request_begin ();
visible_child_name = "app"; if (load_event == WebKit.LoadEvent.FINISHED) {
if (app_notification.reveal_child) { visible_child_name = "app";
app_notification.reveal_child = false; if (app_notification.reveal_child) {
app_notification.reveal_child = false;
}
request_finished ();
} }
request_finished (); });
}
});
web_view.show_notification.connect ((notification) => { web_view.show_notification.connect (
desktop_notification (notification.title, notification.body, icon_for_notification); (notification) => {
return true; desktop_notification (notification.title, notification.body, icon_for_notification);
}); return true;
});
web_view.permission_request.connect ((permission) => { web_view.permission_request.connect (
var permission_type = permission as WebKit.NotificationPermissionRequest; (permission) => {
if (permission_type != null) { var permission_type = permission as WebKit.NotificationPermissionRequest;
permission_type.allow (); if (permission_type != null) {
} permission_type.allow ();
return false; }
}); return false;
});
web_view.button_press_event.connect ((event) => { web_view.button_press_event.connect (
if (event.button == 8) { (event) => {
web_view.go_back (); if (event.button == 8) {
return true; web_view.go_back ();
} else if (event.button == 9) { return true;
web_view.go_forward (); } else if (event.button == 9) {
return true; web_view.go_forward ();
} return true;
return base.button_press_event (event); }
}); return base.button_press_event (event);
});
web_view.key_press_event.connect ((event) => { web_view.key_press_event.connect (
if (event.keyval == Gdk.Key.Back) { (event) => {
web_view.go_back (); if (event.keyval == Gdk.Key.Back) {
return true; web_view.go_back ();
} else if (event.keyval == Gdk.Key.Forward) { return true;
web_view.go_forward (); } else if (event.keyval == Gdk.Key.Forward) {
return true; web_view.go_forward ();
} return true;
return base.key_press_event (event); }
}); return base.key_press_event (event);
});
} }
} }
} }