delegate link with non-supported protocol to the external applictation

This commit is contained in:
yggverse 2024-09-27 17:19:12 +03:00
parent f62550b8ad
commit 6add8a54b0

View File

@ -5,7 +5,7 @@ use parser::link::Link;
use parser::plain::Plain; use parser::plain::Plain;
use gtk::{ use gtk::{
glib::{GString, Propagation, Uri}, glib::{GString, Propagation, Uri, UriFlags},
prelude::{StyleContextExt, ToVariant, WidgetExt}, prelude::{StyleContextExt, ToVariant, WidgetExt},
Align, CssProvider, Label, STYLE_PROVIDER_PRIORITY_APPLICATION, Align, CssProvider, Label, STYLE_PROVIDER_PRIORITY_APPLICATION,
}; };
@ -78,10 +78,26 @@ impl Reader {
.style_context() .style_context()
.add_provider(&css, STYLE_PROVIDER_PRIORITY_APPLICATION); .add_provider(&css, STYLE_PROVIDER_PRIORITY_APPLICATION);
// Connect actions @TODO move actions init outside // Connect actions
widget.connect_activate_link(|label, uri| { widget.connect_activate_link(|label, href| {
let _ = label.activate_action("page.open", Some(&uri.to_variant())); // Detect requested protocol
Propagation::Stop // |Proceed @TODO parse external scheme if let Ok(uri) = Uri::parse(&href, UriFlags::NONE) {
return match uri.scheme().as_str() {
"gemini" => {
label
.activate_action("page.open", Some(&uri.to_str().to_variant()))
.expect("Action `page.open` not found");
// Prevent link open in external application
Propagation::Stop
}
// Protocol not supported
_ => Propagation::Proceed,
};
}
// Delegate unparsable
Propagation::Proceed
}); });
// Result // Result