From 23cc695896be2a9dd7cad7e2395e3be9264ce4bc Mon Sep 17 00:00:00 2001 From: yggverse Date: Mon, 13 Jan 2025 03:14:56 +0200 Subject: [PATCH] try parse `Uri` from request if parsed object not provided --- src/app/browser/window/tab/item/page.rs | 16 ++++++++++++---- src/profile/history/memory/request.rs | 4 ++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/app/browser/window/tab/item/page.rs b/src/app/browser/window/tab/item/page.rs index 4ffa60e9..26c572f0 100644 --- a/src/app/browser/window/tab/item/page.rs +++ b/src/app/browser/window/tab/item/page.rs @@ -919,14 +919,22 @@ fn is_external_uri(subject: &Uri, base: &Uri) -> bool { subject.host() != base.host() } -/// Make new history record for given `navigation` object -/// * applies on shared conditions match only +/// Make new history record in related components +/// * optional [Uri](https://docs.gtk.org/glib/struct.Uri.html) reference wanted only for performance reasons, to not parse it twice fn snap_history(profile: &Profile, navigation: &Navigation, uri: Option<&Uri>) { let request = navigation.request.widget.entry.text(); // Add new record into the global memory index (used in global menu) - if let Some(uri) = uri { - profile.history.memory.request.set(uri); + // * if the `Uri` is `None`, try parse it from `request` + match uri { + Some(uri) => profile.history.memory.request.set(uri.clone()), + None => { + // this case especially useful for some routes that contain redirects + // maybe some parental optimization wanted @TODO + if let Some(uri) = navigation.request.uri() { + profile.history.memory.request.set(uri); + } + } } // Add new record into the page navigation history diff --git a/src/profile/history/memory/request.rs b/src/profile/history/memory/request.rs index 1fd64e39..726b3b94 100644 --- a/src/profile/history/memory/request.rs +++ b/src/profile/history/memory/request.rs @@ -32,12 +32,12 @@ impl Request { /// Add new record with `request` as key and `unix_timestamp` as value /// * replace with new value if `request` already exists - pub fn set(&self, uri: &Uri) { + pub fn set(&self, uri: Uri) { self.index.borrow_mut().insert( uri.to_str(), Value { unix_timestamp: DateTime::now_local().unwrap().to_unix(), - uri: uri.clone(), + uri, }, ); }