fix redirection handler

This commit is contained in:
yggverse 2025-01-19 10:51:58 +02:00
parent 0ff182f15d
commit acfd730c95
3 changed files with 28 additions and 37 deletions

View File

@ -219,7 +219,7 @@ impl Tab {
pub fn save_as(&self, page_position: Option<i32>) {
if let Some(item) = self.item(page_position) {
item.page.navigation.request.to_download();
item::page::load(&item.page, true);
item::page::load(&item.page, None, true);
}
}
@ -227,7 +227,7 @@ impl Tab {
pub fn source(&self, page_position: Option<i32>) {
if let Some(item) = self.item(page_position) {
item.page.navigation.request.to_source();
item::page::load(&item.page, true);
item::page::load(&item.page, None, true);
}
}
@ -269,7 +269,7 @@ impl Tab {
/// Reload page at `i32` position or selected page on `None` given
pub fn page_reload(&self, page_position: Option<i32>) {
if let Some(item) = self.item(page_position) {
item::page::load(&item.page, true);
item::page::load(&item.page, None, true);
}
}

View File

@ -73,9 +73,8 @@ impl Item {
if let Some(text) = request {
page.navigation.request.widget.entry.set_text(&text);
if is_load {
page::load(&page, true);
page::load(&page, None, true);
}
}
@ -111,7 +110,7 @@ impl Item {
if let Some(text) = request {
page.navigation.request.widget.entry.set_text(&text);
}
page::load(&page, is_history);
page::load(&page, None, is_history);
}
});

View File

@ -239,8 +239,6 @@ impl Page {
}
}
// Private helpers
// Tools
pub fn migrate(tx: &Transaction) -> Result<(), String> {
@ -301,12 +299,8 @@ fn snap_history(profile: &Profile, navigation: &Navigation, uri: Option<&Uri>) {
/// Navigate home URL (parsed from current navigation entry)
/// * this method create new history record in memory as defined in `action_page_open` action
pub fn home(page: &Rc<Page>) {
if let Some(url) = page.navigation.home.url() {
// Update navigation entry
page.navigation.request.widget.entry.set_text(&url);
// Load page (with history record)
load(page, true);
if let Some(request) = page.navigation.home.url() {
load(page, Some(request.as_str()), false);
}
}
@ -314,11 +308,7 @@ pub fn home(page: &Rc<Page>) {
/// * this method does not create new history record in memory
pub fn history_back(page: &Rc<Page>) {
if let Some(request) = page.navigation.history.back(true) {
// Update navigation entry
page.navigation.request.widget.entry.set_text(&request);
// Load page (without history record)
load(page, false);
load(page, Some(request.as_str()), false);
}
}
@ -326,16 +316,15 @@ pub fn history_back(page: &Rc<Page>) {
/// * this method does not create new history record in memory
pub fn history_forward(page: &Rc<Page>) {
if let Some(request) = page.navigation.history.forward(true) {
// Update navigation entry
page.navigation.request.widget.entry.set_text(&request);
// Load page (without history record)
load(page, false);
load(page, Some(request.as_str()), false);
}
}
/// Page load function with recursive redirection support
pub fn load(page: &Rc<Page>, is_history: bool) {
pub fn load(page: &Rc<Page>, request: Option<&str>, is_history: bool) {
use client::response::{Certificate, Failure, Input, Redirect};
use client::Response;
// Move focus out from navigation entry
page.browser_action
.escape
@ -347,8 +336,6 @@ pub fn load(page: &Rc<Page>, is_history: bool) {
// Reset widgets
page.search.unset();
page.input.unset();
// Update
page.status.replace(Status::Loading { time: now() });
page.title.replace("Loading..".into());
page.browser_action.update.activate(Some(&page.id));
@ -357,11 +344,13 @@ pub fn load(page: &Rc<Page>, is_history: bool) {
snap_history(&page.profile, &page.navigation, None); // @TODO
}
use client::response::{Certificate, Failure, Input, Redirect};
use client::Response;
let query = match request {
Some(query) => query,
None => &page.navigation.request.widget.entry.text(),
};
page.client
.request(&page.navigation.request.widget.entry.text(), {
.request(&query, {
let page = page.clone();
move |response| {
match response {
@ -457,13 +446,16 @@ pub fn load(page: &Rc<Page>, is_history: bool) {
},
Response::Redirect(this) => match this {
Redirect::Background(request) => {
println!("{}",request.as_uri());load(&page, false)
}, // @TODO
Redirect::Foreground(request) => {page.navigation
.request
.widget
.entry
.set_text(&request.as_uri().to_string())} // @TODO handle
load(&page, Some(&request.as_uri().to_string()), false)
},
Redirect::Foreground(request) => {
page.navigation
.request
.widget
.entry
.set_text(&request.as_uri().to_string());
load(&page, Some(&request.as_uri().to_string()), false);
}
}
Response::TextGemini { base, source, is_source_request } => {
let widget = if is_source_request {