Rewrite the launcher in MoonBit (old code moves to legacy/) (#1)
This commit was merged in pull request #1.
This commit is contained in:
1 parent
7d2bf5996f
commit
2fa7bd745b
150 files changed
+8319
-462
No files matched your search
@@ -1,39 +1,97 @@
|
||||
# ultra launcher
|
||||
|
||||
An Android home screen written as an [ultra](https://github.com/nandi-conda/ultra) app (LPython compiled to WebAssembly, Elm-style). The home starts blank (add a clock widget if you want one): long-press it to add apps (the drawer opens in a pick mode) or widgets, and long-press anything on it to drag it somewhere else; let go without moving to get its menu, or, for a widget, handles on its edges that resize it to the grid. Swipe down for the drawer with every app and a search (Enter opens the first match); long-press an app there for its menu (add to home, app info, uninstall; system apps have no uninstall), and swipe up to close it. The panel at the top has a **Windows** button that opens Recents. The layout is saved in localStorage.
|
||||
An Android home screen, written in [MoonBit](https://www.moonbitlang.com). Home starts blank: long-press it to add apps (the drawer opens in a pick mode) or widgets, and long-press anything on it to drag it somewhere else; let go without moving to get its menu, or, for a widget, handles on its edges that resize it to the grid. Swipe down (or tap the search pill) for the drawer with every app and a search (Enter opens the first match); long-press an app there for its menu (add to home, app info, uninstall; system apps have no uninstall), and swipe up to close it. The **Windows** button in the panel at the top opens Recents. The layout is saved on the device, and the app updates itself from the latest release here.
|
||||
|
||||
| home | drawer | app menu | resize handles |
|
||||
|---|---|---|---|
|
||||
|  |  |  |  |
|
||||
|
||||
(Screenshots are of the browser demo at phone size.)
|
||||
|
||||
## Install
|
||||
|
||||
Get the APK from the [latest release](https://git.site.latha.org/experiments/launcher/releases/latest) on the Gitea forge, which CI rebuilds on every push to `main`. Open it once, press Home, and pick **ultra Home** as the default. Builds are signed with the committed `android/app/debug.keystore`, so each one installs over the last.
|
||||
Get the APK from the [latest release](https://git.site.latha.org/experiments/launcher/releases/latest), which CI rebuilds on every push to `main`. Open it once, press Home, and pick **ultra Home** as the default. The package is `dev.ultra.launcher` and builds are signed with the committed `android/debug.keystore`, the same key every earlier build (WebView, Qt) used, so this installs over them. The activity keeps the Qt build's class name, so the default-home choice survives.
|
||||
|
||||
The **Windows** button uses an accessibility service (`RecentsService`, which only performs the Recents action). Enable it once under Settings → Accessibility; on Android 13+ a sideloaded APK may first need App info → ⋮ → Allow restricted settings.
|
||||
|
||||
## Layout
|
||||
On first start the old WebView build's home screen (its `ultra.home.*` localStorage) is imported. The Qt build's layout is not imported (see *Not done* below).
|
||||
|
||||
- `web/` is the UI: `app.py` is the ultra app and `app.wasm` its committed build, with `index.html`, `style.css` and the `ultra.js` / `ui.css` runtime the build copies in. `apps.json` and `widgets.json` are demo data for desktop browsers.
|
||||
- `android/` is a small native shell (Java, no dependencies) that serves `web/` to a transparent WebView over the wallpaper. It answers `apps.json` from `LauncherApps` and `widgets.json` from the installed widget providers, hands icons to the page through the `window.Android` bridge, and draws real `AppWidgetHostView`s over the slots the page reports.
|
||||
- The ultra framework comes from the `ultra` conda package on [prefix.dev/nandi-testing](https://prefix.dev/channels/nandi-testing), which pixi installs.
|
||||
- `tests/e2e.cjs` is a Playwright test of the browser demo.
|
||||
## How it is built
|
||||
|
||||
## Build
|
||||
MoonBit owns the logic and the UI; Java is only what Android itself requires.
|
||||
|
||||
```sh
|
||||
pixi run build # web/app.py -> web/app.wasm
|
||||
pixi run install-playwright && pixi run test
|
||||
cd android && ./gradlew assembleDebug # needs JDK 17 and the Android SDK
|
||||
```
|
||||
┌──────────────── pure MoonBit (no platform deps; moon test on js and wasm-gc) ───────────────┐
|
||||
pointer / touch / │ gesture ──► app.input ──► app.update(Model, Msg) ──► Effects (data) │
|
||||
key events ───────►│ │ │
|
||||
│ └──► app.view(Model) ──► vdom tree (data) │
|
||||
└───────────────┬────────────────────────────────────────────────┬───────────────────────────┘
|
||||
│ effects │ tree
|
||||
┌───────────────▼─────────────────────────────────────────────────▼──────────────┐
|
||||
│ web/ (js backend): runs effects against window.Android, patches the DOM, │
|
||||
│ listens for events │
|
||||
└───────────────┬─────────────────────────────────────────────────────────────────┘
|
||||
│ window.Android.* / window.launcher.*
|
||||
┌───────────────▼─────────────────────────────────────────────────────────────────┐
|
||||
│ android/java (Java): HomeActivity + WebView + AppWidgetHostViews, Updater, │
|
||||
│ RecentsService │
|
||||
└─────────────────────────────────────────────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
`pixi run serve` serves `web/` on http://localhost:8000. In a desktop browser the launcher runs against the demo JSON files, shows a toast instead of launching, and draws widgets as labelled placeholders. Click the bar at the top to open the drawer.
|
||||
| package | what | tested by |
|
||||
|---|---|---|
|
||||
| `grid/` | the home grid: packing (dense, with pinned cells), cell/box math, pin, resize steps, widget columns | `moon test` |
|
||||
| `gesture/` | pointer state machine: tap, long press (500 ms, 10 px slop), drag, release, swipe | `moon test` |
|
||||
| `updater/` | release/`version.json` parsing, `build-N` tags, the install/skip decision, 6 h throttle | `moon test` |
|
||||
| `jsonx/` | small `Json` accessors | `moon test` |
|
||||
| `vdom/` | a virtual DOM as plain data, generic over the message type; renders to HTML text for snapshots | `moon test` |
|
||||
| `app/` | `Model`, `Msg`, `update` (returns `Effect`s), `view`, JSON persistence and the import of the old localStorage layout, search, sheets/menus, drag and resize, the update flow | 60 headless tests that drive it through pointer input |
|
||||
| `web/` | the js-target program: keyed DOM patcher, event wiring, host bridge (`window.Android`, or stand-ins that show a toast in a desktop browser), icon loading | `tests/e2e.cjs`, `tests/android-sim.cjs` (Playwright) |
|
||||
| `android/` | the Java shell, manifest, resources, signing key, `build.sh` | builds; needs a device to run |
|
||||
|
||||
Every push to ultra's main publishes a new `ultra` package. To pick it up, run `pixi update ultra`, rebuild, and commit the rebuilt `web/` files.
|
||||
Why this shape: the launcher's hard parts are layout math, gestures and state, and all of them are pure functions here, so `moon test` covers them on desktop with no Android and no browser. The view is a data tree rather than direct DOM calls, so its output is snapshot-tested as text, and pointer input is aimed at tree nodes by the tests exactly as the page aims it. Rendering in the existing WebView keeps the design that already works for widgets (real `AppWidgetHostView`s laid over transparent slots in the page).
|
||||
|
||||
## Qt rewrite (in progress)
|
||||
### What stays Java, and why
|
||||
|
||||
`qt/` is the launcher rewritten as a Qt Quick (QML) app for Android, replacing ultra and the WebView. `qt/qml` is the UI (`Main.qml`, with the grid packing in `Layout.js`), `qt/src` a thin C++ backend, and `qt/android` the Java side (`HomeActivity`, a `QtActivity` that lists apps, draws icons, launches, and hosts the native widget views over the QML slots). It uses the same package (`dev.ultra.launcher`) and key as the WebView build, so it installs over it, from the releases on the Gitea forge ([experiments/launcher](https://git.site.latha.org/experiments/launcher)), where `.gitea/workflows/launcher.yml` tests, builds and publishes an APK on every push to main (`ci/gitea-apk.sh`); the installed app updates itself from the latest release there.
|
||||
About 1,100 lines in `android/java/dev/ultra/launcher/`; none of it decides anything, it carries out what the page asks:
|
||||
|
||||
- `HomeActivity`: Android requires an `Activity` for the HOME role; it hosts the WebView, serves `apps.json` / `widgets.json` / icons from `LauncherApps`, `PackageManager` and `AppWidgetManager`, and hosts `AppWidgetHostView`s, which are Java `View`s that can only be created and laid out by Java. Its widget touch interception (long press, drag) must decide synchronously whether to take a gesture from the widget, so it stays there and reports through `window.launcher.widget*`.
|
||||
- `Updater`: `HttpURLConnection` (the page cannot `fetch` the Gitea API from the WebView's origin) and `PackageInstaller`.
|
||||
- `RecentsService`: an `AccessibilityService` must be a Java class listed in the manifest; Android instantiates it by name.
|
||||
|
||||
A pure-MoonBit shell (native backend → C, `NativeActivity` + JNI, drawing through the NDK) was considered and rejected: it would still need the same Java classes (`RecentsService`, and something to host `AppWidgetHostView`), the rest would be hundreds of lines of hand-written JNI in C, and nothing of it could be run or tested here (no Android SDK/NDK on the dev machine, no device). The moon toolchain's Android support on mooncakes (e.g. `Nanaloveyuki/ajni`, `wzzc-dev/moui`) is young and was not evaluated further. Rabbita was also considered for the view layer; it would tie the view to its DOM `Html` type and closures, out of reach of plain-data tests, and the gesture/drag handling needs delegated pointer events and its own hit-testing anyway.
|
||||
|
||||
## Build and test
|
||||
|
||||
Needs [MoonBit](https://www.moonbitlang.com/download) (`curl -fsSL https://cli.moonbitlang.com/install/unix.sh | bash`), Node 22 for the browser tests, and for the APK a JDK 17+ plus the Android SDK's `build-tools;35.0.0` and `platforms/android-35/android.jar`.
|
||||
|
||||
```sh
|
||||
node qt/tests/layout.test.mjs # grid packing
|
||||
cmake -S qt -B build && cmake --build build # desktop build, needs Qt 6.8+
|
||||
build/ultrahome # try it against the demo apps
|
||||
QT_QPA_PLATFORM=offscreen build/ultrahome_e2e # end-to-end test of the UI
|
||||
moon test # the pure core: grid, gestures, updater, the app (js backend)
|
||||
moon test --target wasm-gc # the same tests on a second backend
|
||||
scripts/build-web.sh --demo # the page -> dist/web (with the demo apps.json / widgets.json)
|
||||
npm install && npx playwright install chromium # or CHROMIUM_PATH=/usr/bin/chromium
|
||||
npm test # builds the page, then tests/e2e.cjs and tests/android-sim.cjs
|
||||
android/build.sh # the page + Java shell -> build/ultra-launcher.apk, signed
|
||||
```
|
||||
|
||||
`android/build.sh` runs `moon build` (via `scripts/build-web.sh`), then `aapt2 compile/link`, `javac`, `d8`, `zip`, `zipalign` and `apksigner`, with no Gradle. It reads `versionName` from `moon.mod` and takes `VERSION_CODE` from the environment (default: minutes since the epoch, which is above every earlier build's). `ANDROID_SDK_ROOT` points at the SDK (default `~/android-sdk`).
|
||||
|
||||
To try the page in a desktop browser: `scripts/build-web.sh --demo && python3 -m http.server -d dist/web 8000`. It runs against `web/apps.json` and `web/widgets.json`, shows a toast instead of launching, and draws widgets as labelled placeholders. Click the search pill, or hold the empty home.
|
||||
|
||||
## CI and releases
|
||||
|
||||
`.gitea/workflows/launcher.yml`: a `test` job (MoonBit installed like in identicons-web, inside `node:22-bookworm`; `moon test` on js and wasm-gc, then the Playwright tests) and, on push to `main`, an `apk` job (container `git.site.latha.org/cluster-services/android-sdk:latest` from `charts/android-sdk` in nandi/cluster: JDK 17 + SDK 35, no per-run download; swap in `node:22-bookworm` as a fallback until it exists, the script then downloads the SDK itself) running `ci/gitea-apk.sh`, which builds the APK and publishes a Gitea release `build-<versionCode>` holding `ultra-launcher.apk` and `version.json` (a draft first, published once both files are up). The installed app compares that `versionCode` with its own and installs the newer APK. No `actions/setup-node`, no docker, every job has a `timeout-minutes`.
|
||||
|
||||
Releases of the app's version are managed with [sweet](https://github.com/chattocorp/sweet-release): `.sweet.config.yml` (feature → minor, fix/performance → patch, chore/refactor → none) and `.sweet.yml` (`moon.mod`'s `version` line is annotated `// sweet-version`). The Android `versionName` is read from `moon.mod` by the build, so that is the one file that carries the version.
|
||||
|
||||
## `legacy/`
|
||||
|
||||
The previous implementations, moved here with `git mv` so their history follows: the ultra (LPython → wasm) WebView build (`web/`, `android/`), the Qt Quick rewrite (`qt/`), and the experiments (`wasi/`, `android-wasm/`), with their tests and CI script. Their paths are fixed so they still build from `legacy/` (see its README), but they are not maintained; their CI workflows run only by hand. The MoonBit launcher is a port of `legacy/web/app.py` (and the gesture code in its `index.html`), `legacy/qt/qml/Layout.js` and the Java shell.
|
||||
|
||||
## Verified, and not
|
||||
|
||||
Verified here: `moon test` (60 tests, js and wasm-gc), the browser flows in `tests/e2e.cjs` (the legacy test's flows, ported), the page against a stub of the Java bridge (`tests/android-sim.cjs`: icons, widget placement, drawer cover, keyboard, Recents, update check and install request), and that `android/build.sh` produces a signed APK with package `dev.ultra.launcher` that `aapt2 dump badging` and `apksigner verify` accept.
|
||||
|
||||
**Not verified: anything on a device.** There is no Android runtime on the dev machine. The Java shell compiles and packages, and its logic was carried over from the legacy shell that ran on devices, but the combination (the MoonBit page in the WebView, real widget views over it, the installer, the accessibility service) has not been run.
|
||||
|
||||
Not done: importing the Qt build's saved layout (a `QSettings` INI file; the old WebView layout is imported), per-widget configuration beyond what the legacy shell did, and shrinking the page's JS (about 560 KB, mostly MoonBit's JSON and number-parsing runtime).
|
||||
Reference in new issue
Block a user