From 0c4043121f31981cb37c829c65775b65eefc9a34 Mon Sep 17 00:00:00 2001 From: Amit Haridas Date: Tue, 30 Jun 2026 23:28:01 +0530 Subject: [PATCH] chore(pandoc): cache parsed major/minor version for capability checks --- src/main.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/main.js b/src/main.js index 09a7e41..88955a5 100644 --- a/src/main.js +++ b/src/main.js @@ -332,6 +332,7 @@ app.on('web-contents-created', (event, contents) => { let mainWindow; let currentFile = null; // This will now represent the active tab's file let pandocAvailable = null; // Cache pandoc availability check +let pandocVersionCache = null; // Cached parsed { major, minor } from `pandoc --version` let wordTemplatePath = null; // Path to selected Word template let templateStartPage = 3; // Which page to start inserting content (default: page 3) let rendererReady = false; // Track if renderer is ready to receive file data @@ -491,12 +492,30 @@ function checkPandocAvailability() { resolve(pandocAvailable); return; } - execFile('pandoc', ['--version'], (error, _stdout, _stderr) => { + execFile('pandoc', ['--version'], (error, stdout, _stderr) => { pandocAvailable = !error; + if (!error) { + const m = String(stdout).match(/pandoc\s+(\d+)\.(\d+)/); + pandocVersionCache = m ? { major: Number(m[1]), minor: Number(m[2]) } : { major: 0, minor: 0 }; + } else { + pandocVersionCache = { major: 0, minor: 0 }; + } resolve(pandocAvailable); }); }); } + +// Returns cached parsed pandoc version as { major, minor }. +// Falls back to {0,0} when pandoc is missing — callers must treat that as "unsupported". +function getPandocVersion() { + return pandocVersionCache || { major: 0, minor: 0 }; +} + +// --epub-embed-font was added in Pandoc 2.11. +function pandocSupportsEpubEmbedFont() { + const v = getPandocVersion(); + return v.major > 2 || (v.major === 2 && v.minor >= 11); +} function createWindow() { mainWindow = new BrowserWindow({ width: 1200,