feat: add built-in Moon I2P start page to Firefox and Android
- Firefox extension: add start.html/css/js as homepage and new-tab page (manifest bumped to 0.1.5, .xpi rebuilt). Shows router readiness, tunnel/NetDB/DHT tiles, torrents, and a .i2p/magnet address bar. - openManager message now accepts an optional hash and reuses any open manager tab. - Android: default page is file:///android_asset/start.html, backed by a MoonI2pStart JS bridge (status, torrents, open URL, diagnostics, copy .b32). Blocks file: navigation from the WebView. - RouterService: add fetchLocalApiJsonOrNull for bounded local API reads. - Built-in .i2p destinations reordered (NotBob, Postman first); README updated to match.
This commit is contained in:
1 parent
9d3df6e100
commit
7139a64544
11 files changed
+1355
-37
No files matched your search
@@ -0,0 +1,496 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||
<title>Moon I2P Start Page</title>
|
||||
<style>
|
||||
:root {
|
||||
color-scheme: dark;
|
||||
--bg: #0b1120;
|
||||
--card: #131c31;
|
||||
--border: #23304d;
|
||||
--text: #e2e8f0;
|
||||
--muted: #94a3b8;
|
||||
--accent: #6d5dfc;
|
||||
--teal: #14b8a6;
|
||||
--warn: #f59e0b;
|
||||
--danger: #ef4444;
|
||||
}
|
||||
* { box-sizing: border-box; }
|
||||
body {
|
||||
margin: 0;
|
||||
min-height: 100vh;
|
||||
padding: 16px 14px 28px;
|
||||
background:
|
||||
radial-gradient(640px 280px at 50% -60px, rgba(109, 93, 252, 0.22), transparent 72%),
|
||||
var(--bg);
|
||||
color: var(--text);
|
||||
font-family: system-ui, -apple-system, sans-serif;
|
||||
font-size: 14px;
|
||||
line-height: 1.45;
|
||||
}
|
||||
.wrap { max-width: 680px; margin: 0 auto; }
|
||||
header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 10px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.brand { display: flex; align-items: center; gap: 10px; }
|
||||
.brand svg { width: 28px; height: 28px; flex-shrink: 0; }
|
||||
.brand-title { font-size: 16px; font-weight: 700; }
|
||||
.brand-sub { font-size: 11px; color: var(--muted); }
|
||||
.pill {
|
||||
display: inline-block;
|
||||
padding: 3px 9px;
|
||||
border-radius: 999px;
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
background: #1e293b;
|
||||
color: var(--muted);
|
||||
white-space: nowrap;
|
||||
}
|
||||
.pill.online { background: rgba(20, 184, 166, 0.2); color: #5eead4; }
|
||||
.pill.booting { background: rgba(245, 158, 11, 0.2); color: #fcd34d; }
|
||||
.pill.offline { background: rgba(239, 68, 68, 0.2); color: #fca5a5; }
|
||||
.card {
|
||||
background: var(--card);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 12px;
|
||||
padding: 12px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.banner.booting {
|
||||
border-color: rgba(245, 158, 11, 0.55);
|
||||
background: linear-gradient(90deg, rgba(245, 158, 11, 0.1), var(--card) 60%);
|
||||
}
|
||||
.banner.ready {
|
||||
border-color: rgba(20, 184, 166, 0.45);
|
||||
background: linear-gradient(90deg, rgba(20, 184, 166, 0.1), var(--card) 60%);
|
||||
}
|
||||
.banner-title { font-weight: 700; font-size: 13px; }
|
||||
.banner-detail { font-size: 12px; color: var(--muted); margin-top: 2px; }
|
||||
.row { display: flex; gap: 8px; align-items: center; }
|
||||
input[type="text"] {
|
||||
width: 100%;
|
||||
background: #0b1222;
|
||||
color: var(--text);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
padding: 10px 11px;
|
||||
font-size: 14px;
|
||||
}
|
||||
button {
|
||||
background: var(--accent);
|
||||
color: #fff;
|
||||
border: 0;
|
||||
border-radius: 8px;
|
||||
padding: 10px 14px;
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
white-space: nowrap;
|
||||
}
|
||||
button.secondary {
|
||||
background: #1e293b;
|
||||
color: var(--text);
|
||||
border: 1px solid var(--border);
|
||||
}
|
||||
.msg { font-size: 12px; margin-top: 6px; min-height: 16px; color: #5eead4; }
|
||||
.msg.err { color: #fca5a5; }
|
||||
.grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 8px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.stat {
|
||||
background: var(--card);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 10px;
|
||||
padding: 9px 10px;
|
||||
text-align: left;
|
||||
width: 100%;
|
||||
}
|
||||
.stat-label { font-size: 11px; color: var(--muted); }
|
||||
.stat-val { font-size: 14px; font-weight: 700; margin-top: 2px; }
|
||||
.stat-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
|
||||
.actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
margin-bottom: 14px;
|
||||
}
|
||||
.actions button { flex: 1; }
|
||||
h2 {
|
||||
margin: 0 0 8px 0;
|
||||
font-size: 12px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.06em;
|
||||
color: var(--muted);
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
.sites {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
|
||||
gap: 8px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.site {
|
||||
display: block;
|
||||
background: var(--card);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 10px;
|
||||
padding: 11px 12px;
|
||||
text-decoration: none;
|
||||
color: var(--text);
|
||||
}
|
||||
.site-top {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
.site-title { font-weight: 700; font-size: 14px; }
|
||||
.tag {
|
||||
font-size: 10px;
|
||||
font-weight: 600;
|
||||
padding: 2px 7px;
|
||||
border-radius: 999px;
|
||||
background: rgba(109, 93, 252, 0.2);
|
||||
color: #c4b5fd;
|
||||
}
|
||||
.mono { font-family: ui-monospace, monospace; font-size: 11px; }
|
||||
.site-host { color: #5eead4; margin-top: 4px; }
|
||||
.site-desc { color: var(--muted); font-size: 12px; margin-top: 4px; }
|
||||
.torrent-item {
|
||||
padding: 8px 0;
|
||||
border-top: 1px solid rgba(255, 255, 255, 0.08);
|
||||
}
|
||||
.torrent-item:first-child { border-top: 0; padding-top: 0; }
|
||||
.track {
|
||||
width: 100%;
|
||||
height: 6px;
|
||||
background: #0b1222;
|
||||
border-radius: 999px;
|
||||
overflow: hidden;
|
||||
margin: 5px 0;
|
||||
}
|
||||
.fill {
|
||||
height: 100%;
|
||||
background: linear-gradient(90deg, var(--accent), var(--teal));
|
||||
}
|
||||
.footer {
|
||||
border-top: 1px solid var(--border);
|
||||
padding-top: 10px;
|
||||
margin-top: 14px;
|
||||
font-size: 12px;
|
||||
color: var(--muted);
|
||||
}
|
||||
.b32-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-top: 6px;
|
||||
}
|
||||
.b32-text {
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
color: var(--text);
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<main class="wrap">
|
||||
<header>
|
||||
<div class="brand">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 96 96" aria-hidden="true">
|
||||
<defs>
|
||||
<linearGradient id="g" x1="0" y1="0" x2="1" y2="1">
|
||||
<stop offset="0%" stop-color="#6d5dfc" />
|
||||
<stop offset="100%" stop-color="#14b8a6" />
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<rect width="96" height="96" rx="22" fill="#0f172a" />
|
||||
<circle cx="48" cy="48" r="34" fill="none" stroke="url(#g)" stroke-width="6" />
|
||||
<path d="M48 25v29m0 0-12-12m12 12 12-12" fill="none" stroke="#f8fafc" stroke-width="6" stroke-linecap="round" stroke-linejoin="round" />
|
||||
<path d="M29 64h38" stroke="#14b8a6" stroke-width="6" stroke-linecap="round" />
|
||||
</svg>
|
||||
<div>
|
||||
<div class="brand-title">Moon I2P</div>
|
||||
<div class="brand-sub">Private .i2p Browser & BitTorrent/DHT Router</div>
|
||||
</div>
|
||||
</div>
|
||||
<span id="status-pill" class="pill offline">Starting...</span>
|
||||
</header>
|
||||
|
||||
<section id="warmup-banner" class="card banner booting">
|
||||
<div id="warmup-title" class="banner-title">Bootstrapping I2P router & tunnels...</div>
|
||||
<div id="warmup-detail" class="banner-detail">Waiting for local moon-i2p service.</div>
|
||||
</section>
|
||||
|
||||
<section class="card">
|
||||
<form id="nav-form" class="row">
|
||||
<input id="nav-input" type="text" autocomplete="off" spellcheck="false" placeholder="Enter .i2p domain, .b32.i2p, or magnet:..." />
|
||||
<button type="submit">Go</button>
|
||||
</form>
|
||||
<div id="nav-msg" class="msg"></div>
|
||||
</section>
|
||||
|
||||
<section class="grid" aria-label="Router Telemetry">
|
||||
<div class="stat">
|
||||
<div class="stat-label">Tunnels</div>
|
||||
<div id="tile-tunnels-val" class="stat-val">--</div>
|
||||
<div id="tile-tunnels-sub" class="stat-sub">Building pool...</div>
|
||||
</div>
|
||||
<div class="stat">
|
||||
<div class="stat-label">NetDB Peers</div>
|
||||
<div id="tile-netdb-val" class="stat-val">--</div>
|
||||
<div id="tile-netdb-sub" class="stat-sub">-- floodfills</div>
|
||||
</div>
|
||||
<div class="stat">
|
||||
<div class="stat-label">I2P DHT</div>
|
||||
<div id="tile-dht-val" class="stat-val">--</div>
|
||||
<div id="tile-dht-sub" class="stat-sub">Proto 17 / 18</div>
|
||||
</div>
|
||||
<button id="torrents-tile" class="stat" type="button">
|
||||
<div class="stat-label">Torrents</div>
|
||||
<div id="tile-torrents-val" class="stat-val">0 total</div>
|
||||
<div id="tile-torrents-sub" class="stat-sub">Tap to open manager</div>
|
||||
</button>
|
||||
</section>
|
||||
|
||||
<section class="actions">
|
||||
<button id="open-torrents-btn" type="button">Torrents & DHT</button>
|
||||
<button id="open-diag-btn" class="secondary" type="button">Diagnostics</button>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h2><span>Built-in .i2p Destinations</span><span>Ready</span></h2>
|
||||
<div class="sites">
|
||||
<a class="site" href="http://notbob.i2p/">
|
||||
<div class="site-top"><span class="site-title">NotBob Directory</span><span class="tag">Directory</span></div>
|
||||
<div class="site-host mono">notbob.i2p</div>
|
||||
<div class="site-desc">Uptime-monitored directory of live .i2p eepsites</div>
|
||||
</a>
|
||||
<a class="site" href="http://tracker2.postman.i2p/">
|
||||
<div class="site-top"><span class="site-title">Postman Tracker</span><span class="tag">Torrents</span></div>
|
||||
<div class="site-host mono">tracker2.postman.i2p</div>
|
||||
<div class="site-desc">Public I2P BitTorrent tracker & torrent index</div>
|
||||
</a>
|
||||
<a class="site" href="http://insulaocculta.i2p/">
|
||||
<div class="site-top"><span class="site-title">Insula Occulta</span><span class="tag">Torrents</span></div>
|
||||
<div class="site-host mono">insulaocculta.i2p</div>
|
||||
<div class="site-desc">I2P music & media torrent tracker</div>
|
||||
</a>
|
||||
<a class="site" href="http://stats.i2p/">
|
||||
<div class="site-top"><span class="site-title">I2P Stats</span><span class="tag">Network</span></div>
|
||||
<div class="site-host mono">stats.i2p</div>
|
||||
<div class="site-desc">Network health, router stats & hosts.txt addressbook</div>
|
||||
</a>
|
||||
<a class="site" href="http://zzz.i2p/">
|
||||
<div class="site-top"><span class="site-title">zzz.i2p</span><span class="tag">Community</span></div>
|
||||
<div class="site-host mono">zzz.i2p</div>
|
||||
<div class="site-desc">I2P developer forums & protocol proposals</div>
|
||||
</a>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section id="active-torrents-card" class="card" style="display:none;">
|
||||
<h2><span>Active Torrents (<span id="active-torrents-count">0</span>)</span></h2>
|
||||
<div id="active-torrents-list"></div>
|
||||
</section>
|
||||
|
||||
<footer class="footer">
|
||||
<div id="footer-proxy" class="mono">Proxy: starting...</div>
|
||||
<div class="b32-row">
|
||||
<span class="stat-label">Torrent .b32:</span>
|
||||
<span id="footer-b32" class="mono b32-text">--</span>
|
||||
<button id="copy-b32-btn" class="secondary" type="button">Copy</button>
|
||||
</div>
|
||||
</footer>
|
||||
</main>
|
||||
|
||||
<script>
|
||||
"use strict";
|
||||
const $ = (id) => document.getElementById(id);
|
||||
let currentB32 = "";
|
||||
|
||||
function fmtBytes(n) {
|
||||
if (!n || n <= 0) return "0 B";
|
||||
const units = ["B", "KiB", "MiB", "GiB"];
|
||||
let u = 0;
|
||||
let v = n;
|
||||
while (v >= 1024 && u < units.length - 1) {
|
||||
v /= 1024;
|
||||
u++;
|
||||
}
|
||||
return v.toFixed(u === 0 ? 0 : 1) + " " + units[u];
|
||||
}
|
||||
|
||||
function escapeHtml(s) {
|
||||
return String(s || "").replace(/[&<>"']/g, (c) => ({
|
||||
"&": "&",
|
||||
"<": "<",
|
||||
">": ">",
|
||||
'"': """,
|
||||
"'": "'",
|
||||
})[c]);
|
||||
}
|
||||
|
||||
function setNavMsg(text, isErr) {
|
||||
const el = $("nav-msg");
|
||||
el.textContent = text;
|
||||
el.className = isErr ? "msg err" : "msg";
|
||||
}
|
||||
|
||||
function refreshStatus() {
|
||||
if (document.hidden || !window.MoonI2pStart || !window.MoonI2pStart.getStatusJson) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const data = JSON.parse(window.MoonI2pStart.getStatusJson() || "{}");
|
||||
const pPort = Number(data.proxy_port || 0);
|
||||
$("footer-proxy").textContent = pPort > 0 ? "HTTP Proxy: 127.0.0.1:" + pPort : "HTTP Proxy: starting...";
|
||||
|
||||
const rs = data.status || {};
|
||||
const torrents = Array.isArray(data.torrents) ? data.torrents : [];
|
||||
const pill = $("status-pill");
|
||||
const banner = $("warmup-banner");
|
||||
const title = $("warmup-title");
|
||||
const detail = $("warmup-detail");
|
||||
|
||||
if (!data.api_ready || !rs.ok) {
|
||||
pill.textContent = "Bootstrapping...";
|
||||
pill.className = "pill booting";
|
||||
banner.className = "card banner booting";
|
||||
title.textContent = data.status_text || "Starting bundled moon-i2p router...";
|
||||
detail.textContent = "Reseeding public I2P peers and preparing HTTP proxy.";
|
||||
$("tile-tunnels-val").textContent = "--";
|
||||
$("tile-tunnels-sub").textContent = "Router starting";
|
||||
$("tile-netdb-val").textContent = "--";
|
||||
$("tile-netdb-sub").textContent = "-- floodfills";
|
||||
$("tile-dht-val").textContent = "--";
|
||||
$("tile-dht-sub").textContent = "Proto 17 / 18";
|
||||
currentB32 = "";
|
||||
$("footer-b32").textContent = "--";
|
||||
} else {
|
||||
const inT = Number(rs.inbound_tunnels || 0);
|
||||
const outT = Number(rs.outbound_tunnels || 0);
|
||||
const peers = Number(rs.netdb_routers || 0);
|
||||
const ff = Number(rs.netdb_floodfills || 0);
|
||||
const dht = rs.dht || {};
|
||||
|
||||
$("tile-tunnels-val").textContent = inT + "in / " + outT + "out";
|
||||
$("tile-tunnels-sub").textContent = inT > 0 && outT > 0 ? "Tunnels active" : "Building client tunnels";
|
||||
$("tile-netdb-val").textContent = String(peers);
|
||||
$("tile-netdb-sub").textContent = ff + " floodfills";
|
||||
$("tile-dht-val").textContent = (dht.routing_table_nodes || 0) + " nodes";
|
||||
$("tile-dht-sub").textContent = (dht.queries_sent || 0) + " sent / " + (dht.peers_discovered || 0) + " peers";
|
||||
currentB32 = rs.torrent_b32 || "";
|
||||
$("footer-b32").textContent = currentB32 || "--";
|
||||
|
||||
if (inT === 0 || outT === 0) {
|
||||
pill.textContent = "Bootstrapping...";
|
||||
pill.className = "pill booting";
|
||||
banner.className = "card banner booting";
|
||||
title.textContent = "Bootstrapping I2P tunnels (typically 15–30s)...";
|
||||
detail.textContent = "NetDB: " + peers + " peers (" + ff + " floodfills) · " + inT + "in/" + outT + "out tunnels.";
|
||||
} else {
|
||||
pill.textContent = rs.public_mode ? "Public Online" : "I2P Ready";
|
||||
pill.className = "pill online";
|
||||
banner.className = "card banner ready";
|
||||
title.textContent = "I2P tunnels active and ready";
|
||||
detail.textContent = inT + " inbound / " + outT + " outbound tunnels · " + peers + " NetDB peers.";
|
||||
}
|
||||
}
|
||||
|
||||
const active = torrents.filter((t) => !t.completed && !t.paused).length;
|
||||
$("tile-torrents-val").textContent = torrents.length + " total";
|
||||
$("tile-torrents-sub").textContent = active > 0 ? active + " downloading · Tap to view" : "Tap to open manager";
|
||||
|
||||
const card = $("active-torrents-card");
|
||||
const list = $("active-torrents-list");
|
||||
$("active-torrents-count").textContent = String(torrents.length);
|
||||
if (torrents.length === 0) {
|
||||
card.style.display = "none";
|
||||
list.innerHTML = "";
|
||||
} else {
|
||||
card.style.display = "";
|
||||
list.innerHTML = torrents.slice(0, 6).map((t) => {
|
||||
const pct = Math.max(0, Math.min(100, Number(t.progress_pct || 0)));
|
||||
return (
|
||||
'<div class="torrent-item">' +
|
||||
'<div class="row" style="justify-content:space-between;">' +
|
||||
"<strong>" + escapeHtml(t.name) + "</strong>" +
|
||||
'<span class="pill ' + (t.completed ? "online" : "") + '">' + escapeHtml(t.state) + " · " + pct + "%</span>" +
|
||||
"</div>" +
|
||||
'<div class="track"><div class="fill" style="width:' + pct + '%"></div></div>' +
|
||||
'<div style="color:var(--muted);font-size:11px;">' +
|
||||
fmtBytes(t.downloaded_bytes) + " / " + fmtBytes(t.total_length) + " · " +
|
||||
(t.connected_peers || 0) + "/" + (t.known_peers || 0) + " peers" +
|
||||
"</div>" +
|
||||
"</div>"
|
||||
);
|
||||
}).join("");
|
||||
}
|
||||
} catch (_e) {
|
||||
// Ignore transient parse/bridge errors
|
||||
}
|
||||
}
|
||||
|
||||
$("nav-form").addEventListener("submit", (e) => {
|
||||
e.preventDefault();
|
||||
const raw = String($("nav-input").value || "").trim();
|
||||
if (!raw) {
|
||||
setNavMsg("");
|
||||
return;
|
||||
}
|
||||
if (!/^magnet:/i.test(raw) && /\s/.test(raw)) {
|
||||
setNavMsg("Enter a .i2p domain (e.g. notbob.i2p), .b32.i2p address, or magnet: link.", true);
|
||||
return;
|
||||
}
|
||||
setNavMsg("");
|
||||
if (window.MoonI2pStart && window.MoonI2pStart.openUrl) {
|
||||
window.MoonI2pStart.openUrl(raw);
|
||||
} else {
|
||||
window.location.href = /^https?:\/\//i.test(raw) ? raw : "http://" + raw;
|
||||
}
|
||||
});
|
||||
|
||||
document.querySelectorAll("a.site").forEach((a) => {
|
||||
a.addEventListener("click", (e) => {
|
||||
if (window.MoonI2pStart && window.MoonI2pStart.openUrl) {
|
||||
e.preventDefault();
|
||||
window.MoonI2pStart.openUrl(a.getAttribute("href"));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const openTorrents = () => window.MoonI2pStart && window.MoonI2pStart.openTorrents();
|
||||
$("torrents-tile").addEventListener("click", openTorrents);
|
||||
$("open-torrents-btn").addEventListener("click", openTorrents);
|
||||
$("open-diag-btn").addEventListener("click", () => window.MoonI2pStart && window.MoonI2pStart.openDiagnostics());
|
||||
$("copy-b32-btn").addEventListener("click", () => {
|
||||
if (!currentB32) {
|
||||
setNavMsg("Router has not published a .b32.i2p address yet.", true);
|
||||
return;
|
||||
}
|
||||
if (window.MoonI2pStart && window.MoonI2pStart.copyText) {
|
||||
window.MoonI2pStart.copyText(currentB32);
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener("visibilitychange", () => {
|
||||
if (!document.hidden) refreshStatus();
|
||||
});
|
||||
|
||||
refreshStatus();
|
||||
setInterval(refreshStatus, 1500);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -36,6 +36,7 @@ import android.widget.ScrollView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
@@ -52,23 +53,25 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Embedded I2P WebView browser defaulting to http://insulaocculta.i2p/ paired
|
||||
* with a same-origin Torrents & I2P DHT management dashboard tab and full
|
||||
* Embedded I2P WebView browser defaulting to the built-in Moon I2P Start Page
|
||||
* paired with a same-origin Torrents & I2P DHT management dashboard tab and full
|
||||
* diagnostics report export.
|
||||
*/
|
||||
public class MainActivity extends Activity {
|
||||
private static final String HOMEPAGE = "http://insulaocculta.i2p/";
|
||||
private static final String HOMEPAGE = "file:///android_asset/start.html";
|
||||
private static final int REQ_PICK_TORRENT = 2001;
|
||||
private static final int REQ_NOTIF_PERM = 2002;
|
||||
|
||||
private static final String[][] BOOKMARKS = new String[][] {
|
||||
{ "NotBob Directory", "http://notbob.i2p/" },
|
||||
{ "Postman Tracker", "http://tracker2.postman.i2p/" },
|
||||
{ "Insula Occulta", "http://insulaocculta.i2p/" },
|
||||
{ "I2P Stats", "http://stats.i2p/" },
|
||||
{ "zzz.i2p", "http://zzz.i2p/" },
|
||||
{ "Postman Tracker", "http://tracker2.postman.i2p/" },
|
||||
{ "NotBob Directory", "http://notbob.i2p/" },
|
||||
};
|
||||
|
||||
private LinearLayout mTopBar;
|
||||
@@ -104,7 +107,7 @@ public class MainActivity extends Activity {
|
||||
}
|
||||
|
||||
buildUi();
|
||||
mBrowserView.loadUrl(HOMEPAGE);
|
||||
navigateBrowser(HOMEPAGE);
|
||||
handleIntent(getIntent());
|
||||
startStatusPoll();
|
||||
}
|
||||
@@ -167,7 +170,8 @@ public class MainActivity extends Activity {
|
||||
mTopBar.addView(makeIconBtn("R", v -> mBrowserView.reload()));
|
||||
|
||||
mUrlInput = new EditText(this);
|
||||
mUrlInput.setText(HOMEPAGE);
|
||||
mUrlInput.setHint("Enter .i2p address or magnet: URI...");
|
||||
mUrlInput.setText("");
|
||||
mUrlInput.setTextColor(Color.parseColor("#F8FAFC"));
|
||||
mUrlInput.setHintTextColor(Color.parseColor("#94A3B8"));
|
||||
mUrlInput.setBackgroundColor(Color.parseColor("#0B1222"));
|
||||
@@ -211,6 +215,7 @@ public class MainActivity extends Activity {
|
||||
mBrowserView = new WebView(this);
|
||||
configureWebView(mBrowserView);
|
||||
mBrowserView.addJavascriptInterface(new BrowserLinkBridge(), "MoonI2pPage");
|
||||
mBrowserView.addJavascriptInterface(new StartPageBridge(), "MoonI2pStart");
|
||||
mBrowserView.setWebViewClient(new I2pWebViewClient());
|
||||
mBrowserView.setDownloadListener((dlUrl, userAgent, contentDisposition, mimetype, contentLength) -> {
|
||||
if (dlUrl == null) return;
|
||||
@@ -338,16 +343,25 @@ public class MainActivity extends Activity {
|
||||
|
||||
private void navigateBrowser(String raw) {
|
||||
String s = raw == null ? "" : raw.trim();
|
||||
if (s.isEmpty()) s = HOMEPAGE;
|
||||
if (!s.contains("://") && !s.startsWith("magnet:")) {
|
||||
s = "http://" + s;
|
||||
if (s.isEmpty() || HOMEPAGE.equals(s)) {
|
||||
mUrlInput.setText("");
|
||||
switchTab(false);
|
||||
mBrowserView.loadUrl(HOMEPAGE);
|
||||
return;
|
||||
}
|
||||
if (!s.contains("://") && !s.toLowerCase(Locale.ROOT).startsWith("magnet:")) {
|
||||
if (!s.contains(".") && !s.contains("/") && !s.contains(":") && !s.contains(" ")) {
|
||||
s = "http://" + s + ".i2p/";
|
||||
} else {
|
||||
s = "http://" + s;
|
||||
}
|
||||
}
|
||||
mUrlInput.setText(s);
|
||||
if (s.toLowerCase(Locale.ROOT).startsWith("magnet:")) {
|
||||
submitMagnetAsync(s);
|
||||
switchTab(true);
|
||||
return;
|
||||
}
|
||||
mUrlInput.setText(s);
|
||||
switchTab(false);
|
||||
mBrowserView.loadUrl(s);
|
||||
}
|
||||
@@ -653,11 +667,88 @@ public class MainActivity extends Activity {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isCurrentBrowserPageStart() {
|
||||
if (Looper.myLooper() == Looper.getMainLooper()) {
|
||||
return HOMEPAGE.equals(mBrowserView.getUrl());
|
||||
}
|
||||
final boolean[] result = new boolean[] { false };
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
runOnUiThread(() -> {
|
||||
try {
|
||||
result[0] = HOMEPAGE.equals(mBrowserView.getUrl());
|
||||
} finally {
|
||||
latch.countDown();
|
||||
}
|
||||
});
|
||||
try {
|
||||
latch.await(250, TimeUnit.MILLISECONDS);
|
||||
} catch (InterruptedException ignored) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
return result[0];
|
||||
}
|
||||
|
||||
private class StartPageBridge {
|
||||
@JavascriptInterface
|
||||
public String getStatusJson() {
|
||||
if (!isCurrentBrowserPageStart()) return "{}";
|
||||
try {
|
||||
JSONObject out = new JSONObject();
|
||||
boolean apiReady = RouterService.isApiReady();
|
||||
out.put("api_ready", apiReady);
|
||||
out.put("status_text", RouterService.getStatusText());
|
||||
out.put("proxy_port", RouterService.getProxyPort());
|
||||
out.put("api_port", RouterService.getApiPort());
|
||||
if (apiReady) {
|
||||
String stRaw = RouterService.fetchLocalApiJsonOrNull("/api/status");
|
||||
if (stRaw != null) {
|
||||
out.put("status", new JSONObject(stRaw));
|
||||
}
|
||||
String tlRaw = RouterService.fetchLocalApiJsonOrNull("/api/torrents");
|
||||
if (tlRaw != null) {
|
||||
JSONObject tlObj = new JSONObject(tlRaw);
|
||||
JSONArray arr = tlObj.optJSONArray("torrents");
|
||||
out.put("torrents", arr != null ? arr : new JSONArray());
|
||||
}
|
||||
}
|
||||
return out.toString();
|
||||
} catch (Exception e) {
|
||||
return "{\"api_ready\":false}";
|
||||
}
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public void openUrl(String url) {
|
||||
if (!isCurrentBrowserPageStart()) return;
|
||||
runOnUiThread(() -> navigateBrowser(url));
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public void openTorrents() {
|
||||
if (!isCurrentBrowserPageStart()) return;
|
||||
runOnUiThread(() -> switchTab(true));
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public void openDiagnostics() {
|
||||
if (!isCurrentBrowserPageStart()) return;
|
||||
runOnUiThread(() -> showDiagnosticsDialog());
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public void copyText(String text) {
|
||||
if (!isCurrentBrowserPageStart()) return;
|
||||
runOnUiThread(() -> copyToClipboard(text != null ? text : "", "Copied to clipboard"));
|
||||
}
|
||||
}
|
||||
|
||||
private class I2pWebViewClient extends WebViewClient {
|
||||
@Override
|
||||
public void onPageFinished(WebView view, String url) {
|
||||
super.onPageFinished(view, url);
|
||||
if (url != null && !url.startsWith("about:")) {
|
||||
if (HOMEPAGE.equals(url)) {
|
||||
mUrlInput.setText("");
|
||||
} else if (url != null && !url.startsWith("about:")) {
|
||||
mUrlInput.setText(url);
|
||||
try {
|
||||
Uri u = Uri.parse(url);
|
||||
@@ -692,6 +783,9 @@ public class MainActivity extends Activity {
|
||||
Uri uri = request.getUrl();
|
||||
String url = uri.toString();
|
||||
String lower = url.toLowerCase(Locale.ROOT);
|
||||
if (lower.startsWith("file:")) {
|
||||
return true;
|
||||
}
|
||||
if (lower.startsWith("magnet:")) {
|
||||
submitMagnetAsync(url);
|
||||
switchTab(true);
|
||||
|
||||
@@ -177,6 +177,37 @@ public class RouterService extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
public static String fetchLocalApiJsonOrNull(String path) {
|
||||
int port = sApiPort;
|
||||
if (!sApiReady || port <= 0) return null;
|
||||
HttpURLConnection conn = null;
|
||||
try {
|
||||
URL u = new URL("http://127.0.0.1:" + port + path);
|
||||
conn = (HttpURLConnection) u.openConnection();
|
||||
conn.setConnectTimeout(1000);
|
||||
conn.setReadTimeout(1500);
|
||||
if (conn.getResponseCode() != 200) {
|
||||
return null;
|
||||
}
|
||||
InputStream in = conn.getInputStream();
|
||||
if (in == null) return null;
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
byte[] buf = new byte[4096];
|
||||
int total = 0;
|
||||
int n;
|
||||
while (total < 128 * 1024 && (n = in.read(buf)) > 0) {
|
||||
out.write(buf, 0, n);
|
||||
total += n;
|
||||
}
|
||||
String body = new String(out.toByteArray(), StandardCharsets.UTF_8).trim();
|
||||
return body.startsWith("{") ? body : null;
|
||||
} catch (Exception ignored) {
|
||||
return null;
|
||||
} finally {
|
||||
if (conn != null) conn.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects device info, service state, router API snapshots, Android proxy events,
|
||||
* and the verbose moon-i2p router log. Call from a background thread.
|
||||
|
||||
Reference in new issue
Block a user