handle directory route errors, use referenced Page argument, remove extra Rc ns dependencies

This commit is contained in:
yggverse 2025-02-13 19:30:50 +02:00
parent bcf4f44cfb
commit 2a1f4a89ac
4 changed files with 47 additions and 61 deletions

View file

@ -31,6 +31,7 @@ impl File {
let url = uri.to_string();
let file = File::for_uri(&url);
let page = self.page.clone();
match file.query_file_type(FileQueryInfoFlags::NONE, Some(&cancellable)) {
FileType::Directory => file.enumerate_children_async(
@ -38,7 +39,7 @@ impl File {
FileQueryInfoFlags::NONE,
Priority::DEFAULT,
Some(&cancellable),
|result| match result {
move |result| match result {
Ok(file_enumerator) => {
for entry in file_enumerator {
match entry {
@ -52,11 +53,11 @@ impl File {
FileType::Mountable => 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(
@ -64,57 +65,49 @@ impl File {
FileQueryInfoFlags::NONE,
Priority::DEFAULT,
Some(&cancellable.clone()),
{
let page = self.page.clone();
move |result| match result {
Ok(file_info) => match file_info.content_type() {
Some(content_type) => match content_type.as_str() {
"text/plain" => {
if matches!(*feature, Feature::Source) {
load_contents_async(file, cancellable, move |result| {
match result {
Ok(data) => Text::Source(uri, data).handle(page),
Err(message) => {
Status::Failure(message).handle(page)
}
}
})
} else if url.ends_with(".txt") {
load_contents_async(file, cancellable, move |result| {
match result {
Ok(data) => Text::Plain(uri, data).handle(page),
Err(message) => {
Status::Failure(message).handle(page)
}
}
});
} else {
load_contents_async(file, cancellable, move |result| {
match result {
Ok(data) => Text::Gemini(uri, data).handle(page),
Err(message) => {
Status::Failure(message).handle(page)
}
}
})
}
move |result| match result {
Ok(file_info) => match file_info.content_type() {
Some(content_type) => match content_type.as_str() {
"text/plain" => {
if matches!(*feature, Feature::Source) {
load_contents_async(file, cancellable, move |result| {
match result {
Ok(data) => Text::Source(uri, data).handle(&page),
Err(message) => Status::Failure(message).handle(&page),
}
})
} else if url.ends_with(".txt") {
load_contents_async(file, cancellable, move |result| {
match result {
Ok(data) => Text::Plain(uri, data).handle(&page),
Err(message) => Status::Failure(message).handle(&page),
}
});
} else {
load_contents_async(file, cancellable, move |result| {
match result {
Ok(data) => Text::Gemini(uri, data).handle(&page),
Err(message) => Status::Failure(message).handle(&page),
}
})
}
"image/png" | "image/gif" | "image/jpeg" | "image/webp" => {
match gtk::gdk::Texture::from_file(&file) {
Ok(texture) => Image::Bitmap(uri, texture).handle(page),
Err(e) => Status::Failure(e.to_string()).handle(page),
}
}
"image/png" | "image/gif" | "image/jpeg" | "image/webp" => {
match gtk::gdk::Texture::from_file(&file) {
Ok(texture) => Image::Bitmap(uri, texture).handle(&page),
Err(e) => Status::Failure(e.to_string()).handle(&page),
}
mime => Status::Failure(format!(
"Content type `{mime}` yet not supported"
))
.handle(page),
},
None => Status::Failure("Undetectable content type".to_string())
.handle(page),
}
mime => {
Status::Failure(format!("Content type `{mime}` yet not supported"))
.handle(&page)
}
},
Err(e) => Status::Failure(e.to_string()).handle(page),
}
None => {
Status::Failure("Undetectable content type".to_string()).handle(&page)
}
},
Err(e) => Status::Failure(e.to_string()).handle(&page),
},
),
}