diff --git a/.forge/jobs.toml b/.forge/jobs.toml deleted file mode 100644 index 7a4141e..0000000 --- a/.forge/jobs.toml +++ /dev/null @@ -1,18 +0,0 @@ -# fileapi forge CI (https://fileapi.fastapicloud.dev/forge/nandi.uk/launcher). -# This repo is where the launcher is built and released: each push to main here builds the -# Qt APK on Depot and publishes it as a release, which the phone's updater reads -# (releases/latest/assets/version.json). Needs DEPOT_TOKEN and DEPOT_PROJECT_ID (user secrets). - -[[job]] -name = "apk" -branches = ["main"] -timeout = 3600 -image = "eclipse-temurin:17-jdk-noble" -run = "bash ci/forge-apk.sh" - -[[job]] -name = "wasm-apk" -branches = ["main"] -timeout = 3600 -image = "eclipse-temurin:17-jdk-noble" -run = "bash ci/forge-wasm-apk.sh" diff --git a/.gitea/workflows/launcher.yml b/.gitea/workflows/launcher.yml new file mode 100644 index 0000000..464f912 --- /dev/null +++ b/.gitea/workflows/launcher.yml @@ -0,0 +1,17 @@ +name: Launcher + +on: + push: + branches: [main] + +jobs: + apk: + runs-on: ubuntu-latest + timeout-minutes: 60 + container: eclipse-temurin:17-jdk-noble + steps: + - uses: actions/checkout@v4 + - name: Test, build and release the Qt APK + env: + GITEA_TOKEN: ${{ github.token }} + run: bash ci/gitea-apk.sh diff --git a/README.md b/README.md index 9553038..c6d48c9 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ An Android home screen written as an [ultra](https://github.com/nandi-conda/ultr ## Install -Get the APK from the [`launcher-latest` release](https://github.com/codegod100/launcher/releases/tag/launcher-latest), 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) 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. 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. @@ -29,7 +29,7 @@ Every push to ultra's main publishes a new `ultra` package. To pick it up, run ` ## Qt rewrite (in progress) -`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 fileapi forge ([nandi.uk/launcher](https://fileapi.fastapicloud.dev/forge/nandi.uk/launcher)), where `.forge/jobs.toml` builds and publishes an APK on every push to main (`ci/forge-apk.sh`). +`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. ```sh node qt/tests/layout.test.mjs # grid packing diff --git a/ci/forge-wasm-apk.sh b/ci/forge-wasm-apk.sh deleted file mode 100644 index 90d5a04..0000000 --- a/ci/forge-wasm-apk.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env bash -# Builds the WASI launcher component (wasi/) and the wasmtime runtime APK (android-wasm/). -set -euo pipefail -cd /src - -export PIXI_HOME=/opt/pixi -curl -fsSL https://pixi.sh/install.sh | bash -export PATH="$PIXI_HOME/bin:$PATH" - -pixi run --manifest-path wasi/pixi.toml build -mkdir -p android-wasm/assets -cp wasi/build/launcher.wasm android-wasm/assets/launcher.wasm - -curl -fsSL https://sh.rustup.rs | sh -s -- -y --no-modify-path --profile minimal --target aarch64-linux-android -export PATH="$HOME/.cargo/bin:$PATH" -cargo install cargo-apk --version 0.10.0 --locked - -bash android-wasm/build.sh -cp android-wasm/target/release/apk/ultra-launcher-wasm.apk ultra-launcher-wasm.apk diff --git a/ci/forge-apk.sh b/ci/gitea-apk.sh similarity index 55% rename from ci/forge-apk.sh rename to ci/gitea-apk.sh index e4bf45c..2d8a699 100755 --- a/ci/forge-apk.sh +++ b/ci/gitea-apk.sh @@ -1,19 +1,22 @@ #!/usr/bin/env bash -# Builds the Qt launcher APK (qt/) and publishes it as a forge release: build-, -# holding ultra-launcher.apk and version.json, made a draft first and published once both -# files are up, so releases/latest never lacks them. Runs in .forge/jobs.toml's "apk" job. +# Tests the Qt launcher (qt/), builds its APK and publishes it as a Gitea release: +# build-, holding ultra-launcher.apk and version.json, made a draft first +# and published once both files are up, so the latest release never lacks them. +# Runs in .gitea/workflows/launcher.yml's "apk" job (JDK 17 container, as root). set -euo pipefail -cd /src +cd "$(dirname "$0")/.." QT_VERSION=6.8.3 NDK=26.1.10909125 # Minutes since the epoch: always above the GitHub builds' run numbers and always rising. VERSION_CODE=$(( $(date +%s) / 60 )) +COMMIT="${GITHUB_SHA:-$(git rev-parse HEAD)}" echo "== tools" apt-get update -qq -# The host Qt tools (moc, qmlimportscanner, qmlcachegen) need glib, GL and friends. -apt-get install -y -qq --no-install-recommends python3-pip python3-venv ninja-build cmake unzip curl ca-certificates \ +# The host Qt tools (moc, qmlimportscanner, qmlcachegen) need glib, GL and friends; +# g++ builds the desktop test and nodejs runs the layout test. +apt-get install -y -qq --no-install-recommends python3-pip python3-venv ninja-build cmake g++ nodejs unzip curl ca-certificates git \ libglib2.0-0t64 libgl1 libegl1 libopengl0 libfontconfig1 libfreetype6 libxkbcommon0 libdbus-1-3 >/dev/null python3 -m venv /opt/aqt && /opt/aqt/bin/pip install -q aqtinstall @@ -22,6 +25,12 @@ echo "== Qt $QT_VERSION (android arm64 + host)" QT_ROOT=/opt/Qt/$QT_VERSION/android_arm64_v8a QT_HOST=/opt/Qt/$QT_VERSION/gcc_64 +echo "== tests (desktop Qt)" +node qt/tests/layout.test.mjs +cmake -S qt -B build-desktop -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH="$QT_HOST" +cmake --build build-desktop +QT_QPA_PLATFORM=offscreen build-desktop/ultrahome_e2e + echo "== Android SDK + NDK $NDK" export ANDROID_SDK_ROOT=/opt/android-sdk mkdir -p "$ANDROID_SDK_ROOT/cmdline-tools" @@ -33,7 +42,7 @@ export ANDROID_NDK_ROOT=$ANDROID_SDK_ROOT/ndk/$NDK echo "== build (versionCode $VERSION_CODE)" # Signed with the committed key, like every earlier build, so it installs over them. -export QT_ANDROID_KEYSTORE_PATH=/src/android/app/debug.keystore +export QT_ANDROID_KEYSTORE_PATH="$PWD/android/app/debug.keystore" export QT_ANDROID_KEYSTORE_ALIAS=androiddebugkey export QT_ANDROID_KEYSTORE_STORE_PASS=android export QT_ANDROID_KEYSTORE_KEY_PASS=android @@ -44,17 +53,20 @@ cmake --build build-android --target apk apk=$(find build-android -name "*-signed.apk" | head -1) test -n "$apk" || { find build-android -name "*.apk"; exit 1; } cp "$apk" ultra-launcher.apk -printf '{"versionCode": %s, "commit": "%s"}\n' "$VERSION_CODE" "${FORGE_SHA:-}" > version.json +printf '{"versionCode": %s, "commit": "%s"}\n' "$VERSION_CODE" "$COMMIT" > version.json echo "== release build-$VERSION_CODE" -api="${FORGE_URL:-https://fileapi.fastapicloud.dev}" -api="${api%/}/api/forge/repos/${FORGE_REPO:-nandi.uk/launcher}/releases" -echo "env: FORGE_REPO=${FORGE_REPO:-} FORGE_URL=${FORGE_URL:-} FORGE_API=${FORGE_API:-}" -auth=(-H "Authorization: Bearer $FORGE_TOKEN") +server="${GITHUB_SERVER_URL:-https://git.site.latha.org}" +repo="${GITHUB_REPOSITORY:-experiments/launcher}" +api="${server%/}/api/v1/repos/$repo" +token="${GITEA_TOKEN:-${GITHUB_TOKEN:-}}" +test -n "$token" || { echo "no GITEA_TOKEN/GITHUB_TOKEN in the environment"; exit 1; } +auth=(-H "Authorization: token $token") tag="build-$VERSION_CODE" -curl -fsS "${auth[@]}" -H "Content-Type: application/json" -X POST "$api" \ - -d "{\"tag\": \"$tag\", \"name\": \"ultra Home build $VERSION_CODE\", \"ref\": \"${FORGE_SHA:-}\", \"draft\": true, \"notes\": \"Qt launcher built from ${FORGE_SHA:-?}.\"}" >/dev/null -curl -fsS "${auth[@]}" -T ultra-launcher.apk "$api/$tag/assets/ultra-launcher.apk" >/dev/null -curl -fsS "${auth[@]}" -T version.json "$api/$tag/assets/version.json" >/dev/null -curl -fsS "${auth[@]}" -H "Content-Type: application/json" -X PATCH "$api/$tag" -d '{"draft": false}' >/dev/null -echo "published $tag" +id=$(curl -fsS "${auth[@]}" -H "Content-Type: application/json" -X POST "$api/releases" \ + -d "{\"tag_name\": \"$tag\", \"name\": \"ultra Home build $VERSION_CODE\", \"target_commitish\": \"$COMMIT\", \"draft\": true, \"body\": \"Qt launcher built from $COMMIT.\"}" \ + | python3 -c 'import sys, json; print(json.load(sys.stdin)["id"])') +curl -fsS "${auth[@]}" -F "attachment=@ultra-launcher.apk" "$api/releases/$id/assets?name=ultra-launcher.apk" >/dev/null +curl -fsS "${auth[@]}" -F "attachment=@version.json" "$api/releases/$id/assets?name=version.json" >/dev/null +curl -fsS "${auth[@]}" -H "Content-Type: application/json" -X PATCH "$api/releases/$id" -d '{"draft": false}' >/dev/null +echo "published $tag to $server/$repo" diff --git a/qt/android/src/dev/ultra/launcher/Updater.java b/qt/android/src/dev/ultra/launcher/Updater.java index 971c633..9faee74 100644 --- a/qt/android/src/dev/ultra/launcher/Updater.java +++ b/qt/android/src/dev/ultra/launcher/Updater.java @@ -14,6 +14,7 @@ import android.os.Looper; import android.util.Log; import android.widget.Toast; +import org.json.JSONArray; import org.json.JSONObject; import java.io.ByteArrayOutputStream; @@ -26,19 +27,20 @@ import java.nio.charset.StandardCharsets; import java.util.concurrent.atomic.AtomicBoolean; /** - * Updates the launcher from the newest release on V's fileapi forge (nandi.uk/launcher), - * which .forge/jobs.toml builds on every commit to main. Each release holds - * version.json ({"versionCode": N, "commit": SHA}) next to ultra-launcher.apk, with N the - * APK's versionCode. When N is newer than the installed - * build, the APK is streamed into a PackageInstaller session and committed. Android then asks - * the user to confirm (or, on Android 12+ once this app installed itself, may not ask at all). + * Updates the launcher from the newest release on the Gitea forge (experiments/launcher + * on git.site.latha.org), which .gitea/workflows/launcher.yml builds on every commit to + * main. Each release holds version.json ({"versionCode": N, "commit": SHA}) next to + * ultra-launcher.apk, with N the APK's versionCode; the latest-release API names their + * download URLs. When N is newer than the installed build, the APK is streamed into a + * PackageInstaller session and committed. Android then asks the user to confirm (or, on + * Android 12+ once this app installed itself, may not ask at all). * * The home screen checks on start at most every CHECK_EVERY; the home menu's * "Check for updates" checks now and reports what it found. */ final class Updater { - static final String BASE = - "https://fileapi.fastapicloud.dev/api/forge/repos/nandi.uk/launcher/releases/latest/assets/"; + static final String LATEST = + "https://git.site.latha.org/api/v1/repos/experiments/launcher/releases/latest"; static final long CHECK_EVERY = 6 * 60 * 60 * 1000L; static final String EXTRA_VERSION = "dev.ultra.launcher.VERSION"; @@ -75,7 +77,10 @@ final class Updater { } private static void run(Context c, boolean manual) throws Exception { - JSONObject v = new JSONObject(new String(get(BASE + "version.json"), StandardCharsets.UTF_8)); + JSONObject release = new JSONObject(new String(get(LATEST), StandardCharsets.UTF_8)); + String versionUrl = assetUrl(release, "version.json"); + String apkUrl = assetUrl(release, "ultra-launcher.apk"); + JSONObject v = new JSONObject(new String(get(versionUrl), StandardCharsets.UTF_8)); long latest = v.getLong("versionCode"); long installed = installedVersion(c); if (latest <= installed) { @@ -85,7 +90,17 @@ final class Updater { // An install the user cancelled isn't offered again until there is a newer one, or they ask. if (!manual && latest == prefs(c).getLong("declined", -1)) return; toast(c, "Downloading launcher update (build " + latest + ")…"); - install(c, latest); + install(c, apkUrl, latest); + } + + /** The download URL of the named asset in a release's JSON. */ + private static String assetUrl(JSONObject release, String name) throws Exception { + JSONArray assets = release.getJSONArray("assets"); + for (int i = 0; i < assets.length(); i++) { + JSONObject a = assets.getJSONObject(i); + if (name.equals(a.getString("name"))) return a.getString("browser_download_url"); + } + throw new IOException("no " + name + " asset in the latest release"); } @SuppressWarnings("deprecation") @@ -94,7 +109,7 @@ final class Updater { return Build.VERSION.SDK_INT >= 28 ? p.getLongVersionCode() : p.versionCode; } - private static void install(Context c, long version) throws IOException { + private static void install(Context c, String apkUrl, long version) throws IOException { PackageInstaller pi = c.getPackageManager().getPackageInstaller(); PackageInstaller.SessionParams params = new PackageInstaller.SessionParams(PackageInstaller.SessionParams.MODE_FULL_INSTALL); @@ -104,7 +119,7 @@ final class Updater { } int id = pi.createSession(params); try (PackageInstaller.Session s = pi.openSession(id)) { - HttpURLConnection conn = open(BASE + "ultra-launcher.apk"); + HttpURLConnection conn = open(apkUrl); try (InputStream in = conn.getInputStream(); OutputStream out = s.openWrite("ultra-launcher.apk", 0, conn.getContentLengthLong())) { byte[] buf = new byte[64 * 1024]; @@ -128,7 +143,7 @@ final class Updater { conn.setConnectTimeout(15000); conn.setReadTimeout(30000); conn.setUseCaches(false); - conn.setInstanceFollowRedirects(true); // github.com redirects assets to its download host + conn.setInstanceFollowRedirects(true); // asset downloads redirect to their storage host int code = conn.getResponseCode(); if (code != HttpURLConnection.HTTP_OK) { conn.disconnect();