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