The WebView requests a screenful of icons at once on several threads, and loading and drawing icon drawables concurrently failed for that first batch (and for every widget icon). Icons are now drawn one at a time under a lock from a mutated drawable, widget icons fall back to the app icon, and failures are logged under the "ultra" tag. The page retries a failed icon twice and then shows a blank disc instead of a broken image. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019EEjkJVV72Lu8ndDVWg5BT
124 lines
5.5 KiB
HTML
124 lines
5.5 KiB
HTML
<!doctype html>
|
|
<html lang="en" class="dark">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
|
|
<title>ultra · Launcher</title>
|
|
<link rel="stylesheet" href="ui.css">
|
|
<link rel="stylesheet" href="style.css">
|
|
</head>
|
|
<body>
|
|
<main id="app"></main>
|
|
<div id="toast" role="status"></div>
|
|
<script type="module">
|
|
import { mount } from "./ultra.js";
|
|
|
|
// On a phone, MainActivity.java adds window.Android, serves apps.json and
|
|
// widgets.json, and draws widgets over the slots reported by place().
|
|
// In a desktop browser the demo JSON files are served and these stand-ins run.
|
|
const toast = (s) => {
|
|
const t = document.getElementById("toast");
|
|
t.textContent = s; t.classList.add("show");
|
|
clearTimeout(toast.t); toast.t = setTimeout(() => t.classList.remove("show"), 1600);
|
|
};
|
|
let demoWidget = 100;
|
|
const host = window.Android || {
|
|
launch: (c) => toast("Open " + c),
|
|
appInfo: (c) => toast("App info for " + c),
|
|
addWidget: () => setTimeout(() => window.ultraHome.widgetAdded(demoWidget++), 0),
|
|
removeWidget: () => {},
|
|
placeWidgets: () => {},
|
|
openSettings: () => toast("Open system settings"),
|
|
pickWallpaper: () => toast("Pick a wallpaper"),
|
|
haptic: () => navigator.vibrate?.(10),
|
|
is24Hour: () => false,
|
|
};
|
|
if (!window.Android) document.documentElement.classList.add("demo");
|
|
|
|
let fmtTime, fmtDate;
|
|
const formats = () => {
|
|
fmtTime = new Intl.DateTimeFormat(undefined,
|
|
{ hour: "numeric", minute: "2-digit", hourCycle: host.is24Hour() ? "h23" : "h12" });
|
|
fmtDate = new Intl.DateTimeFormat(undefined, { weekday: "long", month: "long", day: "numeric" });
|
|
};
|
|
formats();
|
|
|
|
// Tell the shell where the live widget slots are (CSS px, viewport-relative).
|
|
let placed = "";
|
|
const place = () => {
|
|
const slots = [...document.querySelectorAll(".widget-slot[data-wid]")].map((s) => {
|
|
const r = s.getBoundingClientRect();
|
|
return [+s.dataset.wid, Math.round(r.left), Math.round(r.top), Math.round(r.width), Math.round(r.height)];
|
|
});
|
|
const j = JSON.stringify(slots);
|
|
if (j !== placed) { placed = j; host.placeWidgets(j); }
|
|
};
|
|
|
|
const app = await mount("#app", "./app.wasm", {
|
|
onRender: place,
|
|
imports: ({ strs }) => ({
|
|
launch: (h) => host.launch(strs[h]),
|
|
app_info: (h) => host.appInfo(strs[h]),
|
|
add_widget: (h) => host.addWidget(strs[h]),
|
|
remove_widget: (id) => host.removeWidget(id),
|
|
open_settings: () => host.openSettings(),
|
|
pick_wallpaper: () => host.pickWallpaper(),
|
|
haptic: () => host.haptic(),
|
|
clock_time: (h) => { strs[h] = fmtTime.format(new Date()).replace(/\s?[AP]M$/i, ""); },
|
|
clock_date: (h) => { strs[h] = fmtDate.format(new Date()); },
|
|
}),
|
|
});
|
|
|
|
// Messages the shell and the gestures below send (keep in sync with app.py).
|
|
const TICK = 1, RELOAD = 2, HOME = 3, BACK = 4, SWIPE_DOWN = 5, SWIPE_UP = 6,
|
|
WIDGET_ADDED = 7, WIDGET_MENU = 8;
|
|
window.ultraHome = {
|
|
tick: () => { formats(); app.dispatch(TICK, 1); },
|
|
reload: () => app.dispatch(RELOAD, 0),
|
|
home: () => { app.dispatch(HOME, 0); window.scrollTo({ top: 0, behavior: "smooth" }); },
|
|
back: () => app.dispatch(BACK, 0),
|
|
widgetAdded: (id) => app.dispatch(WIDGET_ADDED, id),
|
|
widgetMenu: (id) => app.dispatch(WIDGET_MENU, id),
|
|
place: () => { placed = ""; place(); },
|
|
};
|
|
// An icon that fails to load is retried twice with backoff, then drawn as a blank
|
|
// disc instead of the browser's broken-image box.
|
|
document.addEventListener("error", (e) => {
|
|
const img = e.target;
|
|
if (!(img instanceof HTMLImageElement) || !img.classList.contains("icon")) return;
|
|
const n = (img.__retries = (img.__retries || 0) + 1);
|
|
if (n > 2) { img.classList.add("missing"); return; }
|
|
setTimeout(() => {
|
|
const base = img.getAttribute("src").replace(/[?&]retry=\d+$/, "");
|
|
img.src = base + (base.includes("?") ? "&" : "?") + "retry=" + n;
|
|
}, 300 * n);
|
|
}, true);
|
|
document.addEventListener("load", (e) => {
|
|
if (e.target instanceof HTMLImageElement) e.target.classList.remove("missing");
|
|
}, true);
|
|
document.addEventListener("visibilitychange", () => { if (!document.hidden) window.ultraHome.tick(); });
|
|
addEventListener("scroll", () => requestAnimationFrame(place), { passive: true });
|
|
addEventListener("resize", () => requestAnimationFrame(place));
|
|
|
|
// Swipe down on the home screen opens the drawer; swipe up closes it once its
|
|
// list is scrolled to the end (or doesn't scroll).
|
|
let start = null;
|
|
addEventListener("touchstart", (e) => {
|
|
const t = e.touches[0];
|
|
start = e.touches.length === 1 ? { x: t.clientX, y: t.clientY, at: Date.now() } : null;
|
|
}, { passive: true });
|
|
addEventListener("touchend", (e) => {
|
|
if (!start) return;
|
|
const t = e.changedTouches[0], dx = t.clientX - start.x, dy = t.clientY - start.y;
|
|
const quick = Date.now() - start.at < 700;
|
|
start = null;
|
|
if (!quick || Math.abs(dy) < 60 || Math.abs(dx) > Math.abs(dy)) return;
|
|
if (document.querySelector(".sheet")) return;
|
|
const list = document.querySelector(".drawer .apps");
|
|
if (dy > 0 && !list && window.scrollY <= 0) app.dispatch(SWIPE_DOWN, 0);
|
|
else if (dy < 0 && list && list.scrollTop + list.clientHeight >= list.scrollHeight - 2) app.dispatch(SWIPE_UP, 0);
|
|
}, { passive: true });
|
|
</script>
|
|
</body>
|
|
</html>
|