added task count
This commit is contained in:
@@ -895,10 +895,21 @@ async function triggerInstall() {
|
||||
const runBtn = document.querySelector('.run-button');
|
||||
runBtn.disabled = true;
|
||||
|
||||
const statusBox = document.getElementById('status-box');
|
||||
statusBox.innerHTML = '';
|
||||
|
||||
try {
|
||||
// Count how many tasks are checked
|
||||
const taskCount = tasks.filter(t => {
|
||||
const cb = document.getElementById(t.id);
|
||||
return cb && cb.checked;
|
||||
}).length;
|
||||
setTotalTaskCount(taskCount);
|
||||
|
||||
// 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);
|
||||
@@ -915,12 +926,23 @@ async function triggerInstall() {
|
||||
Name: name
|
||||
})
|
||||
});
|
||||
logProgress('Install DattoRMM', true);
|
||||
} catch (e) {
|
||||
logProgress('Install DattoRMM', false);
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Run the remaining tasks
|
||||
@@ -930,7 +952,13 @@ async function triggerInstall() {
|
||||
const cb = document.getElementById(t.id);
|
||||
if (!cb || !cb.checked) 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);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Error during triggerInstall:', e);
|
||||
@@ -940,7 +968,6 @@ async function triggerInstall() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
// =======================================================================
|
||||
// Shutdown Handler
|
||||
// =======================================================================
|
||||
@@ -1019,6 +1046,66 @@ window.addEventListener('beforeunload', () => {
|
||||
fetch('/quit', { method: 'GET', keepalive: true });
|
||||
});
|
||||
|
||||
<script>
|
||||
let completedTasks = 0;
|
||||
let totalTasks = 0;
|
||||
|
||||
function setTotalTaskCount(count) {
|
||||
totalTasks = count;
|
||||
completedTasks = 0;
|
||||
updateTitle();
|
||||
}
|
||||
|
||||
function logProgress(label, isSuccess) {
|
||||
const statusBox = document.getElementById('status-box');
|
||||
completedTasks++;
|
||||
updateTitle();
|
||||
|
||||
const msg = isSuccess
|
||||
? `✅ ${completedTasks}/${totalTasks} done: ${label}`
|
||||
: `❌ ${completedTasks}/${totalTasks} failed: ${label}`;
|
||||
|
||||
const div = document.createElement('div');
|
||||
div.style.color = isSuccess ? 'lime' : 'red';
|
||||
div.textContent = msg;
|
||||
statusBox.appendChild(div);
|
||||
|
||||
if (completedTasks === totalTasks) {
|
||||
const finalMsg = document.createElement('div');
|
||||
finalMsg.style.marginTop = '10px';
|
||||
finalMsg.innerHTML = `<strong>✅ All tasks complete (${completedTasks}/${totalTasks})</strong>`;
|
||||
statusBox.appendChild(finalMsg);
|
||||
|
||||
document.title = `✅ ScriptMonkey - Complete (${completedTasks}/${totalTasks})`;
|
||||
|
||||
// Optional: Play sound
|
||||
const sound = new Audio('data:audio/wav;base64,UklGRiQAAABXQVZFZm10IBAAAAABAAEAESsAACJWAAACABAAZGF0YQAAAAA=');
|
||||
sound.play().catch(() => {});
|
||||
|
||||
// Optional: Flash title
|
||||
flashTitle(`✅ ScriptMonkey - Complete (${completedTasks}/${totalTasks})`);
|
||||
}
|
||||
}
|
||||
|
||||
function updateTitle() {
|
||||
document.title = `ScriptMonkey - ${completedTasks}/${totalTasks} Done`;
|
||||
}
|
||||
|
||||
function flashTitle(finalTitle) {
|
||||
let flashes = 0;
|
||||
const interval = setInterval(() => {
|
||||
document.title = (document.title === '') ? finalTitle : '';
|
||||
flashes++;
|
||||
if (flashes >= 10) {
|
||||
clearInterval(interval);
|
||||
document.title = finalTitle;
|
||||
}
|
||||
}, 800);
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
'@
|
||||
|
||||
Reference in New Issue
Block a user