delegate non-supported links handler to the external app

This commit is contained in:
yggverse 2024-10-14 21:06:34 +03:00
parent 918838fe96
commit bb9ddda109

View File

@ -10,7 +10,7 @@ use widget::Widget;
use adw::StyleManager; use adw::StyleManager;
use gtk::{ use gtk::{
gdk::{BUTTON_MIDDLE, BUTTON_PRIMARY}, gdk::{BUTTON_MIDDLE, BUTTON_PRIMARY},
gio::SimpleAction, gio::{AppInfo, AppLaunchContext, SimpleAction},
glib::{GString, TimeZone, Uri}, glib::{GString, TimeZone, Uri},
pango::Style, pango::Style,
prelude::{ActionExt, TextBufferExt, TextBufferExtManual, TextViewExt, ToVariant, WidgetExt}, prelude::{ActionExt, TextBufferExt, TextBufferExtManual, TextViewExt, ToVariant, WidgetExt},
@ -216,13 +216,20 @@ impl Reader {
for tag in iter.tags() { for tag in iter.tags() {
// Tag is link // Tag is link
if let Some(uri) = _links_.get(&tag) { if let Some(uri) = _links_.get(&tag) {
// Select handler by scheme // Select link handler by scheme
return match uri.scheme().as_str() { return match uri.scheme().as_str() {
"gemini" => { "gemini" => {
// Open new page // Open new page in browser
action_page_open.activate(Some(&uri.to_str().to_variant())); action_page_open.activate(Some(&uri.to_str().to_variant()));
} }
_ => (), // Protocol not supported, delegate to the external app @TODO // Scheme not supported, delegate link to the external app
_ => match AppInfo::launch_default_for_uri(
&uri.to_str(),
Some(&AppLaunchContext::new()),
) {
Ok(_) => (),
Err(e) => todo!("{e}"),
},
}; };
} }
} }