From 6920cec90e52374b5d4de5c54f7c7e8ff103dccc Mon Sep 17 00:00:00 2001 From: yggverse Date: Tue, 26 Nov 2024 14:10:47 +0200 Subject: [PATCH] define shared add_history method #2 --- src/app/browser/window/tab/item/page.rs | 36 +++++++++++++++++-------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/src/app/browser/window/tab/item/page.rs b/src/app/browser/window/tab/item/page.rs index ba14f1b3..6bcdaab2 100644 --- a/src/app/browser/window/tab/item/page.rs +++ b/src/app/browser/window/tab/item/page.rs @@ -162,7 +162,7 @@ impl Page { /// Main loader for different protocols, that routed by scheme /// * every protocol has it own (children) method implementation - pub fn load(&self, history: bool) { + pub fn load(&self, is_history: bool) { /// Global limit to prevent infinitive redirects (ALL protocols) /// * every protocol implementation has own value checker, according to specification const DEFAULT_MAX_REDIRECT_COUNT: i8 = 10; @@ -219,15 +219,8 @@ impl Page { }; // Add history record - if history { - match self.navigation.history().current() { - Some(current) => { - if current != request { - self.navigation.history().add(request.clone(), true); - } - } - None => self.navigation.history().add(request.clone(), true), - } + if is_history { + self.add_history(Some(request.clone())); } // Update @@ -424,7 +417,28 @@ impl Page { &self.widget } - // Private helpers @TODO move outside + // Private helpers + + /// Make new history record match shared conditions + /// * use `request` value from `navigation` entry if `None` + fn add_history(&self, request: Option) { + // Get request from argument or use navigation entry value + let request = match request { + Some(value) => value, + None => self.navigation.request().widget().gobject().text(), + }; + + // Apply additional filters + if match self.navigation.history().current() { + Some(current) => current != request, + None => true, + } { + // Add new record match conditions + self.navigation.history().add(request, true) + } + } + + // @TODO move outside fn load_gemini(&self, uri: Uri) { // Stream wrapper for TLS connections fn auth(