diff --git a/src/app/browser/window/tab/item/page/navigation.rs b/src/app/browser/window/tab/item/page/navigation.rs index 8042e366..6278be2d 100644 --- a/src/app/browser/window/tab/item/page/navigation.rs +++ b/src/app/browser/window/tab/item/page/navigation.rs @@ -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, diff --git a/src/app/browser/window/tab/item/page/navigation/home.rs b/src/app/browser/window/tab/item/page/navigation/home.rs index 39b9a41c..ab4ce799 100644 --- a/src/app/browser/window/tab/item/page/navigation/home.rs +++ b/src/app/browser/window/tab/item/page/navigation/home.rs @@ -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) { - // 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 { - // 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 +}