- Introduced a new IPC handler for reading binary files as base64 for inline previews, enhancing the editor's capability to display images directly. - Implemented a placeholder component for non-previewable binary files, providing users with file information and an option to open in the system viewer. - Enhanced the EditorFileWatcher to ignore permission errors and adjusted debounce timing for better performance during file system events. - Updated the ProjectFileService to include a method for reading binary previews with security checks and MIME type validation. - Improved the EditorImagePreview component to handle loading states and display images with a checkerboard background for transparency. - Refactored the EditorBinaryState component to utilize the new binary preview functionality, streamlining the display of binary files.
42 lines
1.3 KiB
TypeScript
42 lines
1.3 KiB
TypeScript
/**
|
|
* Placeholder for non-previewable binary files — shows file info and "Open in System Viewer" button.
|
|
*/
|
|
|
|
import { Button } from '@renderer/components/ui/button';
|
|
import { useStore } from '@renderer/store';
|
|
import { FileQuestion } from 'lucide-react';
|
|
|
|
interface EditorBinaryPlaceholderProps {
|
|
filePath: string;
|
|
fileName: string;
|
|
size: number;
|
|
}
|
|
|
|
export const EditorBinaryPlaceholder = ({
|
|
filePath,
|
|
fileName,
|
|
size,
|
|
}: EditorBinaryPlaceholderProps): React.ReactElement => {
|
|
const projectPath = useStore((s) => s.editorProjectPath);
|
|
const sizeFormatted =
|
|
size < 1024
|
|
? `${size} B`
|
|
: size < 1024 * 1024
|
|
? `${(size / 1024).toFixed(1)} KB`
|
|
: `${(size / 1024 / 1024).toFixed(1)} MB`;
|
|
|
|
const handleOpenExternal = (): void => {
|
|
window.electronAPI.openPath(filePath, projectPath ?? undefined).catch(console.error);
|
|
};
|
|
|
|
return (
|
|
<div className="flex h-full flex-col items-center justify-center gap-3 text-text-muted">
|
|
<FileQuestion className="size-12 opacity-30" />
|
|
<p className="text-sm font-medium text-text-secondary">{fileName}</p>
|
|
<p className="text-xs">Binary file ({sizeFormatted})</p>
|
|
<Button variant="outline" size="sm" className="mt-2" onClick={handleOpenExternal}>
|
|
Open in System Viewer
|
|
</Button>
|
|
</div>
|
|
);
|
|
};
|