fix: 增強 headless 環境支援

- 添加 QT_QPA_PLATFORM=offscreen 環境變數
- 添加 DISPLAY=:99 環境變數
- Calibre 轉換器使用 xvfb-run 包裝
- 添加 CALIBRE_USE_SYSTEM_THEME=0

確保 Qt/GTK 應用在無 display 環境下運作
This commit is contained in:
Your Name 2026-01-23 11:59:47 +08:00
parent 0d0c0025fb
commit e084d68b95
2 changed files with 29 additions and 2 deletions

View file

@ -58,6 +58,17 @@ export const properties = {
},
};
/**
* Calibre ebook-convert
*
* Headless
* Calibre Qt display
* 使 xvfb-run DISPLAY
*
* Dockerfile
* QT_QPA_PLATFORM=offscreen
* QTWEBENGINE_CHROMIUM_FLAGS="--no-sandbox"
*/
export async function convert(
filePath: string,
fileType: string,
@ -67,7 +78,16 @@ export async function convert(
execFile: ExecFileFn = execFileOriginal, // to make it mockable
): Promise<string> {
return new Promise((resolve, reject) => {
execFile("ebook-convert", [filePath, targetPath], (error, stdout, stderr) => {
// 使用 xvfb-run 包裝 ebook-convert確保在無 DISPLAY 環境下也能運作
const args = [
"-a",
"--server-args=-screen 0 1024x768x24",
"ebook-convert",
filePath,
targetPath,
];
execFile("xvfb-run", args, (error, stdout, stderr) => {
if (error) {
reject(`error: ${error}`);
}