mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-03-13 06:01:21 +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 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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user