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
4 changes: 2 additions & 2 deletions src/main/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { FileHandle } from 'node:fs/promises';
import { constants } from 'node:fs';
import { basename, dirname, isAbsolute, join, normalize, relative, resolve, sep } from 'node:path';
import { homedir } from 'node:os';
import { imageMimeForPath } from '../shared/imageTypes';
import { imageMimeForDiskPath } from '../shared/imageTypes';

/**
* Lexical containment — pure string math, no filesystem access.
Expand Down Expand Up @@ -261,7 +261,7 @@ export async function readFileBinary(root: string, rel: string, maxBytes = MAX_B
return {
ok: true,
bytes,
mime: imageMimeForPath(abs) ?? 'application/octet-stream',
mime: imageMimeForDiskPath(abs) ?? 'application/octet-stream',
path: abs,
size: s.size
};
Expand Down
23 changes: 22 additions & 1 deletion src/renderer/src/hooks/useWorkspaceImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,27 @@ export type WorkspaceImageState =
| { status: 'ready'; url: string; mime: string; size: number }
| { status: 'error'; error: string };

/** What one `fs:readBinary` round trip settles to. */
export type WorkspaceImageRead = Awaited<ReturnType<Window['cth']['readBinary']>>;

/**
* Run one image read so that EVERY failure comes back as `{ ok: false, error }`
* — never as a throw.
*
* A trailing `.catch()` only sees a REJECTED promise. A read that throws while
* being CALLED (the preload bridge missing, or throwing before it returns a
* promise) escapes it, and inside an effect that exception unmounts the whole
* preview through the error boundary instead of turning one image into a chip.
* Taking a thunk puts the call itself inside the `try`.
*/
export async function settleImageRead(read: () => Promise<WorkspaceImageRead>): Promise<WorkspaceImageRead> {
try {
return await read();
} catch (e) {
return { ok: false, error: e instanceof Error ? e.message : String(e) };
}
}

