linux下截图时添加安装截图工具的提示

This commit is contained in:
fofolee 2025-02-17 08:48:29 +08:00
parent 45b22f6115
commit e130b05033

View File

@ -13,12 +13,7 @@ const unlinkAsync = promisify(fs.unlink);
async function captureWindowsScreen() { async function captureWindowsScreen() {
const tmpFile = path.join(os.tmpdir(), `screen-${Date.now()}.png`); const tmpFile = path.join(os.tmpdir(), `screen-${Date.now()}.png`);
try { try {
await runCsharpFeature("utils", [ await runCsharpFeature("utils", ["-type", "screenshot", "-path", tmpFile]);
"-type",
"screenshot",
"-path",
tmpFile,
]);
const imageBuffer = await readFileAsync(tmpFile); const imageBuffer = await readFileAsync(tmpFile);
return `data:image/png;base64,${imageBuffer.toString("base64")}`; return `data:image/png;base64,${imageBuffer.toString("base64")}`;
} catch (error) { } catch (error) {
@ -64,7 +59,9 @@ async function captureLinuxScreen() {
await execFileAsync("which", ["import"]); await execFileAsync("which", ["import"]);
tool = "import"; tool = "import";
} catch { } catch {
console.error("未找到可用的Linux截图工具"); quickcommand.showSystemMessageBox(
"请先安装截图工具命令sudo apt install scrot"
);
return null; return null;
} }
} }
@ -86,8 +83,7 @@ async function captureLinuxScreen() {
const imageBuffer = await readFileAsync(tmpFile); const imageBuffer = await readFileAsync(tmpFile);
return `data:image/png;base64,${imageBuffer.toString("base64")}`; return `data:image/png;base64,${imageBuffer.toString("base64")}`;
} catch (error) { } catch (error) {
console.error("Linux截图失败:", error); throw error;
return null;
} finally { } finally {
await unlinkAsync(tmpFile).catch(() => {}); await unlinkAsync(tmpFile).catch(() => {});
} }
@ -95,7 +91,6 @@ async function captureLinuxScreen() {
// 统一的截图接口 // 统一的截图接口
async function captureFullScreen() { async function captureFullScreen() {
try {
if (process.platform === "darwin") { if (process.platform === "darwin") {
return await captureMacScreen(); return await captureMacScreen();
} else if (process.platform === "win32") { } else if (process.platform === "win32") {
@ -103,10 +98,6 @@ async function captureFullScreen() {
} else if (process.platform === "linux") { } else if (process.platform === "linux") {
return await captureLinuxScreen(); return await captureLinuxScreen();
} }
} catch (error) {
console.error("截图失败:", error);
}
return null;
} }
function captureAreaScreen() { function captureAreaScreen() {