Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/scripts/android-smoke.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env bash
# Installs the test APK on the emulator, opens it, and prints small screenshots (base64 JPEG
# between markers) and the app's log lines, so the run's log shows how it started.
set -u
# Every adb call has a time limit, so a stuck emulator ends the check instead of the whole job.
a() { timeout 60 adb "$@"; }
command -v convert >/dev/null || sudo apt-get install -y -q imagemagick >/dev/null
apk=$(find src-tauri/gen/android/app/build/outputs/apk -name '*.apk' | head -1)
echo "APK: $apk"
a install -r "$apk"
# Let Google Play services finish starting first: when it restarts during our start-up, Android
# also closes apps that use its fonts.
sleep 60
a logcat -c
# The log is kept on this machine as it comes, so it's there even if the emulator stops.
adb logcat -v time > logcat.txt 2>&1 &
# Shut any system dialog left from the emulator's start ("isn't responding").
a shell am broadcast -a android.intent.action.CLOSE_SYSTEM_DIALOGS >/dev/null
a shell am start -n com.recomplauncher.app/.MainActivity
shot() {
a exec-out screencap -p > "shot-$1.png" || return 1
convert "shot-$1.png" -resize 960x -quality 60 "shot-$1.jpg" || return 1
echo "=====SHOT $1 BEGIN====="
base64 -w0 "shot-$1.jpg"
echo
echo "=====SHOT $1 END====="
}
for n in 1 2 3 4; do
sleep 15
shot "$n" || { echo "Emulator stopped answering after shot $((n - 1))."; break; }
done
echo "=====LOG BEGIN====="
grep -iE 'recomplauncher|RustStdoutStderr|chromium|Tauri|AndroidRuntime|FATAL|ActivityManager|lowmemory' logcat.txt | tail -400
echo "=====LOG END====="
23 changes: 22 additions & 1 deletion .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
- src-tauri/gen/android/**
- src-tauri/src/mobile.rs
- src-tauri/src/*_mobile.rs
- .github/scripts/android-smoke.sh

permissions:
contents: read
Expand Down Expand Up @@ -55,11 +56,31 @@ jobs:
run: |
export NDK_HOME="${ANDROID_NDK_LATEST_HOME:-$ANDROID_NDK_HOME}"
echo "NDK: $NDK_HOME"
npx tauri android build --debug --apk --target aarch64
npx tauri android build --debug --apk --target aarch64 --target x86_64

- uses: actions/upload-artifact@v5
with:
name: recomplauncher-android-test
path: src-tauri/gen/android/app/build/outputs/apk/**/*.apk
retention-days: 1
if-no-files-found: error

# Opens the APK on an Android emulator and prints two small screenshots and the app's log into
# this job's log, so a build can be checked without a phone.
- name: Enable KVM for the emulator
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm

