From 197fc68075d950af30f261832027579bdf9c2d41 Mon Sep 17 00:00:00 2001 From: Skyler Lehmkuhl Date: Thu, 5 Dec 2024 16:30:59 -0500 Subject: [PATCH] fix drag and drop on macOS --- src-tauri/tauri.conf.json | 3 ++- src/main.js | 40 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index f2326d4..229c8e1 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -13,7 +13,8 @@ { "title": "Lightningbeam", "width": 1500, - "height": 1024 + "height": 1024, + "dragDropEnabled": false } ], "security": { diff --git a/src/main.js b/src/main.js index bc7439e..b90d315 100644 --- a/src/main.js +++ b/src/main.js @@ -3092,3 +3092,43 @@ const panes = { func: infopanel }, } + + +async function convertToDataURL(filePath) { + try { + // Read the image file as a binary file (buffer) + const binaryData = await readBinaryFile(filePath); + const mimeType = getMimeType(filePath); + if (!mimeType) { + throw new Error('Unsupported image type'); + } + + const base64Data = binaryData.toString('base64'); + const dataURL = `data:${mimeType};base64,${base64Data}`; + + return dataURL; + } catch (error) { + console.error('Error reading the image file:', error); + return null; + } +} + +// Determine the MIME type based on the file extension +function getMimeType(filePath) { + const ext = filePath.split('.').pop().toLowerCase(); + switch (ext) { + case 'jpg': + case 'jpeg': + return 'image/jpeg'; + case 'png': + return 'image/png'; + case 'gif': + return 'image/gif'; + case 'bmp': + return 'image/bmp'; + case 'webp': + return 'image/webp'; + default: + return null; // Unsupported file type + } +} \ No newline at end of file