Skip to content

Commit

Permalink
feat: in-app browser (#1323)
Browse files Browse the repository at this point in the history
  • Loading branch information
GeopJr authored Feb 9, 2025
1 parent b3654da commit ed6b2bb
Show file tree
Hide file tree
Showing 16 changed files with 532 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.PHONY: all install uninstall build test potfiles
PREFIX ?= /usr

clapper ?=
clapper ?= 1
# Remove the devel headerbar style:
# make release=1
release ?=
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ icu | ✅
libspelling | ❌
gstreamer + gst-plugins-good | ❌
clapper | ❌
webkitgtk | ❌

</details>

Expand Down
3 changes: 3 additions & 0 deletions data/dev.geopjr.Tuba.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@
<key name="status-aria-verbosity" type="i">
<default>3</default>
</key>
<key name="use-in-app-browser-if-available" type="b">
<default>true</default>
</key>

<key name="window-w" type="i">
<default>600</default>
Expand Down
2 changes: 2 additions & 0 deletions data/gresource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@
<file preprocess="xml-stripblanks">icons/scalable/actions/tuba-quotation-symbolic.svg</file>
<file preprocess="xml-stripblanks">icons/scalable/actions/tuba-fish-symbolic.svg</file>
<file preprocess="xml-stripblanks">icons/scalable/actions/tuba-dock-right-symbolic.svg</file>
<file preprocess="xml-stripblanks">icons/scalable/actions/tuba-channel-insecure-symbolic.svg</file>
<file preprocess="xml-stripblanks">icons/scalable/actions/tuba-view-refresh-symbolic.svg</file>
<!-- <file preprocess="xml-stripblanks">icons/scalable/actions/tuba-language-symbolic.svg</file> -->

<file>gtk/help-overlay.ui</file>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions data/icons/scalable/actions/tuba-view-refresh-symbolic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions 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">
<object class="GtkOverlay" id="main_overlay">
<child type="overlay">
<object class="TubaViewsMediaViewer" id="media_viewer">
<property name="visible">0</property>
Expand All @@ -35,4 +35,4 @@
</object>
</child>
</template>
</interface>
</interface>
13 changes: 10 additions & 3 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ endif

devel = get_option('devel')
distro = get_option('distro')
clapper_support = get_option('clapper')

# Setup configuration file
config = configuration_data()
Expand Down Expand Up @@ -78,6 +77,7 @@ asresources = gnome.compile_resources(
)

gstreamer = false
webkit = false
gtk_dep = dependency('gtk4', version: '>=4.13.4', required: true)
libadwaita_dep = dependency('libadwaita-1', version: '>=1.5', required: true)
gtksourceview_dep = dependency('gtksourceview-5', required: true, version: '>=5.6.0')
Expand All @@ -86,6 +86,7 @@ libspelling = dependency('libspelling-1', required: false)
clapper_dep = dependency('clapper-0.0', required: false, version: '>=0.8.0')
clapper_gtk_dep = dependency('clapper-gtk-0.0', required: false)
gstreamer_dep = dependency('gstreamer-1.0', required: false)
webkit_dep = dependency('webkitgtk-6.0', required: false)

if not libwebp_dep.found ()
warning('WebP support might be missing, please install webp-pixbuf-loader.')
Expand All @@ -104,13 +105,18 @@ if gstreamer_dep.found ()
gstreamer = true
endif

if clapper_support and clapper_dep.found () and clapper_dep.version().version_compare('>=0.6.0') and clapper_gtk_dep.found ()
if get_option('clapper') and clapper_dep.found () and clapper_dep.version().version_compare('>=0.6.0') and clapper_gtk_dep.found ()
add_project_arguments(['--define=CLAPPER'], language: 'vala')
if (clapper_dep.get_variable('features').split().contains('mpris'))
add_project_arguments(['--define=CLAPPER_MPRIS'], language: 'vala')
endif
endif

if get_option('in-app-browser') and webkit_dep.found ()
add_project_arguments(['--define=WEBKIT'], language: 'vala')
webkit = true
endif

sources = files()
subdir('src')

Expand All @@ -129,7 +135,8 @@ final_deps = [
meson.get_compiler('c').find_library('m', required: false),
clapper_dep,
clapper_gtk_dep,
gstreamer_dep
gstreamer_dep,
webkit_dep
]

executable(
Expand Down
1 change: 1 addition & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
option('devel', type: 'boolean', value: false)
option('distro', type: 'boolean', value: false)
option('clapper', type: 'boolean', value: true)
option('in-app-browser', type: 'boolean', value: true)
19 changes: 15 additions & 4 deletions src/API/Status/PreviewCard.vala
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public class Tuba.API.PreviewCard : Entity, Widgetizable {

public void open_special_card () {
if (this.tuba_uri == null) {
Host.open_url.begin (this.url);
open_url (this.url);
return;
}

Expand Down Expand Up @@ -206,7 +206,7 @@ public class Tuba.API.PreviewCard : Entity, Widgetizable {
return;
#endif
default:
Host.open_url.begin (this.url);
open_url (this.url);
return;
}

Expand All @@ -232,13 +232,24 @@ public class Tuba.API.PreviewCard : Entity, Widgetizable {
}
break;
default:
Host.open_url.begin (this.url);
open_url (this.url);
break;
}
})
.on_error (() => {
Host.open_url.begin (this.url);
open_url (this.url);
})
.exec ();
}

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);
return;
}
#endif

Host.open_url.begin (url);
}
}
23 changes: 23 additions & 0 deletions src/Dialogs/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ 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 @@ -165,6 +169,25 @@ 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
4 changes: 3 additions & 1 deletion src/Services/Settings.vala
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ public class Tuba.Settings : GLib.Settings {
public string last_contributors_update { get; set; }
public string[] contributors { get; set; default = {}; }
public int status_aria_verbosity { get; set; default = 3; }
public bool use_in_app_browser_if_available { get; set; }

private static string[] keys_to_init = {
"active-account",
Expand Down Expand Up @@ -189,7 +190,8 @@ public class Tuba.Settings : GLib.Settings {
"dim-trivial-notifications",
"analytics",
"update-contributors",
"status-aria-verbosity"
"status-aria-verbosity",
"use-in-app-browser-if-available"
};

public Settings () {
Expand Down
Loading

0 comments on commit ed6b2bb

Please sign in to comment.