- name: Open it on an emulator
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 34
arch: x86_64
target: google_apis
profile: pixel_6
ram-size: 4096M
emulator-options: -no-window -gpu guest -noaudio -no-boot-anim -no-snapshot
disable-animations: true
script: bash .github/scripts/android-smoke.sh
9 changes: 8 additions & 1 deletion docs/BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,15 @@ export ANDROID_HOME=<your Android SDK> NDK_HOME=$ANDROID_HOME/ndk/<version>
npx tauri android build --debug --apk --target aarch64
```

On Android the launcher is always in Big Picture mode, held sideways: there's no desktop view to
leave for, and Settings leaves out what only a PC has (monitor, tray, start with your PC, Discord,
controller as a mouse). A finger drags a page or a row of games, a tap opens, and Android's Back is
B. On a phone, Auto size draws the stage a little bigger (1600×900) so words stay readable.

The Android workflow (`.github/workflows/android.yml`) builds the same APK on GitHub when the
Android parts change, or when run by hand, and keeps it for a day.
Android parts change, or when run by hand, and keeps it for a day. It also opens the APK on an
Android emulator and prints two small screenshots (base64 JPEG between `=====SHOT` lines) and
the app's log into the job's log (`.github/scripts/android-smoke.sh`).

## Pull request builds

Expand Down
18 changes: 18 additions & 0 deletions src-tauri/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ fn main() {
}
if std::env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("android") {
empty_pthread();
// unrar is C++ built against the NDK's libc++, which Android doesn't have on the phone:
// it goes into the launcher's library, or the app stops at start (length_error not found).
android_cxx();
}
tauri_build::build()
}
Expand Down Expand Up @@ -73,6 +76,21 @@ fn empty_pthread() {
}
}

/// Links the NDK's static libc++ (and libc++abi), found where the NDK's own clang keeps them.
fn android_cxx() {
let cc = cc::Build::new().get_compiler();
let out = std::process::Command::new(cc.path()).arg("-print-file-name=libc++_static.a").output();
let path = out.ok().filter(|o| o.status.success()).map(|o| String::from_utf8_lossy(&o.stdout).trim().to_string());
let Some(dir) = path.as_deref().map(std::path::Path::new).filter(|p| p.is_file()).and_then(|p| p.parent()) else {
println!("cargo:warning=the NDK's libc++_static.a wasn't found; the app may stop at start");
return;
};
// Handed to the linker as files (not as static libraries Rust bundles into the rlib, which
// brings in Rust's own runtime a second time: rust_eh_personality defined twice).
println!("cargo:rustc-link-arg={}", dir.join("libc++_static.a").display());
println!("cargo:rustc-link-arg={}", dir.join("libc++abi.a").display());
}

/// unrar_sys's C++ sources, in Cargo's download folder.
fn unrar_src() -> Option<std::path::PathBuf> {
let home = std::env::var_os("CARGO_HOME").map(std::path::PathBuf::from).or_else(|| std::env::var_os("HOME").map(|h| std::path::PathBuf::from(h).join(".cargo")))?;
Expand Down
5 changes: 4 additions & 1 deletion src-tauri/capabilities/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
"core:window:allow-is-fullscreen",
"core:window:allow-hide",
"core:window:allow-show",
"core:window:allow-set-focus"
"core:window:allow-set-focus",
"core:app:allow-register-listener",
"core:app:allow-remove-listener",
"notification:default"
]
}
1 change: 1 addition & 0 deletions src-tauri/gen/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<activity
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode"
android:launchMode="singleTask"
android:screenOrientation="sensorLandscape"
android:label="@string/main_activity_title"
android:name=".MainActivity"
android:exported="true">
Expand Down
3 changes: 3 additions & 0 deletions src-tauri/src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ pub fn os_now() -> &'static str {
"windows"
} else if cfg!(target_os = "macos") {
"macos"
} else if cfg!(target_os = "android") {
// Android games are APKs (assets.android in the Android catalog), never the Linux builds.
"android"
} else {
"linux"
}
Expand Down
47 changes: 47 additions & 0 deletions tests/android-tv.test.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const { test } = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const vm = require('node:vm');

const app = fs.readFileSync(path.join(__dirname, '../ui/app.js'), 'utf8');
const tv = fs.readFileSync(path.join(__dirname, '../ui/tv.js'), 'utf8');
const fn = (src, name, indent = '') => src.match(new RegExp(`^${indent}(?:async )?function ${name}\\([^]*?^${indent}}`, 'm'))[0];

function settingsContext(os) {
const c = vm.createContext({
S: { os, settings: {}, libs: [], library: {}, owned: {}, steam: false },
t: (s) => s, N_: (s) => s, tc: (s) => s, esc: String,
tf: (s, values) => s.replace(/\{(\w+)\}/g, (_, k) => values[k]),
backdrop: () => '', bar: () => '', region: (s) => s, pageHead: (s, sub) => `${s}|${sub}`,
homePinned: () => false, bgMode: () => '', langName: () => 'English',
svg: () => '', hints: () => '', HEART: '', clockRow: () => '', startAtLoginNote: () => '',
});
c.window = c;
c.monitorPicked = () => ''; c.monitorName = () => '';
vm.runInContext(fn(tv, 'pageSettings', ' '), c);
return c;
}

test('Big Picture on Android leaves out the PC-only settings', () => {
const html = settingsContext('android').pageSettings();
for (const gone of ['Leave Big Picture mode', 'Start in Big Picture mode', 'Close to tray', 'Discord status', 'Controller as a Mouse', 'Monitor']) {
assert.doesNotMatch(html, new RegExp(gone), gone);
}
assert.match(html, /Auto-Install/);
});

test('Big Picture on a PC keeps them', () => {
const html = settingsContext('windows').pageSettings();
for (const kept of ['Leave Big Picture mode', 'Start in Big Picture mode', 'Close to tray', 'Discord status', 'Controller as a Mouse', 'Monitor']) {
assert.match(html, new RegExp(kept), kept);
}
});

test('Android always starts in Big Picture mode', () => {
const c = vm.createContext({ S: { os: 'android', settings: {}, desktopArg: true } });
vm.runInContext(fn(app, 'startsInTV'), c);
assert.equal(c.startsInTV(), true);
c.S.os = 'windows';
assert.equal(c.startsInTV(), false);
});
8 changes: 6 additions & 2 deletions ui/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function screenLabels(su) {
}

const GENRES = { action: N_('Action'), adventure: N_('Adventure'), platformer: N_('Platformers'), racing: N_('Racing'), fighting: N_('Fighting'), shooter: N_('Shooters'), sports: N_('Sports'), rpg: N_('RPG'), puzzle: N_('Puzzle') };
const OS_NAME = { windows: 'Windows', macos: 'Mac', linux: 'Linux' };
const OS_NAME = { windows: 'Windows', macos: 'Mac', linux: 'Linux', android: 'Android' };
// Text for searching: lower case and without accents, so "pokemon" finds Pokémon.
const fold = (x) => String(x || '').normalize('NFD').replace(/[\u0300-\u036f]/g, '').toLowerCase();
// Search: accents folded and punctuation as spaces, so "sky racer", "skyracer" and "Sky-Racer!!"
Expand Down Expand Up @@ -8292,7 +8292,8 @@ const selfAuto = () => !S.flatpak && !!(S.settings.ui || {}).self_auto_update;
const ARROW_R = '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 12h14m-5-5 5 5-5 5"/></svg>';

// An update restart returns to the mode that was on screen.
function startsInTV() { return !S.desktopArg && !!(S.settings.start_in_tv || S.bigArg); }
// Android has no desktop view: it's always Big Picture mode.
function startsInTV() { return S.os === 'android' || (!S.desktopArg && !!(S.settings.start_in_tv || S.bigArg)); }

// The update window at start: not during first-time setup, in Big Picture, with a game running
// (started from a shortcut) or a window already open (a game link, a Set Up), and not for a
Expand Down Expand Up @@ -10807,6 +10808,9 @@ T.event.listen('screenshot', ({ payload: p }) => { delete S.shots[p.id]; forgetL
upd.finally(() => loadNews());
// The first time: the setup, like a new console. After that, TV mode if that's how they play.
if (document.readyState === 'loading') await new Promise((ok) => addEventListener('DOMContentLoaded', ok, { once: true }));
// Android skips the desktop's first-time setup (folders, the PC's own options): Big Picture asks
// what it needs.
if (!S.settings.setup_done && S.os === 'android') await saveSettings({ setup_done: true, asked_location: true }, true);
if (!S.settings.setup_done && window.firstRun) window.firstRun();
else if (window.startTV && startsInTV()) window.startTV();
else setTimeout(askData, 800);
Expand Down
Loading