Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Browser): dialog #1338

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion data/ui/dialogs/main.ui
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<child>
<object class="AdwToastOverlay" id="toast_overlay">
<property name="child">
<object class="GtkOverlay" id="main_overlay">
<object class="GtkOverlay">
<child type="overlay">
<object class="TubaViewsMediaViewer" id="media_viewer">
<property name="visible">0</property>
Expand Down
2 changes: 1 addition & 1 deletion src/API/Status/PreviewCard.vala
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public class Tuba.API.PreviewCard : Entity, Widgetizable {
private void open_url (string url) {
#if WEBKIT
if (settings.use_in_app_browser_if_available && Views.Browser.can_handle_url (url)) {
app.main_window.open_in_app_browser_for_url (url);
(new Views.Browser.with_url (url)).present (app.main_window);
return;
}
#endif
Expand Down
23 changes: 0 additions & 23 deletions src/Dialogs/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ public class Tuba.Dialogs.MainWindow: Adw.ApplicationWindow, Saveable {
[GtkChild] unowned Adw.Breakpoint breakpoint;
[GtkChild] unowned Adw.ToastOverlay toast_overlay;

#if WEBKIT
[GtkChild] unowned Gtk.Overlay main_overlay;
#endif

public void set_sidebar_selected_item (int pos) {
sidebar.set_sidebar_selected_item (pos);
}
Expand Down Expand Up @@ -169,25 +165,6 @@ public class Tuba.Dialogs.MainWindow: Adw.ApplicationWindow, Saveable {
}
}

#if WEBKIT
Gtk.Widget? browser_last_focused_widget = null;
public void open_in_app_browser_for_url (string url) {
browser_last_focused_widget = app.main_window.get_focus ();
var browser = new Views.Browser ();
browser.exit.connect (on_browser_exit);
browser.load_url (url);
main_overlay.add_overlay (browser);
browser.reveal_child = true;
}

private void on_browser_exit (Views.Browser browser) {
main_overlay.remove_overlay (browser);

browser_last_focused_widget.grab_focus ();
browser_last_focused_widget = null;
}
#endif

public Views.Base open_view (Views.Base view) {
if (
(
Expand Down
82 changes: 13 additions & 69 deletions src/Views/Browser.vala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
public class Tuba.Views.Browser : Adw.Bin {
public class Tuba.Views.Browser : Adw.Dialog {
private class HeaderBar : Adw.Bin {
~HeaderBar () {
debug ("Destroying Browser HeaderBar");
Expand Down Expand Up @@ -127,19 +127,12 @@ public class Tuba.Views.Browser : Adw.Bin {

window_title = new Adw.WindowTitle ("", "");
var headerbar = new Adw.HeaderBar () {
show_start_title_buttons = false,
show_end_title_buttons = false,
title_widget = window_title
};

var back_btn = new Gtk.Button.from_icon_name (is_rtl ? "tuba-right-large-symbolic" : "tuba-left-large-symbolic") {
tooltip_text = _("Back")
};
back_btn.clicked.connect (on_exit);
headerbar.pack_start (back_btn);

ssl_icon = new Gtk.Image () {
visible = false
visible = false,
margin_start = 8
};
headerbar.pack_start (ssl_icon);

Expand Down Expand Up @@ -214,56 +207,6 @@ public class Tuba.Views.Browser : Adw.Bin {
private void on_go_forward () {
go_forward ();
}

private void on_exit () {
exit ();
}
}

const uint ANIMATION_DURATION = 250;
public override void snapshot (Gtk.Snapshot snapshot) {
var progress = this.animation.value;
if (progress == 1.0) {
base.snapshot (snapshot);
return;
}

float width = (float) this.get_width ();
snapshot.translate (Graphene.Point () {
x = width - width * (float) progress,
y = 0
});
base.snapshot (snapshot);
}

private void animation_target_cb (double value) {
this.queue_draw ();
}

private void on_animation_end () {
if (reveal_child) {
this.grab_focus ();
} else {
exit ();
animation = null; // leaks without
}
}

private bool _reveal_child = false;
public bool reveal_child {
get {
return _reveal_child;
}

set {
if (_reveal_child == value) return;
animation.value_from = animation.value;
animation.value_to = value ? 1.0 : 0.0;

_reveal_child = value;
animation.play ();
this.notify_property ("reveal-child");
}
}

~Browser () {
Expand All @@ -272,19 +215,18 @@ public class Tuba.Views.Browser : Adw.Bin {

WebKit.WebView webview;
HeaderBar headerbar;
Adw.TimedAnimation animation;

public new bool grab_focus () {
return this.webview.grab_focus ();
}

public signal void exit ();
public Browser.with_url (string url) {
load_url (url);
}

construct {
var target = new Adw.CallbackAnimationTarget (animation_target_cb);
animation = new Adw.TimedAnimation (this, 0.0, 1.0, ANIMATION_DURATION, target) {
easing = Adw.Easing.EASE_IN_OUT_QUART
};
animation.done.connect (on_animation_end);
this.content_width = 1200;
this.content_height = 1200;

this.webview = new WebKit.WebView () {
vexpand = true,
Expand Down Expand Up @@ -319,7 +261,8 @@ public class Tuba.Views.Browser : Adw.Bin {
hardware_acceleration_policy = WebKit.HardwareAccelerationPolicy.NEVER
};

webkit_settings.set_user_agent_with_application_details (Build.NAME, Build.VERSION);
if (Build.PROFILE != "development")
webkit_settings.set_user_agent_with_application_details (Build.NAME, Build.VERSION);
webview.settings = webkit_settings;

Gtk.GestureClick back_click_gesture = new Gtk.GestureClick () {
Expand Down Expand Up @@ -356,6 +299,7 @@ public class Tuba.Views.Browser : Adw.Bin {

toolbar_view.content = this.webview;
this.child = toolbar_view;
this.focus_widget = this.webview;
}

protected virtual void on_load_changed (WebKit.LoadEvent load_event) {
Expand Down Expand Up @@ -442,6 +386,6 @@ public class Tuba.Views.Browser : Adw.Bin {
}

private void on_exit () {
this.reveal_child = false;
this.force_close ();
}
}
2 changes: 1 addition & 1 deletion src/Views/Profile.vala
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ public class Tuba.Views.Profile : Views.Accounts {
open_in_browser_action.activate.connect (v => {
#if WEBKIT
if (settings.use_in_app_browser_if_available && Views.Browser.can_handle_url (profile.account.url)) {
app.main_window.open_in_app_browser_for_url (profile.account.url);
(new Views.Browser.with_url (profile.account.url)).present (app.main_window);
return;
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/Widgets/RichLabel.vala
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public class Tuba.Widgets.RichLabel : Adw.Bin {
(uri != null && Views.Browser.can_handle_uri (uri))
|| Views.Browser.can_handle_url (url)
) {
app.main_window.open_in_app_browser_for_url (url);
(new Views.Browser.with_url (url)).present (app.main_window);
return;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Widgets/Status.vala
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@
string final_url = status.formal.url ?? status.formal.account.url;
#if WEBKIT
if (settings.use_in_app_browser_if_available && Views.Browser.can_handle_url (final_url)) {
app.main_window.open_in_app_browser_for_url (final_url);
(new Views.Browser.with_url (final_url)).present (app.main_window);
return;
}
#endif
Expand Down