Skip to content
Open
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
29 changes: 29 additions & 0 deletions apps/extension/e2e/capture.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import { expect, test } from "./fixtures";

const BASE_URL = "http://localhost:8934";
const SHOT_QA_BIN = process.env.SHOT_QA_BIN ?? "/tmp/opencapture-target/debug/shot-qa";
// What the download stub in the restore test records, declared so the
// assertions can read it back without casting at every call site.
declare global {
// eslint-disable-next-line no-var
var __downloads: string[];
}
// A real, small PNG already in the repo — no synthetic fixture needed.
const LOGO_FIXTURE_PATH = join(dirname(fileURLToPath(import.meta.url)), "..", "public", "icons", "icon48.png");

Expand Down Expand Up @@ -46,6 +52,7 @@ test("popup renders its controls", async ({ context, extensionId }) => {
await page.goto(`chrome-extension://${extensionId}/popup.html`);
await expect(page.locator("#captureFullPage")).toBeVisible();
await expect(page.locator("#captureVisible")).toBeVisible();
await expect(page.locator("#savePng")).toBeVisible();
await page.close();
});

Expand Down Expand Up @@ -2372,10 +2379,32 @@ test("popup: restores report/preview/enabled buttons after closing and reopening
const previewSrc = await popup.locator("#preview").getAttribute("src");
expect(previewSrc).toMatch(/^blob:/);
await expect(popup.locator("#exportPdf")).toBeEnabled();
await expect(popup.locator("#savePng")).toBeEnabled();
await expect(popup.locator("#copyToClipboard")).toBeEnabled();
await expect(popup.locator("#openEditor")).toBeEnabled();
await expect(popup.locator("#status")).toHaveText("Opened in editor — crop, annotate, then choose PNG or PDF to save.");

// And the PNG button saves from this restored state, the same way the
// format panel's PNG answer does — counted at the download call rather
// than in a folder, like too-long.spec.ts does.
await serviceWorker.evaluate(() => {
globalThis.__downloads = [];
const real = chrome.downloads.download;
chrome.downloads.download = ((options: chrome.downloads.DownloadOptions) => {
globalThis.__downloads.push(options.filename ?? "");
return real(options);
}) as typeof chrome.downloads.download;
});
await popup.click("#savePng");
await expect
.poll(async () => serviceWorker.evaluate(() => globalThis.__downloads.length), { timeout: 60_000 })
.toBeGreaterThan(0);
expect(await serviceWorker.evaluate(() => globalThis.__downloads.every((name) => name.endsWith(".png")))).toBe(true);
await serviceWorker.evaluate(() => {
// @ts-expect-error test-only stub installed above
delete globalThis.__downloads;
});

await popup.close();

// Reset for any other test that happens to run in this same worker
Expand Down
4 changes: 4 additions & 0 deletions apps/extension/e2e/too-long.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ test("a capture too long to finish is left to the user, not downloaded or opened
console.log("TOO LONG downloads: " + JSON.stringify(saved));
expect(saved.every((name) => name.endsWith(".png"))).toBe(true);
expect(saved.length).toBe(report.output_image_count);
// Both places the count now shows agree with what was written: the status
// line, and the button that names how many files its click will produce.
await expect(popup3.locator("#status")).toHaveText(`Done, captured in ${report.output_image_count} files.`);
await expect(popup3.locator("#savePngLabel")).toHaveText(`PNG (${report.output_image_count})`);
await popup3.close();

// And the PDF answer, which is the recommended one, says where a PDF of a
Expand Down
1 change: 1 addition & 0 deletions apps/extension/src/i18n/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ const messages: Record<string, string> = {
"Copying to clipboard…": "Wird in die Zwischenablage kopiert…",
"Copied to clipboard.": "In die Zwischenablage kopiert.",
"Done.": "Fertig.",
"Done, captured in {count} files.": "Fertig, in {count} Dateien erfasst.",
"Selection cancelled.": "Auswahl abgebrochen.",
"Too large to edit on this device.": "Zu groß, um auf diesem Gerät bearbeitet zu werden.",
"No captured image found — capture a page first, then click Annotate.": "Keine Aufnahme gefunden — nehmen Sie zuerst eine Seite auf und klicken Sie dann auf Kommentieren.",
Expand Down
1 change: 1 addition & 0 deletions apps/extension/src/i18n/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ const messages: Record<string, string> = {
"Copying to clipboard…": "Copiando al portapapeles…",
"Copied to clipboard.": "Copiado al portapapeles.",
"Done.": "Listo.",
"Done, captured in {count} files.": "Listo, capturado en {count} archivos.",
"Selection cancelled.": "Selección cancelada.",
"Too large to edit on this device.": "Demasiado grande para editarla en este dispositivo.",
"No captured image found — capture a page first, then click Annotate.": "No se encontró ninguna captura: captura una página primero y luego pulsa Anotar.",
Expand Down
1 change: 1 addition & 0 deletions apps/extension/src/i18n/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ const messages: Record<string, string> = {
"Copying to clipboard…": "クリップボードにコピーしています…",
"Copied to clipboard.": "クリップボードにコピーしました。",
"Done.": "完了しました。",
"Done, captured in {count} files.": "完了しました。{count} つのファイルとしてキャプチャしました。",
"Selection cancelled.": "選択をキャンセルしました。",
"Too large to edit on this device.": "この端末で編集するには大きすぎます。",
"No captured image found — capture a page first, then click Annotate.": "キャプチャが見つかりません。先にページをキャプチャしてから「注釈」を選んでください。",
Expand Down
1 change: 1 addition & 0 deletions apps/extension/src/i18n/ko.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ const messages: Record<string, string> = {
"Copying to clipboard…": "클립보드에 복사하는 중…",
"Copied to clipboard.": "클립보드에 복사했습니다.",
"Done.": "완료했습니다.",
"Done, captured in {count} files.": "완료했습니다. {count}개의 파일로 캡처했습니다.",
"Selection cancelled.": "선택을 취소했습니다.",
"Too large to edit on this device.": "이 기기에서 편집하기에는 너무 큽니다.",
"No captured image found — capture a page first, then click Annotate.": "캡처한 이미지가 없습니다. 먼저 페이지를 캡처한 다음 주석을 누르세요.",
Expand Down
1 change: 1 addition & 0 deletions apps/extension/src/i18n/pt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ const messages: Record<string, string> = {
"Copying to clipboard…": "Copiando para a área de transferência…",
"Copied to clipboard.": "Copiado para a área de transferência.",
"Done.": "Pronto.",
"Done, captured in {count} files.": "Pronto, capturado em {count} arquivos.",
"Selection cancelled.": "Seleção cancelada.",
"Too large to edit on this device.": "Grande demais para editar neste dispositivo.",
"No captured image found — capture a page first, then click Annotate.": "Nenhuma imagem capturada — capture uma página primeiro e clique em Anotar.",
Expand Down
1 change: 1 addition & 0 deletions apps/extension/src/i18n/zh-Hans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ const messages: Record<string, string> = {
"Copying to clipboard…": "正在复制到剪贴板…",
"Copied to clipboard.": "已复制到剪贴板。",
"Done.": "完成。",
"Done, captured in {count} files.": "完成,已捕获为 {count} 个文件。",
"Selection cancelled.": "已取消选择。",
"Too large to edit on this device.": "太大,无法在此设备上编辑。",
"No captured image found — capture a page first, then click Annotate.": "未找到已捕获的图片——请先捕获网页,再点击“标注”。",
Expand Down
1 change: 1 addition & 0 deletions apps/extension/src/i18n/zh-Hant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ const messages: Record<string, string> = {
"Copying to clipboard…": "正在複製到剪貼簿…",
"Copied to clipboard.": "已複製到剪貼簿。",
"Done.": "完成。",
"Done, captured in {count} files.": "完成,已擷取為 {count} 個檔案。",
"Selection cancelled.": "已取消選取。",
"Too large to edit on this device.": "太大,無法在此裝置上編輯。",
"No captured image found — capture a page first, then click Annotate.": "找不到已擷取的圖片——請先擷取網頁,再點選「標註」。",
Expand Down
4 changes: 4 additions & 0 deletions apps/extension/src/popup/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,10 @@
<span class="oa-icon oa-icon-14 icon-file-down"></span>
PDF
</button>
<button id="savePng" class="btn btn-secondary btn-sm" disabled>
<span class="oa-icon oa-icon-14 icon-image"></span>
<span id="savePngLabel">PNG</span>
</button>
<button id="copyToClipboard" class="btn btn-secondary btn-sm" disabled>
<span class="oa-icon oa-icon-14 icon-copy"></span>
Copy
Expand Down
43 changes: 39 additions & 4 deletions apps/extension/src/popup/popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ const statusEl = $("status");
const reportEl = $("report") as HTMLPreElement;
const previewEl = $("preview") as HTMLImageElement;
const exportPdfBtn = $("exportPdf") as HTMLButtonElement;
const savePngBtn = $("savePng") as HTMLButtonElement;
const savePngLabelEl = $("savePngLabel");
const copyBtn = $("copyToClipboard") as HTMLButtonElement;
const openEditorBtn = $("openEditor") as HTMLButtonElement;
const resultActionsEl = $("resultActions");
Expand Down Expand Up @@ -307,7 +309,7 @@ refreshCustomFolder();
function captureStatusText(ui: LastCaptureUi): string {
if (ui.openedEditor) return t("Opened in editor — crop, annotate, then choose PNG or PDF to save.");
if (isChoicePending(ui)) return t("Captured. Nothing saved yet — choose how to keep it.");
return t("Done.");
return doneStatusText(ui.report);
}

const count = new Intl.NumberFormat();
Expand All @@ -317,6 +319,25 @@ function isChoicePending(ui: LastCaptureUi): boolean {
return !ui.openedEditor && !ui.formatChosen && needsFormatChoice(ui.report);
}

/**
* The Done status, counting files only when one PNG save would not write
* the whole capture as one file. The catalogue has no plural rules (see
* i18n/index.ts), so the numbered form only runs above 1 — "1 files" can
* never ship.
*/
function doneStatusText(report: CaptureReport): string {
const files = report.output_image_count;
return files > 1 ? t("Done, captured in {count} files.", { count: files }) : t("Done.");
}

/** The same count on the button, so its label names what a click writes. */
function setSavePngLabel(report: CaptureReport): void {
const files = report.output_image_count;
// "PNG" is a format name, not prose — the button label is untranslated
// in every language, same as "PDF" beside it.
savePngLabelEl.textContent = files > 1 ? `PNG (${files})` : "PNG";
}

/**
* Offer the three ways to keep a capture too long to finish automatically.
*
Expand Down Expand Up @@ -348,8 +369,8 @@ function showFormatChoice(report: CaptureReport): void {
? `Annotate part 1 of ${parts} only. The rest is kept, but not shown there.`
: `Annotate the first ${count.format(editableHeightFor(width, height))} rows of ${count.format(height)}. The rest is kept, but not shown there.`;
formatChoiceEl.hidden = false;
// Not both: the row of small actions underneath offers two of these three
// again, unlabelled and without the cost attached, which is exactly the
// Not both: the row of small actions underneath offers these three again,
// unlabelled and without the cost attached, which is exactly the
// sight-unseen click this panel exists to replace.
resultActionsEl.hidden = true;
// The tickbox follows the PDF option into the list, rather than sitting
Expand Down Expand Up @@ -416,8 +437,10 @@ async function restoreLastCaptureUi(): Promise<void> {
reportEl.textContent = JSON.stringify(ui.report, null, 2);

exportPdfBtn.disabled = false;
savePngBtn.disabled = false;
copyBtn.disabled = false;
openEditorBtn.disabled = false;
setSavePngLabel(ui.report);
// Before the preview, deliberately. The capture this asks about is the
// large kind by definition, and reading tens of megabytes of PNG out of
// the store to show a thumbnail of it takes long enough to be visible —
Expand Down Expand Up @@ -493,6 +516,7 @@ function setBusy(busy: boolean, busyMessage?: string): void {
allButtons.forEach((b) => (b.disabled = busy));
if (!busy) {
exportPdfBtn.disabled = false;
savePngBtn.disabled = false;
copyBtn.disabled = false;
openEditorBtn.disabled = false;
}
Expand Down Expand Up @@ -586,8 +610,12 @@ async function showCaptureResult(response: PopupResponse): Promise<void> {
const ui: LastCaptureUi = { report: response.report, openedEditor: response.openedEditor };
if (isChoicePending(ui)) showFormatChoice(response.report);
setStatusText(captureStatusText(ui));
setSavePngLabel(response.report);
} else {
setStatusText(t("Done."));
// The save actions answer {ok} without a report; the count comes from
// the persisted record, which still describes the capture just saved.
const ui = await getLastCaptureUi();
setStatusText(ui ? doneStatusText(ui.report) : t("Done."));
}
}

Expand Down Expand Up @@ -732,6 +760,13 @@ $("choosePdf").addEventListener("click", () =>
);
$("choosePng").addEventListener("click", () => takeFormatChoice({ action: "savePngs" }, t("Saving PNG…")));
$("chooseEditor").addEventListener("click", () => takeFormatChoice({ action: "openEditor" }, t("Opening editor…")));

// The same save the format panel's PNG answer performs — {action:
// "savePngs"} in background/index.ts — reached the ordinary way. The button
// sits with the other two ways to keep a capture, so PNG is offered after
// every capture rather than only when the page is too long for the format
// panel to appear.
savePngBtn.addEventListener("click", () => runCapture({ action: "savePngs" }, t("Saving PNG…")));
// The same follow-up as the format panel's PDF answer, because it is the
// same file and the same question. Wiring it only to the panel meant anyone
// who reached for this button — the ordinary way to get a PDF — was told
Expand Down