- Detección de ecoind via JSON-RPC (puerto 7474, lee ~/.ecoin/ecoin.conf) - Botones INICIAR/DETENER/ABRIR GUI/VER INFO en pestaña ECOIN - ABRIR GUI para ecoind antes de lanzar ecoin-qt (no pueden coexistir) - Compilación automática de ecoin-qt con qmake si no está compilado - Grid en tiempo real: balance ECO, bloques, conexiones, wallet, daemon - ecoin_rpc() helper para llamadas JSON-RPC al daemon - _start_ecoin/_stop_ecoin/_open_ecoin_gui/_ecoin_info en panel.py Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
119 lines
5.3 KiB
JavaScript
119 lines
5.3 KiB
JavaScript
// =============================================================
|
|
// Solar Net Hub — app.js
|
|
// Bridge JS ↔ Python y lógica de UI
|
|
// =============================================================
|
|
|
|
// ── Bridge JS → Python ────────────────────────────────────────
|
|
function send(action) {
|
|
window.location.href = 'oasis://' + action;
|
|
}
|
|
|
|
// ── Tabs ──────────────────────────────────────────────────────
|
|
function switchTab(name) {
|
|
document.querySelectorAll('.tab-panel').forEach(el => el.classList.remove('active'));
|
|
document.querySelectorAll('.tabBtn').forEach(el => el.classList.remove('active'));
|
|
const panel = document.getElementById('tab-' + name);
|
|
const btn = document.querySelector('[data-tab="' + name + '"]');
|
|
if (panel) panel.classList.add('active');
|
|
if (btn) btn.classList.add('active');
|
|
}
|
|
|
|
// ── Actualizar estado (llamado desde Python) ──────────────────
|
|
function updateStatus(data) {
|
|
// --- OASIS ---
|
|
const oCard = document.getElementById('oasisCard');
|
|
const state = data.oasis_running ? 'running'
|
|
: data.oasis_installed ? 'stopped'
|
|
: 'unknown';
|
|
|
|
oCard.dataset.state = state;
|
|
|
|
if (data.oasis_running) {
|
|
document.getElementById('oasisState').textContent = 'ACTIVO';
|
|
document.getElementById('oasisSub').textContent = 'servidor corriendo en puerto 3000';
|
|
_btn('btnStart', true);
|
|
_btn('btnStop', false);
|
|
_btn('btnInstall', true);
|
|
_btn('btnBrowser', false);
|
|
} else if (data.oasis_installed) {
|
|
document.getElementById('oasisState').textContent = 'INSTALADO';
|
|
document.getElementById('oasisSub').textContent = 'servidor detenido';
|
|
_btn('btnStart', false);
|
|
_btn('btnStop', true);
|
|
_btn('btnInstall', true);
|
|
_btn('btnBrowser', true);
|
|
} else {
|
|
document.getElementById('oasisState').textContent = 'NO INSTALADO';
|
|
document.getElementById('oasisSub').textContent = 'instala OASIS para comenzar';
|
|
_btn('btnStart', true);
|
|
_btn('btnStop', true);
|
|
_btn('btnInstall', false);
|
|
_btn('btnBrowser', true);
|
|
}
|
|
|
|
document.getElementById('iVer').textContent = data.oasis_version ? 'v' + data.oasis_version : '—';
|
|
document.getElementById('iNode').textContent = data.node_version || '—';
|
|
document.getElementById('iDir').textContent = data.oasis_dir || '—';
|
|
|
|
// Global dot
|
|
document.getElementById('globalDot').dataset.state = state;
|
|
|
|
// --- ECOIN ---
|
|
const eCard = document.getElementById('ecoinCard');
|
|
eCard.dataset.state = data.ecoin_running ? 'running' : (data.ecoin_installed ? 'stopped' : 'unknown');
|
|
|
|
if (data.ecoin_running) {
|
|
document.getElementById('ecoinState').textContent = 'ACTIVO';
|
|
document.getElementById('ecoinSub').textContent = 'daemon corriendo (headless)';
|
|
_btn('btnEStart', true);
|
|
_btn('btnEStop', false);
|
|
_btn('btnEGui', false);
|
|
_btn('btnEInfo', false);
|
|
} else if (data.ecoin_installed) {
|
|
document.getElementById('ecoinState').textContent = 'INSTALADO';
|
|
document.getElementById('ecoinSub').textContent = 'daemon detenido';
|
|
_btn('btnEStart', false);
|
|
_btn('btnEStop', true);
|
|
_btn('btnEGui', false);
|
|
_btn('btnEInfo', true);
|
|
} else {
|
|
document.getElementById('ecoinState').textContent = 'NO INSTALADO';
|
|
document.getElementById('ecoinSub').textContent = 'instala ECOIN para comenzar';
|
|
_btn('btnEStart', true);
|
|
_btn('btnEStop', true);
|
|
_btn('btnEGui', true);
|
|
_btn('btnEInfo', true);
|
|
}
|
|
|
|
// Info grid ecoin
|
|
document.getElementById('eBalance').textContent = data.ecoin_balance != null ? data.ecoin_balance + ' ECO' : '—';
|
|
document.getElementById('eBlocks').textContent = data.ecoin_blocks != null ? data.ecoin_blocks : '—';
|
|
document.getElementById('eConns').textContent = data.ecoin_connections != null ? data.ecoin_connections : '—';
|
|
document.getElementById('eWallet').textContent = data.ecoin_wallet ? 'Si' : 'No';
|
|
document.getElementById('eDaemon').textContent = data.ecoin_daemon ? 'Si' : 'No';
|
|
}
|
|
|
|
// ── Log (llamado desde Python) ────────────────────────────────
|
|
function appendLog(text) {
|
|
const area = document.getElementById('logArea');
|
|
const div = document.createElement('div');
|
|
div.className = 'log-line';
|
|
|
|
if (text.startsWith('$')) div.classList.add('cmd');
|
|
else if (text.startsWith('──')) div.classList.add('end');
|
|
else if (text.startsWith('[Error')) div.classList.add('error');
|
|
|
|
div.textContent = text;
|
|
area.appendChild(div);
|
|
area.scrollTop = area.scrollHeight;
|
|
}
|
|
|
|
function clearLog() {
|
|
document.getElementById('logArea').innerHTML = '';
|
|
}
|
|
|
|
// ── Helper: deshabilitar/habilitar botón ──────────────────────
|
|
function _btn(id, disabled) {
|
|
const el = document.getElementById(id);
|
|
if (el) el.disabled = disabled;
|
|
}
|