cleanup odd behavior on refresh after exiting certain dialogs. remove unintended bypass for files needing to be verified before printing

This commit is contained in:
Gangoke
2026-06-17 00:24:19 -10:00
parent 34b3c1601a
commit 755b82137c

View File

@@ -10,8 +10,8 @@ var camUserStopped=false; // user stopped camera manually — suppress auto-rest
var _camPollInterval=null; // snapshot-polling interval for Android (no MJPEG support)
var _lastLoadedFile=null; // zuletzt geladene/gedruckte Datei für Progress-Karten-Aktionen (Issue #55)
var _fdDialogOpen=false; // Dialog ist gerade offen
var _fdAutoOpenedFile=null; // Dateiname für den der Dialog auto-geöffnet wurde
var _fdUserCancelled=false; // User hat den Auto-Open-Dialog abgebrochen
var _fdAutoOpenedFile=sessionStorage.getItem('fdAutoOpenedFile')||null;
var _fdUserCancelled=sessionStorage.getItem('fdUserCancelled')==='1';
var currentStep=1;
var currentPanel='dashboard';
var aceAutoRefillPrefs=(function(){
@@ -664,7 +664,11 @@ function applyState(){
if(s.file_ready&&s.print_state==='standby'){
document.getElementById('file-ready-name').textContent=s.file_ready;
// Neue Datei → Abbruch-Sperre aufheben
if(_fdAutoOpenedFile&&_fdAutoOpenedFile!==s.file_ready) _fdUserCancelled=false;
if(_fdAutoOpenedFile&&_fdAutoOpenedFile!==s.file_ready){
_fdUserCancelled=false;
sessionStorage.removeItem('fdUserCancelled');
sessionStorage.removeItem('fdAutoOpenedFile');
}
if(shouldAutoOpen){
// Dialog-Modus: nur Dialog verwenden, den Banner niemals anzeigen.
frb.style.display='none';
@@ -1333,23 +1337,40 @@ function slotEditFeed(){
}
function startReadyFile(filename){
var fn=filename||S.file_ready;
function _doStartReadyFile(){
var btn=document.getElementById('file-ready-btn');
if(btn){btn.disabled=true;btn.textContent='…';}
post('/printer/print/start',{filename:fn})
.then(function(r){return r.json();})
.then(function(r){
document.getElementById('file-ready-banner').style.display='none';
if(btn){btn.disabled=false;setText('file-ready-btn',T.file_ready_btn);}
})
.catch(function(e){
clog(tr('log_error')+' '+e,'msg-err');
if(btn){btn.disabled=false;setText('file-ready-btn',T.file_ready_btn);}
});
}
function _gateAndStart(fileObj){
if(fileObj && fileObj.web_unverified && webUploadWarningEnabled()){
maybeGateWebUpload(fileObj, function(){ startReadyFile(fn); });
return;
}
_doStartReadyFile();
}
var currentFile=(storeFiles||[]).find(function(f){return f.filename===fn;});
if(currentFile && currentFile.web_unverified && webUploadWarningEnabled()){
maybeGateWebUpload(currentFile, function(){ startReadyFile(fn); });
if(currentFile){
_gateAndStart(currentFile);
return;
}
var btn=document.getElementById('file-ready-btn');
if(btn){btn.disabled=true;btn.textContent='…';}
post('/printer/print/start',{filename:fn})
.then(function(r){return r.json();})
.then(function(r){
document.getElementById('file-ready-banner').style.display='none';
if(btn){btn.disabled=false;setText('file-ready-btn',T.file_ready_btn);}
})
.catch(function(e){
clog(tr('log_error')+' '+e,'msg-err');
if(btn){btn.disabled=false;setText('file-ready-btn',T.file_ready_btn);}
});
// Fresh page loads may not have storeFiles populated yet.
fetch(_apiUrl('/kx/files')).then(function(r){return r.json();}).then(function(d){
storeFiles=d.result||[];
var refreshed=(storeFiles||[]).find(function(f){return f.filename===fn;})||null;
_gateAndStart(refreshed);
}).catch(function(){
_doStartReadyFile();
});
}
function cancelReadyFile(){
post('/api/file_ready/clear',{})
@@ -2136,6 +2157,7 @@ var _filamentDialogMode='store'; // 'store' oder 'banner'
var _pendingWebVerifyFileId=null;
var _pendingWebVerifyFilename='';
var _pendingWebVerifyAction=null;
var _pendingWebVerifyAutoOpen=false;
// GCode-Store-Dateiliste. MUSS deklariert sein sonst ReferenceError, wenn
// "Slots wählen" im Banner geklickt wird, bevor der Browser-Tab je geladen
// wurde (Issue #29 / Theme-Auslagerung PR #27).
@@ -2203,7 +2225,8 @@ function clearWebUploadWarningFlag(fileId, onDone){
});
}
function maybeGateWebUpload(fileObj, onContinue){
function maybeGateWebUpload(fileObj, onContinue, opts){
opts=opts||{};
if(!fileObj || !fileObj.web_unverified){
if(onContinue) onContinue();
return;
@@ -2212,15 +2235,20 @@ function maybeGateWebUpload(fileObj, onContinue){
if(onContinue) onContinue();
return;
}
var cancelledId=sessionStorage.getItem('webVerifyCancelledFileId')||'';
if(opts.autoOpen && cancelledId && cancelledId===String(fileObj.id||'')){
return;
}
openWebVerifyDialog(fileObj.id, fileObj.filename, function(){
clearWebUploadWarningFlag(fileObj.id, onContinue);
});
}, !!opts.autoOpen);
}
function openWebVerifyDialog(fileId, filename, onConfirm){
function openWebVerifyDialog(fileId, filename, onConfirm, autoOpen){
_pendingWebVerifyFileId=fileId;
_pendingWebVerifyFilename=filename;
_pendingWebVerifyAction=onConfirm||null;
_pendingWebVerifyAutoOpen=!!autoOpen;
var status=document.getElementById('store-web-verify-status');
if(status){status.textContent='';}
openStoreWebVerifyDialog();
@@ -2234,9 +2262,13 @@ function openStoreWebVerifyDialog(){
function closeStoreWebVerifyDialog(){
var modal=document.getElementById('store-web-verify-dialog');
if(modal){modal.classList.remove('open');}
if(_pendingWebVerifyAutoOpen && _pendingWebVerifyFileId){
sessionStorage.setItem('webVerifyCancelledFileId', String(_pendingWebVerifyFileId));
}
_pendingWebVerifyFileId=null;
_pendingWebVerifyFilename='';
_pendingWebVerifyAction=null;
_pendingWebVerifyAutoOpen=false;
}
function confirmStoreWebVerify(){
@@ -2256,9 +2288,11 @@ function confirmStoreWebVerify(){
.then(function(){
var fileObj=(storeFiles||[]).find(function(f){return f.id===fileId;});
if(fileObj){fileObj.web_unverified=false;}
sessionStorage.removeItem('webVerifyCancelledFileId');
_pendingWebVerifyFileId=null;
_pendingWebVerifyFilename='';
_pendingWebVerifyAction=null;
_pendingWebVerifyAutoOpen=false;
closeStoreWebVerifyDialog();
loadStore();
if(typeof action==='function') action();
@@ -2274,7 +2308,7 @@ function startReadyFileWithSlots(filename,_autoOpen){
var fn=filename||S.file_ready;
var currentFile=(storeFiles||[]).find(function(f){return f.filename===fn;});
if(currentFile && currentFile.web_unverified && webUploadWarningEnabled()){
maybeGateWebUpload(currentFile, function(){ startReadyFileWithSlots(fn,_autoOpen); });
maybeGateWebUpload(currentFile, function(){ startReadyFileWithSlots(fn,_autoOpen); }, {autoOpen:!!_autoOpen});
return;
}
_filamentDialogMode='banner';
@@ -2295,23 +2329,31 @@ function startReadyFileWithSlots(filename,_autoOpen){
});
}
function _proceedWithFileObj(fileObj){
if(fileObj && fileObj.web_unverified && webUploadWarningEnabled()){
// Verify gate was bypassed (storeFiles was empty on page load) — re-gate now.
if(_autoOpen){_fdDialogOpen=false;}
maybeGateWebUpload(fileObj, function(){ startReadyFileWithSlots(fn,_autoOpen); }, {autoOpen:!!_autoOpen});
return;
}
if(fileObj){
_storeFileId=fileObj.id;
_setGcodeFilamentsFromFileObj(fileObj);
}
openWithSlots();
}
var fileObj=(storeFiles||[]).find(function(f){return f.filename===_storeFilename;});
if(fileObj){
_storeFileId=fileObj.id;
_setGcodeFilamentsFromFileObj(fileObj);
openWithSlots();
_proceedWithFileObj(fileObj);
return;
}
// Fallback: refresh file list, then resolve current file by filename.
fetch(_apiUrl('/kx/files')).then(function(r){return r.json()}).then(function(d){
storeFiles=d.result||[];
var refreshed=(storeFiles||[]).find(function(f){return f.filename===_storeFilename;});
if(refreshed){
_storeFileId=refreshed.id;
_setGcodeFilamentsFromFileObj(refreshed);
}
openWithSlots();
var refreshed=(storeFiles||[]).find(function(f){return f.filename===_storeFilename;})||null;
_proceedWithFileObj(refreshed);
}).catch(function(){
openWithSlots();
});
@@ -2495,7 +2537,11 @@ function closeFilamentDialog(){
var dlg=document.getElementById('filament-dialog');
if(dlg)dlg.classList.remove('open');
_fdDialogOpen=false;
if(_fdAutoOpenedFile) _fdUserCancelled=true;
if(_fdAutoOpenedFile){
_fdUserCancelled=true;
sessionStorage.setItem('fdUserCancelled','1');
sessionStorage.setItem('fdAutoOpenedFile',_fdAutoOpenedFile);
}
}
function confirmFilamentPrint(){