fix: corregge drag & drop e riconoscimento estensioni CAD versionate

This commit is contained in:
2026-03-05 16:46:03 +01:00
parent 8edc2673b3
commit 5b65a9bd04
3 changed files with 21 additions and 8 deletions

View File

@@ -1,9 +1,10 @@
const { contextBridge, ipcRenderer } = require('electron'); const { contextBridge, ipcRenderer, webUtils } = require('electron');
contextBridge.exposeInMainWorld('api', { contextBridge.exposeInMainWorld('api', {
selectFolder: () => ipcRenderer.invoke('select-folder'), selectFolder: () => ipcRenderer.invoke('select-folder'),
selectZip: () => ipcRenderer.invoke('select-zip'), selectZip: () => ipcRenderer.invoke('select-zip'),
processDroppedPath: (path) => ipcRenderer.invoke('process-dropped-path', { path }), processDroppedPath: (path) => ipcRenderer.invoke('process-dropped-path', { path }),
getPathForDroppedFile: (file) => webUtils.getPathForFile(file),
getDestination: () => ipcRenderer.invoke('get-destination'), getDestination: () => ipcRenderer.invoke('get-destination'),
selectDestinationFolder: () => ipcRenderer.invoke('select-destination-folder'), selectDestinationFolder: () => ipcRenderer.invoke('select-destination-folder'),
updateDestination: (destination) => ipcRenderer.invoke('update-destination', { destination }), updateDestination: (destination) => ipcRenderer.invoke('update-destination', { destination }),

View File

@@ -106,8 +106,15 @@ dropZone.addEventListener('drop', async (event) => {
event.preventDefault(); event.preventDefault();
dropZone.classList.remove('active'); dropZone.classList.remove('active');
const droppedFile = event.dataTransfer?.files?.[0]; const droppedFile = event.dataTransfer?.files?.[0] || event.dataTransfer?.items?.[0]?.getAsFile?.();
const droppedPath = droppedFile?.path; let droppedPath = '';
if (droppedFile) {
try {
droppedPath = window.api.getPathForDroppedFile(droppedFile) || droppedFile.path || '';
} catch {
droppedPath = '';
}
}
if (!droppedPath) { if (!droppedPath) {
setDropZoneError('Elemento non valido. Trascina una cartella o un file .zip'); setDropZoneError('Elemento non valido. Trascina una cartella o un file .zip');

View File

@@ -1,15 +1,21 @@
const path = require('path'); 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) { 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() : ''; const globalDestination = typeof config?.destination === 'string' ? config.destination.trim() : '';
if (globalDestination && ['prt', 'asm', 'dwr'].includes(ext)) { if (globalDestination && cadType) {
return globalDestination; return globalDestination;
} }
for (const rule of config.rules || []) { for (const rule of config.rules || []) {
if ((rule.ext || '').toLowerCase() !== ext) { if ((rule.ext || '').toLowerCase() !== cadType) {
continue; continue;
} }
@@ -27,8 +33,7 @@ function findDestination(filename, config) {
} }
function isCadFile(filename) { function isCadFile(filename) {
const ext = path.extname(filename).slice(1).toLowerCase(); return Boolean(getCadType(filename));
return ['prt', 'asm', 'dwr'].includes(ext);
} }
module.exports = { findDestination, isCadFile }; module.exports = { findDestination, isCadFile };