diff --git a/StackMonkey.ps1 b/StackMonkey.ps1 index e3374a8..f3da843 100644 --- a/StackMonkey.ps1 +++ b/StackMonkey.ps1 @@ -893,72 +893,49 @@ catch (e) { async function triggerInstall() { const runBtn = document.querySelector('.run-button'); - if (runBtn) runBtn.disabled = true; - - const statusBox = document.getElementById('status-box'); - if (statusBox) statusBox.innerHTML = ''; + runBtn.disabled = true; try { - const allTasks = typeof tasks !== 'undefined' ? tasks : []; - const checkedTasks = allTasks.filter(t => { - const cb = document.getElementById(t.id); - return cb && cb.checked; - }); - - setTotalTaskCount(checkedTasks.length); - - // Step 1: Run DattoRMM if selected + // 1. Run DattoRMM first const dattoCB = document.getElementById('installDattoRMM'); if (dattoCB && dattoCB.checked) { - try { - 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 || 'Datto'; + 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 }) - }); - - logProgress('Install DattoRMM', true); - } catch (e) { - logProgress('Install DattoRMM', false); - console.error(e); - } + await fetch('/installDattoRMM', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + checkedValues: sub, + UID: uid, + Name: name + }) + }); } - // Step 2: Run SVSMSP module install + // 2. Run SVSMSP module install second const svsCB = document.getElementById('installSVSMSPModule'); if (svsCB && svsCB.checked) { - try { - await fetch('/installSVSMSPModule', { method: 'GET' }); - logProgress('Install SVSMSP Module', true); - } catch (e) { - logProgress('Install SVSMSP Module', false); - console.error(e); - } + await fetch('/installSVSMSPModule', { method: 'GET' }); } - // Step 3: Remaining tasks - for (const t of checkedTasks) { + // 3. Run the remaining tasks + for (const t of tasks) { if (['installDattoRMM', 'installSVSMSPModule'].includes(t.id)) continue; - try { - await fetch(t.handler, { method: 'GET' }); - logProgress(t.label || t.id, true); - } catch (e) { - logProgress(t.label || t.id, false); - console.error(`Error running ${t.id}:`, e); - } + const cb = document.getElementById(t.id); + if (!cb || !cb.checked) continue; + + await fetch(t.handler, { method: 'GET' }); } - } catch (mainErr) { - console.error('triggerInstall failed:', mainErr); + } catch (e) { + console.error('Error during triggerInstall:', e); } finally { - if (runBtn) runBtn.disabled = false; + runBtn.disabled = false; } } @@ -1042,66 +1019,6 @@ window.addEventListener('beforeunload', () => { fetch('/quit', { method: 'GET', keepalive: true }); }); - - - - '@