mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 17:15:28 +00:00
delegate home url parse to request component
This commit is contained in:
parent
eae35d5ab8
commit
137301200f
8 changed files with 56 additions and 88 deletions
|
|
@ -106,7 +106,7 @@ impl Request {
|
|||
|
||||
/// Try get current request value as [Uri](https://docs.gtk.org/glib/struct.Uri.html)
|
||||
/// * `strip_prefix` on parse
|
||||
pub fn as_uri(&self) -> Option<Uri> {
|
||||
pub fn uri(&self) -> Option<Uri> {
|
||||
match Uri::parse(&strip_prefix(self.widget.entry.text()), UriFlags::NONE) {
|
||||
Ok(uri) => Some(uri),
|
||||
_ => None,
|
||||
|
|
@ -119,6 +119,24 @@ impl Request {
|
|||
strip_prefix(self.widget.entry.text())
|
||||
}
|
||||
|
||||
/// Parse home [Uri](https://docs.gtk.org/glib/struct.Uri.html) for self
|
||||
pub fn home(&self) -> Option<GString> {
|
||||
match self.uri() {
|
||||
Some(uri) => {
|
||||
let scheme = uri.scheme().replace("titan", "gemini");
|
||||
let port = uri.port();
|
||||
uri.host().map(|host| {
|
||||
if port.is_positive() {
|
||||
gformat!("{scheme}://{host}:{port}/")
|
||||
} else {
|
||||
gformat!("{scheme}://{host}/")
|
||||
}
|
||||
})
|
||||
}
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Get request value in `download:` format
|
||||
pub fn download(&self) -> GString {
|
||||
gformat!("download:{}", self.strip_prefix())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue