Browse Source

drop page progress_fraction, use status enum instead

master
yggverse 2 months ago
parent
commit
85629e9dcb
  1. 21
      src/browser/main/tab/page.rs
  2. 9
      src/browser/main/tab/page/meta.rs

21
src/browser/main/tab/page.rs

@ -119,7 +119,6 @@ impl Page { @@ -119,7 +119,6 @@ impl Page {
meta.borrow_mut().status = Some(Status::Reload);
meta.borrow_mut().title = Some(gformat!("Loading.."));
meta.borrow_mut().description = None;
meta.borrow_mut().progress_fraction = 0.0;
action_update.activate(None);
@ -139,7 +138,7 @@ impl Page { @@ -139,7 +138,7 @@ impl Page {
};
// Update
meta.borrow_mut().progress_fraction = 0.25;
meta.borrow_mut().status = Some(Status::Prepare);
meta.borrow_mut().description = Some(gformat!("Connect {host}.."));
action_update.activate(None);
@ -160,7 +159,7 @@ impl Page { @@ -160,7 +159,7 @@ impl Page {
move |result| match result {
Ok(connection) => {
// Update
meta.borrow_mut().progress_fraction = 0.50;
meta.borrow_mut().status = Some(Status::Connect);
meta.borrow_mut().description = Some(gformat!("Connected to {host}.."));
action_update.activate(None);
@ -173,7 +172,7 @@ impl Page { @@ -173,7 +172,7 @@ impl Page {
move |result| match result {
Ok(_) => {
// Update
meta.borrow_mut().progress_fraction = 0.75;
meta.borrow_mut().status = Some(Status::Request);
meta.borrow_mut().description = Some(gformat!("Request data from {host}.."));
action_update.activate(None);
@ -190,7 +189,7 @@ impl Page { @@ -190,7 +189,7 @@ impl Page {
) {
Ok(data) => {
// Format response
meta.borrow_mut().progress_fraction = 1.0;
meta.borrow_mut().status = Some(Status::Response);
meta.borrow_mut().description = Some(host);
meta.borrow_mut().title = Some(uri.path());
@ -250,10 +249,9 @@ impl Page { @@ -250,10 +249,9 @@ impl Page {
// Redirect (@TODO implement limits to auto-redirect)
"31" => {
// Update meta
meta.borrow_mut().mime = Some(Mime::TextGemini);
meta.borrow_mut().status = Some(Status::Redirect);
meta.borrow_mut().mime = Some(Mime::TextGemini);
meta.borrow_mut().title = Some(gformat!("Redirect"));
meta.borrow_mut().progress_fraction = 1.0;
// Select widget
match parts.get(3) {
@ -273,7 +271,6 @@ impl Page { @@ -273,7 +271,6 @@ impl Page {
meta.borrow_mut().status = Some(Status::Failure);
meta.borrow_mut().title = Some(gformat!("Oops"));
meta.borrow_mut().description = Some(gformat!("Status {code} not supported"));
meta.borrow_mut().progress_fraction = 1.0;
},
}
None => todo!(),
@ -286,7 +283,6 @@ impl Page { @@ -286,7 +283,6 @@ impl Page {
meta.borrow_mut().status = Some(Status::Failure);
meta.borrow_mut().title = Some(gformat!("Oops"));
meta.borrow_mut().description = Some(gformat!("Failed to read buffer data: {e}"));
meta.borrow_mut().progress_fraction = 1.0;
action_update.activate(None);
}
@ -302,7 +298,6 @@ impl Page { @@ -302,7 +298,6 @@ impl Page {
meta.borrow_mut().status = Some(Status::Failure);
meta.borrow_mut().title = Some(gformat!("Oops"));
meta.borrow_mut().description = Some(gformat!("Failed to read response: {:?}", e));
meta.borrow_mut().progress_fraction = 1.0;
action_update.activate(None);
@ -319,7 +314,6 @@ impl Page { @@ -319,7 +314,6 @@ impl Page {
meta.borrow_mut().status = Some(Status::Failure);
meta.borrow_mut().title = Some(gformat!("Oops"));
meta.borrow_mut().description = Some(gformat!("Failed to read request: {:?}", e));
meta.borrow_mut().progress_fraction = 1.0;
action_update.activate(None);
@ -336,7 +330,6 @@ impl Page { @@ -336,7 +330,6 @@ impl Page {
meta.borrow_mut().status = Some(Status::Failure);
meta.borrow_mut().title = Some(gformat!("Oops"));
meta.borrow_mut().description = Some(gformat!("Failed to connect: {:?}", e));
meta.borrow_mut().progress_fraction = 1.0;
action_update.activate(None);
}
@ -348,10 +341,10 @@ impl Page { @@ -348,10 +341,10 @@ impl Page {
*/
scheme => {
// Update
meta.borrow_mut().status = Some(Status::Failure);
meta.borrow_mut().title = Some(gformat!("Oops"));
meta.borrow_mut().description =
Some(gformat!("Protocol {scheme} not supported"));
meta.borrow_mut().progress_fraction = 1.0;
action_update.activate(None);
}
@ -394,6 +387,8 @@ impl Page { @@ -394,6 +387,8 @@ impl Page {
}
pub fn update(&self) {
// Interpret status to progress fraction
// @TODO
self.navigation.update();
// @TODO self.content.update();
}

9
src/browser/main/tab/page/meta.rs

@ -10,9 +10,13 @@ pub enum Mime { @@ -10,9 +10,13 @@ pub enum Mime {
// Internal page status (not related with gemini status code)
// Useful for widgets composition
pub enum Status {
Connect,
Failure,
Prepare,
Redirect,
Reload,
Request,
Response,
Success,
}
@ -24,10 +28,6 @@ pub struct Meta { @@ -24,10 +28,6 @@ pub struct Meta {
// Enums
pub mime: Option<Mime>,
pub status: Option<Status>,
// Useful to compose other widgets
// (e.g. navigation bar listen for this value update)
// @TODO deprecated, calculate by Status enum
pub progress_fraction: f32,
}
impl Meta {
@ -37,7 +37,6 @@ impl Meta { @@ -37,7 +37,6 @@ impl Meta {
description: None,
mime: None,
status: None,
progress_fraction: 0.0,
}
}
}

Loading…
Cancel
Save