From f939e427b82f1fb6fa44498b9fb2e8105d3182e6 Mon Sep 17 00:00:00 2001 From: yggverse Date: Fri, 27 Sep 2024 18:10:16 +0300 Subject: [PATCH] change meta update on page reload --- src/browser/header/subject/title/mod.rs | 17 +++++++----- src/browser/main/tab/page/mod.rs | 35 +++++++++++++++---------- 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/src/browser/header/subject/title/mod.rs b/src/browser/header/subject/title/mod.rs index 228e7bb5..ee0ff679 100644 --- a/src/browser/header/subject/title/mod.rs +++ b/src/browser/header/subject/title/mod.rs @@ -21,12 +21,17 @@ impl Title { // Actions pub fn update(&self, text: Option) { - match text { - Some(value) => self - .widget - .set_text(&format!("{} - {}", value, DEFAULT_TEXT)), - None => self.widget.set_text(DEFAULT_TEXT), - }; + let mut name = Vec::new(); + + if let Some(value) = text { + if !value.is_empty() { + name.push(value); + } + } + + name.push(GString::from(DEFAULT_TEXT)); + + self.widget.set_text(&name.join(" - ")); } // Getters diff --git a/src/browser/main/tab/page/mod.rs b/src/browser/main/tab/page/mod.rs index 1d91d7b7..bb2a04d7 100644 --- a/src/browser/main/tab/page/mod.rs +++ b/src/browser/main/tab/page/mod.rs @@ -93,12 +93,13 @@ impl Page { let widget = self.widget.clone(); // Update - meta.borrow_mut().title = GString::from("Reload"); - meta.borrow_mut().description = request_text.clone(); meta.borrow_mut().mime = Mime::Undefined; + meta.borrow_mut().description = gformat!("Loading.."); meta.borrow_mut().progress_fraction = 0.0; - let _ = widget.activate_action("win.update", None); + widget + .activate_action("win.update", None) + .expect("Action `win.update` not found"); /*let _uri = */ match Uri::parse(&request_text, UriFlags::NONE) { @@ -109,15 +110,19 @@ impl Page { todo!() } "gemini" => { - // Update - meta.borrow_mut().title = GString::from("Connect"); - meta.borrow_mut().description = match uri.host() { + // Get host + let host = match uri.host() { Some(host) => host, None => panic!(), }; - meta.borrow_mut().progress_fraction = 0.25; - let _ = widget.activate_action("win.update", None); + // Update + meta.borrow_mut().progress_fraction = 0.25; + meta.borrow_mut().description = gformat!("Connect {host}.."); + + widget + .activate_action("win.update", None) + .expect("Action `win.update` not found"); // Create new connection let cancellable = Cancellable::new(); @@ -135,10 +140,10 @@ impl Page { move |result| match result { Ok(connection) => { // Update - meta.borrow_mut().title = GString::from("Request"); meta.borrow_mut().progress_fraction = 0.50; + meta.borrow_mut().description = gformat!("Connected to {host}.."); - let _ = widget.activate_action("win.update", None); + widget.activate_action("win.update", None).expect("Action `win.update` not found"); // Send request connection.output_stream().write_all_async( @@ -148,10 +153,10 @@ impl Page { move |result| match result { Ok(_) => { // Update - meta.borrow_mut().title = GString::from("Response"); meta.borrow_mut().progress_fraction = 0.75; + meta.borrow_mut().description = gformat!("Request data from {host}.."); - let _ = widget.activate_action("win.update", None); + widget.activate_action("win.update", None).expect("Action `win.update` not found"); // Read response connection.input_stream().read_all_async( @@ -165,8 +170,8 @@ impl Page { ) { Ok(data) => { // Format response - meta.borrow_mut().title = GString::from("Done"); // @TODO meta.borrow_mut().progress_fraction = 1.0; + meta.borrow_mut().description = host; // Parse response @TODO read bytes let parts = Regex::split_simple( @@ -296,7 +301,9 @@ impl Page { meta.borrow_mut().description = gformat!("Protocol {scheme} not supported"); meta.borrow_mut().progress_fraction = 1.0; - let _ = widget.activate_action("win.update", None); + widget + .activate_action("win.update", None) + .expect("Action `win.update` not found"); } } }