ElyPDF: failed reads stay unread until an edit; a save stales a signature read (P-08)

This commit is contained in:
ZacharyZhang-NY committed 2026-10-09 23:26:40 -04:00
1 parent 547dbf2cc5
commit bd7bc46d8c
9 files changed
+180 -23

No files matched your search

+13 -4
View File
@@ -17,7 +17,7 @@ use ely_platform::trust::{self, Trust};
use gpui::{AnyElement, App, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement, ParentElement as _, StatefulInteractiveElement as _, Styled as _, TaskExt as _, Window, div};
use crate::redact::beside;
use crate::view::PdfView;
use crate::view::{PdfView, Unread};
use crate::viewer::Viewer;
/// A signature field and the system's word on its certificate.
@@ -47,11 +47,13 @@ pub struct Signer {
impl PdfView {
/// Reads and checks the signatures of the file at `path`.
pub fn ask_signatures(&mut self, path: PathBuf, cx: &mut Context<Self>) {
if self.signatures.as_ref().is_some_and(|(read, _)| *read == path) || self.reading_signatures {
let failed = self.unread.contains(&Unread::Signatures(path.clone()));
if self.signatures.as_ref().is_some_and(|(read, _)| *read == path) || self.reading_signatures || failed {
return;
}
self.reading_signatures = true;
let (doc, asked) = (self.doc, path.clone());
// A save in between makes this read stale: dropped.
let (doc, asked, saves) = (self.doc, path.clone(), self.saves);
self.off(
move |worker| {
let fields = worker.signatures(doc, &path)?;
@@ -64,9 +66,16 @@ impl PdfView {
},
move |view, read: io::Result<Vec<Checked>>, cx| {
view.reading_signatures = false;
if view.saves != saves {
log::info!("pdf: a signature read from before a save is dropped");
return cx.notify();
}
match read {
Ok(read) => view.signatures = Some((asked, read)),
Err(error) => view.fail("reading signatures", &error, cx),
Err(error) => {
view.unread.insert(Unread::Signatures(asked));
view.fail("reading signatures", &error, cx)
}
}
cx.notify();
},