(entries)
| 14061 | console.error(`Failed to start Pwnagotchi ${verb.toLowerCase()}:`, error); |
| 14062 | addConsoleMessage(`${verb} failed: ${error.message}`, 'error'); |
| 14063 | stopPwnLogStreaming(); |
| 14064 | setPwnLogEmptyMessage('Installer failed to start. Check Ragnar logs for details.'); |
| 14065 | } finally { |
| 14066 | updatePwnButtons(); |
| 14067 | } |
| 14068 | } |
| 14069 | |
| 14070 | function handlePwnInstallClick() { |
| 14071 | return runPwnInstaller('install'); |
| 14072 | } |
| 14073 | |
| 14074 | function handlePwnRepairClick() { |
| 14075 | return runPwnInstaller('repair'); |
| 14076 | } |
| 14077 | |
| 14078 | function handlePwnReinstallClick() { |
| 14079 | return runPwnInstaller('reinstall'); |
| 14080 | } |
| 14081 | |
| 14082 | async function handlePwnSwap(targetMode) { |
| 14083 | const normalized = targetMode === 'pwnagotchi' ? 'pwnagotchi' : 'ragnar'; |
| 14084 | |
| 14085 | if (normalized === 'pwnagotchi' && !pwnStatus.installed) { |
| 14086 | addConsoleMessage('Install Pwnagotchi before swapping', 'warning'); |
| 14087 | return; |
| 14088 | } |
| 14089 | |
| 14090 | const buttonId = normalized === 'pwnagotchi' ? 'pwn-swap-to-pwn-btn' : 'pwn-swap-to-ragnar-btn'; |
| 14091 | const button = document.getElementById(buttonId); |
| 14092 | if (button) { |
| 14093 | button.disabled = true; |
| 14094 | button.textContent = 'Scheduling switch...'; |
| 14095 | button.classList.add('opacity-60', 'cursor-not-allowed'); |
| 14096 | } |
| 14097 | |
| 14098 | try { |
| 14099 | const result = await postPwnAPI('/api/pwnagotchi/swap', { target: normalized }); |
| 14100 | if (normalized === 'pwnagotchi') _pwnSwapRequestedThisSession = true; |
| 14101 | const message = (result && result.message) ? result.message : `Switch scheduled to ${formatPwnModeLabel(normalized)}`; |
| 14102 | addConsoleMessage(message, 'info'); |
| 14103 | if (result && result.status) { |
| 14104 | updatePwnagotchiUI(result.status); |
| 14105 | } else { |
| 14106 | refreshPwnagotchiStatus({ silent: true }); |
| 14107 | } |
| 14108 | } catch (error) { |
| 14109 | console.error('Failed to schedule Pwnagotchi swap:', error); |
| 14110 | addConsoleMessage(`Swap failed: ${error.message}`, 'error'); |
| 14111 | } finally { |
| 14112 | updatePwnButtons(); |
| 14113 | } |
| 14114 | } |
| 14115 | |
| 14116 | async function postPwnAPI(endpoint, payload = {}) { |
| 14117 | const response = await fetch(endpoint, { |
| 14118 | method: 'POST', |
| 14119 | headers: { |
| 14120 | 'Content-Type': 'application/json' |
no test coverage detected