# Yokan

Yokan is a Kotlin Multiplatform media library for manga, anime, and novels. The shared Compose Multiplatform app targets Android, desktop JVM, iOS, and WebAssembly browsers.

Yokan includes no extensions or preconfigured catalogs. Add repositories or
catalogs yourself, or restore them and your extensions from a backup.

## Features

- Manga, anime, and novel libraries with categories, history, updates, downloads, and tracking
- Source and extension catalogs with QuickJS, LNReader, and Mihon-compatible runtimes
- Configurable manga, novel, and anime reader/player experiences
- Room-backed local persistence with repository-provided source metadata and schema migrations
- Backup and restore, cloud sync, metadata lookup, recommendations, and watch order
- Periodic metadata refresh, library updates, and sync with result notifications via WorkManager on Android, BGTaskScheduler on iOS, and an in-app fallback on desktop/web
- Adaptive Material 3 navigation for compact and wide layouts
- Light, dark, dynamic-color, and custom palette themes

## Requirements

- JDK 21
- Android SDK for Android builds
- Xcode for iOS builds

Gradle selects an installed JDK 21 using `gradle/gradle-daemon-jvm.properties`,
even when your shell defaults to a newer Java version. Set `JAVA_HOME` to JDK 21
as well to use it for the Gradle launcher. If your JDK is outside Gradle's
auto-detected locations, add its path to `org.gradle.java.installations.paths`
in your user-level `~/.gradle/gradle.properties`. The optional
`yokan.desktop.java.home` property selects the desktop app's runtime.
Set `ANDROID_HOME` or `ANDROID_SDK_ROOT` to the Android SDK location so each included build can resolve it.

## Getting started

```bash
git clone --recurse-submodules https://git.friedcutlet.com/friedcutlet/yokan.git
cd yokan
```

For an existing clone, initialize the pinned repositories with `git submodule update --init --recursive`. The media-kit dependency does not need a separate checkout.

## Build and run

```bash
# Desktop
./gradlew :composeApp:run

# Web development server
./gradlew :composeApp:wasmJsBrowserDevelopmentRun

# Production web bundle
./gradlew :composeApp:wasmJsBrowserDistribution

# Android debug APK
./gradlew :androidApp:assembleDebug

# Shared and desktop tests
./gradlew :composeApp:desktopTest

# iOS simulator framework
./gradlew :composeApp:linkDebugFrameworkIosSimulatorArm64
```

Open `iosApp/iosApp.xcodeproj` to run the iOS host application.

Forgejo CI (`.forgejo/workflows/ci.yml`) runs on pushes to `main` and on pull
requests: desktop tests and Android unit tests, plus Android and Kotlin/Wasm
compilation. Kotlin/Wasm browser tests and iOS simulator tests are not in CI yet:
`wasmJsBrowserTest` fails in Karma (`import.meta` outside a module) and
`IosLocalMediaInputTest` fails on the simulator; both predate this setup.

