implement Page::info::reset method

This commit is contained in:
yggverse 2025-03-27 01:04:56 +02:00
parent a832936054
commit 560adff490
2 changed files with 35 additions and 44 deletions

View file

@ -39,7 +39,7 @@ impl Gemini {
p.set_progress(match event { p.set_progress(match event {
// 0.1 reserved for handle begin // 0.1 reserved for handle begin
SocketClientEvent::Resolving => { SocketClientEvent::Resolving => {
i.clear_events().add_event("Resolving".to_string()); i.reset().add_event("Resolving".to_string());
0.2 0.2
} }
SocketClientEvent::Resolved => { SocketClientEvent::Resolved => {
@ -181,13 +181,7 @@ fn handle(
/// * includes commit action! /// * includes commit action!
fn update_page_info(page: &Page, event_name: &str) { fn update_page_info(page: &Page, event_name: &str) {
let mut i = page.navigation.request.info.borrow_mut(); let mut i = page.navigation.request.info.borrow_mut();
i i.add_event(event_name.to_string()).commit();
.add_event(event_name.to_string())
.set_header(None)
.set_mime(None)
.set_size(None)
.commit();
page.navigation.request.update_secondary_icon(&i) page.navigation.request.update_secondary_icon(&i)
} }
// Update socket info at the point, where the connection is active yet // Update socket info at the point, where the connection is active yet
@ -197,10 +191,10 @@ fn handle(
let mut i = page.navigation.request.info.borrow_mut(); let mut i = page.navigation.request.info.borrow_mut();
i i
.set_request(Some(uri.to_string())) .set_request(Some(uri.to_string()))
.set_socket( .set_socket(Some((
connection.socket_connection.local_address().unwrap(), connection.socket_connection.local_address().unwrap(),
connection.socket_connection.remote_address().unwrap() connection.socket_connection.remote_address().unwrap()
); )));
// * unwrap fails only on `connection.socket_connection.is_closed()` // * unwrap fails only on `connection.socket_connection.is_closed()`
// drop the panic as unexpected. // drop the panic as unexpected.
} }
@ -219,7 +213,6 @@ fn handle(
.add_event(EVENT_COMPLETED.to_string()) .add_event(EVENT_COMPLETED.to_string())
.set_header(Some(input.as_str().to_string())) .set_header(Some(input.as_str().to_string()))
.set_size(Some(input.as_bytes().len())) .set_size(Some(input.as_bytes().len()))
.set_mime(None)
.commit(); .commit();
page.navigation.request.update_secondary_icon(&i); page.navigation.request.update_secondary_icon(&i);
match input { match input {
@ -493,7 +486,6 @@ fn handle(
.add_event(EVENT_COMPLETED.to_string()) .add_event(EVENT_COMPLETED.to_string())
.set_header(Some(success.as_header_str().to_string())) .set_header(Some(success.as_header_str().to_string()))
.set_mime(Some(mime.to_string())) .set_mime(Some(mime.to_string()))
.set_size(None)
.commit(); .commit();
page.navigation.request.update_secondary_icon(&i) page.navigation.request.update_secondary_icon(&i)
}, },
@ -562,10 +554,7 @@ fn handle(
i i
.add_event(EVENT_COMPLETED.to_string()) .add_event(EVENT_COMPLETED.to_string())
.set_header(Some(redirect.as_str().to_string())) .set_header(Some(redirect.as_str().to_string()))
.set_mime(None)
.set_size(None)
.commit(); .commit();
page.navigation.request.info.replace(match redirect { page.navigation.request.info.replace(match redirect {
Redirect::Permanent { .. } => i.into_permanent_redirect(), Redirect::Permanent { .. } => i.into_permanent_redirect(),
Redirect::Temporary { .. } => i.into_temporary_redirect(), Redirect::Temporary { .. } => i.into_temporary_redirect(),
@ -590,7 +579,6 @@ fn handle(
.add_event(EVENT_COMPLETED.to_string()) .add_event(EVENT_COMPLETED.to_string())
.set_header(Some(certificate.as_str().to_string())) .set_header(Some(certificate.as_str().to_string()))
.set_size(Some(certificate.as_bytes().len())) .set_size(Some(certificate.as_bytes().len()))
.set_mime(None)
.commit(); .commit();
page.navigation.request.update_secondary_icon(&i); page.navigation.request.update_secondary_icon(&i);
// update page content widget // update page content widget
@ -631,12 +619,7 @@ fn handle(
} }
redirects.replace(0); // reset redirects.replace(0); // reset
let mut i = page.navigation.request.info.borrow_mut(); let mut i = page.navigation.request.info.borrow_mut();
i.add_event(EVENT_COMPLETED.to_string()) i.add_event(EVENT_COMPLETED.to_string()).set_request(Some(uri.to_string())).commit();
.set_request(Some(uri.to_string()))
.set_header(None)
.set_size(None)
.set_mime(None)
.commit();
page.navigation.request.update_secondary_icon(&i) page.navigation.request.update_secondary_icon(&i)
} }
} }

View file

@ -53,6 +53,22 @@ impl Info {
} }
} }
/// Take `Self`, convert it into the new `Redirect` member,
/// * return new `Self` back
fn into_redirect(self, method: redirect::Method) -> Self {
let mut this = Self::new();
this.redirect = Some(Box::new(Redirect { info: self, method }));
this
}
pub fn into_permanent_redirect(self) -> Self {
self.into_redirect(redirect::Method::Permanent)
}
pub fn into_temporary_redirect(self) -> Self {
self.into_redirect(redirect::Method::Temporary)
}
// Actions // Actions
pub fn dialog(&self, parent: &impl IsA<gtk::Widget>, profile: &Profile) { pub fn dialog(&self, parent: &impl IsA<gtk::Widget>, profile: &Profile) {
@ -66,28 +82,24 @@ impl Info {
} }
/// Mark `Self` as deprecated /// Mark `Self` as deprecated
/// * tip: usually called on page handler begin /// * tip: usually called on page load begin,
/// to prevent driver implementation mistakes
pub fn deprecate(&mut self) { pub fn deprecate(&mut self) {
self.is_deprecated = true; self.is_deprecated = true;
} }
// Setters // Setters
// * useful to update `Self` as chain of values // * update `Self` in chain
/// Take `Self`, convert it into the redirect member, /// Reset `Self` to the clean state
/// then, return new `Self` back /// * this method keeps `Redirect` value!
pub fn into_redirect(self, method: redirect::Method) -> Self { pub fn reset(&mut self) -> &mut Self {
let mut this = Self::new(); self.clear_events()
this.redirect = Some(Box::new(Redirect { info: self, method })); .set_header(None)
this .set_mime(None)
} .set_request(None)
.set_size(None)
pub fn into_permanent_redirect(self) -> Self { .set_socket(None)
self.into_redirect(redirect::Method::Permanent)
}
pub fn into_temporary_redirect(self) -> Self {
self.into_redirect(redirect::Method::Temporary)
} }
pub fn add_event(&mut self, name: String) -> &mut Self { pub fn add_event(&mut self, name: String) -> &mut Self {
@ -110,12 +122,8 @@ impl Info {
self self
} }
pub fn set_socket( pub fn set_socket(&mut self, address: Option<(SocketAddress, SocketAddress)>) -> &mut Self {
&mut self, self.socket = address.map(|(local_address, remote_address)| Socket {
local_address: SocketAddress,
remote_address: SocketAddress,
) -> &mut Self {
self.socket = Some(Socket {
local_address, local_address,
remote_address, remote_address,
}); });