const OS_TYPE = { DEB: 'deb', RPM: 'rpm', ARCH: 'arch', GENERIC: 'generic' }; function detectOS() { const userAgent = navigator.userAgent.toLowerCase(); if (userAgent.includes('ubuntu') || userAgent.includes('debian') || userAgent.includes('linuxmint') || userAgent.includes('pop!_os')) { return { type: OS_TYPE.DEB, name: 'Debian/Ubuntu-based' }; } if (userAgent.includes('fedora') || userAgent.includes('rhel') || userAgent.includes('redhat') || userAgent.includes('centos') || userAgent.includes('opensuse') || userAgent.includes('suse')) { return { type: OS_TYPE.RPM, name: 'Fedora/RedHat-based' }; } if (userAgent.includes('arch') || userAgent.includes('endeavouros') || userAgent.includes('manjaro')) { return { type: OS_TYPE.ARCH, name: 'Arch Linux' }; } return { type: OS_TYPE.GENERIC, name: 'Generic Linux' }; } function renderApps(apps) { const container = document.getElementById('apps-container'); apps.forEach(app => { const appCard = document.createElement('div'); appCard.className = 'bg-gray-850 rounded-xl overflow-hidden shadow-lg hover:shadow-2xl transition-shadow duration-300 border border-gray-700'; appCard.innerHTML = `

${app.name}

${app.description}

Installazione:
Caricamento...
`; container.appendChild(appCard); }); } function updateInstallLink(appId, aptPackage, appstreamId, flatpakUrl) { const osInfo = detectOS(); const installDiv = document.getElementById(`install-${appId}`); let installCommand = ''; let protocol = ''; switch (osInfo.type) { case OS_TYPE.DEB: protocol = 'apt://'; installCommand = `${protocol}${aptPackage}`; break; case OS_TYPE.RPM: protocol = 'appstream://'; installCommand = `${protocol}${appstreamId}`; break; case OS_TYPE.ARCH: protocol = 'appstream://'; installCommand = `${protocol}${appstreamId} (pacman -S ${aptPackage})`; break; case OS_TYPE.GENERIC: protocol = 'flatpak'; installCommand = `Download: ${flatpakUrl}`; break; } installDiv.innerHTML = ` ${installCommand}`; const installBtn = document.querySelector(`button[onclick="installApp('${appId}', '${aptPackage}', '${appstreamId}', '${flatpakUrl}')"]`); installBtn.onclick = function() { handleInstall(appId, aptPackage, appstreamId, flatpakUrl); }; } function handleInstall(appId, aptPackage, appstreamId, flatpakUrl) { const osInfo = detectOS(); let url = ''; switch (osInfo.type) { case OS_TYPE.DEB: url = `apt://${aptPackage}`; break; case OS_TYPE.RPM: url = `appstream://${appstreamId}`; break; case OS_TYPE.ARCH: url = `appstream://${appstreamId}`; break; case OS_TYPE.GENERIC: url = flatpakUrl; break; } if (url.startsWith('apt://') || url.startsWith('appstream://')) { const protocol = url.split(':')[0]; let command = url.replace(`${protocol}://`, ''); if (protocol === 'apt') { command = `sudo apt install ${command}`; } else { command = `${protocol} install ${command}`; } const notification = createNotification(`Comando generato per ${osInfo.name}:
${command}`, 'success'); document.body.appendChild(notification); setTimeout(() => notification.remove(), 5000); } else if (url) { window.open(url, '_blank'); } } function createNotification(message, type) { const notification = document.createElement('div'); notification.className = `fixed top-4 right-4 bg-gray-800 border-l-4 border-${type === 'success' ? 'green' : 'red'}-500 text-white px-6 py-4 rounded shadow-lg z-50 transition-all duration-500 transform translate-x-full`; notification.innerHTML = `
${message}
`; setTimeout(() => { notification.classList.remove('translate-x-full'); }, 100); return notification; } function highlightOS(osInfo) { const osDisplay = document.getElementById('os-display'); if (osDisplay) { osDisplay.innerHTML = `${osInfo.name}`; osDisplay.classList.remove('hidden'); } } function init() { fetch('apps.json') .then(response => response.json()) .then(data => { const osInfo = detectOS(); highlightOS(osInfo); renderApps(data.apps); data.apps.forEach(app => { updateInstallLink(app.id, app.packages.apt, app.packages.appstream, app.packages.flatpak); }); }) .catch(error => { console.error('Error loading apps:', error); const container = document.getElementById('apps-container'); container.innerHTML = `

Errore nel caricamento delle applicazioni

`; }); } document.addEventListener('DOMContentLoaded', init);