mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-03 01:55:27 +00:00
update ggemini api version
This commit is contained in:
parent
2cc69288fb
commit
47f254c372
2 changed files with 188 additions and 186 deletions
|
|
@ -14,10 +14,10 @@ use widget::Widget;
|
|||
use meta::{Meta, Status};
|
||||
|
||||
use gtk::{
|
||||
gio::{Cancellable, SimpleAction},
|
||||
gio::SimpleAction,
|
||||
glib::{
|
||||
gformat, uuid_string_random, GString, Priority, Regex, RegexCompileFlags, RegexMatchFlags,
|
||||
Uri, UriFlags,
|
||||
gformat, uuid_string_random, GString, Regex, RegexCompileFlags, RegexMatchFlags, Uri,
|
||||
UriFlags,
|
||||
},
|
||||
prelude::{ActionExt, StaticVariantType, ToVariant},
|
||||
Box,
|
||||
|
|
@ -188,24 +188,19 @@ impl Page {
|
|||
"gemini" => {
|
||||
// Define local NS
|
||||
use gemini::client::{
|
||||
request_async,
|
||||
response::header::{Mime as ResponseMime, Status as ResponseStatus},
|
||||
simple_socket_request_async,
|
||||
};
|
||||
|
||||
// Update page status
|
||||
meta.borrow_mut().status = Some(Status::Prepare);
|
||||
meta.borrow_mut().description = Some(gformat!("Connect.."));
|
||||
meta.borrow_mut().status = Some(Status::Connecting);
|
||||
action_update.activate(Some(&id));
|
||||
|
||||
// Begin request
|
||||
request_async(
|
||||
uri.clone(),
|
||||
Some(Cancellable::new()),
|
||||
Some(Priority::DEFAULT),
|
||||
move |result| match result {
|
||||
simple_socket_request_async(uri.clone(), move |result| match result {
|
||||
Ok(response) => {
|
||||
// Format response
|
||||
meta.borrow_mut().status = Some(Status::Response);
|
||||
meta.borrow_mut().status = Some(Status::Connected);
|
||||
meta.borrow_mut().title = uri.host();
|
||||
|
||||
action_update.activate(Some(&id));
|
||||
|
|
@ -251,9 +246,7 @@ impl Page {
|
|||
action_update.activate(Some(&id));
|
||||
}
|
||||
// 20
|
||||
Some(ResponseStatus::Success) => match response
|
||||
.header()
|
||||
.mime()
|
||||
Some(ResponseStatus::Success) => match response.header().mime()
|
||||
{
|
||||
Some(ResponseMime::TextGemini) => {
|
||||
// Update data
|
||||
|
|
@ -387,15 +380,27 @@ impl Page {
|
|||
}
|
||||
};
|
||||
}
|
||||
Err(_) => {
|
||||
Err(reason) => {
|
||||
// Define common data
|
||||
let status = Status::Failure;
|
||||
let title = gformat!("Oops");
|
||||
let description = gformat!("Failed to request");
|
||||
let description = match reason {
|
||||
gemini::client::Error::Connection => {
|
||||
gformat!("Failed to connect")
|
||||
}
|
||||
gemini::client::Error::Request => {
|
||||
gformat!("Failed to send request")
|
||||
}
|
||||
gemini::client::Error::Response => {
|
||||
gformat!("Failed to read response")
|
||||
}
|
||||
gemini::client::Error::Close => {
|
||||
gformat!("Failed to close connection")
|
||||
}
|
||||
}; // @TODO explain
|
||||
|
||||
// Update widget
|
||||
content
|
||||
.set_status_failure(title.as_str(), description.as_str());
|
||||
content.set_status_failure(title.as_str(), description.as_str());
|
||||
|
||||
// Update meta
|
||||
meta.borrow_mut().status = Some(status);
|
||||
|
|
@ -405,8 +410,7 @@ impl Page {
|
|||
// Update window
|
||||
action_update.activate(Some(&id));
|
||||
}
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
/* @TODO
|
||||
"nex" => {}
|
||||
|
|
@ -544,10 +548,10 @@ impl Page {
|
|||
pub fn progress_fraction(&self) -> Option<f64> {
|
||||
// Interpret status to progress fraction
|
||||
match self.meta.borrow().status {
|
||||
Some(Status::Prepare | Status::Reload) => Some(0.0),
|
||||
Some(Status::Connect) => Some(0.25),
|
||||
Some(Status::Request) => Some(0.50),
|
||||
Some(Status::Response) => Some(0.75),
|
||||
Some(Status::Reload) => Some(0.0),
|
||||
Some(Status::Connecting) => Some(0.25),
|
||||
Some(Status::Connected) => Some(0.50),
|
||||
// Some(Status::Response) => Some(0.75),
|
||||
Some(Status::Failure | Status::Redirect | Status::Success | Status::Input) => Some(1.0),
|
||||
_ => None,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,20 +3,18 @@ use gtk::glib::GString;
|
|||
pub enum Status {
|
||||
// SensitiveInput,
|
||||
// Complete,
|
||||
Connect,
|
||||
// Connected,
|
||||
// Connecting,
|
||||
Failure,
|
||||
Input,
|
||||
Prepare,
|
||||
Connecting,
|
||||
Connected,
|
||||
// ProxyNegotiated,
|
||||
// ProxyNegotiating,
|
||||
Redirect,
|
||||
Reload,
|
||||
Request,
|
||||
// Request,
|
||||
// Resolved,
|
||||
// Resolving,
|
||||
Response,
|
||||
// Response,
|
||||
Success,
|
||||
// TlsHandshaked,
|
||||
// TlsHandshaking,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue