diff --git a/preload.js b/preload.js index 00be9ac..e69c810 100644 --- a/preload.js +++ b/preload.js @@ -1,9 +1,10 @@ -const { contextBridge, ipcRenderer } = require('electron'); +const { contextBridge, ipcRenderer, webUtils } = require('electron'); contextBridge.exposeInMainWorld('api', { selectFolder: () => ipcRenderer.invoke('select-folder'), selectZip: () => ipcRenderer.invoke('select-zip'), processDroppedPath: (path) => ipcRenderer.invoke('process-dropped-path', { path }), + getPathForDroppedFile: (file) => webUtils.getPathForFile(file), getDestination: () => ipcRenderer.invoke('get-destination'), selectDestinationFolder: () => ipcRenderer.invoke('select-destination-folder'), updateDestination: (destination) => ipcRenderer.invoke('update-destination', { destination }), diff --git a/renderer/renderer.js b/renderer/renderer.js index 0076468..2a8255a 100644 --- a/renderer/renderer.js +++ b/renderer/renderer.js @@ -106,8 +106,15 @@ dropZone.addEventListener('drop', async (event) => { event.preventDefault(); dropZone.classList.remove('active'); - const droppedFile = event.dataTransfer?.files?.[0]; - const droppedPath = droppedFile?.path; + const droppedFile = event.dataTransfer?.files?.[0] || event.dataTransfer?.items?.[0]?.getAsFile?.(); + let droppedPath = ''; + if (droppedFile) { + try { + droppedPath = window.api.getPathForDroppedFile(droppedFile) || droppedFile.path || ''; + } catch { + droppedPath = ''; + } + } if (!droppedPath) { setDropZoneError('Elemento non valido. Trascina una cartella o un file .zip'); diff --git a/services/router.js b/services/router.js index 5370a20..8ae1f94 100644 --- a/services/router.js +++ b/services/router.js @@ -1,15 +1,21 @@ const path = require('path'); +function getCadType(filename) { + const baseName = path.basename(filename).toLowerCase(); + const match = baseName.match(/\.(prt|asm|drw|dwr)(?:\.\d+)?$/); + return match ? match[1] : null; +} + function findDestination(filename, config) { - const ext = path.extname(filename).slice(1).toLowerCase(); + const cadType = getCadType(filename); const globalDestination = typeof config?.destination === 'string' ? config.destination.trim() : ''; - if (globalDestination && ['prt', 'asm', 'dwr'].includes(ext)) { + if (globalDestination && cadType) { return globalDestination; } for (const rule of config.rules || []) { - if ((rule.ext || '').toLowerCase() !== ext) { + if ((rule.ext || '').toLowerCase() !== cadType) { continue; } @@ -27,8 +33,7 @@ function findDestination(filename, config) { } function isCadFile(filename) { - const ext = path.extname(filename).slice(1).toLowerCase(); - return ['prt', 'asm', 'dwr'].includes(ext); + return Boolean(getCadType(filename)); } module.exports = { findDestination, isCadFile };