feat: unifica lo smistamento CAD su destinazione unica configurabile da UI

This commit is contained in:
2026-03-05 16:11:01 +01:00
parent 7008f57119
commit cc38413400
8 changed files with 194 additions and 130 deletions

50
main.js
View File

@@ -3,9 +3,19 @@ const path = require('path');
const { processFolder } = require('./services/folderProcessor');
const { processZip } = require('./services/zipProcessor');
const { loadConfig } = require('./services/configService');
let config;
const CAD_EXTENSIONS = ['prt', 'asm', 'dwr'];
const DEFAULT_DESTINATION = './output/cad';
function buildConfig(destination) {
const resolvedDestination = String(destination || '').trim() || DEFAULT_DESTINATION;
return {
destination: resolvedDestination,
rules: CAD_EXTENSIONS.map((ext) => ({ ext, destination: resolvedDestination })),
};
}
let config = buildConfig(DEFAULT_DESTINATION);
function createWindow() {
const win = new BrowserWindow({
@@ -21,12 +31,7 @@ function createWindow() {
win.loadFile(path.join(__dirname, 'renderer', 'index.html'));
}
async function initConfig() {
config = await loadConfig();
}
app.whenReady().then(async () => {
await initConfig();
app.whenReady().then(() => {
createWindow();
app.on('activate', () => {
@@ -67,6 +72,31 @@ ipcMain.handle('select-zip', async () => {
return { canceled: false, ...routingResult };
});
ipcMain.handle('get-config-path', async () => ({
configPath: loadConfig.getConfigPath(),
ipcMain.handle('get-destination', async () => ({
destination: config.destination || DEFAULT_DESTINATION,
}));
ipcMain.handle('select-destination-folder', async () => {
const result = await dialog.showOpenDialog({
properties: ['openDirectory'],
});
if (result.canceled || !result.filePaths[0]) {
return { canceled: true };
}
return {
canceled: false,
path: result.filePaths[0],
};
});
ipcMain.handle('update-destination', async (_event, payload) => {
const destination = String(payload?.destination || '').trim();
if (!destination) {
throw new Error('La destinazione non puo essere vuota');
}
config = buildConfig(destination);
return { destination: config.destination };
});