open external urls in default browser instead webpin view

This commit is contained in:
Artem Anufrij 2017-08-10 21:12:33 +02:00
parent 13731f65fc
commit 8dadbb3164
4 changed files with 17 additions and 140 deletions

View file

@ -3,7 +3,6 @@ vala_precompile(VALA_C ${CMAKE_PROJECT_NAME}
Widgets/ApplicationsView.vala
Widgets/Assistant.vala
Widgets/WebApp.vala
Widgets/WebBar.vala
Objects/DesktopFile.vala
Dialogs/InfoDialog.vala
Settings.vala

View file

@ -35,17 +35,14 @@ namespace Webpin {
//widgets
private WebApp web_app;
private WebBar headerbar;
public WebWindow (string webapp_name, string webapp_uri) {
set_wmclass(webapp_uri, webapp_uri);
web_app = new WebApp(webapp_name, webapp_uri);
headerbar = new WebBar(web_app.external_view);
headerbar.show_close_button = true;
var headerbar = new Gtk.HeaderBar ();
headerbar.title = webapp_name;
headerbar.set_title_mode (WebBar.title_mode.TITLE);
//style
if (web_app.ui_color != "none") {
@ -91,23 +88,13 @@ namespace Webpin {
this.destroy.connect(Gtk.main_quit);
web_app.external_request.connect ( () => {
debug ("Web app external request\n");
web_app.set_transition_type (Gtk.StackTransitionType.SLIDE_LEFT);
headerbar.set_title_mode (WebBar.title_mode.BROWSER);
web_app.set_visible_child_name ("external");
});
headerbar.back_event.connect ( () => {
debug ("back");
headerbar.set_title_mode (WebBar.title_mode.TITLE);
web_app.set_transition_type (Gtk.StackTransitionType.SLIDE_RIGHT);
web_app.set_visible_child_name ("app");
//wait the animation to end before "cleaning" the web view
GLib.Timeout.add(web_app.get_transition_duration(), () => {
web_app.external_view.load_uri ("about:blank");
return false;
});
web_app.external_request.connect ((action) => {
debug ("Web app external request: %s", action.get_request ().uri);
try {
Process.spawn_command_line_async ("xdg-open " + action.get_request ().uri);
} catch (Error e) {
warning (e.message);
}
});
add(web_app);

View file

@ -30,7 +30,6 @@ namespace Webpin {
public class WebApp : Gtk.Stack {
public WebKit.WebView app_view;
public WebKit.WebView external_view;
public string ui_color = "none";
private string app_url;
private GLib.DesktopAppInfo info;
@ -38,13 +37,12 @@ namespace Webpin {
private WebKit.CookieManager cookie_manager;
private Gtk.Box container; //the spinner container
public signal void external_request ();
public signal void external_request (WebKit.NavigationAction action);
public signal void theme_color_changed(string color);
public WebApp (string webapp_name, string app_url) {
this.app_url = app_url;
set_transition_duration (1000);
//configure cookies settings
cookie_manager = WebKit.WebContext.get_default ().get_cookie_manager ();
@ -66,12 +64,9 @@ namespace Webpin {
cookie_manager.set_persistent_storage (cookie_db + "cookies.db", WebKit.CookiePersistentStorage.SQLITE);
//load app viewer
app_view = new WebKit.WebView.with_context (WebKit.WebContext.get_default ());
app_view = new WebKit.WebView.with_context (WebKit.WebContext.get_default ());
app_view.load_uri (app_url);
//create external viewer
this.external_view = new WebKit.WebView ();
//loading view
var spinner = new Gtk.Spinner();
spinner.active = true;
@ -88,19 +83,12 @@ namespace Webpin {
overlay.add(app_view);
overlay.add_overlay(container);
add_titled(overlay, "app", "app");
add_titled(external_view, "external", "external");
set_visible_child_name ("app");
add(overlay);
app_view.create.connect ( () => {
app_view.create.connect ((action) => {
print("external request");
external_request ();
return external_view;
});
external_view.create.connect ( () => {
print("external request");
set_visible_child_name ("external");
return external_view;
external_request (action);
return new WebKit.WebView ();
});
info = DesktopFile.get_app_by_url(app_url);
@ -132,9 +120,9 @@ namespace Webpin {
});
}
public DesktopFile get_desktop_file () {
return this.file;
}
public DesktopFile get_desktop_file () {
return this.file;
}
/**Taken from WebView.vala in lp:midori
* Check for the theme-color meta tag in the page and if that one can't be

View file

@ -1,97 +0,0 @@
/*-
* Copyright (c) 2015 Erasmo Marín <erasmo.marin@gmail.com>
* Copyright (c) 2017-2017 Artem Anufrij <artem.anufrij@live.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* The Noise authors hereby grant permission for non-GPL compatible
* GStreamer plugins to be used and distributed together with GStreamer
* and Noise. This permission is above and beyond the permissions granted
* by the GPL license by which Noise is covered. If you modify this code
* you may extend this exception to your version of the code, but you are not
* obligated to do so. If you do not wish to do so, delete this exception
* statement from your version.
*
* Authored by: Artem Anufrij <artem.anufrij@live.de>
*/
namespace Webpin {
public class WebBar : Gtk.HeaderBar {
public enum title_mode {
TITLE,
BROWSER;
}
UrlEntry url_entry;
Gtk.Button share_button;
Gtk.Button back_button;
WebKit.WebView webview;
public signal void back_event();
public WebBar (WebKit.WebView webview) {
this.get_style_context ().remove_class ("header-bar");
this.webview = webview;
url_entry = new UrlEntry();
url_entry.show_all();
share_button = new Gtk.Button.from_icon_name ("application-menu-symbolic", Gtk.IconSize.SMALL_TOOLBAR);
share_button.margin_start = 15;
share_button.show_all ();
back_button = new Gtk.Button.from_icon_name ("go-next-symbolic-rtl", Gtk.IconSize.SMALL_TOOLBAR);
back_button.margin_end = 15;
back_button.show_all ();
pack_start (back_button);
pack_start (url_entry);
pack_end (share_button);
custom_title = new Gtk.Label(null);
connect_signals ();
show();
}
private void connect_signals () {
webview.load_changed.connect ( (event) => {
if (event == WebKit.LoadEvent.STARTED)
url_entry.set_text (webview.uri);
});
back_button.clicked.connect( () => { back_event(); });
back_button.activate.connect( () => { back_event(); });
}
public void set_title_mode (title_mode mode) {
if (mode == title_mode.TITLE) {
custom_title = null;
remove (share_button);
remove (back_button);
remove (url_entry);
this.get_style_context ().remove_class ("header-bar");
} else {
pack_start (back_button);
pack_start (url_entry);
pack_end (share_button);
custom_title = new Gtk.Label(null);
this.get_style_context ().add_class ("header-bar");
}
}
}
}