Rewrite the launcher in MoonBit (old code moves to legacy/) #1

Merged
nandi merged 9 commits from moonbit-rewrite into main 2026-11-23 01:57:10 +00:00
Owner

What

Rewrites the launcher in MoonBit. The old code moved into legacy/ with git mv (history follows); the MoonBit project is at the repo root. Not merged, not yet run on a device.

Architecture, and why

pure MoonBit (moon test on js and wasm-gc):  gesture ─► app.input ─► app.update(Model, Msg) ─► Effects (data)
                                                                 └─► app.view(Model) ─► vdom tree (data)
web/ (js backend):  runs the Effects against window.Android, patches the DOM, listens for events
android/java:       HomeActivity + WebView + AppWidgetHostViews, Updater, RecentsService
  • grid/ packing and cell math (port of Layout.js / app.py), gesture/ pointer state machine, updater/ release/version logic, vdom/ a data-only virtual DOM, app/ the Elm-style Model/Msg/update/view plus JSON persistence, search, menus, drag, resize and the update flow. No platform dependency in any of them.
  • The view is a data tree, so it is snapshot-tested as text, and the 60 headless tests drive the whole app through pointer input aimed at tree nodes, the way the page aims it.
  • Rendering stays in the WebView (existing design: real AppWidgetHostViews over transparent slots), so the platform layer is thin: web/ is ~700 lines of MoonBit with one-line JS FFI bodies.
  • Rabbita was considered and not used: it ties the view to its DOM type and closures (not testable as plain data), and the drag/hit-test/gesture handling needs delegated pointer events anyway. A pure-MoonBit native/NDK shell was rejected: it would still need the same Java classes, add hundreds of lines of hand-written JNI, and could not be run or tested here.
  • Java that remains (~1,100 lines, android/java/), and why: HomeActivity (an Activity for the HOME role, the WebView, LauncherApps/PackageManager/AppWidgetManager queries, and the AppWidgetHostViews, which are Java Views whose touch interception must decide synchronously), Updater (HttpURLConnection and PackageInstaller), RecentsService (an AccessibilityService must be a Java class named in the manifest). None of it decides anything; update decisions, layout and gestures are all MoonBit.

What runs where

where how
core + app logic desktop, CI moon test (js, wasm-gc)
page desktop Chromium, CI tests/e2e.cjs (legacy flows ported), tests/android-sim.cjs (page against a stub window.Android)
APK build only android/build.sh: aapt2, javac, d8, zipalign, apksigner (no Gradle)
Java shell on a device not run

