Merge pull request #465 from presenton/libreoffice-win-fix

Libreoffice win fix
This commit is contained in:
Sudip Parajuli 2026-03-25 11:30:33 +05:45 committed by GitHub
commit a516664683
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 47 additions and 4 deletions

View file

@ -275,12 +275,18 @@ export async function isLibreOfficeInstalled(): Promise<LibreOfficeCheckResult>
// --- Step 1: check well-known paths synchronously (no exec overhead) ---
for (const candidate of getCandidatePaths()) {
if (fs.existsSync(candidate)) {
// On Windows, avoid probing with "--version" because some LibreOffice
// builds open a transient console window for this command.
if (process.platform === "win32") {
return { installed: true, path: candidate };
}
// Binary found at a known location try to get the version string.
try {
const quoted = `"${candidate}"`;
const { stdout } = await execAsync(`${quoted} --version`, {
timeout: 8_000,
windowsHide: process.platform === "win32",
windowsHide: (process.platform as string) === "win32",
});
return { installed: true, version: stdout.trim(), path: candidate };
} catch {
@ -291,10 +297,30 @@ export async function isLibreOfficeInstalled(): Promise<LibreOfficeCheckResult>
}
// --- Step 2: try the PATH-based command ---
if (process.platform === "win32") {
try {
// Use "where" for PATH detection without launching LibreOffice itself.
const { stdout } = await execAsync("where soffice.exe", {
timeout: 8_000,
windowsHide: true,
});
const firstPath = stdout
.split(/\r?\n/)
.map((line) => line.trim())
.find((line) => line.length > 0);
if (firstPath) {
return { installed: true, path: firstPath };
}
} catch {
// Keep behavior: if PATH lookup fails, report not installed.
}
return { installed: false };
}
try {
const { stdout } = await execAsync("soffice --version", {
timeout: 8_000,
windowsHide: process.platform === "win32",
windowsHide: (process.platform as string) === "win32",
});
// Found via PATH record the bare command name as the path so callers
// can pass it directly to subprocess invocations.
@ -400,4 +426,4 @@ export async function checkLibreOfficeBeforeWindow(
// Always proceed never block the app
return true;
}
}

View file

@ -26,7 +26,23 @@ def _get_soffice_binary() -> str:
environment variable. Falling back to the bare ``"soffice"`` command keeps
Docker / server deployments working unchanged.
"""
return os.environ.get("SOFFICE_PATH") or "soffice"
configured = os.environ.get("SOFFICE_PATH")
if configured:
return configured
return "soffice.exe" if os.name == "nt" else "soffice"
def _windows_hidden_subprocess_kwargs() -> Dict[str, object]:
"""Return subprocess kwargs that suppress Windows console windows."""
if os.name != "nt":
return {}
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
return {
"creationflags": getattr(subprocess, "CREATE_NO_WINDOW", 0),
"startupinfo": startupinfo,
}
PPTX_SLIDES_ROUTER = APIRouter(prefix="/pptx-slides", tags=["PPTX Slides"])
@ -596,6 +612,7 @@ async def _convert_pptx_to_pdf(pptx_path: str, temp_dir: str) -> str:
text=True,
timeout=500,
env=env,
**_windows_hidden_subprocess_kwargs(),
)
print(f"LibreOffice PDF conversion output: {result.stdout}")