mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-02-10 10:24:13 +00:00
delegate link with non-supported protocol to the external applictation
This commit is contained in:
parent
f62550b8ad
commit
6add8a54b0
@ -5,7 +5,7 @@ use parser::link::Link;
|
||||
use parser::plain::Plain;
|
||||
|
||||
use gtk::{
|
||||
glib::{GString, Propagation, Uri},
|
||||
glib::{GString, Propagation, Uri, UriFlags},
|
||||
prelude::{StyleContextExt, ToVariant, WidgetExt},
|
||||
Align, CssProvider, Label, STYLE_PROVIDER_PRIORITY_APPLICATION,
|
||||
};
|
||||
@ -78,10 +78,26 @@ impl Reader {
|
||||
.style_context()
|
||||
.add_provider(&css, STYLE_PROVIDER_PRIORITY_APPLICATION);
|
||||
|
||||
// Connect actions @TODO move actions init outside
|
||||
widget.connect_activate_link(|label, uri| {
|
||||
let _ = label.activate_action("page.open", Some(&uri.to_variant()));
|
||||
Propagation::Stop // |Proceed @TODO parse external scheme
|
||||
// Connect actions
|
||||
widget.connect_activate_link(|label, href| {
|
||||
// Detect requested protocol
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user