Parity checklist

  • Blank home, hint
  • Long-press home: menu (Add apps / Add widget / Wallpaper / Settings / Check for updates)
  • Add apps via the drawer's pick mode; add widgets (picker with search by widget or app, Enter picks first)
  • Long-press to lift and drag; reorder over another app; drop in an empty cell (pinned, persisted); release without moving opens the item menu (move earlier/later, app info, remove)
  • Widget handles (right/bottom/corner) snapping to the grid within the widget's limits; pressing the body moves it; Done/Remove bar
  • Dense packing of apps beside widgets
  • Drawer with search, Enter opens the first match, long-press menu (add/remove from home, app info, uninstall; none for system apps), swipe down/up
  • Home search pill that opens the drawer (from the Qt build)
  • Windows button (Recents via RecentsService)
  • Layout persisted (JSON in localStorage); the old WebView build's ultra.home.* layout imported
  • Desktop demo mode (demo JSON, toasts, placeholder widgets)
  • Self-update: release API → version.json → decide (newer, declined, 6 h throttle, build-N tag fallback) → PackageInstaller, all decisions in MoonBit
  • [~] Native widget touch handling, drawer cover of native widgets, keyboard, icons: ported unchanged from the legacy shell; the page side is tested against a stub, the Java side is not run
  • Qt build's saved layout (QSettings INI) is not imported
  • Page JS is ~560 KB (MoonBit's JSON/number runtime); not shrunk

Verified

  • moon test: 60 passed on js and on wasm-gc
  • tests/e2e.cjs: passes against the build (Playwright 1.65.1, Chromium); screenshots in docs/screenshots/
  • tests/android-sim.cjs: passes (icons, widget placement and cover, keyboard, Recents, update check and install request)
  • android/build.sh produces dev.ultra.launcher versionCode N / versionName 0.1.0, aapt2 dump badging and apksigner verify accept it, signer SHA-256 F9:08:30:93:…:9C:BC, the committed key's
  • sweet doctor: no problems

Not verified

Anything on a device: the WebView + widget views + installer + accessibility service together. The CI workflow has not run yet on the Gitea runner (it follows identicons-web's: MoonBit installed by script in node:22-bookworm, no setup-node, timeout-minutes on both jobs).

Install path

The APK keeps package dev.ultra.launcher, the activity class name dev.ultra.launcher.HomeActivity (the Qt build's, so a default-home choice survives) and the same committed signing key (android/debug.keystore, copied from legacy/android/app/), and its versionCode is minutes since the epoch like the Qt build's, so it installs over the existing APK and the installed app's updater picks it up from the next build-<N> release.

CI

.gitea/workflows/launcher.yml is the new pipeline (test on PRs; APK + release on push to main via ci/gitea-apk.sh). The legacy workflows (.gitea/workflows/legacy.yml, .github/workflows/legacy.yml) run from legacy/ and only by hand; the Gitea one does not publish unless asked, so it cannot take over "latest".

Sweet

.sweet.config.yml (sweet init repo) and .sweet.yml (launcher, 0.1.0, moon.mod annotated // sweet-version). The Android versionName is read from moon.mod by the build, so no second version file.

🤖 Generated with Claude Code

## What Rewrites the launcher in MoonBit. The old code moved into `legacy/` with `git mv` (history follows); the MoonBit project is at the repo root. **Not merged, not yet run on a device.** ## Architecture, and why ``` pure MoonBit (moon test on js and wasm-gc): gesture ─► app.input ─► app.update(Model, Msg) ─► Effects (data) └─► app.view(Model) ─► vdom tree (data) web/ (js backend): runs the Effects against window.Android, patches the DOM, listens for events android/java: HomeActivity + WebView + AppWidgetHostViews, Updater, RecentsService ``` - `grid/` packing and cell math (port of `Layout.js` / `app.py`), `gesture/` pointer state machine, `updater/` release/version logic, `vdom/` a data-only virtual DOM, `app/` the Elm-style Model/Msg/update/view plus JSON persistence, search, menus, drag, resize and the update flow. No platform dependency in any of them. - The view is a data tree, so it is snapshot-tested as text, and the 60 headless tests drive the whole app through pointer input aimed at tree nodes, the way the page aims it. - Rendering stays in the WebView (existing design: real `AppWidgetHostView`s over transparent slots), so the platform layer is thin: `web/` is ~700 lines of MoonBit with one-line JS FFI bodies. - Rabbita was considered and not used: it ties the view to its DOM type and closures (not testable as plain data), and the drag/hit-test/gesture handling needs delegated pointer events anyway. A pure-MoonBit native/NDK shell was rejected: it would still need the same Java classes, add hundreds of lines of hand-written JNI, and could not be run or tested here. - **Java that remains (~1,100 lines, `android/java/`), and why:** `HomeActivity` (an `Activity` for the HOME role, the WebView, `LauncherApps`/`PackageManager`/`AppWidgetManager` queries, and the `AppWidgetHostView`s, which are Java Views whose touch interception must decide synchronously), `Updater` (`HttpURLConnection` and `PackageInstaller`), `RecentsService` (an `AccessibilityService` must be a Java class named in the manifest). None of it decides anything; update decisions, layout and gestures are all MoonBit. ## What runs where | | where | how | |---|---|---| | core + app logic | desktop, CI | `moon test` (js, wasm-gc) | | page | desktop Chromium, CI | `tests/e2e.cjs` (legacy flows ported), `tests/android-sim.cjs` (page against a stub `window.Android`) | | APK | build only | `android/build.sh`: aapt2, javac, d8, zipalign, apksigner (no Gradle) | | Java shell on a device | **not run** | | ## Parity checklist - [x] Blank home, hint - [x] Long-press home: menu (Add apps / Add widget / Wallpaper / Settings / Check for updates) - [x] Add apps via the drawer's pick mode; add widgets (picker with search by widget or app, Enter picks first) - [x] Long-press to lift and drag; reorder over another app; drop in an empty cell (pinned, persisted); release without moving opens the item menu (move earlier/later, app info, remove) - [x] Widget handles (right/bottom/corner) snapping to the grid within the widget's limits; pressing the body moves it; Done/Remove bar - [x] Dense packing of apps beside widgets - [x] Drawer with search, Enter opens the first match, long-press menu (add/remove from home, app info, uninstall; none for system apps), swipe down/up - [x] Home search pill that opens the drawer (from the Qt build) - [x] Windows button (Recents via `RecentsService`) - [x] Layout persisted (JSON in localStorage); the old WebView build's `ultra.home.*` layout imported - [x] Desktop demo mode (demo JSON, toasts, placeholder widgets) - [x] Self-update: release API → `version.json` → decide (newer, declined, 6 h throttle, `build-N` tag fallback) → PackageInstaller, all decisions in MoonBit - [~] Native widget touch handling, drawer cover of native widgets, keyboard, icons: ported unchanged from the legacy shell; the page side is tested against a stub, the Java side is not run - [ ] Qt build's saved layout (QSettings INI) is not imported - [ ] Page JS is ~560 KB (MoonBit's JSON/number runtime); not shrunk ## Verified - `moon test`: 60 passed on js and on wasm-gc - `tests/e2e.cjs`: passes against the build (Playwright 1.65.1, Chromium); screenshots in `docs/screenshots/` - `tests/android-sim.cjs`: passes (icons, widget placement and cover, keyboard, Recents, update check and install request) - `android/build.sh` produces `dev.ultra.launcher` versionCode N / versionName 0.1.0, `aapt2 dump badging` and `apksigner verify` accept it, signer SHA-256 `F9:08:30:93:…:9C:BC`, the committed key's - `sweet doctor`: no problems ## Not verified Anything on a device: the WebView + widget views + installer + accessibility service together. The CI workflow has not run yet on the Gitea runner (it follows identicons-web's: MoonBit installed by script in `node:22-bookworm`, no `setup-node`, `timeout-minutes` on both jobs). ## Install path The APK keeps package `dev.ultra.launcher`, the activity class name `dev.ultra.launcher.HomeActivity` (the Qt build's, so a default-home choice survives) and the same committed signing key (`android/debug.keystore`, copied from `legacy/android/app/`), and its versionCode is minutes since the epoch like the Qt build's, so it installs over the existing APK and the installed app's updater picks it up from the next `build-<N>` release. ## CI `.gitea/workflows/launcher.yml` is the new pipeline (test on PRs; APK + release on push to main via `ci/gitea-apk.sh`). The legacy workflows (`.gitea/workflows/legacy.yml`, `.github/workflows/legacy.yml`) run from `legacy/` and only by hand; the Gitea one does not publish unless asked, so it cannot take over "latest". ## Sweet `.sweet.config.yml` (`sweet init repo`) and `.sweet.yml` (`launcher`, 0.1.0, `moon.mod` annotated `// sweet-version`). The Android versionName is read from `moon.mod` by the build, so no second version file. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
nandi added 7 commits 2026-11-23 01:15:06 +00:00
git mv of everything (web/ android/ qt/ wasi/ android-wasm/ tests/ ci/ pixi.toml
README) so history follows; legacy/ keeps its own .gitignore and a new root
.gitignore starts for the MoonBit project.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
grid: packing, pinning, resize steps (port of Layout.js and app.py's grid logic).
gesture: pointer state machine (tap, long press, drag, release, swipe).
updater: release/version parsing and the update decision.
vdom: pure virtual DOM with an HTML-text renderer for tests.
app: Elm-style Model/Msg/update/view with effects as data, persistence (JSON
layout, import of the old WebView build's localStorage), drawer/search, menus,
drag and resize. 60 headless tests drive it through pointer input.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
web/ is the js-target MoonBit program: it renders app.view into the DOM with a
keyed patcher, turns pointer/touch/key events into app input, runs effects
against window.Android or demo stand-ins, and exposes window.launcher.* for the
Android shell. tests/e2e.cjs ports the legacy Playwright flows and passes
against the build; scripts/build-web.sh assembles dist/web.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
android/: HomeActivity (derived from the legacy MainActivity, same package
dev.ultra.launcher and class name as the Qt build so the default-home choice
carries over), Updater reduced to httpGet + PackageInstaller, RecentsService,
manifest and resources, the committed debug keystore. android/build.sh builds
the APK with aapt2, javac, d8, zipalign and apksigner (no Gradle).
tests/android-sim.cjs drives the page against a stub of window.Android.
.sweet.config.yml / .sweet.yml with moon.mod as the annotated version file.
CI: test job (moon test on js and wasm-gc, browser tests) and an apk job that
publishes a Gitea release.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Root README for the new layout; legacy/README.md points back. Legacy Gitea and
GitHub workflows run only by hand from legacy/ and the Gitea one does not
publish unless asked. Fix compiler warnings.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Shell: drop the resetIcons call the page does itself
Launcher / test (pull_request) Failing after 5m46s
Launcher / apk (pull_request) Skipped
67b6b58c94
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
nandi added 1 commit 2026-11-23 01:15:53 +00:00
CI: build the APK in the cluster's android-sdk image
Launcher / test (pull_request) Failing after 5m41s
Launcher / apk (pull_request) Skipped
a8ce535f37
apk job uses git.site.latha.org/cluster-services/android-sdk:latest; gitea-apk.sh
uses the image's JDK/SDK when present and falls back to installing them
(documented, for use with node:22-bookworm until the image is built).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
nandi added 1 commit 2026-11-23 01:49:56 +00:00
CI: run the browser tests on Debian's chromium
Launcher / test (pull_request) Successful in 1m11s
Launcher / apk (pull_request) Skipped
49ea6c54ae
Playwright's Chromium download from cdn.playwright.dev timed out on the runner
(the only failing step; moon tests passed). Install chromium with apt, skip the
Playwright download, and let the tests take CHROMIUM_PATH. The workflow now also
runs tests/android-sim.cjs.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
nandi merged commit 2fa7bd745b into main 2026-11-23 01:57:10 +00:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: experiments/launcher#1