mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-29 20:32:44 +08:00
linux下截图时添加安装截图工具的提示
This commit is contained in:
parent
45b22f6115
commit
e130b05033
@ -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,18 +91,13 @@ 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") {
|
return await captureWindowsScreen();
|
||||||
return await captureWindowsScreen();
|
} 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() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user