Show native preview during durable file publication

This commit is contained in:
gloamxun committed 2026-11-19 17:19:11 +08:00
1 parent 75d156f0cf
commit eda01fb689
5 files changed
+439 -58

No files matched your search

+33
View File
@@ -85,6 +85,32 @@ pub enum CompileStage {
/// schedule compilation after the callback returns, rather than recursing.
pub trait CompileObserver: Send + Sync {
fn stage(&self, revision: u64, stage: CompileStage) -> Result<(), String>;
/// Called for a completed native draft before its staged files are synced
/// and installed. The caller can display these pages provisionally. The
/// compile result determines whether this revision actually published.
fn draft_ready(&self, _draft: DraftPreview<'_>) -> Result<(), String> {
Ok(())
}
}
/// The same revision's native preview, available before artifact publication.
pub struct DraftPreview<'a> {
document: &'a CompiledDocument,
}
impl DraftPreview<'_> {
pub fn preview_since(&self, visible_revision: Option<u64>) -> Result<PreviewUpdate, String> {
self.document.preview_since(visible_revision)
}
pub fn execution_steps(&self) -> usize {
self.document.execution.execution.steps
}
pub fn entry_checkpoint_work(&self) -> &EntryCheckpointWork {
&self.document.entry_checkpoint_work
}
}
fn notify(
request: &CompileRequest,
@@ -1155,6 +1181,13 @@ impl CompileJob {
CompileStage::ReadyToPublish,
&cancellation,
)?;
if checkpoints.is_some()
&& let Some(observer) = &request.observer
{
let observed = observer.draft_ready(DraftPreview { document: &result });
check(&cancellation)?;
observed?;
}
evidence.phase = AttemptPhase::Publishing;
let expose = || {
*self