mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-15 17:20:08 +00:00
strip system prefix from request on homepage detection
This commit is contained in:
parent
eb1090341f
commit
4e0797bd6e
@ -72,7 +72,7 @@ impl Navigation {
|
||||
self.bookmark
|
||||
.update(self.profile.bookmark.get(&request_text).is_ok());
|
||||
self.history.update();
|
||||
self.home.update(self.request.uri());
|
||||
self.home.update(&request_text);
|
||||
self.reload.update(!request_text.is_empty());
|
||||
self.request.update(
|
||||
progress_fraction,
|
||||
|
@ -3,7 +3,7 @@ mod widget;
|
||||
use widget::Widget;
|
||||
|
||||
use crate::app::browser::window::action::Action as WindowAction;
|
||||
use gtk::glib::{gformat, GString, Uri};
|
||||
use gtk::glib::{gformat, GString, Uri, UriFlags};
|
||||
use std::{cell::RefCell, rc::Rc};
|
||||
|
||||
pub struct Home {
|
||||
@ -23,28 +23,26 @@ impl Home {
|
||||
}
|
||||
|
||||
// Actions
|
||||
pub fn update(&self, uri: Option<Uri>) {
|
||||
// Detect sensitivity value
|
||||
let status = match &uri {
|
||||
Some(uri) => "/" != uri.path(),
|
||||
None => false,
|
||||
pub fn update(&self, request: &str) {
|
||||
let has_home = match Uri::parse(strip_prefix(request), UriFlags::NONE) {
|
||||
Ok(uri) => {
|
||||
let has_home = "/" != uri.path();
|
||||
self.uri.replace(Some(uri));
|
||||
has_home
|
||||
}
|
||||
_ => {
|
||||
self.uri.replace(None);
|
||||
false
|
||||
}
|
||||
};
|
||||
|
||||
// Update parsed cache
|
||||
self.uri.replace(uri);
|
||||
|
||||
// Update action status
|
||||
self.action.home.gobject.set_enabled(status);
|
||||
|
||||
// Update child components
|
||||
self.widget.update(status);
|
||||
self.action.home.gobject.set_enabled(has_home);
|
||||
self.widget.update(has_home);
|
||||
}
|
||||
|
||||
// Getters
|
||||
|
||||
pub fn url(&self) -> Option<GString> {
|
||||
// Build URL from parsed URI cache
|
||||
if let Some(uri) = self.uri.take() {
|
||||
if let Some(uri) = &*self.uri.borrow() {
|
||||
let scheme = uri.scheme();
|
||||
let port = uri.port();
|
||||
if let Some(host) = uri.host() {
|
||||
@ -58,3 +56,19 @@ impl Home {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
// Tools
|
||||
|
||||
fn strip_prefix(request: &str) -> &str {
|
||||
let request = match request.strip_prefix("source:") {
|
||||
Some(postfix) => postfix,
|
||||
None => request,
|
||||
};
|
||||
|
||||
let request = match request.strip_prefix("download:") {
|
||||
Some(postfix) => postfix,
|
||||
None => request,
|
||||
};
|
||||
|
||||
request
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user