fix: corregge drag & drop e riconoscimento estensioni CAD versionate
This commit is contained in:
@@ -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 }),
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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 };
|
||||
|
||||
Reference in New Issue
Block a user