fix: enhance file paste handler to support clipboard images on Linux with Tauri

This commit is contained in:
2026-01-25 11:31:51 +11:00
parent d226b1810a
commit 72ba2e200a
2 changed files with 46 additions and 2 deletions

View File

@@ -168,3 +168,34 @@ export const sendNotification = async (options: {
sendBrowserNotification({ title, body, icon, onClick });
}
};
/**
* Check if we're running on Linux
*/
export const isLinux = (): boolean => {
const ua = navigator.userAgent.toLowerCase();
return ua.includes('linux') && !ua.includes('android');
};
/**
* Read clipboard image on Linux using Tauri command with arboard/Wayland support
* Returns a data URL if an image is found, null otherwise
*/
export const readClipboardImage = async (): Promise<File | null> => {
if (!isTauri() || !isLinux()) return null;
try {
const { invoke } = await import('@tauri-apps/api/core');
const dataUrl = await invoke<string | null>('read_clipboard_image');
if (!dataUrl) return null;
// Convert data URL to File
const response = await fetch(dataUrl);
const blob = await response.blob();
return new File([blob], 'clipboard-image.png', { type: 'image/png' });
} catch (err) {
console.warn('Failed to read clipboard image:', err);
return null;
}
};