mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-03-13 06:01:21 +00:00
update ggemini api version
This commit is contained in:
parent
2cc69288fb
commit
47f254c372
@ -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,188 +188,133 @@ 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 {
|
||||
Ok(response) => {
|
||||
// Format response
|
||||
meta.borrow_mut().status = Some(Status::Response);
|
||||
meta.borrow_mut().title = uri.host();
|
||||
simple_socket_request_async(uri.clone(), move |result| match result {
|
||||
Ok(response) => {
|
||||
// Format response
|
||||
meta.borrow_mut().status = Some(Status::Connected);
|
||||
meta.borrow_mut().title = uri.host();
|
||||
|
||||
action_update.activate(Some(&id));
|
||||
action_update.activate(Some(&id));
|
||||
|
||||
match response.header().status() {
|
||||
// 10 | 11
|
||||
Some(ResponseStatus::Input)
|
||||
| Some(ResponseStatus::SensitiveInput) => {
|
||||
// Format response
|
||||
let status = Status::Input;
|
||||
let title = gformat!("Input expected");
|
||||
let description = match response.header().meta() {
|
||||
Some(meta) => match meta.to_gstring() {
|
||||
Ok(value) => value,
|
||||
Err(_) => title.clone(),
|
||||
},
|
||||
None => title.clone(),
|
||||
};
|
||||
match response.header().status() {
|
||||
// 10 | 11
|
||||
Some(ResponseStatus::Input)
|
||||
| Some(ResponseStatus::SensitiveInput) => {
|
||||
// Format response
|
||||
let status = Status::Input;
|
||||
let title = gformat!("Input expected");
|
||||
let description = match response.header().meta() {
|
||||
Some(meta) => match meta.to_gstring() {
|
||||
Ok(value) => value,
|
||||
Err(_) => title.clone(),
|
||||
},
|
||||
None => title.clone(),
|
||||
};
|
||||
|
||||
// Make input form
|
||||
match response.header().status() {
|
||||
Some(ResponseStatus::SensitiveInput) => input
|
||||
.set_new_sensitive(
|
||||
action_page_open,
|
||||
uri,
|
||||
Some(&description),
|
||||
Some(1024),
|
||||
),
|
||||
_ => input.set_new_response(
|
||||
// Make input form
|
||||
match response.header().status() {
|
||||
Some(ResponseStatus::SensitiveInput) => input
|
||||
.set_new_sensitive(
|
||||
action_page_open,
|
||||
uri,
|
||||
Some(&description),
|
||||
Some(1024),
|
||||
),
|
||||
}
|
||||
|
||||
// Update meta
|
||||
meta.borrow_mut().status = Some(status);
|
||||
meta.borrow_mut().description = Some(description);
|
||||
meta.borrow_mut().title = Some(title);
|
||||
|
||||
// Update page
|
||||
action_update.activate(Some(&id));
|
||||
_ => input.set_new_response(
|
||||
action_page_open,
|
||||
uri,
|
||||
Some(&description),
|
||||
Some(1024),
|
||||
),
|
||||
}
|
||||
// 20
|
||||
Some(ResponseStatus::Success) => match response
|
||||
.header()
|
||||
.mime()
|
||||
{
|
||||
Some(ResponseMime::TextGemini) => {
|
||||
// Update data
|
||||
match response.body().to_gstring() {
|
||||
Ok(source) => {
|
||||
meta.borrow_mut().status =
|
||||
Some(Status::Success);
|
||||
|
||||
// This content type may return parsed title
|
||||
meta.borrow_mut().title =
|
||||
content.set_text_gemini(&uri, &source);
|
||||
// Update meta
|
||||
meta.borrow_mut().status = Some(status);
|
||||
meta.borrow_mut().description = Some(description);
|
||||
meta.borrow_mut().title = Some(title);
|
||||
|
||||
// Add new history record
|
||||
let request = uri.to_str();
|
||||
// Update page
|
||||
action_update.activate(Some(&id));
|
||||
}
|
||||
// 20
|
||||
Some(ResponseStatus::Success) => match response.header().mime()
|
||||
{
|
||||
Some(ResponseMime::TextGemini) => {
|
||||
// Update data
|
||||
match response.body().to_gstring() {
|
||||
Ok(source) => {
|
||||
meta.borrow_mut().status =
|
||||
Some(Status::Success);
|
||||
|
||||
match navigation.history_current() {
|
||||
Some(current) => {
|
||||
if current != request {
|
||||
navigation.history_add(request);
|
||||
}
|
||||
// This content type may return parsed title
|
||||
meta.borrow_mut().title =
|
||||
content.set_text_gemini(&uri, &source);
|
||||
|
||||
// Add new history record
|
||||
let request = uri.to_str();
|
||||
|
||||
match navigation.history_current() {
|
||||
Some(current) => {
|
||||
if current != request {
|
||||
navigation.history_add(request);
|
||||
}
|
||||
None => navigation.history_add(request),
|
||||
}
|
||||
|
||||
// Update window components
|
||||
action_update.activate(Some(&id));
|
||||
None => navigation.history_add(request),
|
||||
}
|
||||
Err(_) => todo!(),
|
||||
|
||||
// Update window components
|
||||
action_update.activate(Some(&id));
|
||||
}
|
||||
}
|
||||
Some(ResponseMime::TextPlain) => {
|
||||
meta.borrow_mut().status = Some(Status::Success);
|
||||
|
||||
action_update.activate(Some(&id));
|
||||
todo!()
|
||||
}
|
||||
Some(ResponseMime::ImagePng)
|
||||
| Some(ResponseMime::ImageGif)
|
||||
| Some(ResponseMime::ImageJpeg)
|
||||
| Some(ResponseMime::ImageWebp) => {
|
||||
// Update meta
|
||||
meta.borrow_mut().status = Some(Status::Success);
|
||||
meta.borrow_mut().title = Some(gformat!("Picture")); // @TODO
|
||||
|
||||
// Update content
|
||||
content.set_image(); // @TODO
|
||||
|
||||
// Add new history record
|
||||
let request = uri.to_str();
|
||||
|
||||
match navigation.history_current() {
|
||||
Some(current) => {
|
||||
if current != request {
|
||||
navigation.history_add(request);
|
||||
}
|
||||
}
|
||||
None => navigation.history_add(request),
|
||||
}
|
||||
|
||||
// Update window components
|
||||
action_update.activate(Some(&id));
|
||||
}
|
||||
_ => {
|
||||
// Define common data
|
||||
let status = Status::Failure;
|
||||
let title = gformat!("Oops");
|
||||
let description =
|
||||
gformat!("Content type not supported");
|
||||
|
||||
// Update widget
|
||||
content.set_status_failure(
|
||||
title.as_str(),
|
||||
description.as_str(),
|
||||
);
|
||||
|
||||
// Update meta
|
||||
meta.borrow_mut().status = Some(status);
|
||||
meta.borrow_mut().title = Some(title);
|
||||
meta.borrow_mut().description = Some(description);
|
||||
|
||||
// Update window
|
||||
action_update.activate(Some(&id));
|
||||
}
|
||||
},
|
||||
// 32
|
||||
Some(ResponseStatus::Redirect) => {
|
||||
// Update meta
|
||||
meta.borrow_mut().status = Some(Status::Redirect);
|
||||
meta.borrow_mut().title = Some(gformat!("Redirect"));
|
||||
|
||||
action_update.activate(Some(&id));
|
||||
|
||||
// Select widget
|
||||
match response.header().meta() {
|
||||
Some(meta) => {
|
||||
let _ = content.set_text_gemini(
|
||||
&uri,
|
||||
// @TODO use template file
|
||||
&gformat!(
|
||||
"# Redirect\n\nAuto-follow disabled, click on link below to continue\n\n=> {}",
|
||||
match meta.to_gstring() {
|
||||
Ok(url) => url,
|
||||
Err(_) => todo!()
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
None => todo!(),
|
||||
Err(_) => todo!(),
|
||||
}
|
||||
}
|
||||
// @TODO
|
||||
None => {
|
||||
Some(ResponseMime::TextPlain) => {
|
||||
meta.borrow_mut().status = Some(Status::Success);
|
||||
|
||||
action_update.activate(Some(&id));
|
||||
todo!()
|
||||
}
|
||||
Some(ResponseMime::ImagePng)
|
||||
| Some(ResponseMime::ImageGif)
|
||||
| Some(ResponseMime::ImageJpeg)
|
||||
| Some(ResponseMime::ImageWebp) => {
|
||||
// Update meta
|
||||
meta.borrow_mut().status = Some(Status::Success);
|
||||
meta.borrow_mut().title = Some(gformat!("Picture")); // @TODO
|
||||
|
||||
// Update content
|
||||
content.set_image(); // @TODO
|
||||
|
||||
// Add new history record
|
||||
let request = uri.to_str();
|
||||
|
||||
match navigation.history_current() {
|
||||
Some(current) => {
|
||||
if current != request {
|
||||
navigation.history_add(request);
|
||||
}
|
||||
}
|
||||
None => navigation.history_add(request),
|
||||
}
|
||||
|
||||
// Update window components
|
||||
action_update.activate(Some(&id));
|
||||
}
|
||||
_ => {
|
||||
// Define common data
|
||||
let status = Status::Failure;
|
||||
let title = gformat!("Oops");
|
||||
let description = gformat!("Status code not supported");
|
||||
let description =
|
||||
gformat!("Content type not supported");
|
||||
|
||||
// Update widget
|
||||
content.set_status_failure(
|
||||
@ -385,28 +330,87 @@ impl Page {
|
||||
// Update window
|
||||
action_update.activate(Some(&id));
|
||||
}
|
||||
};
|
||||
}
|
||||
Err(_) => {
|
||||
// Define common data
|
||||
let status = Status::Failure;
|
||||
let title = gformat!("Oops");
|
||||
let description = gformat!("Failed to request");
|
||||
},
|
||||
// 32
|
||||
Some(ResponseStatus::Redirect) => {
|
||||
// Update meta
|
||||
meta.borrow_mut().status = Some(Status::Redirect);
|
||||
meta.borrow_mut().title = Some(gformat!("Redirect"));
|
||||
|
||||
// Update widget
|
||||
content
|
||||
.set_status_failure(title.as_str(), description.as_str());
|
||||
action_update.activate(Some(&id));
|
||||
|
||||
// Update meta
|
||||
meta.borrow_mut().status = Some(status);
|
||||
meta.borrow_mut().title = Some(title);
|
||||
meta.borrow_mut().description = Some(description);
|
||||
// Select widget
|
||||
match response.header().meta() {
|
||||
Some(meta) => {
|
||||
let _ = content.set_text_gemini(
|
||||
&uri,
|
||||
// @TODO use template file
|
||||
&gformat!(
|
||||
"# Redirect\n\nAuto-follow disabled, click on link below to continue\n\n=> {}",
|
||||
match meta.to_gstring() {
|
||||
Ok(url) => url,
|
||||
Err(_) => todo!()
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
None => todo!(),
|
||||
}
|
||||
}
|
||||
// @TODO
|
||||
None => {
|
||||
// Define common data
|
||||
let status = Status::Failure;
|
||||
let title = gformat!("Oops");
|
||||
let description = gformat!("Status code not supported");
|
||||
|
||||
// Update window
|
||||
action_update.activate(Some(&id));
|
||||
}
|
||||
},
|
||||
);
|
||||
// Update widget
|
||||
content.set_status_failure(
|
||||
title.as_str(),
|
||||
description.as_str(),
|
||||
);
|
||||
|
||||
// Update meta
|
||||
meta.borrow_mut().status = Some(status);
|
||||
meta.borrow_mut().title = Some(title);
|
||||
meta.borrow_mut().description = Some(description);
|
||||
|
||||
// Update window
|
||||
action_update.activate(Some(&id));
|
||||
}
|
||||
};
|
||||
}
|
||||
Err(reason) => {
|
||||
// Define common data
|
||||
let status = Status::Failure;
|
||||
let title = gformat!("Oops");
|
||||
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());
|
||||
|
||||
// Update meta
|
||||
meta.borrow_mut().status = Some(status);
|
||||
meta.borrow_mut().title = Some(title);
|
||||
meta.borrow_mut().description = Some(description);
|
||||
|
||||
// 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…
x
Reference in New Issue
Block a user