Show inline image previews for binary files
Add inline image preview support for binary image files in diffs and the file viewer. Frontend: new CSS rules for diff/viewer image panels and macOS window radius, JS templates to render base64 image previews and wire previewMime/previewBase64 into rendering flow, plus applyPlatformChrome to set platform-specific chrome. Backend (Tauri): add base64 and ico deps and expose image preview data (mime + base64) on GitFileDiff and LocalRepoFile; implement mime detection, size-limited preview generation (5MB), .ico → PNG extraction, and integration into get_file_diff and local_repo_file to return previews when available. Also updates icon asset.
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 407 KiB After Width: | Height: | Size: 407 KiB |
@@ -4,10 +4,13 @@
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
border-radius: var(--radius-window);
|
||||
background: var(--bg-app);
|
||||
}
|
||||
|
||||
#app[data-platform="macos"] {
|
||||
border-radius: var(--radius-window);
|
||||
}
|
||||
|
||||
.layout {
|
||||
display: grid;
|
||||
grid-template-rows: 48px 1fr;
|
||||
@@ -998,6 +1001,67 @@
|
||||
.diff-line-hunk { color: var(--accent); background: var(--accent-subtle); }
|
||||
.diff-line-meta { color: var(--text-muted); background: rgba(156, 166, 181, 0.06); }
|
||||
|
||||
.diff-binary-image-panel {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
min-height: 200px;
|
||||
padding: 12px;
|
||||
}
|
||||
|
||||
.diff-image-preview-frame {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 120px;
|
||||
padding: 12px;
|
||||
border-radius: var(--radius-md);
|
||||
background: rgba(0, 0, 0, 0.12);
|
||||
}
|
||||
|
||||
.diff-image-preview {
|
||||
min-width: 96px;
|
||||
min-height: 96px;
|
||||
max-width: 100%;
|
||||
max-height: min(70vh, 720px);
|
||||
object-fit: contain;
|
||||
border-radius: var(--radius-md);
|
||||
}
|
||||
|
||||
.diff-binary-caption {
|
||||
margin: 0;
|
||||
padding: 12px;
|
||||
font-family: ui-monospace, "Cascadia Code", "Fira Code", "Consolas", monospace;
|
||||
font-size: 11px;
|
||||
line-height: 1.5;
|
||||
color: var(--text-muted);
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius-md);
|
||||
background: rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
|
||||
.viewer-image-preview-wrap {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 160px;
|
||||
padding: 16px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius-lg);
|
||||
background: var(--bg-code);
|
||||
}
|
||||
|
||||
.viewer-image-preview {
|
||||
min-width: 96px;
|
||||
min-height: 96px;
|
||||
max-width: 100%;
|
||||
max-height: min(75vh, 800px);
|
||||
object-fit: contain;
|
||||
border-radius: var(--radius-md);
|
||||
}
|
||||
|
||||
/* ── Workflow empty state ─────────────────────────────────────────────────── */
|
||||
|
||||
.workflow-empty-state {
|
||||
|
||||
@@ -130,6 +130,10 @@ function currentPlatform() {
|
||||
return "linux";
|
||||
}
|
||||
|
||||
function applyPlatformChrome() {
|
||||
appRoot.dataset.platform = currentPlatform();
|
||||
}
|
||||
|
||||
function currentTauriWindow() {
|
||||
const tauriWindow = window.__TAURI__?.window;
|
||||
if (tauriWindow?.getCurrentWindow) {
|
||||
@@ -443,6 +447,18 @@ function groupedChangedFiles(files = []) {
|
||||
return order.map((status) => ({ status, files: groups.get(status) })).filter((group) => group.files.length);
|
||||
}
|
||||
|
||||
function diffBinaryImagePreviewTemplate(diffResult) {
|
||||
const mime = escapeHtml(diffResult.previewMime || "");
|
||||
const b64 = diffResult.previewBase64 || "";
|
||||
const caption = diffResult.diff ? escapeHtml(diffResult.diff) : "";
|
||||
return `<div class="diff-preview diff-binary-image-panel">
|
||||
<div class="diff-image-preview-frame">
|
||||
<img class="diff-image-preview" alt="" decoding="async" src="data:${mime};base64,${b64}" />
|
||||
</div>
|
||||
${caption ? `<pre class="diff-binary-caption">${caption}</pre>` : ""}
|
||||
</div>`;
|
||||
}
|
||||
|
||||
function diffTemplate(diffResult) {
|
||||
if (!diffResult) {
|
||||
return workflowEmptyStateTemplate({
|
||||
@@ -452,6 +468,9 @@ function diffTemplate(diffResult) {
|
||||
actions: false,
|
||||
});
|
||||
}
|
||||
if (diffResult.previewBase64 && diffResult.previewMime) {
|
||||
return diffBinaryImagePreviewTemplate(diffResult);
|
||||
}
|
||||
if (diffResult.isBinary) {
|
||||
return workflowEmptyStateTemplate({
|
||||
title: "Binary file",
|
||||
@@ -928,6 +947,11 @@ function filePreviewTemplate(file) {
|
||||
<span class="muted">${escapeHtml(meta)}</span>
|
||||
</div>`;
|
||||
|
||||
if (file.previewBase64 && file.previewMime) {
|
||||
const mime = escapeHtml(file.previewMime);
|
||||
const b64 = file.previewBase64;
|
||||
return `${header}<div class="viewer-image-preview-wrap"><img class="viewer-image-preview" alt="" decoding="async" src="data:${mime};base64,${b64}" /></div>`;
|
||||
}
|
||||
if (file.tooLarge) {
|
||||
return header + `<div class="empty-state viewer-empty"><div>File too large to preview</div><div class="muted">Preview is limited to ${formatBytes(maxPreviewBytes)}.</div></div>`;
|
||||
}
|
||||
@@ -1993,6 +2017,8 @@ async function openViewerFile(path) {
|
||||
content: file.content || "",
|
||||
isBinary: file.isBinary,
|
||||
tooLarge: file.tooLarge,
|
||||
previewMime: file.previewMime,
|
||||
previewBase64: file.previewBase64,
|
||||
};
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -2670,11 +2696,13 @@ function bindDashboardEvents() {
|
||||
|
||||
function render() {
|
||||
applyTheme();
|
||||
applyPlatformChrome();
|
||||
dashboardView();
|
||||
}
|
||||
|
||||
window.addEventListener("DOMContentLoaded", async () => {
|
||||
applyTheme();
|
||||
applyPlatformChrome();
|
||||
await loadRepositories();
|
||||
if (getState().selectedRepoPath) {
|
||||
await refreshRepoData();
|
||||
|
||||
Reference in New Issue
Block a user