From 23973cee8f73bb8f1d50b8c5d79c6f9b646db4b7 Mon Sep 17 00:00:00 2001 From: "mula.liu" Date: Sun, 1 Nov 2026 11:59:42 +0800 Subject: [PATCH] fix(runtime): report the bundled renderer for document PDF on macOS 0.1.8 turned the renderer branch of document_pdf_component into a bare expression, so the component it built was discarded and every Mac fell through to the Pandoc row. That row requires a LaTeX or Typst engine macOS never runs, so Settings -> Runtime components read 'Pandoc PDF pipeline: missing' with no Install button, because document-pdf has no macOS install target. The two platforms now have their own function, like every other platform-specific row in the file, so the fall-through is a compile error rather than a silent one. The Pandoc half is still real on macOS - it turns a picture-bearing DOCX into HTML for the renderer - and it keeps its own row and install target. Two guards cover it: the row must stay bundled on macOS, and no row may read as missing without either an install entry or a non-external source. The second reproduces the reported symptom exactly when the fix is reverted. The matching PDF-engine error now names what the panel actually shows on each platform. --- src-tauri/src/files.rs | 10 ++++++ src-tauri/src/runtime.rs | 76 +++++++++++++++++++++++++++++++++------- 2 files changed, 73 insertions(+), 13 deletions(-) diff --git a/src-tauri/src/files.rs b/src-tauri/src/files.rs index 1a9f431..d2fae27 100644 --- a/src-tauri/src/files.rs +++ b/src-tauri/src/files.rs @@ -1255,6 +1255,16 @@ fn convert_document( let target = target.to_ascii_lowercase(); let pdf_engine = (target == "pdf").then(document_pdf_engine).flatten(); if target == "pdf" && pdf_engine.is_none() { + // Only Windows and Linux drive a PDF engine through Pandoc, and only they list + // one in Settings > Runtime components. Reaching this on macOS means the + // built-in renderer is unavailable too, so pointing at a Typst row there would + // send the user to a row that panel never shows. + #[cfg(target_os = "macos")] + return Err( + "PDF output needs the built-in document renderer or a Pandoc PDF engine (Typst, WeasyPrint, or a LaTeX engine on your PATH)." + .into(), + ); + #[cfg(not(target_os = "macos"))] return Err( "PDF output needs a Pandoc PDF engine. Install Typst from Settings > Runtime Components or add a supported engine to your PATH." .into(), diff --git a/src-tauri/src/runtime.rs b/src-tauri/src/runtime.rs index 4f8ebb5..49fcb89 100644 --- a/src-tauri/src/runtime.rs +++ b/src-tauri/src/runtime.rs @@ -172,21 +172,39 @@ fn external_component( ) } +/// The document -> PDF row. macOS prints through the bundled AppKit renderer, and the +/// renderer alone decides the row. +/// +/// Regression this shape prevents: the `if let Some(renderer)` once built this component +/// without returning it, so every Mac fell through to the Pandoc row below, which asks +/// for a LaTeX/Typst engine macOS never runs. The panel then reported "Pandoc PDF +/// pipeline" as missing and offered no install button, because `document-pdf` has no +/// install target on macOS. Splitting the two platforms into their own functions makes +/// that fall-through a compile error instead of a silent one. +/// +/// Pandoc is still genuinely needed on macOS, but only to turn a picture-bearing DOCX +/// into HTML for this renderer, and it already has its own row and install target in +/// `machine_info`. +#[cfg(target_os = "macos")] fn document_pdf_component() -> RuntimeComponent { - #[cfg(target_os = "macos")] - if let Some(renderer) = files::doc_render_bridge() { - component( - "document-pdf", - "AppKit document renderer", - "documents", - "DOCX / RTF / ODT / TXT / MD / HTML -> PDF (a DOCX with pictures also needs Pandoc, which keeps the images)", - "bundled", - true, - None, - Some(renderer), - ); - } + let renderer = files::doc_render_bridge(); + component( + "document-pdf", + "AppKit document renderer", + "documents", + "DOCX / RTF / ODT / TXT / MD / HTML -> PDF (a DOCX with pictures also needs Pandoc, which keeps the images)", + "bundled", + renderer.is_some(), + None, + renderer, + ) +} +/// Elsewhere the conversion really is Pandoc driving a PDF engine, so the row names +/// whichever engine was found and stays missing until both halves exist. Each half +/// carries its own install target, so a missing row is always fixable from the panel. +#[cfg(not(target_os = "macos"))] +fn document_pdf_component() -> RuntimeComponent { let pandoc = files::resolve_tool("pandoc"); let pdf_engine = files::document_pdf_engine(); let available = pandoc.is_some() && pdf_engine.is_some(); @@ -667,4 +685,36 @@ mod tests { let typst = windows_install_target("pdf-engine").expect("Typst should be installable"); assert_eq!(typst.package_id, "Typst.Typst"); } + + /// Regression: 0.1.8 built the bundled renderer's component inside `if let + /// Some(renderer)` but dropped the `return`, so every Mac fell through to the Pandoc + /// row. That row wants a LaTeX/Typst engine macOS never runs, so the panel read + /// "Pandoc PDF pipeline: missing" while offering no install button, because + /// `document-pdf` has no macOS install target. The two platforms now have their own + /// function, so the fall-through cannot come back silently. + #[cfg(target_os = "macos")] + #[test] + fn macos_document_pdf_is_the_bundled_renderer_not_a_pandoc_pipeline() { + let row = document_pdf_component(); + assert_eq!(row.id, "document-pdf"); + assert_eq!( + row.source, "bundled", + "macOS must report its own renderer, not the external Pandoc pipeline" + ); + assert_eq!(row.name, "AppKit document renderer"); + } + + /// A row the panel marks missing is only honest when the user can do something about + /// it: either an install button, or a built-in/system component they cannot install. + #[cfg(target_os = "macos")] + #[test] + fn a_missing_component_always_offers_a_way_forward() { + for component in machine_info_sync().components { + assert!( + component.available || component.installable || component.source != "external", + "{} is reported missing with no install entry", + component.id + ); + } + } }