From e130b050333eebdeb0729c171ea8a20d1a633b48 Mon Sep 17 00:00:00 2001 From: fofolee Date: Mon, 17 Feb 2025 08:48:29 +0800 Subject: [PATCH] =?UTF-8?q?linux=E4=B8=8B=E6=88=AA=E5=9B=BE=E6=97=B6?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=AE=89=E8=A3=85=E6=88=AA=E5=9B=BE=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E7=9A=84=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../quickcomposer/simulate/screenCapture.js | 31 +++++++------------ 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/plugin/lib/quickcomposer/simulate/screenCapture.js b/plugin/lib/quickcomposer/simulate/screenCapture.js index 9bb7fa9..954b720 100644 --- a/plugin/lib/quickcomposer/simulate/screenCapture.js +++ b/plugin/lib/quickcomposer/simulate/screenCapture.js @@ -13,12 +13,7 @@ const unlinkAsync = promisify(fs.unlink); async function captureWindowsScreen() { const tmpFile = path.join(os.tmpdir(), `screen-${Date.now()}.png`); try { - await runCsharpFeature("utils", [ - "-type", - "screenshot", - "-path", - tmpFile, - ]); + await runCsharpFeature("utils", ["-type", "screenshot", "-path", tmpFile]); const imageBuffer = await readFileAsync(tmpFile); return `data:image/png;base64,${imageBuffer.toString("base64")}`; } catch (error) { @@ -64,7 +59,9 @@ async function captureLinuxScreen() { await execFileAsync("which", ["import"]); tool = "import"; } catch { - console.error("未找到可用的Linux截图工具"); + quickcommand.showSystemMessageBox( + "请先安装截图工具,命令:sudo apt install scrot" + ); return null; } } @@ -86,8 +83,7 @@ async function captureLinuxScreen() { const imageBuffer = await readFileAsync(tmpFile); return `data:image/png;base64,${imageBuffer.toString("base64")}`; } catch (error) { - console.error("Linux截图失败:", error); - return null; + throw error; } finally { await unlinkAsync(tmpFile).catch(() => {}); } @@ -95,18 +91,13 @@ async function captureLinuxScreen() { // 统一的截图接口 async function captureFullScreen() { - try { - if (process.platform === "darwin") { - return await captureMacScreen(); - } else if (process.platform === "win32") { - return await captureWindowsScreen(); - } else if (process.platform === "linux") { - return await captureLinuxScreen(); - } - } catch (error) { - console.error("截图失败:", error); + if (process.platform === "darwin") { + return await captureMacScreen(); + } else if (process.platform === "win32") { + return await captureWindowsScreen(); + } else if (process.platform === "linux") { + return await captureLinuxScreen(); } - return null; } function captureAreaScreen() {