56 lines
1.6 KiB
JavaScript
56 lines
1.6 KiB
JavaScript
|
|
const folderBtn = document.getElementById('folderBtn');
|
||
|
|
const zipBtn = document.getElementById('zipBtn');
|
||
|
|
const output = document.getElementById('output');
|
||
|
|
const configInfo = document.getElementById('configInfo');
|
||
|
|
|
||
|
|
function setLoading(isLoading) {
|
||
|
|
folderBtn.disabled = isLoading;
|
||
|
|
zipBtn.disabled = isLoading;
|
||
|
|
}
|
||
|
|
|
||
|
|
function renderResult(title, result) {
|
||
|
|
const details = (result.details || []).slice(0, 20);
|
||
|
|
const detailsText = details.length
|
||
|
|
? details
|
||
|
|
.map((d) => (d.destination ? `- ${d.file} -> ${d.destination}` : `- ${d.file}: ${d.reason}`))
|
||
|
|
.join('\n')
|
||
|
|
: '- nessun dettaglio';
|
||
|
|
|
||
|
|
output.textContent = [
|
||
|
|
title,
|
||
|
|
`scansionati: ${result.scanned ?? 0}`,
|
||
|
|
`copiati: ${result.copied ?? 0}`,
|
||
|
|
`saltati: ${result.skipped ?? 0}`,
|
||
|
|
'',
|
||
|
|
'dettagli (max 20):',
|
||
|
|
detailsText,
|
||
|
|
].join('\n');
|
||
|
|
}
|
||
|
|
|
||
|
|
async function handleAction(actionName, actionFn) {
|
||
|
|
setLoading(true);
|
||
|
|
output.textContent = `${actionName} in corso...`;
|
||
|
|
|
||
|
|
try {
|
||
|
|
const result = await actionFn();
|
||
|
|
|
||
|
|
if (!result || result.canceled) {
|
||
|
|
output.textContent = `${actionName} annullato.`;
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
renderResult(actionName, result);
|
||
|
|
} catch (error) {
|
||
|
|
output.textContent = `${actionName} fallito:\n${error.message}`;
|
||
|
|
} finally {
|
||
|
|
setLoading(false);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
folderBtn.addEventListener('click', () => handleAction('Process Folder', window.api.selectFolder));
|
||
|
|
zipBtn.addEventListener('click', () => handleAction('Process ZIP', window.api.selectZip));
|
||
|
|
|
||
|
|
window.api.getConfigPath().then(({ configPath }) => {
|
||
|
|
configInfo.textContent = `Config utente: ${configPath}`;
|
||
|
|
});
|