change meta update on page reload

This commit is contained in:
yggverse 2024-09-27 18:10:16 +03:00
parent 696fafe3f9
commit f939e427b8
2 changed files with 32 additions and 20 deletions

View File

@ -21,12 +21,17 @@ impl Title {
// Actions // Actions
pub fn update(&self, text: Option<GString>) { pub fn update(&self, text: Option<GString>) {
match text { let mut name = Vec::new();
Some(value) => self
.widget if let Some(value) = text {
.set_text(&format!("{} - {}", value, DEFAULT_TEXT)), if !value.is_empty() {
None => self.widget.set_text(DEFAULT_TEXT), name.push(value);
}; }
}
name.push(GString::from(DEFAULT_TEXT));
self.widget.set_text(&name.join(" - "));
} }
// Getters // Getters

View File

@ -93,12 +93,13 @@ impl Page {
let widget = self.widget.clone(); let widget = self.widget.clone();
// Update // Update
meta.borrow_mut().title = GString::from("Reload");
meta.borrow_mut().description = request_text.clone();
meta.borrow_mut().mime = Mime::Undefined; meta.borrow_mut().mime = Mime::Undefined;
meta.borrow_mut().description = gformat!("Loading..");
meta.borrow_mut().progress_fraction = 0.0; 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 = */ /*let _uri = */
match Uri::parse(&request_text, UriFlags::NONE) { match Uri::parse(&request_text, UriFlags::NONE) {
@ -109,15 +110,19 @@ impl Page {
todo!() todo!()
} }
"gemini" => { "gemini" => {
// Update // Get host
meta.borrow_mut().title = GString::from("Connect"); let host = match uri.host() {
meta.borrow_mut().description = match uri.host() {
Some(host) => host, Some(host) => host,
None => panic!(), 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 // Create new connection
let cancellable = Cancellable::new(); let cancellable = Cancellable::new();
@ -135,10 +140,10 @@ impl Page {
move |result| match result { move |result| match result {
Ok(connection) => { Ok(connection) => {
// Update // Update
meta.borrow_mut().title = GString::from("Request");
meta.borrow_mut().progress_fraction = 0.50; 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 // Send request
connection.output_stream().write_all_async( connection.output_stream().write_all_async(
@ -148,10 +153,10 @@ impl Page {
move |result| match result { move |result| match result {
Ok(_) => { Ok(_) => {
// Update // Update
meta.borrow_mut().title = GString::from("Response");
meta.borrow_mut().progress_fraction = 0.75; 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 // Read response
connection.input_stream().read_all_async( connection.input_stream().read_all_async(
@ -165,8 +170,8 @@ impl Page {
) { ) {
Ok(data) => { Ok(data) => {
// Format response // Format response
meta.borrow_mut().title = GString::from("Done"); // @TODO
meta.borrow_mut().progress_fraction = 1.0; meta.borrow_mut().progress_fraction = 1.0;
meta.borrow_mut().description = host;
// Parse response @TODO read bytes // Parse response @TODO read bytes
let parts = Regex::split_simple( let parts = Regex::split_simple(
@ -296,7 +301,9 @@ impl Page {
meta.borrow_mut().description = gformat!("Protocol {scheme} not supported"); meta.borrow_mut().description = gformat!("Protocol {scheme} not supported");
meta.borrow_mut().progress_fraction = 1.0; 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");
} }
} }
} }