diff --git a/StackMonkey.ps1 b/StackMonkey.ps1 index 533f39c..fc37d99 100644 --- a/StackMonkey.ps1 +++ b/StackMonkey.ps1 @@ -856,39 +856,49 @@ $style = @' + const runBtn = document.querySelector('.run-button'); + async function triggerInstall() { - for (const t of tasks) { - const cb = document.getElementById(t.id); - if (!cb || !cb.checked) continue; + // disable the button so you can’t double‐click while work is in flight + runBtn.disabled = true; - // special case: DattoRMM is POST - if (t.id === 'installDattoRMM') { - const sub = Array.from( - document.querySelectorAll('.sub-option-installDattoRMM:checked') - ).map(x=>x.value); - const dropdown = document.getElementById('dattoDropdown'); - const uid = dropdown.value; - const name = dropdown.selectedOptions[0].text; + try { + for (const t of tasks) { + const cb = document.getElementById(t.id); + if (!cb || !cb.checked) continue; - await fetch('/installDattoRMM', { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ - checkedValues: sub, - UID: uid, - Name: name - }) - }); - } - else { - // your existing GET for everyone else - await fetch(t.handler, { method: 'GET' }); + if (t.id === 'installDattoRMM') { + const sub = Array.from( + document.querySelectorAll('.sub-option-installDattoRMM:checked') + ).map(x => x.value); + const dropdown = document.getElementById('dattoDropdown'); + const uid = dropdown.value; + const name = dropdown.selectedOptions[0].text; + + await fetch('/installDattoRMM', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + checkedValues: sub, + UID: uid, + Name: name + }) + }); + } else { + await fetch(t.handler, { method: 'GET' }); + } } + } catch (e) { + console.error('Error during triggerInstall:', e); + } finally { + // always re-enable, even if an error occurred + runBtn.disabled = false; } } + // ======================================================================= // Shutdown Handler // =======================================================================