export function useWorkspaceImage(
root: string | null | undefined,
rel: string | null | undefined
Expand All @@ -46,7 +67,7 @@ export function useWorkspaceImage(
let created: string | null = null;
setState({ status: 'loading' });

void window.cth.readBinary(root, rel).then((res) => {
void settleImageRead(() => window.cth.readBinary(root, rel)).then((res) => {
// Bail BEFORE creating the URL when the consumer already unmounted — a URL
// created after cleanup has run would never be revoked by anyone.
if (!alive) return;
Expand Down
8 changes: 8 additions & 0 deletions src/renderer/src/i18n/locales/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -2437,5 +2437,13 @@
"usageNotice": {
"telemetryOff": "تم إيقافه لأن عدّ الرموز الخاص به متوقف. احذف CLAUDE_CODE_ENABLE_TELEMETRY وأي إعدادات OTEL_ من قسم env في ‎~/.claude/settings.json ومن الأمر الذي يشغّله، ثم شغّله مرة أخرى. إذا كانت مؤسستك تدير إعدادات Claude Code لديك، فاسأل المسؤول.",
"engineNotCounted": "في الخطة المجانية لا يمكن تشغيل هذا المحرك بعد، لأن التطبيق لا يستطيع عدّ رموزه. تعمل Claude وCodex وAntigravity وGrok وQwen وCrush، وتفتح Pro أو Max كل المحركات."
},
"markdownImage": {
"untitled": "صورة",
"notImage": "ليس نوع صورة مدعومًا",
"malformedEncoding": "يحتوي المسار على ترميز % غير صالح",
"unsafeSegment": "يُرمّز المسار فاصلًا أو ..",
"loading": "جارٍ التحميل",
"decodeFailed": "تعذّر فك الترميز"
}
}
8 changes: 8 additions & 0 deletions src/renderer/src/i18n/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -2437,5 +2437,13 @@
"usageNotice": {
"telemetryOff": "Er wurde gestoppt, weil seine Token Zählung ausgeschaltet ist. Entferne CLAUDE_CODE_ENABLE_TELEMETRY und alle OTEL_ Einstellungen aus dem env Block von ~/.claude/settings.json und aus dem Befehl, der ihn startet, und starte ihn dann neu. Wenn deine Organisation deine Claude Code Einstellungen verwaltet, frag deine Administration.",
"engineNotCounted": "Im kostenlosen Plan kann diese Engine noch nicht starten, weil die App ihre Tokens nicht zählen kann. Claude, Codex, Antigravity, Grok, Qwen und Crush funktionieren, und Pro oder Max schaltet jede Engine frei."
},
"markdownImage": {
"untitled": "Bild",
"notImage": "kein unterstütztes Bildformat",
"malformedEncoding": "der Pfad enthält eine ungültige %-Kodierung",
"unsafeSegment": "der Pfad kodiert ein Trennzeichen oder ..",
"loading": "wird geladen",
"decodeFailed": "konnte nicht dekodiert werden"
}
}
8 changes: 8 additions & 0 deletions src/renderer/src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2437,5 +2437,13 @@
"usageNotice": {
"telemetryOff": "It was stopped because its token count is switched off. Remove CLAUDE_CODE_ENABLE_TELEMETRY and any OTEL_ settings from the env block of ~/.claude/settings.json and from the command that starts it, then start it again. If your organization manages your Claude Code settings, ask your administrator.",
"engineNotCounted": "On the free plan this engine cannot start yet, because the app cannot count its tokens. Claude, Codex, Antigravity, Grok, Qwen and Crush work, and Pro or Max unlocks every engine."
},
"markdownImage": {
"untitled": "image",
"notImage": "not a supported image type",
"malformedEncoding": "the path has an invalid % escape",
"unsafeSegment": "the path encodes a separator or ..",
"loading": "loading",
"decodeFailed": "could not decode"
}
}
8 changes: 8 additions & 0 deletions src/renderer/src/i18n/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -2437,5 +2437,13 @@
"usageNotice": {
"telemetryOff": "Se detuvo porque su conteo de tokens está desactivado. Quita CLAUDE_CODE_ENABLE_TELEMETRY y cualquier ajuste OTEL_ del bloque env de ~/.claude/settings.json y del comando que lo inicia, y vuelve a iniciarlo. Si tu organización gestiona tus ajustes de Claude Code, pregunta a tu administrador.",
"engineNotCounted": "En el plan gratuito este motor todavía no puede iniciarse, porque la app no puede contar sus tokens. Claude, Codex, Antigravity, Grok, Qwen y Crush funcionan, y Pro o Max desbloquea todos los motores."
},
"markdownImage": {
"untitled": "imagen",
"notImage": "no es un tipo de imagen compatible",
"malformedEncoding": "la ruta tiene un escape % no válido",
"unsafeSegment": "la ruta codifica un separador o ..",
"loading": "cargando",
"decodeFailed": "no se pudo decodificar"
}
}
8 changes: 8 additions & 0 deletions src/renderer/src/i18n/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -2437,5 +2437,13 @@
"usageNotice": {
"telemetryOff": "Il a été arrêté car son comptage de tokens est désactivé. Retire CLAUDE_CODE_ENABLE_TELEMETRY et tout réglage OTEL_ du bloc env de ~/.claude/settings.json et de la commande qui le lance, puis relance-le. Si ton organisation gère tes réglages Claude Code, demande à ton administrateur.",
"engineNotCounted": "Avec l'offre gratuite, ce moteur ne peut pas encore démarrer, car l'app ne peut pas compter ses tokens. Claude, Codex, Antigravity, Grok, Qwen et Crush fonctionnent, et Pro ou Max débloque tous les moteurs."
},
"markdownImage": {
"untitled": "image",
"notImage": "type d’image non pris en charge",
"malformedEncoding": "le chemin contient un échappement % invalide",
"unsafeSegment": "le chemin encode un séparateur ou ..",
"loading": "chargement",
"decodeFailed": "décodage impossible"
}
}
8 changes: 8 additions & 0 deletions src/renderer/src/i18n/locales/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -2437,5 +2437,13 @@
"usageNotice": {
"telemetryOff": "È stato fermato perché il suo conteggio dei token è disattivato. Rimuovi CLAUDE_CODE_ENABLE_TELEMETRY e ogni impostazione OTEL_ dal blocco env di ~/.claude/settings.json e dal comando che lo avvia, poi avvialo di nuovo. Se la tua organizzazione gestisce le tue impostazioni di Claude Code, chiedi al tuo amministratore.",
"engineNotCounted": "Con il piano gratuito questo motore non può ancora avviarsi, perché l'app non può contare i suoi token. Claude, Codex, Antigravity, Grok, Qwen e Crush funzionano, e Pro o Max sblocca tutti i motori."
},
"markdownImage": {
"untitled": "immagine",
"notImage": "tipo di immagine non supportato",
"malformedEncoding": "il percorso contiene un escape % non valido",
"unsafeSegment": "il percorso codifica un separatore o ..",
"loading": "caricamento",
"decodeFailed": "impossibile decodificare"
}
}
8 changes: 8 additions & 0 deletions src/renderer/src/i18n/locales/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -2437,5 +2437,13 @@
"usageNotice": {
"telemetryOff": "トークンの計測がオフになっているため停止しました。~/.claude/settings.json の env ブロックと、起動するコマンドから CLAUDE_CODE_ENABLE_TELEMETRY と OTEL_ の設定をすべて削除してから、もう一度起動してください。組織が Claude Code の設定を管理している場合は、管理者に確認してください。",
"engineNotCounted": "無料プランでは、このエンジンはまだ起動できません。アプリがトークンを計測できないためです。Claude、Codex、Antigravity、Grok、Qwen、Crush は使えます。Pro または Max ではすべてのエンジンが使えます。"
},
"markdownImage": {
"untitled": "画像",
"notImage": "対応していない画像形式です",
"malformedEncoding": "パスに無効な % エスケープが含まれています",
"unsafeSegment": "パスに区切り文字または .. がエンコードされています",
"loading": "読み込み中",
"decodeFailed": "デコードできませんでした"
}
}
8 changes: 8 additions & 0 deletions src/renderer/src/i18n/locales/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -2437,5 +2437,13 @@
"usageNotice": {
"telemetryOff": "토큰 집계가 꺼져 있어 중지되었습니다. ~/.claude/settings.json의 env 블록과 이를 시작하는 명령에서 CLAUDE_CODE_ENABLE_TELEMETRY와 모든 OTEL_ 설정을 지운 뒤 다시 시작하세요. 조직에서 Claude Code 설정을 관리한다면 관리자에게 문의하세요.",
"engineNotCounted": "무료 플랜에서는 앱이 이 엔진의 토큰을 집계할 수 없어 아직 시작할 수 없습니다. Claude, Codex, Antigravity, Grok, Qwen, Crush는 사용할 수 있으며, Pro 또는 Max에서는 모든 엔진을 사용할 수 있습니다."
},
"markdownImage": {
"untitled": "이미지",
"notImage": "지원하지 않는 이미지 형식입니다",
"malformedEncoding": "경로에 잘못된 % 이스케이프가 있습니다",
"unsafeSegment": "경로에 구분자 또는 ..가 인코딩되어 있습니다",
"loading": "불러오는 중",
"decodeFailed": "디코딩할 수 없습니다"
}
}
8 changes: 8 additions & 0 deletions src/renderer/src/i18n/locales/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -2437,5 +2437,13 @@
"usageNotice": {
"telemetryOff": "Ele foi parado porque a contagem de tokens dele está desligada. Remova CLAUDE_CODE_ENABLE_TELEMETRY e qualquer configuração OTEL_ do bloco env de ~/.claude/settings.json e do comando que o inicia, e inicie de novo. Se a sua organização gerencia suas configurações do Claude Code, fale com o administrador.",
"engineNotCounted": "No plano gratuito este motor ainda não pode iniciar, porque o app não consegue contar os tokens dele. Claude, Codex, Antigravity, Grok, Qwen e Crush funcionam, e o Pro ou o Max libera todos os motores."
},
"markdownImage": {
"untitled": "imagem",
"notImage": "tipo de imagem não suportado",
"malformedEncoding": "o caminho tem um escape % inválido",
"unsafeSegment": "o caminho codifica um separador ou ..",
"loading": "carregando",
"decodeFailed": "não foi possível decodificar"
}
}
8 changes: 8 additions & 0 deletions src/renderer/src/i18n/locales/tr.json
Original file line number Diff line number Diff line change
Expand Up @@ -2437,5 +2437,13 @@
"usageNotice": {
"telemetryOff": "Token sayımı kapalı olduğu için durduruldu. ~/.claude/settings.json dosyasındaki env bloğundan ve onu başlatan komuttan CLAUDE_CODE_ENABLE_TELEMETRY ve tüm OTEL_ ayarlarını kaldır, sonra yeniden başlat. Claude Code ayarlarını kuruluşun yönetiyorsa yöneticine sor.",
"engineNotCounted": "Ücretsiz planda bu motor henüz başlayamaz, çünkü uygulama tokenlarını sayamıyor. Claude, Codex, Antigravity, Grok, Qwen ve Crush çalışır; Pro veya Max tüm motorların kilidini açar."
},
"markdownImage": {
"untitled": "görsel",
"notImage": "desteklenen bir görsel türü değil",
"malformedEncoding": "yolda geçersiz bir % kaçış dizisi var",
"unsafeSegment": "yol bir ayırıcı veya .. kodluyor",
"loading": "yükleniyor",
"decodeFailed": "çözülemedi"
}
}
8 changes: 8 additions & 0 deletions src/renderer/src/i18n/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -2437,5 +2437,13 @@
"usageNotice": {
"telemetryOff": "它已被停止,因为它的 token 计数已关闭。请从 ~/.claude/settings.json 的 env 部分以及启动它的命令中删除 CLAUDE_CODE_ENABLE_TELEMETRY 和所有 OTEL_ 设置,然后重新启动它。如果你的组织管理你的 Claude Code 设置,请联系管理员。",
"engineNotCounted": "在免费计划中,此引擎暂时无法启动,因为应用无法统计它的 token。Claude、Codex、Antigravity、Grok、Qwen 和 Crush 可以使用,Pro 或 Max 可解锁所有引擎。"
},
"markdownImage": {
"untitled": "图片",
"notImage": "不是支持的图片格式",
"malformedEncoding": "路径含有无效的 % 编码",
"unsafeSegment": "路径中编码了分隔符或 ..",
"loading": "加载中",
"decodeFailed": "无法解码"
}
}
8 changes: 4 additions & 4 deletions src/renderer/src/ide/IdePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import { UnsavedDialog } from './UnsavedDialog';
import { MarkdownBody, OutlinePane, type OutlineJump } from './MarkdownReview';
import { Breadcrumb, EditorStatusBar, SaveChip, ShortcutSheet } from './EditorChrome';
import { IdeIcon, IDE_YELLOW } from './ideIcons';
import { isImagePath, isSvgPath } from '@shared/imageTypes';
import { isImageDiskPath, isSvgDiskPath } from '@shared/imageTypes';
import { markdownOutline } from '@shared/markdownOutline';
import { languageForPath } from './monaco';
import { parentOfRel } from '@shared/ideNewFile';
Expand Down Expand Up @@ -349,7 +349,7 @@ export function IdePanel() {
* reader rejects anything with a null byte. SVG is a picture first here
* too, with view source one click away. */
const openEdit = useCallback((rel: string) => {
if (isImagePath(rel)) { openTab('image', rel); touchRecent(rel); return; }
if (isImageDiskPath(rel)) { openTab('image', rel); touchRecent(rel); return; }
openSource(rel);
}, [openSource, openTab, touchRecent]);

Expand Down Expand Up @@ -1156,7 +1156,7 @@ export function IdePanel() {
root={root}
rel={activeTab.rel}
onCopyPath={() => copyAbs(activeTab.rel)}
onViewSource={isSvgPath(activeTab.rel) ? () => openSource(activeTab.rel) : undefined}
onViewSource={isSvgDiskPath(activeTab.rel) ? () => openSource(activeTab.rel) : undefined}
/>
</div>
)}
Expand Down Expand Up @@ -1195,7 +1195,7 @@ export function IdePanel() {
</button>
</>
)}
{isImagePath(activeTab.rel) && (
{isImageDiskPath(activeTab.rel) && (
<button type="button" onClick={() => openTab('image', activeTab.rel)} title={t('idePanel.viewImage')} style={ghostBtn}><IdeIcon name="fileImage" size={13} />{t('idePanel.viewImage')}</button>
)}
<button type="button" onClick={() => copyAbs(activeTab.rel)} title={t('idePanel.copyPath')} aria-label={t('idePanel.copyPath')} style={iconBtn}><IdeIcon name="copy" size={14} /></button>
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/src/ide/ImagePreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import { useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useWorkspaceImage } from '@/hooks/useWorkspaceImage';
import { formatBytes, isSvgPath } from '@shared/imageTypes';
import { formatBytes } from '@shared/imageTypes';
import { ideBarStyle, ideIconBtn, ideTextBtn } from './chrome';
import { FileIcon, IdeIcon } from './ideIcons';

Expand Down
Loading
Loading