diff --git a/web/kanban-users.js b/web/kanban-users.js index 88bb1b2..3f7e510 100644 --- a/web/kanban-users.js +++ b/web/kanban-users.js @@ -636,12 +636,28 @@ async function pullTo(order, machineId){ const alert=(machine?.alerts||[]).find(row=>row.blocking); if(alert&&!await machineAlertDialog(order,target,alert))return; try{ - await move(order,'imp','',target); + await pullMove(order,target); }catch(e){ if(e.status===409&&String(e.message).startsWith('Antes do próximo arquivo')){say(e.message,true);return;} throw e; } } +// The card changed elsewhere between the board's load and the pull (another +// tab or person; the machine alert in between gives it time): reload and, if +// it still waits in Arte conferida, pull once more with the fresh version; +// the server checks everything again (Sentry DTF-WEB-K, as DTF-WEB-7). +async function pullMove(order,target){ + try{ + await move(order,'imp','',target); + }catch(error){ + if(error.status!==409||!String(error.message).startsWith('O pedido mudou'))throw error; + await load(); + const fresh=(board.orders||[]).find(row=>row.id===order.id); + if(fresh?.state==='imp'&&fresh.machine?.id===target){say('O pedido já estava imprimindo nesta máquina.');return;} + if(!fresh||fresh.cancelled_at||fresh.state!=='tra')throw error; + await move(fresh,'imp','',target); + } +} // Minha conta: who is signed in, and the password, which only the person changes. function accountForm(){ diff --git a/web/kanban.js b/web/kanban.js index e1c3501..b576663 100644 --- a/web/kanban.js +++ b/web/kanban.js @@ -282,7 +282,10 @@ const RECEIPTS_FOLDER='Recibos'; const REVIEWS_FOLDER='Revisões'; const FOLDER={mode:'showDirectoryPicker' in window?'folder':/Firefox\//.test(navigator.userAgent)?'downloads':'none', brave:!!navigator.brave,handle:null,granted:false,downloads:false,since:null, - saved:new Map(),busy:false,status:'',error:'',last:null,lastSig:null}; + saved:new Map(),busy:false,status:'',error:'',last:null,lastSig:null, + // Passes in a row each file was held open by another program (DTF-WEB-M). + locked:new Map()}; +const LOCKED_REPORT_PASSES=10; // When the folders were chosen: every order paid since then ends up in them, // even one that went through while this computer was off (Dropstar's rules, // 2026-10-26). Folders chosen before this existed count from their first round. @@ -610,11 +613,19 @@ async function syncFolder(force=false){ if(moved)say(moved+' arquivo(s) mudaram de pasta com o pedido.'); if(removed)say(removed+' arquivo(s) de pedidos cancelados, excluídos, em correção, trocados ou finalizados há mais de '+KEEP_FINISHED_DAYS+' dias saíram das pastas.'); // What another program held open waits for the next pass; the rest is done. + // Expected while the FlexiPRINT reads a file: a warning the first time, and + // an error (which reaches Sentry) only when the same file is still held + // after LOCKED_REPORT_PASSES passes (Sentry DTF-WEB-M). + for(const name of [...FOLDER.locked.keys()])if(!locked.includes(name))FOLDER.locked.delete(name); + for(const name of locked)FOLDER.locked.set(name,(FOLDER.locked.get(name)||0)+1); if(locked.length){ FOLDER.lastSig=null; FOLDER.error='O arquivo '+locked[0]+(locked.length>1?' e mais '+(locked.length-1):'')+ ' está aberto em outro programa (o FlexiPRINT, por exemplo). Os outros foram gravados; o Kanban tenta este de novo em 30 s.'; - say('Pastas automáticas: '+FOLDER.error,true); + const stuck=locked.filter(name=>FOLDER.locked.get(name)===LOCKED_REPORT_PASSES); + if(stuck.length)say('Pastas automáticas: o arquivo '+stuck.join(', ')+' segue aberto em outro programa há '+ + Math.round(LOCKED_REPORT_PASSES*30/60)+' minutos. Feche-o no programa que o usa.',true); + else if(locked.some(name=>FOLDER.locked.get(name)===1))say('Pastas automáticas: '+FOLDER.error); } }catch(e){ if(e.name==='NotAllowedError')FOLDER.granted=false;