mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-02 17:45:28 +00:00
handle directory route errors, use referenced Page argument, remove extra Rc ns dependencies
This commit is contained in:
parent
bcf4f44cfb
commit
2a1f4a89ac
4 changed files with 47 additions and 61 deletions
|
|
@ -31,6 +31,7 @@ impl File {
|
||||||
|
|
||||||
let url = uri.to_string();
|
let url = uri.to_string();
|
||||||
let file = File::for_uri(&url);
|
let file = File::for_uri(&url);
|
||||||
|
let page = self.page.clone();
|
||||||
|
|
||||||
match file.query_file_type(FileQueryInfoFlags::NONE, Some(&cancellable)) {
|
match file.query_file_type(FileQueryInfoFlags::NONE, Some(&cancellable)) {
|
||||||
FileType::Directory => file.enumerate_children_async(
|
FileType::Directory => file.enumerate_children_async(
|
||||||
|
|
@ -38,7 +39,7 @@ impl File {
|
||||||
FileQueryInfoFlags::NONE,
|
FileQueryInfoFlags::NONE,
|
||||||
Priority::DEFAULT,
|
Priority::DEFAULT,
|
||||||
Some(&cancellable),
|
Some(&cancellable),
|
||||||
|result| match result {
|
move |result| match result {
|
||||||
Ok(file_enumerator) => {
|
Ok(file_enumerator) => {
|
||||||
for entry in file_enumerator {
|
for entry in file_enumerator {
|
||||||
match entry {
|
match entry {
|
||||||
|
|
@ -52,11 +53,11 @@ impl File {
|
||||||
FileType::Mountable => todo!(),
|
FileType::Mountable => todo!(),
|
||||||
_ => todo!(),
|
_ => todo!(),
|
||||||
},
|
},
|
||||||
Err(_) => todo!(),
|
Err(e) => Status::Failure(e.to_string()).handle(&page),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(_) => todo!(),
|
Err(e) => Status::Failure(e.to_string()).handle(&page),
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
_ => file.clone().query_info_async(
|
_ => file.clone().query_info_async(
|
||||||
|
|
@ -64,8 +65,6 @@ impl File {
|
||||||
FileQueryInfoFlags::NONE,
|
FileQueryInfoFlags::NONE,
|
||||||
Priority::DEFAULT,
|
Priority::DEFAULT,
|
||||||
Some(&cancellable.clone()),
|
Some(&cancellable.clone()),
|
||||||
{
|
|
||||||
let page = self.page.clone();
|
|
||||||
move |result| match result {
|
move |result| match result {
|
||||||
Ok(file_info) => match file_info.content_type() {
|
Ok(file_info) => match file_info.content_type() {
|
||||||
Some(content_type) => match content_type.as_str() {
|
Some(content_type) => match content_type.as_str() {
|
||||||
|
|
@ -73,49 +72,43 @@ impl File {
|
||||||
if matches!(*feature, Feature::Source) {
|
if matches!(*feature, Feature::Source) {
|
||||||
load_contents_async(file, cancellable, move |result| {
|
load_contents_async(file, cancellable, move |result| {
|
||||||
match result {
|
match result {
|
||||||
Ok(data) => Text::Source(uri, data).handle(page),
|
Ok(data) => Text::Source(uri, data).handle(&page),
|
||||||
Err(message) => {
|
Err(message) => Status::Failure(message).handle(&page),
|
||||||
Status::Failure(message).handle(page)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} else if url.ends_with(".txt") {
|
} else if url.ends_with(".txt") {
|
||||||
load_contents_async(file, cancellable, move |result| {
|
load_contents_async(file, cancellable, move |result| {
|
||||||
match result {
|
match result {
|
||||||
Ok(data) => Text::Plain(uri, data).handle(page),
|
Ok(data) => Text::Plain(uri, data).handle(&page),
|
||||||
Err(message) => {
|
Err(message) => Status::Failure(message).handle(&page),
|
||||||
Status::Failure(message).handle(page)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
load_contents_async(file, cancellable, move |result| {
|
load_contents_async(file, cancellable, move |result| {
|
||||||
match result {
|
match result {
|
||||||
Ok(data) => Text::Gemini(uri, data).handle(page),
|
Ok(data) => Text::Gemini(uri, data).handle(&page),
|
||||||
Err(message) => {
|
Err(message) => Status::Failure(message).handle(&page),
|
||||||
Status::Failure(message).handle(page)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"image/png" | "image/gif" | "image/jpeg" | "image/webp" => {
|
"image/png" | "image/gif" | "image/jpeg" | "image/webp" => {
|
||||||
match gtk::gdk::Texture::from_file(&file) {
|
match gtk::gdk::Texture::from_file(&file) {
|
||||||
Ok(texture) => Image::Bitmap(uri, texture).handle(page),
|
Ok(texture) => Image::Bitmap(uri, texture).handle(&page),
|
||||||
Err(e) => Status::Failure(e.to_string()).handle(page),
|
Err(e) => Status::Failure(e.to_string()).handle(&page),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mime => Status::Failure(format!(
|
mime => {
|
||||||
"Content type `{mime}` yet not supported"
|
Status::Failure(format!("Content type `{mime}` yet not supported"))
|
||||||
))
|
.handle(&page)
|
||||||
.handle(page),
|
}
|
||||||
},
|
},
|
||||||
None => Status::Failure("Undetectable content type".to_string())
|
None => {
|
||||||
.handle(page),
|
Status::Failure("Undetectable content type".to_string()).handle(&page)
|
||||||
},
|
|
||||||
Err(e) => Status::Failure(e.to_string()).handle(page),
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Err(e) => Status::Failure(e.to_string()).handle(&page),
|
||||||
|
},
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,4 @@
|
||||||
use super::Page;
|
|
||||||
use gtk::{gdk::Texture, glib::Uri};
|
use gtk::{gdk::Texture, glib::Uri};
|
||||||
use std::rc::Rc;
|
|
||||||
|
|
||||||
pub enum Image {
|
pub enum Image {
|
||||||
Bitmap(Uri, Texture),
|
Bitmap(Uri, Texture),
|
||||||
|
|
@ -8,7 +6,7 @@ pub enum Image {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Image {
|
impl Image {
|
||||||
pub fn handle(&self, page: Rc<Page>) {
|
pub fn handle(&self, page: &super::Page) {
|
||||||
let uri = match self {
|
let uri = match self {
|
||||||
Self::Bitmap(uri, texture) => {
|
Self::Bitmap(uri, texture) => {
|
||||||
page.content.to_image(texture);
|
page.content.to_image(texture);
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,9 @@
|
||||||
use super::Page;
|
|
||||||
use std::rc::Rc;
|
|
||||||
|
|
||||||
pub enum Status {
|
pub enum Status {
|
||||||
Failure(String),
|
Failure(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Status {
|
impl Status {
|
||||||
pub fn handle(&self, page: Rc<Page>) {
|
pub fn handle(&self, page: &super::Page) {
|
||||||
let (message, widget) = match self {
|
let (message, widget) = match self {
|
||||||
Self::Failure(message) => (message, page.content.to_status_failure()),
|
Self::Failure(message) => (message, page.content.to_status_failure()),
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,4 @@
|
||||||
use super::Page;
|
|
||||||
use gtk::glib::Uri;
|
use gtk::glib::Uri;
|
||||||
use std::rc::Rc;
|
|
||||||
|
|
||||||
pub enum Text {
|
pub enum Text {
|
||||||
Gemini(Uri, String),
|
Gemini(Uri, String),
|
||||||
|
|
@ -9,7 +7,7 @@ pub enum Text {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Text {
|
impl Text {
|
||||||
pub fn handle(&self, page: Rc<Page>) {
|
pub fn handle(&self, page: &super::Page) {
|
||||||
let (uri, widget) = match self {
|
let (uri, widget) = match self {
|
||||||
Self::Gemini(uri, data) => (uri, page.content.to_text_gemini(uri, data)),
|
Self::Gemini(uri, data) => (uri, page.content.to_text_gemini(uri, data)),
|
||||||
Self::Plain(uri, data) => (uri, page.content.to_text_plain(data)),
|
Self::Plain(uri, data) => (uri, page.content.to_text_plain(data)),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue