diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml new file mode 100644 index 00000000..7b48c381 --- /dev/null +++ b/.github/workflows/android.yml @@ -0,0 +1,65 @@ +name: Android + +# Builds the Android test app (an APK for arm64 phones, handhelds and TVs). It runs when the +# Android parts change, or by hand. The APK is kept for one day only: it's a test build. + +on: + workflow_dispatch: + pull_request: + paths: + - .github/workflows/android.yml + - src-tauri/gen/android/** + - src-tauri/src/mobile.rs + - src-tauri/src/*_mobile.rs + +permissions: + contents: read + +concurrency: + group: android-${{ github.ref }} + cancel-in-progress: true + +jobs: + apk: + name: Android test APK + runs-on: ubuntu-24.04 + timeout-minutes: 60 + steps: + - uses: actions/checkout@v6 + + - uses: actions/setup-node@v6 + with: + node-version: 24 + cache: npm + + - uses: actions/setup-java@v5 + with: + distribution: temurin + java-version: 17 + + - uses: dtolnay/rust-toolchain@stable + with: + targets: aarch64-linux-android + + - uses: Swatinem/rust-cache@v2 + with: + workspaces: src-tauri -> target + key: android + save-if: false + + - name: Install + run: npm ci + + # The runner has the Android SDK and NDK already (ANDROID_HOME, ANDROID_NDK_LATEST_HOME). + - name: Build the APK + run: | + export NDK_HOME="${ANDROID_NDK_LATEST_HOME:-$ANDROID_NDK_HOME}" + echo "NDK: $NDK_HOME" + npx tauri android build --debug --apk --target aarch64 + + - 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 diff --git a/.gitignore b/.gitignore index 38446345..b888a4c4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ node_modules/ src-tauri/target/ -src-tauri/gen/ +# Made by each build (schemas); the Android project in gen/android is kept. +src-tauri/gen/* +!src-tauri/gen/android/ *.log .DS_Store dist/arch/ diff --git a/docs/BUILDING.md b/docs/BUILDING.md index 5bedc0e9..dd75d323 100644 --- a/docs/BUILDING.md +++ b/docs/BUILDING.md @@ -138,6 +138,29 @@ Set `RL_API` to point the launcher somewhere other than recomplauncher.com, for Start the launcher with `RECOMPLAUNCHER_TEST_CONTROL` set to a token of your own, and an MCP client (an AI agent, or a script) can drive it: see [TEST-CONTROL.md](TEST-CONTROL.md). It's off otherwise. +## Android (test builds) + +The Android app is in early testing and isn't released. It needs Android 8.0 or newer (the RAR unpacker and installing other apps both need it). It's the same Rust core and window as +the PC launcher, built with Tauri's Android support; the Android Studio project is +`src-tauri/gen/android`. + +The Android build leaves out what only a PC has: the tray icon, global shortcuts, a second copy +handing over to the first, Discord status and the picture clipboard. Controllers are read by the +window (`navigator.getGamepads`) instead of SDL. Window calls a phone doesn't have (minimise, +full screen, frameless windows) do nothing there; `src-tauri/src/mobile.rs` keeps the shared code +the same for both. `pads_mobile.rs` and `tray_mobile.rs` stand in for `pads.rs` and `tray.rs`. + +To build it yourself you need Android Studio (its SDK and NDK), Java 17 and the Rust target: + +``` +rustup target add aarch64-linux-android +export ANDROID_HOME= NDK_HOME=$ANDROID_HOME/ndk/ +npx tauri android build --debug --apk --target aarch64 +``` + +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. + ## Pull request builds The `PR checks` GitHub Actions workflow runs the Rust and UI tests and builds installers on diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 87fdd341..3bf92462 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -49,19 +49,23 @@ backhand = { version = "0.21", default-features = false, features = ["gzip", "xz dwarfs = { version = "0.2", default-features = false, features = ["zstd"] } dirs = "5" thiserror = "1" -tauri-plugin-single-instance = "2" tauri-plugin-notification = "2" -tauri-plugin-global-shortcut = "2" fs2 = "0.4" crc32fast = "1" chrono = { version = "0.4", default-features = false, features = ["clock"] } -arboard = { version = "3", default-features = false, features = ["image-data"] } image = { version = "0.25", default-features = false, features = ["png", "jpeg"] } -discord-rich-presence = "1" regex-lite = "0.1" qrcode = { version = "0.14", default-features = false, features = ["svg"] } plist = "1" tauri-plugin-deep-link = "2" + +# Desktop only: Android and iOS have no tray, global shortcuts, second copies, Discord client or +# desktop clipboard, and read controllers through the window (navigator.getGamepads). +[target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies] +tauri-plugin-single-instance = "2" +tauri-plugin-global-shortcut = "2" +discord-rich-presence = "1" +arboard = { version = "3", default-features = false, features = ["image-data"] } # Controllers. SDL 3 is built from source and linked in, with only its joystick and HIDAPI parts: # no SDL library to ship, and nothing needed on the player's system. sdl3-sys = { version = "=0.7.2", default-features = false, features = ["build-from-source-static", "no-default-subsystems", "sdl-joystick", "sdl-hidapi", "sdl-unix-console-build"] } diff --git a/src-tauri/build.rs b/src-tauri/build.rs index 3ac87581..91659c55 100644 --- a/src-tauri/build.rs +++ b/src-tauri/build.rs @@ -43,6 +43,9 @@ fn main() { if std::env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("macos") { clang_runtime(); } + if std::env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("android") { + empty_pthread(); + } tauri_build::build() } @@ -59,6 +62,17 @@ fn clang_runtime() { } } +/// unrar_sys always links libpthread, but Android has its threads in libc and no libpthread at +/// all, so the link fails. An empty libpthread.a lets it through; the real calls come from libc. +fn empty_pthread() { + let Ok(out) = std::env::var("OUT_DIR") else { return }; + let dir = std::path::Path::new(&out).join("android-pthread"); + let _ = std::fs::create_dir_all(&dir); + if std::fs::write(dir.join("libpthread.a"), b"!\n").is_ok() { + println!("cargo:rustc-link-search=native={}", dir.display()); + } +} + /// unrar_sys's C++ sources, in Cargo's download folder. fn unrar_src() -> Option { 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")))?; diff --git a/src-tauri/gen/android/.editorconfig b/src-tauri/gen/android/.editorconfig new file mode 100644 index 00000000..ebe51d3b --- /dev/null +++ b/src-tauri/gen/android/.editorconfig @@ -0,0 +1,12 @@ +# EditorConfig is awesome: https://EditorConfig.org + +# top-most EditorConfig file +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = false +insert_final_newline = false \ No newline at end of file diff --git a/src-tauri/gen/android/.gitignore b/src-tauri/gen/android/.gitignore new file mode 100644 index 00000000..1c636c39 --- /dev/null +++ b/src-tauri/gen/android/.gitignore @@ -0,0 +1,20 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +build +/captures +.externalNativeBuild +.cxx +local.properties +key.properties +keystore.properties + +/.tauri +/tauri.settings.gradle \ No newline at end of file diff --git a/src-tauri/gen/android/app/.gitignore b/src-tauri/gen/android/app/.gitignore new file mode 100644 index 00000000..6c4d56b4 --- /dev/null +++ b/src-tauri/gen/android/app/.gitignore @@ -0,0 +1,6 @@ +/src/main/**/generated +/src/main/jniLibs/**/*.so +/src/main/assets/tauri.conf.json +/tauri.build.gradle.kts +/proguard-tauri.pro +/tauri.properties \ No newline at end of file diff --git a/src-tauri/gen/android/app/build.gradle.kts b/src-tauri/gen/android/app/build.gradle.kts new file mode 100644 index 00000000..6e981105 --- /dev/null +++ b/src-tauri/gen/android/app/build.gradle.kts @@ -0,0 +1,83 @@ +import java.util.Properties +import org.jetbrains.kotlin.gradle.dsl.JvmTarget + +plugins { + id("com.android.application") + id("org.jetbrains.kotlin.android") + id("rust") +} + +val tauriProperties = Properties().apply { + val propFile = file("tauri.properties") + if (propFile.exists()) { + propFile.inputStream().use { load(it) } + } +} + +android { + compileSdk = 37 + namespace = "com.recomplauncher.app" + defaultConfig { + manifestPlaceholders["usesCleartextTraffic"] = "false" + applicationId = "com.recomplauncher.app" + minSdk = 26 + targetSdk = 37 + versionCode = tauriProperties.getProperty("tauri.android.versionCode", "1").toInt() + versionName = tauriProperties.getProperty("tauri.android.versionName", "1.0") + } + buildTypes { + getByName("debug") { + manifestPlaceholders["usesCleartextTraffic"] = "true" + isDebuggable = true + isJniDebuggable = true + isMinifyEnabled = false + packaging { + jniLibs.keepDebugSymbols.add("*/arm64-v8a/*.so") + jniLibs.keepDebugSymbols.add("*/armeabi-v7a/*.so") + jniLibs.keepDebugSymbols.add("*/x86/*.so") + jniLibs.keepDebugSymbols.add("*/x86_64/*.so") + } + } + getByName("release") { + optimization { + enable = true + } + proguardFiles( + *fileTree(".") { + include("**/*.pro") + exclude("build/**") + }.files.toTypedArray() + ) + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + } + buildFeatures { + buildConfig = true + } +} + +kotlin { + compilerOptions { + jvmTarget = JvmTarget.JVM_1_8 + } +} + +rust { + rootDirRel = "../../../" +} + +dependencies { + implementation("androidx.webkit:webkit:1.14.0") + implementation("androidx.appcompat:appcompat:1.7.1") + implementation("androidx.activity:activity-ktx:1.10.1") + implementation("com.google.android.material:material:1.12.0") + implementation("androidx.lifecycle:lifecycle-process:2.10.0") + testImplementation("junit:junit:4.13.2") + androidTestImplementation("androidx.test.ext:junit:1.1.4") + androidTestImplementation("androidx.test.espresso:espresso-core:3.5.0") +} + +apply(from = file("tauri.build.gradle.kts")) diff --git a/src-tauri/gen/android/app/proguard-rules.pro b/src-tauri/gen/android/app/proguard-rules.pro new file mode 100644 index 00000000..481bb434 --- /dev/null +++ b/src-tauri/gen/android/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/src-tauri/gen/android/app/src/main/AndroidManifest.xml b/src-tauri/gen/android/app/src/main/AndroidManifest.xml new file mode 100644 index 00000000..6dba3e22 --- /dev/null +++ b/src-tauri/gen/android/app/src/main/AndroidManifest.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/src-tauri/gen/android/app/src/main/java/com/recomplauncher/app/MainActivity.kt b/src-tauri/gen/android/app/src/main/java/com/recomplauncher/app/MainActivity.kt new file mode 100644 index 00000000..93dbe0e9 --- /dev/null +++ b/src-tauri/gen/android/app/src/main/java/com/recomplauncher/app/MainActivity.kt @@ -0,0 +1,11 @@ +package com.recomplauncher.app + +import android.os.Bundle +import androidx.activity.enableEdgeToEdge + +class MainActivity : TauriActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + enableEdgeToEdge() + super.onCreate(savedInstanceState) + } +} diff --git a/src-tauri/gen/android/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/src-tauri/gen/android/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 00000000..2b068d11 --- /dev/null +++ b/src-tauri/gen/android/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src-tauri/gen/android/app/src/main/res/drawable/ic_launcher_background.xml b/src-tauri/gen/android/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 00000000..07d5da9c --- /dev/null +++ b/src-tauri/gen/android/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src-tauri/gen/android/app/src/main/res/layout/activity_main.xml b/src-tauri/gen/android/app/src/main/res/layout/activity_main.xml new file mode 100644 index 00000000..4fc24441 --- /dev/null +++ b/src-tauri/gen/android/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,18 @@ + + + + + + \ No newline at end of file diff --git a/src-tauri/gen/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/src-tauri/gen/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml new file mode 100644 index 00000000..2ffbf24b --- /dev/null +++ b/src-tauri/gen/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/src-tauri/gen/android/app/src/main/res/mipmap-hdpi/ic_launcher.png b/src-tauri/gen/android/app/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 00000000..179cff67 Binary files /dev/null and b/src-tauri/gen/android/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/src-tauri/gen/android/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png b/src-tauri/gen/android/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png new file mode 100644 index 00000000..4c0bd0b3 Binary files /dev/null and b/src-tauri/gen/android/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png differ diff --git a/src-tauri/gen/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png b/src-tauri/gen/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png new file mode 100644 index 00000000..1008ed88 Binary files /dev/null and b/src-tauri/gen/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png differ diff --git a/src-tauri/gen/android/app/src/main/res/mipmap-mdpi/ic_launcher.png b/src-tauri/gen/android/app/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 00000000..e6949a13 Binary files /dev/null and b/src-tauri/gen/android/app/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/src-tauri/gen/android/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png b/src-tauri/gen/android/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png new file mode 100644 index 00000000..27ca7492 Binary files /dev/null and b/src-tauri/gen/android/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png differ diff --git a/src-tauri/gen/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png b/src-tauri/gen/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png new file mode 100644 index 00000000..8cac44aa Binary files /dev/null and b/src-tauri/gen/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png differ diff --git a/src-tauri/gen/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/src-tauri/gen/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 00000000..6a10db67 Binary files /dev/null and b/src-tauri/gen/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/src-tauri/gen/android/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png b/src-tauri/gen/android/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png new file mode 100644 index 00000000..55751707 Binary files /dev/null and b/src-tauri/gen/android/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png differ diff --git a/src-tauri/gen/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/src-tauri/gen/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png new file mode 100644 index 00000000..b09a02a5 Binary files /dev/null and b/src-tauri/gen/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png differ diff --git a/src-tauri/gen/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/src-tauri/gen/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 00000000..92726852 Binary files /dev/null and b/src-tauri/gen/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/src-tauri/gen/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png b/src-tauri/gen/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png new file mode 100644 index 00000000..d5e42c0e Binary files /dev/null and b/src-tauri/gen/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png differ diff --git a/src-tauri/gen/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/src-tauri/gen/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png new file mode 100644 index 00000000..2c43a5b8 Binary files /dev/null and b/src-tauri/gen/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png differ diff --git a/src-tauri/gen/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/src-tauri/gen/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 00000000..fdaf85da Binary files /dev/null and b/src-tauri/gen/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/src-tauri/gen/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png b/src-tauri/gen/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png new file mode 100644 index 00000000..08430a45 Binary files /dev/null and b/src-tauri/gen/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png differ diff --git a/src-tauri/gen/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/src-tauri/gen/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png new file mode 100644 index 00000000..c2337b42 Binary files /dev/null and b/src-tauri/gen/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png differ diff --git a/src-tauri/gen/android/app/src/main/res/values-night/themes.xml b/src-tauri/gen/android/app/src/main/res/values-night/themes.xml new file mode 100644 index 00000000..47cfc870 --- /dev/null +++ b/src-tauri/gen/android/app/src/main/res/values-night/themes.xml @@ -0,0 +1,6 @@ + + + + diff --git a/src-tauri/gen/android/app/src/main/res/values/colors.xml b/src-tauri/gen/android/app/src/main/res/values/colors.xml new file mode 100644 index 00000000..f8c6127d --- /dev/null +++ b/src-tauri/gen/android/app/src/main/res/values/colors.xml @@ -0,0 +1,10 @@ + + + #FFBB86FC + #FF6200EE + #FF3700B3 + #FF03DAC5 + #FF018786 + #FF000000 + #FFFFFFFF + \ No newline at end of file diff --git a/src-tauri/gen/android/app/src/main/res/values/ic_launcher_background.xml b/src-tauri/gen/android/app/src/main/res/values/ic_launcher_background.xml new file mode 100644 index 00000000..f3f76a17 --- /dev/null +++ b/src-tauri/gen/android/app/src/main/res/values/ic_launcher_background.xml @@ -0,0 +1,4 @@ + + + #0B1220 + \ No newline at end of file diff --git a/src-tauri/gen/android/app/src/main/res/values/strings.xml b/src-tauri/gen/android/app/src/main/res/values/strings.xml new file mode 100644 index 00000000..70f41ed6 --- /dev/null +++ b/src-tauri/gen/android/app/src/main/res/values/strings.xml @@ -0,0 +1,4 @@ + + "RecompLauncher" + "RecompLauncher" + \ No newline at end of file diff --git a/src-tauri/gen/android/app/src/main/res/values/themes.xml b/src-tauri/gen/android/app/src/main/res/values/themes.xml new file mode 100644 index 00000000..47cfc870 --- /dev/null +++ b/src-tauri/gen/android/app/src/main/res/values/themes.xml @@ -0,0 +1,6 @@ + + + + diff --git a/src-tauri/gen/android/app/src/main/res/xml/file_paths.xml b/src-tauri/gen/android/app/src/main/res/xml/file_paths.xml new file mode 100644 index 00000000..782d63b9 --- /dev/null +++ b/src-tauri/gen/android/app/src/main/res/xml/file_paths.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/src-tauri/gen/android/build.gradle.kts b/src-tauri/gen/android/build.gradle.kts new file mode 100644 index 00000000..7bd07883 --- /dev/null +++ b/src-tauri/gen/android/build.gradle.kts @@ -0,0 +1,22 @@ +buildscript { + repositories { + google() + mavenCentral() + } + dependencies { + classpath("com.android.tools.build:gradle:9.3.1") + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:2.2.10") + } +} + +allprojects { + repositories { + google() + mavenCentral() + } +} + +tasks.register("clean").configure { + delete("build") +} + diff --git a/src-tauri/gen/android/buildSrc/build.gradle.kts b/src-tauri/gen/android/buildSrc/build.gradle.kts new file mode 100644 index 00000000..cc18ea88 --- /dev/null +++ b/src-tauri/gen/android/buildSrc/build.gradle.kts @@ -0,0 +1,23 @@ +plugins { + `kotlin-dsl` +} + +gradlePlugin { + plugins { + create("pluginsForCoolKids") { + id = "rust" + implementationClass = "RustPlugin" + } + } +} + +repositories { + google() + mavenCentral() +} + +dependencies { + compileOnly(gradleApi()) + implementation("com.android.tools.build:gradle:9.3.1") +} + diff --git a/src-tauri/gen/android/buildSrc/src/main/java/com/recomplauncher/app/kotlin/BuildTask.kt b/src-tauri/gen/android/buildSrc/src/main/java/com/recomplauncher/app/kotlin/BuildTask.kt new file mode 100644 index 00000000..09a45d99 --- /dev/null +++ b/src-tauri/gen/android/buildSrc/src/main/java/com/recomplauncher/app/kotlin/BuildTask.kt @@ -0,0 +1,75 @@ +import java.io.File +import org.apache.tools.ant.taskdefs.condition.Os +import org.gradle.api.DefaultTask +import org.gradle.api.GradleException +import org.gradle.api.logging.LogLevel +import org.gradle.api.tasks.Input +import org.gradle.api.tasks.TaskAction +import javax.inject.Inject +import org.gradle.process.ExecOperations + +abstract class BuildTask : DefaultTask() { + @get:Inject + abstract val execOperations: ExecOperations + + @Input + var rootDirRel: String? = null + @Input + var projectDir: String? = null + @Input + var target: String? = null + @Input + var release: Boolean? = null + + @TaskAction + fun assemble() { + val executable = """npm"""; + try { + runTauriCli(executable) + } catch (e: Exception) { + if (Os.isFamily(Os.FAMILY_WINDOWS)) { + // Try different Windows-specific extensions + val fallbacks = listOf( + "$executable.exe", + "$executable.cmd", + "$executable.bat", + ) + + var lastException: Exception = e + for (fallback in fallbacks) { + try { + runTauriCli(fallback) + return + } catch (fallbackException: Exception) { + lastException = fallbackException + } + } + throw lastException + } else { + throw e; + } + } + } + + fun runTauriCli(executable: String) { + val rootDirRel = rootDirRel ?: throw GradleException("rootDirRel cannot be null") + val target = target ?: throw GradleException("target cannot be null") + val release = release ?: throw GradleException("release cannot be null") + val args = listOf("run", "--", "tauri", "android", "android-studio-script"); + + execOperations.exec { + workingDir(File(projectDir, rootDirRel)) + executable(executable) + args(args) + if (logger.isEnabled(LogLevel.DEBUG)) { + args("-vv") + } else if (logger.isEnabled(LogLevel.INFO)) { + args("-v") + } + if (release) { + args("--release") + } + args(listOf("--target", target)) + }.assertNormalExitValue() + } +} \ No newline at end of file diff --git a/src-tauri/gen/android/buildSrc/src/main/java/com/recomplauncher/app/kotlin/RustPlugin.kt b/src-tauri/gen/android/buildSrc/src/main/java/com/recomplauncher/app/kotlin/RustPlugin.kt new file mode 100644 index 00000000..3309f1cc --- /dev/null +++ b/src-tauri/gen/android/buildSrc/src/main/java/com/recomplauncher/app/kotlin/RustPlugin.kt @@ -0,0 +1,86 @@ +import com.android.build.api.dsl.ApplicationExtension +import org.gradle.api.DefaultTask +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.kotlin.dsl.configure +import org.gradle.kotlin.dsl.get + +const val TASK_GROUP = "rust" + +open class Config { + lateinit var rootDirRel: String +} + +open class RustPlugin : Plugin { + private lateinit var config: Config + + override fun apply(project: Project) = with(project) { + config = extensions.create("rust", Config::class.java) + + val defaultAbiList = listOf("arm64-v8a", "armeabi-v7a", "x86", "x86_64"); + val abiList = (findProperty("abiList") as? String)?.split(',') ?: defaultAbiList + + val defaultArchList = listOf("arm64", "arm", "x86", "x86_64"); + val archList = (findProperty("archList") as? String)?.split(',') ?: defaultArchList + + val targetsList = (findProperty("targetList") as? String)?.split(',') ?: listOf("aarch64", "armv7", "i686", "x86_64") + + extensions.configure { + @Suppress("UnstableApiUsage") + flavorDimensions.add("abi") + productFlavors { + create("universal") { + dimension = "abi" + ndk { + abiFilters += abiList + } + } + defaultArchList.forEachIndexed { index, arch -> + create(arch) { + dimension = "abi" + ndk { + abiFilters.add(defaultAbiList[index]) + } + } + } + } + } + + afterEvaluate { + for (profile in listOf("debug", "release")) { + val profileCapitalized = profile.replaceFirstChar { it.uppercase() } + val buildTask = tasks.maybeCreate( + "rustBuildUniversal$profileCapitalized", + DefaultTask::class.java + ).apply { + group = TASK_GROUP + description = "Build dynamic library in $profile mode for all targets" + } + + tasks["mergeUniversal${profileCapitalized}JniLibFolders"].dependsOn(buildTask) + + for (targetPair in targetsList.withIndex()) { + val targetName = targetPair.value + val targetArch = archList[targetPair.index] + val targetArchCapitalized = targetArch.replaceFirstChar { it.uppercase() } + val targetBuildTask = project.tasks.register( + "rustBuild$targetArchCapitalized$profileCapitalized", + BuildTask::class.java + ) { + group = TASK_GROUP + description = "Build dynamic library in $profile mode for $targetArch" + rootDirRel = config.rootDirRel + projectDir = project.projectDir.path + target = targetName + release = profile == "release" + } + + buildTask.dependsOn(targetBuildTask) + tasks["merge$targetArchCapitalized${profileCapitalized}JniLibFolders"].dependsOn( + targetBuildTask + ) + } + } + } + } +} \ No newline at end of file diff --git a/src-tauri/gen/android/gradle.properties b/src-tauri/gen/android/gradle.properties new file mode 100644 index 00000000..9e6e7b95 --- /dev/null +++ b/src-tauri/gen/android/gradle.properties @@ -0,0 +1,26 @@ +# Project-wide Gradle settings. +# IDE (e.g. Android Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 +org.gradle.configuration-cache=true +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +# org.gradle.parallel=true +# Kotlin code style for this project: "official" or "obsolete": +kotlin.code.style=official + +# Our old plugin template had a bug that caused missing `consumer-rules.pro` files +# so we have to disable it for now. +# See https://github.com/tauri-apps/tauri/pull/15828#issuecomment-5199937796 +android.proguard.failOnMissingFiles=false + +# Keeping Gradle 9 compatible with current plugins +# TODO: Remove this in v3 +android.builtInKotlin=false +android.newDsl=false diff --git a/src-tauri/gen/android/gradle/wrapper/gradle-wrapper.jar b/src-tauri/gen/android/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 00000000..b1b8ef56 Binary files /dev/null and b/src-tauri/gen/android/gradle/wrapper/gradle-wrapper.jar differ diff --git a/src-tauri/gen/android/gradle/wrapper/gradle-wrapper.properties b/src-tauri/gen/android/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..b2ee479e --- /dev/null +++ b/src-tauri/gen/android/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Tue May 10 19:22:52 CST 2022 +distributionBase=GRADLE_USER_HOME +distributionUrl=https\://services.gradle.org/distributions/gradle-9.6.1-bin.zip +distributionPath=wrapper/dists +zipStorePath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME diff --git a/src-tauri/gen/android/gradlew b/src-tauri/gen/android/gradlew new file mode 100755 index 00000000..249efbb0 --- /dev/null +++ b/src-tauri/gen/android/gradlew @@ -0,0 +1,248 @@ +#!/bin/sh + +# +# Copyright © 2015 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# + +############################################################################## +# +# gradlew start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh gradlew +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/3d91ce3b8caaf77ad09f381f43615b715b53f72c/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/src-tauri/gen/android/gradlew.bat b/src-tauri/gen/android/gradlew.bat new file mode 100644 index 00000000..a51ec4f5 --- /dev/null +++ b/src-tauri/gen/android/gradlew.bat @@ -0,0 +1,82 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem gradlew startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables, and ensure extensions are enabled +setlocal EnableExtensions + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +"%COMSPEC%" /c exit 1 + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +"%COMSPEC%" /c exit 1 + +:execute +@rem Setup the command line + + + +@rem Execute gradlew +@rem endlocal doesn't take effect until after the line is parsed and variables are expanded +@rem which allows us to clear the local environment before executing the java command +endlocal & "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* & call :exitWithErrorLevel + +:exitWithErrorLevel +@rem Use "%COMSPEC%" /c exit to allow operators to work properly in scripts +"%COMSPEC%" /c exit %ERRORLEVEL% diff --git a/src-tauri/gen/android/settings.gradle b/src-tauri/gen/android/settings.gradle new file mode 100644 index 00000000..39391166 --- /dev/null +++ b/src-tauri/gen/android/settings.gradle @@ -0,0 +1,3 @@ +include ':app' + +apply from: 'tauri.settings.gradle' diff --git a/src-tauri/src/ach.rs b/src-tauri/src/ach.rs index 04c71bad..59fd1d20 100644 --- a/src-tauri/src/ach.rs +++ b/src-tauri/src/ach.rs @@ -12,6 +12,9 @@ //! Every unlock is saved here first (achievements/store.json in the app's data folder), shown in //! a toast over the game, and sent to the player's account when it can be. +#[cfg(mobile)] +#[allow(unused_imports)] +use crate::mobile::*; use crate::{library::now, App, Error}; use serde::{Deserialize, Serialize}; use serde_json::{json, Value}; diff --git a/src-tauri/src/discord.rs b/src-tauri/src/discord.rs index c3a50c81..3b67158c 100644 --- a/src-tauri/src/discord.rs +++ b/src-tauri/src/discord.rs @@ -5,14 +5,18 @@ //! It needs RecompLauncher's Discord application id: the catalog's top-level `"discord"`, or //! the one built in. +#[cfg(desktop)] use discord_rich_presence::{activity, DiscordIpc, DiscordIpcClient}; +#[cfg(desktop)] use std::sync::mpsc::{channel, Sender}; +#[cfg(desktop)] use std::sync::{Mutex, OnceLock}; /// RecompLauncher's application on discord.com/developers (empty until it's made). The catalog's /// top-level `"discord"` overrides it. pub const APP_ID: &str = "1565871388504367154"; /// The launcher's logo, shown small in the corner of the game's cover. +#[cfg(desktop)] const LOGO: &str = "https://recomplauncher.com/assets/logo-512.png"; pub enum Msg { @@ -28,14 +32,17 @@ pub enum Msg { Shown(bool), } +#[cfg(desktop)] static TX: OnceLock>> = OnceLock::new(); /// What Discord is shown: a game, or the launcher itself. +#[cfg(desktop)] enum Show<'a> { Game { game: &'a str, recomp: &'a str, cover: &'a str, start: u64, line: &'a str }, Launcher { start: u64 }, } +#[cfg(desktop)] fn put(client: &mut Option<(String, DiscordIpcClient)>, app_id: &str, show: Show) { if app_id.is_empty() { return; @@ -88,6 +95,7 @@ fn put(client: &mut Option<(String, DiscordIpcClient)>, app_id: &str, show: Show } } +#[cfg(desktop)] fn tx() -> &'static Mutex> { TX.get_or_init(|| { let (tx, rx) = channel::(); @@ -145,6 +153,7 @@ fn tx() -> &'static Mutex> { /// What the status shows after the launcher's own line changed (turned on or off, the window /// hidden or shown, a game closed). +#[cfg_attr(mobile, allow(dead_code))] #[derive(Debug, PartialEq)] enum Idle<'a> { /// A game is showing: it stays as it is. @@ -157,6 +166,7 @@ enum Idle<'a> { /// "In the launcher" only while the player can see it: closed to the tray, the launcher is just /// waiting by the clock, and saying they're in it would be wrong. +#[cfg_attr(mobile, allow(dead_code))] fn idle_status(playing: bool, idle: Option<&(String, u64)>, shown: bool) -> Idle<'_> { if playing { return Idle::Game; @@ -170,6 +180,7 @@ fn idle_status(playing: bool, idle: Option<&(String, u64)>, shown: bool) -> Idle Idle::Launcher(app_id, *start) } +#[cfg(desktop)] fn show_idle(client: &mut Option<(String, DiscordIpcClient)>, what: Idle) { match what { Idle::Game => {} @@ -182,6 +193,11 @@ fn show_idle(client: &mut Option<(String, DiscordIpcClient)>, what: Idle) { } } +/// There's no Discord app for the launcher to talk to on a phone. +#[cfg(mobile)] +pub fn send(_m: Msg) {} + +#[cfg(desktop)] pub fn send(m: Msg) { let _ = tx().lock().unwrap().send(m); } diff --git a/src-tauri/src/display.rs b/src-tauri/src/display.rs index 83f81870..13e9eb8d 100644 --- a/src-tauri/src/display.rs +++ b/src-tauri/src/display.rs @@ -1,5 +1,8 @@ //! Monitor selection and window placement for the launcher and Big Picture mode. +#[cfg(mobile)] +#[allow(unused_imports)] +use crate::mobile::*; use serde::{Deserialize, Serialize}; use std::sync::Mutex; use tauri::{AppHandle, Manager, PhysicalPosition, PhysicalSize, WebviewWindow}; diff --git a/src-tauri/src/files.rs b/src-tauri/src/files.rs index bd0fa793..ec084562 100644 --- a/src-tauri/src/files.rs +++ b/src-tauri/src/files.rs @@ -308,4 +308,9 @@ pub fn to_trash(path: &Path) -> Result<(), String> { } Ok(()) } + // Android has no Recycle Bin for app files, so nothing is deleted from here. + #[cfg(any(target_os = "android", target_os = "ios"))] + { + Err("there's no Recycle Bin on this device".into()) + } } diff --git a/src-tauri/src/ingame.rs b/src-tauri/src/ingame.rs index 2815198f..23bf83f1 100644 --- a/src-tauri/src/ingame.rs +++ b/src-tauri/src/ingame.rs @@ -2,6 +2,9 @@ //! read in pads.rs. On the keyboard, F12 takes a screenshot and Ctrl+F12 opens the quick menu, held //! only while a game is running. +#[cfg(mobile)] +#[allow(unused_imports)] +use crate::mobile::*; use crate::{App, Error}; use std::path::PathBuf; use std::sync::atomic::Ordering; @@ -197,6 +200,17 @@ pub fn toggle_overlay(app: &AppHandle) { /// F12 and Ctrl+F12, only while a game runs, so they never get in the way otherwise. /// `menu`: Ctrl+F12 opens the quick menu too (the player can turn the quick menu off). pub fn set_hotkeys(app: &AppHandle, on: bool, menu: bool) { + // A phone has no keyboard shortcuts across apps. + #[cfg(mobile)] + { + let _ = (app, on, menu); + } + #[cfg(desktop)] + set_hotkeys_desktop(app, on, menu); +} + +#[cfg(desktop)] +fn set_hotkeys_desktop(app: &AppHandle, on: bool, menu: bool) { use tauri_plugin_global_shortcut::{Code, GlobalShortcutExt, Modifiers, Shortcut, ShortcutState}; let gs = app.global_shortcut(); let _ = gs.unregister_all(); diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 075bbd64..5170beaa 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -3,6 +3,8 @@ //! The window (ui/) asks for things through the commands at the bottom; long jobs (downloads, //! games running) report back through events: `install` with a Progress, `game` when one starts //! or closes. +// Android builds leave out the Windows, Linux and macOS ways of unpacking and setting up games. +#![cfg_attr(mobile, allow(dead_code, unused_assignments))] pub mod ach; pub mod adopt; @@ -43,7 +45,16 @@ pub mod media; pub mod mods; pub mod net; pub mod nup; +#[cfg(desktop)] pub mod pads; +#[cfg(mobile)] +#[path = "pads_mobile.rs"] +pub mod pads; +#[cfg(mobile)] +pub mod mobile; +#[cfg(mobile)] +#[allow(unused_imports)] +use mobile::*; #[cfg(target_os = "linux")] pub mod plain; pub mod own_setup; @@ -68,6 +79,10 @@ pub mod shortcuts; pub mod steam_sync; pub mod swap; pub mod trail; +#[cfg(desktop)] +pub mod tray; +#[cfg(mobile)] +#[path = "tray_mobile.rs"] pub mod tray; mod update_download; mod update_launch; @@ -9585,6 +9600,10 @@ const SPLASH_MIN: std::time::Duration = std::time::Duration::from_millis(900); /// The small start window: the logo in the middle of the screen while the launcher gets ready. fn open_splash(app: &AppHandle) -> Option { + // Android shows its own start screen, and the app is one window. + if cfg!(mobile) { + return None; + } tauri::WebviewWindowBuilder::new(app, "splash", tauri::WebviewUrl::App("splash.html".into())) .title("RecompLauncher") .inner_size(420.0, 280.0) @@ -10217,8 +10236,8 @@ fn wait_for_play(args: &[String]) -> bool { true } -#[cfg_attr(mobile, tauri::mobile_entry_point)] /// The single-instance plugin, on the Flatpak's own D-Bus name when the launcher runs as one. +#[cfg(desktop)] fn single_instance() -> tauri_plugin_single_instance::Builder { let b = tauri_plugin_single_instance::Builder::new(); #[cfg(target_os = "linux")] @@ -10230,6 +10249,7 @@ fn single_instance() -> tauri_plugin_single_instance::Builder b } +#[cfg_attr(mobile, tauri::mobile_entry_point)] pub fn run() { // First, before any thread starts: the test control token leaves the environment here, so // games and tools the launcher starts never see it. @@ -10245,7 +10265,10 @@ pub fn run() { } // Keep what the session's bursts leave in the allocator's arenas from staying (on Linux). sysenv::tune_allocator(); - tauri::Builder::default() + let builder = tauri::Builder::default(); + // Desktop only: a phone never starts a second copy of the launcher. + #[cfg(desktop)] + let builder = builder // A second launch (a shortcut, a Steam entry) hands its job to the launcher already running. // `--quit` (from the installer and uninstaller): the one running closes, wherever it is. // On D-Bus as the app id, not the Tauri identifier: a Flatpak may only own names under its @@ -10284,6 +10307,9 @@ pub fn run() { } } }).build()) + // F12 screenshots and the quick menu while a game runs (ingame.rs). + .plugin(tauri_plugin_global_shortcut::Builder::new().build()); + builder .on_window_event(|w, ev| { if w.label() != "main" { return; @@ -10348,7 +10374,6 @@ pub fn run() { .plugin(tauri_plugin_dialog::init()) .plugin(tauri_plugin_opener::init()) .plugin(tauri_plugin_notification::init()) - .plugin(tauri_plugin_global_shortcut::Builder::new().build()) // Pictures through the disk cache: rlimg://
. .register_asynchronous_uri_scheme_protocol("rlimg", |ctx, req, responder| { let app = ctx.app_handle().clone(); diff --git a/src-tauri/src/media.rs b/src-tauri/src/media.rs index 06bb507e..48dcd3e9 100644 --- a/src-tauri/src/media.rs +++ b/src-tauri/src/media.rs @@ -104,6 +104,7 @@ pub async fn prefetch(http: reqwest::Client, dir: PathBuf, urls: Vec) { } /// Put a PNG on the clipboard, to paste into Discord, X or anywhere. +#[cfg(desktop)] pub fn copy_image(path: &Path) -> Result<(), String> { let img = image::open(path).map_err(|e| e.to_string())?.to_rgba8(); let (w, h) = img.dimensions(); @@ -111,6 +112,12 @@ pub fn copy_image(path: &Path) -> Result<(), String> { cb.set_image(arboard::ImageData { width: w as usize, height: h as usize, bytes: std::borrow::Cow::Owned(img.into_raw()) }).map_err(|e| e.to_string()) } +/// Android has no picture clipboard the launcher can reach yet. +#[cfg(mobile)] +pub fn copy_image(_path: &Path) -> Result<(), String> { + Err("Copying pictures isn't on Android yet.".into()) +} + #[cfg(test)] mod tests { use super::*; diff --git a/src-tauri/src/mobile.rs b/src-tauri/src/mobile.rs new file mode 100644 index 00000000..4233911e --- /dev/null +++ b/src-tauri/src/mobile.rs @@ -0,0 +1,74 @@ +//! Android (and iOS): stand-ins for the desktop window calls Tauri only has on Windows, Linux and +//! macOS. On a phone the launcher is one full-screen window, so minimising, maximising, full +//! screen, always-on-top, click-through and frameless windows have nothing to do; these keep the +//! shared code the same on every system. Nothing here is built for the PC launcher. + +use tauri::{Runtime, WebviewWindow, WebviewWindowBuilder}; + +/// The window calls a desktop has and a phone doesn't. Each does nothing and says it worked. +pub trait PhoneWindow { + fn minimize(&self) -> tauri::Result<()> { + Ok(()) + } + fn unminimize(&self) -> tauri::Result<()> { + Ok(()) + } + fn maximize(&self) -> tauri::Result<()> { + Ok(()) + } + fn unmaximize(&self) -> tauri::Result<()> { + Ok(()) + } + fn set_fullscreen(&self, _on: bool) -> tauri::Result<()> { + Ok(()) + } + fn set_fullscreen_on_monitor(&self, _at: tauri::PhysicalPosition) -> tauri::Result<()> { + Ok(()) + } + fn set_always_on_top(&self, _on: bool) -> tauri::Result<()> { + Ok(()) + } + fn set_ignore_cursor_events(&self, _on: bool) -> tauri::Result<()> { + Ok(()) + } + /// There's no mouse pointer to follow on a touch screen. + fn cursor_position(&self) -> tauri::Result> { + Err(tauri::Error::WindowNotFound) + } +} + +impl PhoneWindow for WebviewWindow {} + +/// Window builder options a phone doesn't have: every window is full screen without a frame. +pub trait PhoneWindowBuilder: Sized { + fn decorations(self, _on: bool) -> Self { + self + } + fn always_on_top(self, _on: bool) -> Self { + self + } + fn center(self) -> Self { + self + } + fn skip_taskbar(self, _on: bool) -> Self { + self + } + fn shadow(self, _on: bool) -> Self { + self + } + fn focused(self, _on: bool) -> Self { + self + } +} + +impl<'a, R: Runtime, M: tauri::Manager> PhoneWindowBuilder for WebviewWindowBuilder<'a, R, M> {} + +/// No tray icon on a phone: `tray_by_id` always finds none, so "close to tray" never hides the window. +pub trait NoTray { + fn tray_by_id(&self, _id: &str) -> Option<()> { + None + } +} + +impl NoTray for tauri::AppHandle {} +impl NoTray for tauri::App {} diff --git a/src-tauri/src/own_setup.rs b/src-tauri/src/own_setup.rs index 9a02f5fc..59e03712 100644 --- a/src-tauri/src/own_setup.rs +++ b/src-tauri/src/own_setup.rs @@ -5,6 +5,9 @@ //! installer) where Windows says the installer put it, by its entry in Settings > Apps and the //! shortcuts it made. +#[cfg(mobile)] +#[allow(unused_imports)] +use crate::mobile::*; use crate::install; use crate::library::Installed; use crate::{App, Error, Res}; diff --git a/src-tauri/src/pads_mobile.rs b/src-tauri/src/pads_mobile.rs new file mode 100644 index 00000000..d1e3f4cb --- /dev/null +++ b/src-tauri/src/pads_mobile.rs @@ -0,0 +1,39 @@ +//! Controllers on Android: the window reads them itself (navigator.getGamepads, the same +//! fallback the desktop window has), since Android hands controller input to the app on screen. +//! These keep the shape of pads.rs, which reads them through SDL on Windows, Linux and macOS. + +use serde::Serialize; +use std::sync::atomic::AtomicBool; +use std::sync::Mutex; +use tauri::AppHandle; + +#[derive(Debug, Clone, Serialize)] +pub struct Pad { + pub name: String, + pub kind: &'static str, +} + +/// Always empty here: the window lists the controllers it sees. +pub static CONNECTED: Mutex> = Mutex::new(Vec::new()); + +pub static FOCUSED: AtomicBool = AtomicBool::new(false); +pub static PLAYING: AtomicBool = AtomicBool::new(false); +pub static STICK: AtomicBool = AtomicBool::new(true); +pub static QUICK_MENU: AtomicBool = AtomicBool::new(true); + +pub fn right_stick() -> [f32; 2] { + [0.0, 0.0] +} + +/// The window always reads controllers on Android. +pub fn window_stays_off() -> bool { + false +} + +pub fn stop() {} + +pub fn start(_app: AppHandle) {} + +pub fn connected() -> Vec { + CONNECTED.lock().unwrap().clone() +} diff --git a/src-tauri/src/test_control/mcp.rs b/src-tauri/src/test_control/mcp.rs index 69943ee6..6e5418b1 100644 --- a/src-tauri/src/test_control/mcp.rs +++ b/src-tauri/src/test_control/mcp.rs @@ -6,6 +6,9 @@ //! bridge.js), so they do exactly what a click or the window's own code would. The others read //! the launcher's state and files, or press controller buttons the way pads.rs does. +#[cfg(mobile)] +#[allow(unused_imports)] +use crate::mobile::*; use super::{page, Ctx}; use serde_json::{json, Value}; use std::time::Duration; diff --git a/src-tauri/src/tray_mobile.rs b/src-tauri/src/tray_mobile.rs new file mode 100644 index 00000000..128d026f --- /dev/null +++ b/src-tauri/src/tray_mobile.rs @@ -0,0 +1,21 @@ +//! Android has no tray: the launcher is an app on the home screen. The window still calls these. + +use std::collections::HashMap; +use tauri::AppHandle; + +/// Big Picture's way out on Home. +#[tauri::command] +pub fn quit_launcher(app: AppHandle) { + app.exit(0); +} + +#[tauri::command(async)] +pub fn tray_words(_app: AppHandle, _words: HashMap) {} + +pub fn refresh(_app: &AppHandle) {} + +pub fn start(_app: &AppHandle) -> tauri::Result<()> { + Ok(()) +} + +pub fn hid(_app: &AppHandle) {} diff --git a/src-tauri/src/webview_crash.rs b/src-tauri/src/webview_crash.rs index beeb377b..bbbdb140 100644 --- a/src-tauri/src/webview_crash.rs +++ b/src-tauri/src/webview_crash.rs @@ -11,6 +11,10 @@ //! all the same, so its tests run on every system. #![cfg_attr(not(windows), allow(dead_code))] +#[cfg(mobile)] +#[allow(unused_imports)] +use crate::mobile::*; + use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Mutex; use std::time::{Duration, Instant}; diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 9a3cacef..8ac64eb1 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -63,6 +63,9 @@ "installerIcon": "icons/icon.ico" } }, + "android": { + "minSdkVersion": 26 + }, "linux": { "deb": { "depends": [