strip system prefix from request on homepage detection

This commit is contained in:
yggverse 2024-12-11 14:59:39 +02:00
parent eb1090341f
commit 4e0797bd6e
2 changed files with 32 additions and 18 deletions

View File

@ -72,7 +72,7 @@ impl Navigation {
self.bookmark self.bookmark
.update(self.profile.bookmark.get(&request_text).is_ok()); .update(self.profile.bookmark.get(&request_text).is_ok());
self.history.update(); self.history.update();
self.home.update(self.request.uri()); self.home.update(&request_text);
self.reload.update(!request_text.is_empty()); self.reload.update(!request_text.is_empty());
self.request.update( self.request.update(
progress_fraction, progress_fraction,

View File

@ -3,7 +3,7 @@ mod widget;
use widget::Widget; use widget::Widget;
use crate::app::browser::window::action::Action as WindowAction; 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}; use std::{cell::RefCell, rc::Rc};
pub struct Home { pub struct Home {
@ -23,28 +23,26 @@ impl Home {
} }
// Actions // Actions
pub fn update(&self, uri: Option<Uri>) { pub fn update(&self, request: &str) {
// Detect sensitivity value let has_home = match Uri::parse(strip_prefix(request), UriFlags::NONE) {
let status = match &uri { Ok(uri) => {
Some(uri) => "/" != uri.path(), let has_home = "/" != uri.path();
None => false, self.uri.replace(Some(uri));
has_home
}
_ => {
self.uri.replace(None);
false
}
}; };
self.action.home.gobject.set_enabled(has_home);
// Update parsed cache self.widget.update(has_home);
self.uri.replace(uri);
// Update action status
self.action.home.gobject.set_enabled(status);
// Update child components
self.widget.update(status);
} }
// Getters // Getters
pub fn url(&self) -> Option<GString> { pub fn url(&self) -> Option<GString> {
// Build URL from parsed URI cache if let Some(uri) = &*self.uri.borrow() {
if let Some(uri) = self.uri.take() {
let scheme = uri.scheme(); let scheme = uri.scheme();
let port = uri.port(); let port = uri.port();
if let Some(host) = uri.host() { if let Some(host) = uri.host() {
@ -58,3 +56,19 @@ impl Home {
None 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
}