/**
* VM Disk Budget Step — rendered inside the Electron wizard.
* Shows disk size presets, a custom slider, and real-time space check.
* Add to wizard.js as a new render step between 'folder' and 'tier'.
*
* Exported function: renderDiskBudgetStep()
* State updates: state.diskBudget.preset, state.diskBudget.customSizeGB
*/
function renderDiskBudgetStep() {
const presets = [
{ id: 'minimal', icon: '💽', sizeGB: 10, label: 'Minimal', desc: 'DashCaddy only, a few small apps' },
{ id: 'balanced', icon: '💿', sizeGB: 30, label: 'Balanced', desc: 'DashCaddy + media tools + containers' },
{ id: 'power', icon: '🧊', sizeGB: 100, label: 'Power', desc: 'DashCaddy + heavy apps + lots of containers' },
{ id: 'custom', icon: '⚙️', sizeGB: 0, label: 'Custom', desc: 'Pick your own size' },
];
const selectedPreset = state.diskBudget?.preset || 'balanced';
const selectedSize = state.diskBudget?.customSizeGB || presets.find(p => p.id === selectedPreset)?.sizeGB || 30;
return `
Storage Budget
DashCaddy creates a sandboxed virtual disk for all its data.
It can never exceed this limit — your main drive stays safe.
💡 The disk starts nearly empty and only grows as you add apps and data.
Deleting DashCaddy removes the entire disk instantly.
${presets.map(p => `
${p.icon}
${p.label}
${p.sizeGB > 0 ? p.sizeGB + 'GB' : 'Custom'} — ${p.desc}
`).join('')}
${selectedPreset === 'custom' ? `
` : `
${selectedSize}GB virtual disk will be created.
The sandbox isolates Docker, all containers, and all DashCaddy data inside it.
`}
`;
}
// State management helpers — call from wizard.js
function selectDiskPreset(presetId, sizeGB) {
if (!state.diskBudget) state.diskBudget = {};
state.diskBudget.preset = presetId;
if (presetId !== 'custom') {
state.diskBudget.diskSizeGB = sizeGB;
}
checkDiskSpace(sizeGB);
render(); // re-render the step
}
function updateDiskSize(val) {
const sizeGB = parseInt(val);
if (!state.diskBudget) state.diskBudget = {};
state.diskBudget.diskSizeGB = sizeGB;
state.diskBudget.customSizeGB = sizeGB;
document.getElementById('disk-size-display').textContent = sizeGB + 'GB';
checkDiskSpace(sizeGB);
}
async function checkDiskSpace(sizeGB) {
const el = document.getElementById('disk-space-check');
if (!el) return;
try {
const info = await window.electronAPI.getDiskSpace(state.paths.install || '');
const freeGB = Math.round(info.free / 1024 / 1024 / 1024);
const neededGB = sizeGB + 2; // 2GB buffer for DashCaddy itself
if (freeGB < neededGB) {
el.innerHTML = `
⚠️ Not enough free space. You have ${freeGB}GB free, but need ${neededGB}GB.
`;
} else {
el.innerHTML = `
✓ You have ${freeGB}GB free — plenty of room for a ${sizeGB}GB disk.
`;
}
} catch {
el.innerHTML = '';
}
}