Recover from 'pdf is damaged' err and update deps

This commit is contained in:
itsjunetime
2024-08-15 18:15:50 -06:00
parent f0c0e06c1c
commit 4296c92d7d
4 changed files with 108 additions and 94 deletions
+14 -7
View File
@@ -197,13 +197,20 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
},
Some(renderer_msg) = tui_rx.next() => {
match renderer_msg {
Ok(RenderInfo::NumPages(num)) => {
tui.set_n_pages(num);
to_converter.send(ConverterMsg::NumPages(num))?;
},
Ok(RenderInfo::Page(info)) => {
tui.got_num_results_on_page(info.page, info.search_results);
to_converter.send(ConverterMsg::AddImg(info))?;
// if an Ok comes through, we know the error has been resolved ('cause it kinda
// bails whenever we run into an error) so just clear it
Ok(render_info) => {
match render_info {
RenderInfo::NumPages(num) => {
tui.set_n_pages(num);
to_converter.send(ConverterMsg::NumPages(num))?;
},
RenderInfo::Page(info) => {
tui.got_num_results_on_page(info.page, info.search_results);
to_converter.send(ConverterMsg::AddImg(info))?;
},
}
tui.set_bottom_msg(None);
},
Err(e) => tui.show_error(e),
}
+15 -1
View File
@@ -90,7 +90,21 @@ pub fn start_rendering(
'reload: loop {
let doc = match Document::from_file(&path, None) {
Err(e) => return sender.send(Err(RenderError::Doc(e))),
Err(e) => {
// if there's an error, tell the main loop
sender.send(Err(RenderError::Doc(e)))?;
// then wait for a reload notif (since what probably happened is that the file was
// temporarily removed to facilitate a save or something like that)
while let Ok(msg) = receiver.recv() {
// and once that comes, just try to reload again
if let RenderNotif::Reload = msg {
continue 'reload;
}
}
// if that while let Ok ever fails and we exit out of that loop, the main thread is
// done, so we're fine to just return
return Ok(());
}
Ok(d) => d
};
+3 -3
View File
@@ -37,7 +37,7 @@ struct LastRender {
}
#[derive(Default)]
enum BottomMessage {
pub enum BottomMessage {
#[default]
Help,
SearchResults(String),
@@ -45,7 +45,7 @@ enum BottomMessage {
Input(InputCommand)
}
enum InputCommand {
pub enum InputCommand {
GoToPage(usize),
Search(String)
}
@@ -503,7 +503,7 @@ impl Tui {
// We have `msg` as optional so that if they reset it to none, it'll replace it with
// `prev_msg`, but if they reset it to something else, it'll put the current thing in prev_msg
fn set_bottom_msg(&mut self, msg: Option<BottomMessage>) {
pub fn set_bottom_msg(&mut self, msg: Option<BottomMessage>) {
match msg {
Some(mut msg) => {
std::mem::swap(&mut self.bottom_msg, &mut msg);