From 6f038539d6ea1c30c2a981c2939c29428307bfbd Mon Sep 17 00:00:00 2001 From: yggverse Date: Wed, 11 Dec 2024 15:50:04 +0200 Subject: [PATCH] move strip_prefix getter to request api --- .../browser/window/tab/item/page/navigation.rs | 2 +- .../window/tab/item/page/navigation/home.rs | 18 +----------------- .../window/tab/item/page/navigation/request.rs | 16 +++++++++++++++- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/app/browser/window/tab/item/page/navigation.rs b/src/app/browser/window/tab/item/page/navigation.rs index 6278be2d..985ce2c8 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(&request_text); + self.home.update(&self.request.strip_prefix()); 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 ab4ce799..c24a997c 100644 --- a/src/app/browser/window/tab/item/page/navigation/home.rs +++ b/src/app/browser/window/tab/item/page/navigation/home.rs @@ -24,7 +24,7 @@ impl Home { // Actions pub fn update(&self, request: &str) { - let has_home = match Uri::parse(strip_prefix(request), UriFlags::NONE) { + let has_home = match Uri::parse(request, UriFlags::NONE) { Ok(uri) => { let has_home = "/" != uri.path(); self.uri.replace(Some(uri)); @@ -56,19 +56,3 @@ 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 -} diff --git a/src/app/browser/window/tab/item/page/navigation/request.rs b/src/app/browser/window/tab/item/page/navigation/request.rs index 9296e326..49643bc8 100644 --- a/src/app/browser/window/tab/item/page/navigation/request.rs +++ b/src/app/browser/window/tab/item/page/navigation/request.rs @@ -5,7 +5,7 @@ use widget::Widget; use crate::app::browser::{window::tab::item::Action as TabAction, Action as BrowserAction}; use gtk::{ - glib::{Uri, UriFlags}, + glib::{GString, Uri, UriFlags}, prelude::EditableExt, }; use sqlite::Transaction; @@ -96,6 +96,20 @@ impl Request { _ => None, } } + + pub fn strip_prefix(&self) -> GString { + let mut text = self.widget.entry.text(); + + if let Some(postfix) = text.strip_prefix("source:") { + text = postfix.into() + }; + + if let Some(postfix) = text.strip_prefix("download:") { + text = postfix.into() + }; + + text + } } // Tools