Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions packages/desktop-linux/src/screenshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { findOnPath } from "./util.js";
const SCREENSHOT_TIMEOUT_MS = 20_000;
const PNG_MAGIC = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);

export type ScreenshotTool = "import" | "xwd" | "scrot";
export type ScreenshotTool = "maim" | "import" | "xwd" | "scrot";

export interface ScreenshotStep {
cmd: string;
Expand All @@ -31,6 +31,9 @@ export interface ScreenshotResult {
export function detectScreenshotTool(
env: EnvLike = process.env,
): ScreenshotTool | null {
if (findOnPath("maim", env) !== null) {
return "maim";
}
if (findOnPath("import", env) !== null) {
return "import";
}
Expand All @@ -51,11 +54,19 @@ export function buildScreenshotCommand(
): ScreenshotStep[] {
parseDisplayNumber(display);
switch (tool) {
case "maim":
return [
{
cmd: "maim",
args: [outPath],
requiresDisplayEnv: true,
},
];
case "import":
return [
{
cmd: "import",
args: ["-display", display, "-window", "root", outPath],
args: ["-silent", "-display", display, "-window", "root", outPath],
},
];
case "xwd": {
Expand Down Expand Up @@ -119,7 +130,7 @@ export async function screenshot(
if (tool === null) {
throw new Error(
"No screenshot tool found on PATH. Install one of: " +
"imagemagick (provides `import` and `convert`), " +
"maim (preferred), imagemagick (provides `import` and `convert`), " +
"xorg-xwd (`xwd`, combined with imagemagick `convert`), or scrot.",
);
}
Expand Down
12 changes: 11 additions & 1 deletion packages/desktop-linux/test/builders.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,21 @@ describe("buildVncArgs", () => {
});

describe("buildScreenshotCommand", () => {
it("builds the maim command, which targets the display via the DISPLAY env", () => {
expect(buildScreenshotCommand("maim", ":92", "/tmp/out.png")).toEqual([
{
cmd: "maim",
args: ["/tmp/out.png"],
requiresDisplayEnv: true,
},
]);
});

it("builds the import command", () => {
expect(buildScreenshotCommand("import", ":92", "/tmp/out.png")).toEqual([
{
cmd: "import",
args: ["-display", ":92", "-window", "root", "/tmp/out.png"],
args: ["-silent", "-display", ":92", "-window", "root", "/tmp/out.png"],
},
]);
});
Expand Down
Loading