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:
@@ -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