For TestFlight, the **iOS TestFlight** Codemagic workflow builds a signed Release
IPA on macOS and distributes it to the **Yokan Testers** group on pushes to
`main` or a manual run. Complete the one-time signing and App Store Connect setup
in [iosApp/README.md](iosApp/README.md#testflight-with-codemagic) before running it.

## Versions and release channels

The version number determines the release channel:

| Version range | Channel | Example |
| --- | --- | --- |
| `0.0.x` | Alpha | `v0.0.1` |
| `0.x.x`, with minor greater than zero | Beta | `v0.1.0` |
| Major version one or higher | Stable | `v1.0.0` |

`version.xcconfig` defines the local version (currently `0.1.0`, beta) for
Gradle and Xcode. Update `CURRENT_PROJECT_VERSION` there when changing the local
version; the default build-number formula is `major * 1000000 + minor * 1000 + patch`
(with a minimum of one). Android and desktop installers, the shared app's About
screen, and iOS sideload packages use the same version. Release workflows override
the local value with their tag and mark alpha/beta releases as previews.

```bash
# Resolve the version/channel without compiling the app
./gradlew :composeApp:printYokanVersion -Pyokan.version=1.0.0

# Build a particular channel/version
./gradlew :androidApp:assembleRelease -Pyokan.version=0.0.1
YOKAN_VERSION=v0.1.0 scripts/build-ios-unsigned-ipa.sh
```

`YOKAN_VERSION` works for all Gradle builds too; `-Pyokan.version` takes precedence.
An optional `-Pyokan.versionCode` / `YOKAN_VERSION_CODE` overrides the derived
Android/iOS build number. Tags must be `vMAJOR.MINOR.PATCH` with no suffix.
The in-app updater includes alpha and beta releases for preview builds: beta
accepts beta/stable updates, alpha accepts all channels, and stable accepts only
stable releases. It chooses the highest eligible version among the 100 most recent
published GitHub releases, skipping drafts.

Update checks and the About screen use
[Schnitzel5/yokan releases](https://github.com/Schnitzel5/yokan/releases).
Checks use the public GitHub API without credentials. A private releases repository
cannot serve updates to ordinary app installations; the releases repository must be
public for these checks to work.

## Manual GitHub releases

In GitHub Actions, select **Manual Release → Run workflow** on `main`, enter an
existing Forgejo `vMAJOR.MINOR.PATCH` tag, and select platforms. All platforms are enabled
by default. GitHub hosts the release assets; app source is cloned from Forgejo using
the `FORGEJO_USERNAME` and `FORGEJO_TOKEN` repository secrets. The workflow validates
the Forgejo tag and builds its resolved commit, using
the workflow's automation rather than whichever workflow exists in that old tag.
Tags predating version overrides may retain their original embedded app version.

Existing assets are skipped unless **Rebuild and replace** is enabled. New releases
start as drafts and are published only after every selected build succeeds. Alpha
and beta tags are marked as prereleases. Resuming a failed run with a new manual
request builds only missing assets; successful assets are preserved.

Builds upload directly to GitHub Releases, without storing copies as Actions
artifacts. Gradle caching avoids repeated dependency downloads and cleans unused
cache entries; it uses the separate Actions cache allowance. The IPA and iOS
framework share one compilation, with the IPA explicitly including the Zero
interpreter and extension server. Jobs have time limits, and a new release request
cancels the previous one. Building all platforms, especially macOS/iOS in a private
repository, still consumes Actions minutes; deselect platforms when unnecessary.

The macOS packager requires a positive major version. Its internal package version
uses `major + 1` (`0.0.1` → `1.0.1`, `0.1.0` → `1.1.0`, `1.0.0` → `2.0.0`)
to keep upgrades ordered across channels; release tags and the in-app version
retain the original number.

The web target stores its database snapshot in browser `localStorage`. Native-only capabilities—QuickJS extensions, the local Mihon server, filesystem downloads, Room/SQLite, and libmpv—are unavailable; media playback uses the HTML5-backed Compose player.

## Project layout

- `composeApp/src/commonMain` — shared code under `eu.friedcutlet.yokan`: `app` (composition root: `YokanRuntime`, `ServiceRegistry`, bootstrap), `data` (repository, settings and library-index holders), `database` (+ `sync`), `domain`, `services/<domain>`, and `ui` (`navigation` with the typed `Route`/`Navigator`, `components`, `theme`, `image`, `status`, `screens/<feature>`)
- `composeApp/src/androidMain` — Android services and platform integrations
- `composeApp/src/desktopMain` — desktop services and packaging
- `composeApp/src/iosMain` — iOS services and framework integration
- `composeApp/src/wasmJsMain` — browser services, localStorage persistence, and the Compose viewport entry point
- `composeApp/src/nonWebMain` — Room (`database/room`), QuickJS, and libmpv implementations shared by native/JVM targets
- `composeApp/src/commonTest` — shared tests
- `iosApp` — SwiftUI iOS host
- `vendor/kmp-mpv` — pinned submodule providing Kotlin Multiplatform libmpv bindings
- `vendor/yokan-ext` — pinned submodule providing Yokan extensions

Room schema snapshots live in `composeApp/schemas` and must be committed with migration changes.

## Android release signing

The release workflow signs and verifies the APK before upload. Configure the stable signing key on GitHub using repository secrets `ANDROID_KEYSTORE_BASE64` (base64-encoded keystore), `ANDROID_KEYSTORE_PASSWORD`, `ANDROID_KEY_ALIAS`, and `ANDROID_KEY_PASSWORD`. Missing secrets fail the release; unsigned APKs are never published. Keep the keystore backed up outside this repository so future versions can update existing installations.

Local `assembleRelease` builds remain unsigned. On Linux with Android build-tools 36.0.0 installed, set these environment variables and run `bash scripts/sign-android-apk.sh <unsigned.apk> <signed.apk>` to produce the same verified artifact.
