Compare commits
210 Commits
b3811ff72e
...
v0.3.0
| Author | SHA1 | Date | |
|---|---|---|---|
| ed54f22997 | |||
| 031ee86ed5 | |||
| 7591425f6f | |||
| d1d2ca293d | |||
| 705a8fa94e | |||
| 4ba63b7da6 | |||
| bee1f0416d | |||
| 54d9246ca7 | |||
| 91bb955d0c | |||
| 36259b264f | |||
| 6f903f79bc | |||
| 3532e35b75 | |||
| 6b846913f5 | |||
| 26c6c939a2 | |||
| b6e6f2bff5 | |||
| e3034958ee | |||
| 8672026e97 | |||
| 75627c8afe | |||
| 6383e5f4fd | |||
| 6a93d164a0 | |||
| 9e98618e5f | |||
| 1bd60ffb34 | |||
| 30d0d36efe | |||
| 3947d5b07a | |||
| 238501597e | |||
| 04dd3e3a19 | |||
| 61aa1053e7 | |||
| 50e17b3508 | |||
| 94c556f0e3 | |||
| 32c1929948 | |||
| 3915a82780 | |||
| a4833e4780 | |||
| 4e79e6cdad | |||
| f74bc4a3f1 | |||
| 8e18d01af5 | |||
| 3477cbe7ce | |||
| 5a2e07e865 | |||
| 6e949b6748 | |||
| 8ae161fe61 | |||
| 3a89ee8cd7 | |||
| dac0fee4e3 | |||
| 125a51d81d | |||
| 7b99b41ede | |||
| 9ea2c17419 | |||
| a9cca82fb8 | |||
| 7ab0661ddc | |||
| 92e68024f1 | |||
| 64abce6daa | |||
| bdfab8e0d5 | |||
| 8e87e617df | |||
| 5bf787eb2b | |||
| 0a6c9d8852 | |||
| 0eedfb3c1f | |||
| f6490f4c28 | |||
| d01a8fd17a | |||
| 3e7c9bd059 | |||
| 7aa787a789 | |||
| 3514702d8c | |||
| 327a5fa828 | |||
| 9777ed7fb3 | |||
| ba68a98873 | |||
| 22359f5dc8 | |||
| 7e9023faad | |||
| 5acc12d9e9 | |||
| aed0bf0c2a | |||
| b65745284e | |||
| 8ca695eb4c | |||
| 61c02e695e | |||
| 203ad8069d | |||
| 5f8c6b6147 | |||
| cd3368fc71 | |||
| bd05bc8c30 | |||
| 658564353c | |||
| 6b3cbce120 | |||
| 739fa74e68 | |||
| c87ca577a3 | |||
| e68b7330ae | |||
| e5c2b4e7f5 | |||
| 7ad3a57e68 | |||
| 22bef1fd0a | |||
| bf577044f1 | |||
| 4c95ba72a3 | |||
| 011607ec10 | |||
| 803573b4ec | |||
| 00cf51d610 | |||
| 84a3b95f17 | |||
| 8cde8621ce | |||
| 0bf3984614 | |||
| 75ee53d1dd | |||
| 0255a8289c | |||
| 6bed5d9e8e | |||
| 48202a0f89 | |||
| bf57aa4000 | |||
| 0ccd0fe676 | |||
| e1ca2e4d3c | |||
| e119aa50e9 | |||
| 683c81be03 | |||
| fe61597d92 | |||
| d9b8b88a42 | |||
| 15202011c1 | |||
| 05e87e6ab0 | |||
| 38c68c33e5 | |||
| a0427cd2a3 | |||
| a4c85af155 | |||
| 9ba90d4b77 | |||
| 5358ef9fee | |||
| 0a63154293 | |||
| e5057f6cc1 | |||
| a3eefc2374 | |||
| cd591514ad | |||
| a2bd0cd77c | |||
| 48f980ebb1 | |||
| 1cd87066d7 | |||
| 789ad49bc4 | |||
| c87bfe0e7b | |||
| f98ab07dd6 | |||
| dbab1f98ba | |||
| 5d279f8886 | |||
| e60cda3939 | |||
| d638a93e04 | |||
| a755d6eab7 | |||
| b0d28380b5 | |||
| ed583650a6 | |||
| e5c9ee8327 | |||
| 0a7ae5ef09 | |||
| 95dcef3515 | |||
| 0badc17d87 | |||
| a11b0dd3c7 | |||
| 3b21d8ecf8 | |||
| 83d3d6384a | |||
| 6399d2817d | |||
| e2f004589c | |||
| 590ceaa850 | |||
| d8a453f6ca | |||
| 024e709191 | |||
| 94e82df9f3 | |||
| bbc891e50a | |||
| 3e535f1de4 | |||
| c94a81d523 | |||
| df32060655 | |||
| 55899bf73f | |||
| 725e596d2b | |||
| d17aeefd1c | |||
| 1b0a13c25e | |||
| 3d3dd3627c | |||
| ad27174027 | |||
| d0d31b1040 | |||
| 4f10f3439d | |||
| 788e4acbb5 | |||
| d7a9fbf0b6 | |||
| f652617f30 | |||
| ae803b24d5 | |||
| 3fbabc854c | |||
| 8c4e7b07bf | |||
| 6d8c7a5185 | |||
| 2f7847ce9b | |||
| c6a818e985 | |||
| f34e956818 | |||
| 04e52b0c22 | |||
| 2df3c0f2b4 | |||
| 60df3c9c52 | |||
| 9fd19b90a9 | |||
| 6975691f7d | |||
| f896f70bb8 | |||
| b24c10a723 | |||
| 1682b83b3f | |||
| 838cac4f69 | |||
| 4f62643c82 | |||
| c91e7a0e38 | |||
| bed4711096 | |||
| 5d3cb5e63f | |||
| d3e4ea0118 | |||
| 43144203fa | |||
| d8a7d6f3a2 | |||
| 8a04db9844 | |||
| 0b663cefb6 | |||
| e2c9bfd3d9 | |||
| c5dab484df | |||
| e27abc065e | |||
| d39da4bc06 | |||
| 095540efc2 | |||
| de232ec2f7 | |||
| e4e34fdb48 | |||
| 3ec462c2ea | |||
| 58f4dccc02 | |||
| 32879f45bf | |||
| b54f781524 | |||
| 5e106c51cf | |||
| d2746bd65a | |||
| 9b840151e4 | |||
| a12c6e0ba4 | |||
| b0c82333d2 | |||
| f208f3d92e | |||
| 51de8ccbdb | |||
| 118752c136 | |||
| 9af8e9a7d9 | |||
| e466814ef8 | |||
| 95c6ceb072 | |||
| e919fa6a2e | |||
| 6db3525e29 | |||
| 6a501f484a | |||
| 72eeedc4da | |||
| fde438a1ed | |||
| 01dc0b616c | |||
| 4a73102d48 | |||
| aa159df33f | |||
| 983adc5347 | |||
| 78c16e5136 | |||
| 0205c7b8d6 | |||
| 3e6c9f6060 |
@@ -0,0 +1,23 @@
|
|||||||
|
# cargo-audit configuration — consumed by `.gitea/workflows/audit.yml` (`cargo audit`).
|
||||||
|
#
|
||||||
|
# Silence only advisories that are KNOWN-UNFIXABLE and either not applicable to how we use the crate
|
||||||
|
# or an accepted, documented risk. Keep this list TIGHT and justify every entry — an ignore here
|
||||||
|
# means the audit job stops flagging it, so the reasoning must hold up.
|
||||||
|
#
|
||||||
|
# NOTE: `cargo audit` (no `--deny warnings`) fails only on *vulnerabilities*, not on the
|
||||||
|
# `unmaintained` warnings (audiopus_sys via opus, paste via utoipa-axum). Both are transitive, at
|
||||||
|
# their latest published version with no successor, so there's nothing to bump — left visible on
|
||||||
|
# purpose so we keep getting the maintenance signal; they do not fail CI. (rustls-pemfile was dropped
|
||||||
|
# 2026-06-29 by removing axum-server's unused tls-rustls feature + moving our own PEM parsing to
|
||||||
|
# rustls-pki-types; memmap2's unsoundness was fixed by the 0.9.11 bump.)
|
||||||
|
|
||||||
|
[advisories]
|
||||||
|
ignore = [
|
||||||
|
# rsa "Marvin Attack" — a timing sidechannel in RSA *decryption* (PKCS#1 v1.5 padding oracle).
|
||||||
|
# There is NO fixed rsa release (the constant-time rewrite is still unreleased upstream), and rsa
|
||||||
|
# is required for GameStream/Moonlight pairing. Crucially, the host uses rsa ONLY for PKCS#1 v1.5
|
||||||
|
# SIGNING / VERIFYING (gamestream/cert.rs + gamestream/pairing.rs: SigningKey / VerifyingKey /
|
||||||
|
# Signer / Verifier) — it never performs RSA decryption, which is the operation Marvin targets.
|
||||||
|
# So the vulnerable code path is not exercised. Revisit if a fixed rsa ships or we add RSA decrypt.
|
||||||
|
"RUSTSEC-2023-0071",
|
||||||
|
]
|
||||||
+2
-2
@@ -1,9 +1,9 @@
|
|||||||
# Root build context is used only by web/Dockerfile, which needs web/ and
|
# Root build context is used only by web/Dockerfile, which needs web/ and
|
||||||
# docs/api/openapi.json. Allowlist those; keep everything else (target/, .git, crates)
|
# api/openapi.json. Allowlist those; keep everything else (target/, .git, crates)
|
||||||
# out of the context upload.
|
# out of the context upload.
|
||||||
*
|
*
|
||||||
!web
|
!web
|
||||||
!docs/api/openapi.json
|
!api/openapi.json
|
||||||
web/node_modules
|
web/node_modules
|
||||||
web/.output
|
web/.output
|
||||||
web/dist
|
web/dist
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
# Android client screenshots for the Play listing / marketing. Roborazzi renders the real Compose
|
||||||
|
# UI with mock state on the host JVM via Robolectric — NO emulator, GPU, KVM, host, or JNI core
|
||||||
|
# (`-PskipRustBuild` skips the cargo-ndk native build). The Android analogue of apple.yml's
|
||||||
|
# `screenshots` job, gated to STABLE RELEASE tags only. Standalone + best-effort: a failure here
|
||||||
|
# reds nothing else. PNGs land as a 30-day artifact; not committed or published.
|
||||||
|
name: android-screenshots
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags: ["v*"]
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
screenshots:
|
||||||
|
if: startsWith(github.ref, 'refs/tags/v') || github.event_name == 'workflow_dispatch'
|
||||||
|
runs-on: ubuntu-24.04
|
||||||
|
timeout-minutes: 45
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: JDK 21 (AGP 9.2 + Robolectric's SDK-36 android-all jar both want 17–21)
|
||||||
|
uses: actions/setup-java@v4
|
||||||
|
with:
|
||||||
|
distribution: temurin
|
||||||
|
java-version: "21"
|
||||||
|
|
||||||
|
- name: Android SDK
|
||||||
|
uses: android-actions/setup-android@v3
|
||||||
|
|
||||||
|
# No NDK/CMake — the screenshot unit tests are pure JVM. compileSdk 37 auto-downloads via AGP
|
||||||
|
# if the platform channel lacks it (same note as android.yml).
|
||||||
|
- name: platform-tools + platform 36 + build-tools
|
||||||
|
run: sdkmanager "platform-tools" "platforms;android-36" "build-tools;37.0.0"
|
||||||
|
|
||||||
|
- name: Cache (gradle)
|
||||||
|
uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
~/.gradle/caches
|
||||||
|
~/.gradle/wrapper
|
||||||
|
key: android-screenshots-${{ hashFiles('clients/android/**/*.gradle.kts') }}
|
||||||
|
restore-keys: android-screenshots-
|
||||||
|
|
||||||
|
# Roborazzi renders Compose on the JVM (Robolectric Native Graphics). `-PskipRustBuild` keeps
|
||||||
|
# the cargo-ndk native build out of the graph — the tests never load libpunktfunk_android.so.
|
||||||
|
- name: Capture screenshots (Roborazzi)
|
||||||
|
working-directory: clients/android
|
||||||
|
run: ./gradlew :app:testDebugUnitTest -PskipRustBuild --stacktrace
|
||||||
|
|
||||||
|
- name: Upload screenshots
|
||||||
|
if: always()
|
||||||
|
# v3: Gitea's API rejects upload-artifact@v4 (see apple.yml). Download is a zip.
|
||||||
|
uses: actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: punktfunk-android-screenshots
|
||||||
|
path: clients/android/app/build/outputs/roborazzi
|
||||||
|
retention-days: 30
|
||||||
@@ -12,6 +12,10 @@ name: android
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [main]
|
branches: [main]
|
||||||
|
# Single project version: a `vX.Y.Z` tag is THE release (uploads to Play's `alpha` closed
|
||||||
|
# track for manual promotion + attaches the .aab/.apk to the unified Gitea Release). A main
|
||||||
|
# push is canary (Play `internal`).
|
||||||
|
tags: ['v*']
|
||||||
pull_request:
|
pull_request:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
@@ -69,11 +73,24 @@ jobs:
|
|||||||
VERSION_CODE: ${{ github.run_number }}
|
VERSION_CODE: ${{ github.run_number }}
|
||||||
run: ./gradlew :app:assembleDebug --stacktrace
|
run: ./gradlew :app:assembleDebug --stacktrace
|
||||||
|
|
||||||
|
# Single source of the version name + the Play track for the release steps below. versionCode
|
||||||
|
# stays github.run_number (monotonic across both tracks; Play rejects a regressed code).
|
||||||
|
- name: Version + channel
|
||||||
|
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v'))
|
||||||
|
run: |
|
||||||
|
case "$GITHUB_REF" in
|
||||||
|
refs/tags/v*) VN="${GITHUB_REF_NAME#v}"; TRACK="alpha" ;; # alpha = built-in closed testing
|
||||||
|
*) VN="0.3.0-ci${GITHUB_RUN_NUMBER}"; TRACK="internal" ;;
|
||||||
|
esac
|
||||||
|
echo "VERSION_NAME=$VN" >> "$GITHUB_ENV"
|
||||||
|
echo "PLAY_TRACK=$TRACK" >> "$GITHUB_ENV"
|
||||||
|
echo "android version $VN -> Play track '$TRACK'"
|
||||||
|
|
||||||
- name: Build Release (signed AAB + universal APK)
|
- name: Build Release (signed AAB + universal APK)
|
||||||
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v'))
|
||||||
working-directory: clients/android
|
working-directory: clients/android
|
||||||
env:
|
env:
|
||||||
VERSION_CODE: ${{ github.run_number }}
|
VERSION_CODE: ${{ github.run_number }} # VERSION_NAME comes from the Version+channel step (GITHUB_ENV)
|
||||||
RELEASE_KEYSTORE_FILE: "../release.jks"
|
RELEASE_KEYSTORE_FILE: "../release.jks"
|
||||||
RELEASE_KEYSTORE_PASSWORD: ${{ secrets.RELEASE_KEYSTORE_PASSWORD }}
|
RELEASE_KEYSTORE_PASSWORD: ${{ secrets.RELEASE_KEYSTORE_PASSWORD }}
|
||||||
RELEASE_KEY_ALIAS: ${{ secrets.RELEASE_KEY_ALIAS }}
|
RELEASE_KEY_ALIAS: ${{ secrets.RELEASE_KEY_ALIAS }}
|
||||||
@@ -85,33 +102,52 @@ jobs:
|
|||||||
|
|
||||||
# Publish BEFORE the Play upload so artifacts land even while the Play step is still failing.
|
# Publish BEFORE the Play upload so artifacts land even while the Play step is still failing.
|
||||||
# Generic registry is public for reads — matches windows-msix.yml / deb.yml (REGISTRY_TOKEN, user enricobuehler).
|
# Generic registry is public for reads — matches windows-msix.yml / deb.yml (REGISTRY_TOKEN, user enricobuehler).
|
||||||
- name: Publish AAB + APK to Gitea generic registry
|
# main = canary store + `canary/` sideload alias; a `vX.Y.Z` tag = `latest/` alias + attached
|
||||||
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
# to the unified Gitea Release.
|
||||||
|
- name: Publish to generic registry + attach to Gitea release
|
||||||
|
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v'))
|
||||||
env:
|
env:
|
||||||
REGISTRY: git.unom.io
|
REGISTRY: git.unom.io
|
||||||
OWNER: unom
|
OWNER: unom
|
||||||
PKG: punktfunk-android
|
PKG: punktfunk-android
|
||||||
VERSION: ${{ github.run_number }}
|
VERSION: ${{ github.run_number }}
|
||||||
REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
|
REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
|
||||||
|
GITEA_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
AAB=clients/android/app/build/outputs/bundle/release/app-release.aab
|
AAB=clients/android/app/build/outputs/bundle/release/app-release.aab
|
||||||
APK=clients/android/app/build/outputs/apk/release/app-release.apk
|
APK=clients/android/app/build/outputs/apk/release/app-release.apk
|
||||||
base="https://$REGISTRY/api/packages/$OWNER/generic/$PKG/$VERSION"
|
base="https://$REGISTRY/api/packages/$OWNER/generic/$PKG"
|
||||||
curl -fsS --user "enricobuehler:$REGISTRY_TOKEN" --upload-file "$AAB" "$base/punktfunk-android-r$VERSION.aab"
|
# 1) immutable, run-number-versioned store (sideload + provenance)
|
||||||
curl -fsS --user "enricobuehler:$REGISTRY_TOKEN" --upload-file "$APK" "$base/punktfunk-android-r$VERSION.apk"
|
curl -fsS --user "enricobuehler:$REGISTRY_TOKEN" --upload-file "$AAB" "$base/$VERSION/punktfunk-android-r$VERSION.aab"
|
||||||
echo "Published artifacts (versionCode=$VERSION):"
|
curl -fsS --user "enricobuehler:$REGISTRY_TOKEN" --upload-file "$APK" "$base/$VERSION/punktfunk-android-r$VERSION.apk"
|
||||||
echo " $base/punktfunk-android-r$VERSION.aab"
|
echo "published store version $VERSION (versionCode)"
|
||||||
echo " $base/punktfunk-android-r$VERSION.apk"
|
# 2) channel alias for a predictable sideload URL: stable -> latest/, canary -> canary/
|
||||||
|
case "$GITHUB_REF" in refs/tags/v*) ALIAS=latest ;; *) ALIAS=canary ;; esac
|
||||||
|
curl -fsS -o /dev/null --user "enricobuehler:$REGISTRY_TOKEN" -X DELETE "$base/$ALIAS/punktfunk-android.apk" || true
|
||||||
|
curl -fsS --user "enricobuehler:$REGISTRY_TOKEN" --upload-file "$APK" "$base/$ALIAS/punktfunk-android.apk"
|
||||||
|
echo "sideload alias: $base/$ALIAS/punktfunk-android.apk"
|
||||||
|
# 3) on a real release, attach the .aab + .apk to the unified Gitea Release (X.Y.Z names)
|
||||||
|
case "$GITHUB_REF" in
|
||||||
|
refs/tags/v*)
|
||||||
|
. scripts/ci/gitea-release.sh
|
||||||
|
RID=$(ensure_release "$GITHUB_REF_NAME" "$GITHUB_REF_NAME" auto)
|
||||||
|
upsert_asset "$RID" "$AAB" "punktfunk-${VERSION_NAME}.aab"
|
||||||
|
upsert_asset "$RID" "$APK" "punktfunk-${VERSION_NAME}.apk"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
# Direct Publishing-API upload instead of r0adkll/upload-google-play — that action hides the
|
# Direct Publishing-API upload instead of r0adkll/upload-google-play — that action hides the
|
||||||
# real API error behind "Unknown error occurred."; this prints it. stdlib + openssl only (no
|
# real API error behind "Unknown error occurred."; this prints it. stdlib + openssl only (no
|
||||||
# pip), reuses SERVICE_ACCOUNT_JSON (raw JSON or base64), auto-handles changesNotSentForReview.
|
# pip), reuses SERVICE_ACCOUNT_JSON (raw JSON or base64), auto-handles changesNotSentForReview.
|
||||||
- name: Upload to Google Play (Internal Testing)
|
# Track: canary main -> `internal`; a vX.Y.Z release -> `alpha` (closed testing) for manual
|
||||||
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
# promotion to production in the Play console.
|
||||||
|
- name: Upload to Google Play
|
||||||
|
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v'))
|
||||||
env:
|
env:
|
||||||
SERVICE_ACCOUNT_JSON: ${{ secrets.SERVICE_ACCOUNT_JSON }}
|
SERVICE_ACCOUNT_JSON: ${{ secrets.SERVICE_ACCOUNT_JSON }}
|
||||||
run: |
|
run: |
|
||||||
|
echo "uploading to Play track '$PLAY_TRACK'"
|
||||||
python3 clients/android/ci/play-upload.py \
|
python3 clients/android/ci/play-upload.py \
|
||||||
--package io.unom.punktfunk \
|
--package io.unom.punktfunk \
|
||||||
--aab clients/android/app/build/outputs/bundle/release/app-release.aab \
|
--aab clients/android/app/build/outputs/bundle/release/app-release.aab \
|
||||||
--track internal --status completed
|
--track "$PLAY_TRACK" --status completed
|
||||||
|
|||||||
@@ -2,6 +2,11 @@
|
|||||||
# see scripts/ci/setup-macos-runner.sh). Builds the Rust core into
|
# see scripts/ci/setup-macos-runner.sh). Builds the Rust core into
|
||||||
# PunktfunkCore.xcframework, then builds + tests the Swift package. Network-dependent
|
# PunktfunkCore.xcframework, then builds + tests the Swift package. Network-dependent
|
||||||
# tests (RemoteFirstLightTests) self-skip without PUNKTFUNK_REMOTE_HOST.
|
# tests (RemoteFirstLightTests) self-skip without PUNKTFUNK_REMOTE_HOST.
|
||||||
|
#
|
||||||
|
# A second job (`screenshots`) captures the App Store Connect screenshots of the REAL UI
|
||||||
|
# (mac window + iOS/iPad/tvOS Simulators, see clients/apple/tools/screenshots.sh) and attaches
|
||||||
|
# them to the run as a single zip artifact (`punktfunk-appstore-screenshots`). It is isolated
|
||||||
|
# from the build/test job and best-effort, so a capture gap never reds the core signal.
|
||||||
name: apple
|
name: apple
|
||||||
|
|
||||||
on:
|
on:
|
||||||
@@ -27,6 +32,25 @@ jobs:
|
|||||||
dirname "$RUSTUP" >> "$GITHUB_PATH"
|
dirname "$RUSTUP" >> "$GITHUB_PATH"
|
||||||
"$RUSTUP" target add aarch64-apple-darwin x86_64-apple-darwin
|
"$RUSTUP" target add aarch64-apple-darwin x86_64-apple-darwin
|
||||||
|
|
||||||
|
# `punktfunk-core` now decodes Opus in-core for the Apple client (surround), pulling
|
||||||
|
# `audiopus_sys`, which builds a vendored static libopus via CMake when pkg-config can't find a
|
||||||
|
# system Opus — so the xcframework is self-contained (no runtime libopus.dylib on end-user Macs).
|
||||||
|
# CMake must be on PATH; install it self-healing on a fresh runner.
|
||||||
|
- name: CMake (for the vendored libopus audiopus_sys builds)
|
||||||
|
run: |
|
||||||
|
# Runner steps run with `bash --noprofile --norc`, so Homebrew's bin dir isn't on PATH —
|
||||||
|
# locate brew explicitly, install cmake if missing, and export its bin dir to GITHUB_PATH so
|
||||||
|
# the xcframework build step (audiopus_sys → vendored libopus) finds `cmake`.
|
||||||
|
for B in /opt/homebrew/bin/brew /usr/local/bin/brew; do [ -x "$B" ] && BREW="$B" && break; done
|
||||||
|
if [ -z "$BREW" ]; then echo "::error::Homebrew not found on the runner"; exit 1; fi
|
||||||
|
BREW_BIN="$(dirname "$BREW")"; export PATH="$BREW_BIN:$PATH"
|
||||||
|
command -v cmake >/dev/null || "$BREW" install cmake
|
||||||
|
echo "$BREW_BIN" >> "$GITHUB_PATH"
|
||||||
|
# Homebrew's CMake 4 dropped compatibility with the vendored libopus's pre-3.5
|
||||||
|
# `cmake_minimum_required`; treat 3.5 as the policy minimum (the cmake crate's child cmake
|
||||||
|
# inherits this from the env during the xcframework build).
|
||||||
|
echo "CMAKE_POLICY_VERSION_MINIMUM=3.5" >> "$GITHUB_ENV"
|
||||||
|
|
||||||
- name: Build PunktfunkCore.xcframework
|
- name: Build PunktfunkCore.xcframework
|
||||||
run: bash scripts/build-xcframework.sh
|
run: bash scripts/build-xcframework.sh
|
||||||
|
|
||||||
@@ -37,3 +61,71 @@ jobs:
|
|||||||
- name: Test (unit + real-codec round trip; remote tests self-skip)
|
- name: Test (unit + real-codec round trip; remote tests self-skip)
|
||||||
working-directory: clients/apple
|
working-directory: clients/apple
|
||||||
run: swift test
|
run: swift test
|
||||||
|
|
||||||
|
# App Store screenshots of the real UI, zipped and attached to the run as a build artifact.
|
||||||
|
# Skipped on PRs (cost); runs on main pushes + manual dispatch. Needs the build/test job green
|
||||||
|
# first, and is a separate job so a capture hiccup can never red the core signal.
|
||||||
|
#
|
||||||
|
# Scope = the two REQUIRED iOS sizes (iPhone 6.9" + iPad 13"), captured on the Simulator
|
||||||
|
# (`simctl io screenshot`, no Screen Recording grant needed). macOS and tvOS are deliberately
|
||||||
|
# NOT in CI: the self-hosted runner is headless (no window-server session), so the mac window
|
||||||
|
# capture can't run there; tvOS needs the Tier-3 build-std slice. Generate those two locally on
|
||||||
|
# a GUI Mac with `clients/apple/tools/screenshots.sh macos tvos`.
|
||||||
|
screenshots:
|
||||||
|
needs: swift
|
||||||
|
if: gitea.event_name != 'pull_request'
|
||||||
|
runs-on: macos-arm64
|
||||||
|
timeout-minutes: 75
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Rust toolchain + iOS Simulator targets
|
||||||
|
run: |
|
||||||
|
if ! command -v rustup >/dev/null && [ ! -x "$HOME/.cargo/bin/rustup" ]; then
|
||||||
|
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \
|
||||||
|
| sh -s -- -y --no-modify-path --profile minimal
|
||||||
|
fi
|
||||||
|
RUSTUP="$(command -v rustup || echo "$HOME/.cargo/bin/rustup")"
|
||||||
|
dirname "$RUSTUP" >> "$GITHUB_PATH"
|
||||||
|
"$RUSTUP" target add aarch64-apple-darwin x86_64-apple-darwin \
|
||||||
|
aarch64-apple-ios aarch64-apple-ios-sim x86_64-apple-ios
|
||||||
|
|
||||||
|
# See the swift job: audiopus_sys (via the in-core Opus decode) builds vendored libopus with CMake.
|
||||||
|
- name: CMake (for the vendored libopus audiopus_sys builds)
|
||||||
|
run: |
|
||||||
|
# Runner steps run with `bash --noprofile --norc`, so Homebrew's bin dir isn't on PATH —
|
||||||
|
# locate brew explicitly, install cmake if missing, and export its bin dir to GITHUB_PATH so
|
||||||
|
# the xcframework build step (audiopus_sys → vendored libopus) finds `cmake`.
|
||||||
|
for B in /opt/homebrew/bin/brew /usr/local/bin/brew; do [ -x "$B" ] && BREW="$B" && break; done
|
||||||
|
if [ -z "$BREW" ]; then echo "::error::Homebrew not found on the runner"; exit 1; fi
|
||||||
|
BREW_BIN="$(dirname "$BREW")"; export PATH="$BREW_BIN:$PATH"
|
||||||
|
command -v cmake >/dev/null || "$BREW" install cmake
|
||||||
|
echo "$BREW_BIN" >> "$GITHUB_PATH"
|
||||||
|
# Homebrew's CMake 4 dropped compatibility with the vendored libopus's pre-3.5
|
||||||
|
# `cmake_minimum_required`; treat 3.5 as the policy minimum (the cmake crate's child cmake
|
||||||
|
# inherits this from the env during the xcframework build).
|
||||||
|
echo "CMAKE_POLICY_VERSION_MINIMUM=3.5" >> "$GITHUB_ENV"
|
||||||
|
|
||||||
|
- name: Build PunktfunkCore.xcframework (mac + iOS slices)
|
||||||
|
run: BUILD_IOS=1 bash scripts/build-xcframework.sh
|
||||||
|
|
||||||
|
- name: Capture screenshots (iPhone 6.9" + iPad 13"; auto-creates the Simulators)
|
||||||
|
working-directory: clients/apple
|
||||||
|
env:
|
||||||
|
SETTLE: "8" # Simulators settle slower than a local run
|
||||||
|
run: |
|
||||||
|
# Independent invocations: one platform failing skips it, not the other.
|
||||||
|
bash tools/screenshots.sh ios || echo "::warning::iOS (iPhone 6.9\") screenshots skipped"
|
||||||
|
bash tools/screenshots.sh ipad || echo "::warning::iPad 13\" screenshots skipped"
|
||||||
|
echo "Produced:"; ls -la screenshots || true
|
||||||
|
|
||||||
|
- name: Upload screenshots (zip artifact)
|
||||||
|
if: always()
|
||||||
|
# v3, not v4: Gitea's artifact backend identifies as GHES, which @actions/artifact v2+
|
||||||
|
# (upload-artifact@v4) refuses. v3 uses the older API Gitea supports; download is still a zip.
|
||||||
|
uses: actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: punktfunk-appstore-screenshots
|
||||||
|
path: clients/apple/screenshots
|
||||||
|
if-no-files-found: warn
|
||||||
|
retention-days: 30
|
||||||
|
|||||||
+32
-14
@@ -13,16 +13,16 @@ name: deb
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [main]
|
branches: [main]
|
||||||
# HOST-scoped tags only. The Apple client uses `v*` (release.yml); those must NOT trigger a
|
# Single project version: a `vX.Y.Z` tag is THE release for every platform (see
|
||||||
# host publish — a `v0.1.1` client tag previously shipped a host package versioned 0.1.1 that
|
# docs-site channels.md). The old version-shadow (a client tag shipping a host package
|
||||||
# outranked every rolling build (the version-shadow). Host releases use `host-v*`.
|
# that outranked rolling builds) is now structurally impossible — main publishes to the
|
||||||
tags: ['host-v*']
|
# `canary` apt distribution, tags to `stable`, so the two never share a version line.
|
||||||
|
tags: ['v*']
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
env:
|
env:
|
||||||
REGISTRY: git.unom.io
|
REGISTRY: git.unom.io
|
||||||
OWNER: unom
|
OWNER: unom
|
||||||
DISTRIBUTION: stable
|
|
||||||
COMPONENT: main
|
COMPONENT: main
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
@@ -34,19 +34,22 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Version
|
- name: Version + channel
|
||||||
# host-vX.Y.Z tag -> X.Y.Z (a real host release). A main push -> 0.2.0~ciN.g<sha>: the '~'
|
# vX.Y.Z tag -> X.Y.Z, published to the `stable` apt distribution (a real release).
|
||||||
# sorts it BELOW the eventual 0.2.0 tag, it climbs monotonically by run number, AND it sits
|
# A main push -> 0.3.0~ciN.g<sha>, published to the `canary` distribution: the '~' sorts
|
||||||
# ABOVE the stray 0.1.1, so `apt upgrade` truly moves boxes forward. Computed BEFORE the
|
# below the eventual 0.3.0 tag, it climbs monotonically by run number, and the canary base
|
||||||
# build so it's stamped into the binary (PUNKTFUNK_BUILD_VERSION -> build.rs -> --version).
|
# stays one minor AHEAD of the latest stable so a stable->canary box re-point still moves
|
||||||
|
# forward (see channels.md). Computed BEFORE the build so it's stamped into the binary
|
||||||
|
# (PUNKTFUNK_BUILD_VERSION -> build.rs -> --version).
|
||||||
run: |
|
run: |
|
||||||
SHORT=$(echo "$GITHUB_SHA" | cut -c1-8)
|
SHORT=$(echo "$GITHUB_SHA" | cut -c1-8)
|
||||||
case "$GITHUB_REF" in
|
case "$GITHUB_REF" in
|
||||||
refs/tags/host-v*) V="${GITHUB_REF_NAME#host-v}" ;;
|
refs/tags/v*) V="${GITHUB_REF_NAME#v}"; DIST=stable ;;
|
||||||
*) V="0.2.0~ci${GITHUB_RUN_NUMBER}.g${SHORT}" ;;
|
*) V="0.3.0~ci${GITHUB_RUN_NUMBER}.g${SHORT}"; DIST=canary ;;
|
||||||
esac
|
esac
|
||||||
echo "VERSION=$V" >> "$GITHUB_ENV"
|
echo "VERSION=$V" >> "$GITHUB_ENV"
|
||||||
echo "package version $V"
|
echo "DISTRIBUTION=$DIST" >> "$GITHUB_ENV"
|
||||||
|
echo "package version $V -> apt distribution '$DIST'"
|
||||||
|
|
||||||
# dpkg-shlibdeps (Depends resolution) + dpkg-deb live in dpkg-dev. The client's link
|
# dpkg-shlibdeps (Depends resolution) + dpkg-deb live in dpkg-dev. The client's link
|
||||||
# deps are also baked into the rust-ci image, but this job runs against the image
|
# deps are also baked into the rust-ci image, but this job runs against the image
|
||||||
@@ -55,7 +58,8 @@ jobs:
|
|||||||
- name: dpkg-dev + client link deps
|
- name: dpkg-dev + client link deps
|
||||||
run: |
|
run: |
|
||||||
apt-get update
|
apt-get update
|
||||||
apt-get install -y --no-install-recommends dpkg-dev \
|
# python3 is used by scripts/ci/gitea-release.sh for the stable-tag release attach.
|
||||||
|
apt-get install -y --no-install-recommends dpkg-dev python3 \
|
||||||
libgtk-4-dev libadwaita-1-dev libsdl3-dev
|
libgtk-4-dev libadwaita-1-dev libsdl3-dev
|
||||||
|
|
||||||
# Share ci.yml's cache keys so the release build reuses its registry + target artifacts.
|
# Share ci.yml's cache keys so the release build reuses its registry + target artifacts.
|
||||||
@@ -124,3 +128,17 @@ jobs:
|
|||||||
"https://$REGISTRY/api/packages/$OWNER/debian/pool/$DISTRIBUTION/$COMPONENT/upload"
|
"https://$REGISTRY/api/packages/$OWNER/debian/pool/$DISTRIBUTION/$COMPONENT/upload"
|
||||||
done
|
done
|
||||||
echo "published to $OWNER/debian $DISTRIBUTION/$COMPONENT"
|
echo "published to $OWNER/debian $DISTRIBUTION/$COMPONENT"
|
||||||
|
|
||||||
|
# On a real release, also attach the .debs to the unified Gitea Release so they're on the
|
||||||
|
# downloads page next to every other platform's artifact (canary builds live in the apt
|
||||||
|
# `canary` distribution above — no release page for those).
|
||||||
|
- name: Attach .debs to the Gitea release (stable tags only)
|
||||||
|
if: startsWith(gitea.ref, 'refs/tags/v')
|
||||||
|
env:
|
||||||
|
GITEA_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
|
||||||
|
run: |
|
||||||
|
. scripts/ci/gitea-release.sh
|
||||||
|
RID=$(ensure_release "$GITHUB_REF_NAME" "$GITHUB_REF_NAME" auto)
|
||||||
|
for DEB in dist/*.deb; do
|
||||||
|
upsert_asset "$RID" "$DEB"
|
||||||
|
done
|
||||||
|
|||||||
+55
-31
@@ -11,12 +11,18 @@
|
|||||||
# punktfunk.zip
|
# punktfunk.zip
|
||||||
# punktfunk/ <- single top-level dir == plugin.json "name"
|
# punktfunk/ <- single top-level dir == plugin.json "name"
|
||||||
# plugin.json [required]
|
# plugin.json [required]
|
||||||
# package.json [required]
|
# package.json [required; CI stamps "version" — Decky reads the installed version here]
|
||||||
# main.py [required: python backend]
|
# main.py [required: python backend]
|
||||||
# dist/index.js [required: rollup output]
|
# dist/index.js [required: rollup output]
|
||||||
|
# update.json [CI-baked {channel, manifest}: where the plugin's self-update check polls]
|
||||||
# README.md (recommended)
|
# README.md (recommended)
|
||||||
# LICENSE [required by the plugin store]
|
# LICENSE [required by the plugin store]
|
||||||
#
|
#
|
||||||
|
# SELF-UPDATE (no Decky store): alongside the zip we also publish a tiny per-channel
|
||||||
|
# `manifest.json` ({version, artifact=<immutable per-version zip URL>, sha256}). The installed
|
||||||
|
# plugin polls it (main.py check_update), and the frontend drives Decky's own install RPC to
|
||||||
|
# apply a newer build. See clients/decky/README.md "Updating".
|
||||||
|
#
|
||||||
# REGISTRY_TOKEN: repo Actions secret, a PAT with write:package scope (shared with deb/rpm/docker).
|
# REGISTRY_TOKEN: repo Actions secret, a PAT with write:package scope (shared with deb/rpm/docker).
|
||||||
name: decky
|
name: decky
|
||||||
|
|
||||||
@@ -56,19 +62,26 @@ jobs:
|
|||||||
pnpm install --frozen-lockfile
|
pnpm install --frozen-lockfile
|
||||||
pnpm run build # rollup -> clients/decky/dist/index.js
|
pnpm run build # rollup -> clients/decky/dist/index.js
|
||||||
|
|
||||||
- name: Version
|
- name: Version + channel + stamp
|
||||||
# Tag v1.2.3 -> 1.2.3; main push -> 0.0.1-ciN.g<sha>. Used only for the registry
|
# Tag vX.Y.Z -> X.Y.Z (stable `latest/` alias + Gitea Release); main push -> 0.3.<run>
|
||||||
# version path + the zip name (the plugin.json version is the source of truth Decky
|
# (`canary/` alias). Decky reads a plugin's INSTALLED version from package.json (NOT
|
||||||
# reads after install).
|
# plugin.json), and the plugin's own update check (clients/decky/main.py check_update)
|
||||||
|
# compares against it — so the build version is STAMPED into package.json here (mirrored
|
||||||
|
# into plugin.json for store parity). Canary is a PLAIN numeric semver, never a
|
||||||
|
# `-ci<N>` prerelease: compare-versions orders prerelease identifiers lexically
|
||||||
|
# (ci10 < ci9), which would break update detection; the run number is monotonic.
|
||||||
working-directory: ${{ gitea.workspace }}
|
working-directory: ${{ gitea.workspace }}
|
||||||
run: |
|
run: |
|
||||||
SHORT=$(echo "$GITHUB_SHA" | cut -c1-8)
|
|
||||||
case "$GITHUB_REF" in
|
case "$GITHUB_REF" in
|
||||||
refs/tags/v*) V="${GITHUB_REF_NAME#v}" ;;
|
refs/tags/v*) V="${GITHUB_REF_NAME#v}"; ALIAS=latest ;;
|
||||||
*) V="0.0.1-ci${GITHUB_RUN_NUMBER}.g${SHORT}" ;;
|
*) V="0.3.${GITHUB_RUN_NUMBER}"; ALIAS=canary ;;
|
||||||
esac
|
esac
|
||||||
|
BASE="https://$REGISTRY/api/packages/$OWNER/generic/$PACKAGE"
|
||||||
echo "VERSION=$V" >> "$GITHUB_ENV"
|
echo "VERSION=$V" >> "$GITHUB_ENV"
|
||||||
echo "decky version $V"
|
echo "ALIAS=$ALIAS" >> "$GITHUB_ENV"
|
||||||
|
echo "BASE=$BASE" >> "$GITHUB_ENV"
|
||||||
|
echo "decky version $V -> alias '$ALIAS'"
|
||||||
|
VERSION="$V" node -e 'const fs=require("fs");for(const f of ["clients/decky/package.json","clients/decky/plugin.json"]){const j=JSON.parse(fs.readFileSync(f,"utf8"));j.version=process.env.VERSION;fs.writeFileSync(f,JSON.stringify(j,null,2)+"\n");}'
|
||||||
|
|
||||||
- name: Assemble store-layout zip
|
- name: Assemble store-layout zip
|
||||||
working-directory: ${{ gitea.workspace }}
|
working-directory: ${{ gitea.workspace }}
|
||||||
@@ -88,9 +101,20 @@ jobs:
|
|||||||
chmod 0755 "$DEST/bin/punktfunkrun.sh"
|
chmod 0755 "$DEST/bin/punktfunkrun.sh"
|
||||||
# Store requires a LICENSE in the plugin root; the project is MIT OR Apache-2.0.
|
# Store requires a LICENSE in the plugin root; the project is MIT OR Apache-2.0.
|
||||||
cp LICENSE-MIT "$DEST/LICENSE"
|
cp LICENSE-MIT "$DEST/LICENSE"
|
||||||
|
# Self-update channel pointer the backend reads (main.py check_update). It points at
|
||||||
|
# THIS channel's manifest.json (published below); that manifest in turn points at the
|
||||||
|
# immutable per-version zip, so its sha256 stays valid across future alias re-uploads.
|
||||||
|
printf '{"channel":"%s","manifest":"%s/%s/manifest.json"}\n' "$ALIAS" "$BASE" "$ALIAS" > "$DEST/update.json"
|
||||||
( cd "$STAGE" && zip -r "$RUNNER_TEMP/punktfunk.zip" "$PLUGIN" )
|
( cd "$STAGE" && zip -r "$RUNNER_TEMP/punktfunk.zip" "$PLUGIN" )
|
||||||
ls -lh "$RUNNER_TEMP/punktfunk.zip"
|
ls -lh "$RUNNER_TEMP/punktfunk.zip"
|
||||||
unzip -l "$RUNNER_TEMP/punktfunk.zip"
|
unzip -l "$RUNNER_TEMP/punktfunk.zip"
|
||||||
|
# The update manifest the plugin polls: the immutable per-version artifact + its
|
||||||
|
# sha256 (Decky's installer verifies the download against this hash, aborting on
|
||||||
|
# mismatch — so it MUST be the per-version URL, never the mutable alias).
|
||||||
|
SHA=$(sha256sum "$RUNNER_TEMP/punktfunk.zip" | cut -d' ' -f1)
|
||||||
|
printf '{"version":"%s","artifact":"%s/%s/punktfunk.zip","sha256":"%s"}\n' \
|
||||||
|
"$VERSION" "$BASE" "$VERSION" "$SHA" > "$RUNNER_TEMP/manifest.json"
|
||||||
|
cat "$RUNNER_TEMP/manifest.json"
|
||||||
|
|
||||||
- name: Publish to the Gitea generic registry
|
- name: Publish to the Gitea generic registry
|
||||||
working-directory: ${{ gitea.workspace }}
|
working-directory: ${{ gitea.workspace }}
|
||||||
@@ -98,33 +122,33 @@ jobs:
|
|||||||
TOKEN: ${{ secrets.REGISTRY_TOKEN }}
|
TOKEN: ${{ secrets.REGISTRY_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
BASE="https://$REGISTRY/api/packages/$OWNER/generic/$PACKAGE"
|
BASE="https://$REGISTRY/api/packages/$OWNER/generic/$PACKAGE"
|
||||||
# 1) Immutable, versioned URL.
|
# 1) Immutable, versioned URL + its update manifest (the manifest's `artifact` points
|
||||||
|
# here, so the published sha256 keeps matching what Decky later downloads).
|
||||||
curl -fsS --user "enricobuehler:$TOKEN" --upload-file "$RUNNER_TEMP/punktfunk.zip" \
|
curl -fsS --user "enricobuehler:$TOKEN" --upload-file "$RUNNER_TEMP/punktfunk.zip" \
|
||||||
"$BASE/$VERSION/punktfunk.zip"
|
"$BASE/$VERSION/punktfunk.zip"
|
||||||
|
curl -fsS --user "enricobuehler:$TOKEN" --upload-file "$RUNNER_TEMP/manifest.json" \
|
||||||
|
"$BASE/$VERSION/manifest.json"
|
||||||
echo "published $BASE/$VERSION/punktfunk.zip"
|
echo "published $BASE/$VERSION/punktfunk.zip"
|
||||||
# 2) Stable `latest/punktfunk.zip` — this is the link to paste into Decky's
|
# 2) Channel alias (stable release -> latest/, canary main build -> canary/) — the
|
||||||
# "install from URL". The generic registry rejects re-uploading an existing
|
# zip is the "install from URL" link; manifest.json is what the installed plugin
|
||||||
# version/file (409), so delete the prior `latest` first (ignore 404 on run #1).
|
# polls for updates. The generic registry rejects re-uploading an existing
|
||||||
curl -fsS -o /dev/null --user "enricobuehler:$TOKEN" -X DELETE \
|
# version/file (409), so delete the prior alias copies first (ignore 404 on run #1).
|
||||||
"$BASE/latest/punktfunk.zip" || true
|
for f in punktfunk.zip manifest.json; do
|
||||||
|
curl -fsS -o /dev/null --user "enricobuehler:$TOKEN" -X DELETE "$BASE/$ALIAS/$f" || true
|
||||||
|
done
|
||||||
curl -fsS --user "enricobuehler:$TOKEN" --upload-file "$RUNNER_TEMP/punktfunk.zip" \
|
curl -fsS --user "enricobuehler:$TOKEN" --upload-file "$RUNNER_TEMP/punktfunk.zip" \
|
||||||
"$BASE/latest/punktfunk.zip"
|
"$BASE/$ALIAS/punktfunk.zip"
|
||||||
echo "install-from-URL link: $BASE/latest/punktfunk.zip"
|
curl -fsS --user "enricobuehler:$TOKEN" --upload-file "$RUNNER_TEMP/manifest.json" \
|
||||||
|
"$BASE/$ALIAS/manifest.json"
|
||||||
|
echo "install-from-URL link: $BASE/$ALIAS/punktfunk.zip"
|
||||||
|
echo "update manifest: $BASE/$ALIAS/manifest.json"
|
||||||
|
|
||||||
- name: Attach zip to the Gitea release (tags only)
|
- name: Attach zip to the Gitea release (stable tags only)
|
||||||
if: startsWith(gitea.ref, 'refs/tags/')
|
if: startsWith(gitea.ref, 'refs/tags/v')
|
||||||
working-directory: ${{ gitea.workspace }}
|
working-directory: ${{ gitea.workspace }}
|
||||||
env:
|
env:
|
||||||
TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITEA_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
API="${{ gitea.server_url }}/api/v1/repos/${{ gitea.repository }}"
|
. scripts/ci/gitea-release.sh
|
||||||
ID=$(curl -sf -X POST "$API/releases" \
|
RID=$(ensure_release "$GITHUB_REF_NAME" "$GITHUB_REF_NAME" auto)
|
||||||
-H "Authorization: token $TOKEN" -H 'Content-Type: application/json' \
|
upsert_asset "$RID" "$RUNNER_TEMP/punktfunk.zip" "punktfunk-${VERSION}.zip"
|
||||||
-d "{\"tag_name\":\"$GITHUB_REF_NAME\",\"name\":\"$GITHUB_REF_NAME\"}" \
|
|
||||||
| python3 -c 'import json,sys;print(json.load(sys.stdin)["id"])' \
|
|
||||||
|| curl -sf "$API/releases/tags/$GITHUB_REF_NAME" -H "Authorization: token $TOKEN" \
|
|
||||||
| python3 -c 'import json,sys;print(json.load(sys.stdin)["id"])')
|
|
||||||
curl -sf -X POST "$API/releases/$ID/assets?name=punktfunk-${VERSION}.zip" \
|
|
||||||
-H "Authorization: token $TOKEN" \
|
|
||||||
-F "attachment=@$RUNNER_TEMP/punktfunk.zip" >/dev/null
|
|
||||||
echo "attached punktfunk-${VERSION}.zip to release $GITHUB_REF_NAME"
|
|
||||||
|
|||||||
@@ -58,16 +58,21 @@ jobs:
|
|||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: |
|
run: |
|
||||||
|
# On a release tag, also tag the image vX.Y.Z so a release pins reproducible web/docs images.
|
||||||
|
EXTRA=""
|
||||||
|
case "$GITHUB_REF" in refs/tags/v*) EXTRA="-t $REGISTRY/$OWNER/${{ matrix.image }}:${GITHUB_REF_NAME}" ;; esac
|
||||||
docker build --pull ${{ matrix.buildargs }} \
|
docker build --pull ${{ matrix.buildargs }} \
|
||||||
-f "${{ matrix.dockerfile }}" \
|
-f "${{ matrix.dockerfile }}" \
|
||||||
-t "$REGISTRY/$OWNER/${{ matrix.image }}:latest" \
|
-t "$REGISTRY/$OWNER/${{ matrix.image }}:latest" \
|
||||||
-t "$REGISTRY/$OWNER/${{ matrix.image }}:sha-${GITHUB_SHA::8}" \
|
-t "$REGISTRY/$OWNER/${{ matrix.image }}:sha-${GITHUB_SHA::8}" \
|
||||||
|
$EXTRA \
|
||||||
"${{ matrix.context }}"
|
"${{ matrix.context }}"
|
||||||
|
|
||||||
- name: Push
|
- name: Push
|
||||||
run: |
|
run: |
|
||||||
docker push "$REGISTRY/$OWNER/${{ matrix.image }}:sha-${GITHUB_SHA::8}"
|
docker push "$REGISTRY/$OWNER/${{ matrix.image }}:sha-${GITHUB_SHA::8}"
|
||||||
docker push "$REGISTRY/$OWNER/${{ matrix.image }}:latest"
|
docker push "$REGISTRY/$OWNER/${{ matrix.image }}:latest"
|
||||||
|
case "$GITHUB_REF" in refs/tags/v*) docker push "$REGISTRY/$OWNER/${{ matrix.image }}:${GITHUB_REF_NAME}" ;; esac
|
||||||
|
|
||||||
# Deploy the docs site to unom-1, the DMZ services VM website/cms also deploy to
|
# Deploy the docs site to unom-1, the DMZ services VM website/cms also deploy to
|
||||||
# (docs.punktfunk.unom.io via Caddy on home-reverse-proxy-1 -> :3220). Same secret set
|
# (docs.punktfunk.unom.io via Caddy on home-reverse-proxy-1 -> :3220). Same secret set
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ on:
|
|||||||
push:
|
push:
|
||||||
branches: [main]
|
branches: [main]
|
||||||
# The flatpak is the CLIENT — only rebuild when the client/core/manifest change, not on every
|
# The flatpak is the CLIENT — only rebuild when the client/core/manifest change, not on every
|
||||||
# docs/host push (this is a heavy flatpak-builder run). Tags (v*, the client release) build too.
|
# design/host push (this is a heavy flatpak-builder run). Tags (v*, the client release) build too.
|
||||||
paths:
|
paths:
|
||||||
- 'clients/linux/**'
|
- 'clients/linux/**'
|
||||||
- 'crates/punktfunk-core/**'
|
- 'crates/punktfunk-core/**'
|
||||||
@@ -71,19 +71,23 @@ jobs:
|
|||||||
https://dl.flathub.org/repo/flathub.flatpakrepo
|
https://dl.flathub.org/repo/flathub.flatpakrepo
|
||||||
git config --global --add safe.directory "$PWD"
|
git config --global --add safe.directory "$PWD"
|
||||||
|
|
||||||
- name: Version
|
- name: Version + channel
|
||||||
# Tag v1.2.3 -> 1.2.3; a main push -> 0.0.1-ciN.g<sha> (sorts before a real release,
|
# Tag vX.Y.Z -> X.Y.Z on the OSTree `stable` branch (a real release); a main push ->
|
||||||
# increases by run number — newest main build always wins). The generic registry
|
# 0.3.0-ciN.g<sha> on the `canary` branch. The two branches live side-by-side in one repo
|
||||||
# version string allows letters/dots/hyphens.
|
# (rsync runs without --delete), each tracked by its own .flatpakref, so `flatpak update`
|
||||||
|
# on a stable box never jumps to a canary build. The generic-registry version string allows
|
||||||
|
# letters/dots/hyphens.
|
||||||
run: |
|
run: |
|
||||||
SHORT=$(echo "$GITHUB_SHA" | cut -c1-8)
|
SHORT=$(echo "$GITHUB_SHA" | cut -c1-8)
|
||||||
case "$GITHUB_REF" in
|
case "$GITHUB_REF" in
|
||||||
refs/tags/v*) V="${GITHUB_REF_NAME#v}" ;;
|
refs/tags/v*) V="${GITHUB_REF_NAME#v}"; BRANCH=stable; ALIAS=latest ;;
|
||||||
*) V="0.0.1-ci${GITHUB_RUN_NUMBER}.g${SHORT}" ;;
|
*) V="0.3.0-ci${GITHUB_RUN_NUMBER}.g${SHORT}"; BRANCH=canary; ALIAS=canary ;;
|
||||||
esac
|
esac
|
||||||
echo "VERSION=$V" >> "$GITHUB_ENV"
|
echo "VERSION=$V" >> "$GITHUB_ENV"
|
||||||
echo "BUNDLE=punktfunk-client-${V}.flatpak" >> "$GITHUB_ENV"
|
echo "BUNDLE=punktfunk-client-${V}.flatpak" >> "$GITHUB_ENV"
|
||||||
echo "flatpak version $V"
|
echo "FLATPAK_BRANCH=$BRANCH" >> "$GITHUB_ENV"
|
||||||
|
echo "ALIAS=$ALIAS" >> "$GITHUB_ENV"
|
||||||
|
echo "flatpak version $V -> branch '$BRANCH' alias '$ALIAS'"
|
||||||
|
|
||||||
- name: Generate offline cargo sources
|
- name: Generate offline cargo sources
|
||||||
# flatpak builds with no network; vendor every crate from Cargo.lock into
|
# flatpak builds with no network; vendor every crate from Cargo.lock into
|
||||||
@@ -108,19 +112,20 @@ jobs:
|
|||||||
# runtime/SDK + the rust-stable (//25.08, rustc 1.96) and llvm20 SDK extensions, plus
|
# runtime/SDK + the rust-stable (//25.08, rustc 1.96) and llvm20 SDK extensions, plus
|
||||||
# the runtime's auto codecs-extra (HEVC libavcodec). --disable-rofiles-fuse is the
|
# the runtime's auto codecs-extra (HEVC libavcodec). --disable-rofiles-fuse is the
|
||||||
# container-safe path (no FUSE).
|
# container-safe path (no FUSE).
|
||||||
# --default-branch=stable pins the ref to app/io.unom.Punktfunk/x86_64/stable so the
|
# --default-branch=$FLATPAK_BRANCH pins the ref to app/io.unom.Punktfunk/x86_64/<branch>
|
||||||
# hosted .flatpakref (Branch=stable) matches deterministically (manifest sets no branch).
|
# (canary or stable) so the matching hosted .flatpakref resolves deterministically
|
||||||
|
# (manifest sets no branch).
|
||||||
flatpak-builder --user --force-clean --disable-rofiles-fuse \
|
flatpak-builder --user --force-clean --disable-rofiles-fuse \
|
||||||
--default-branch=stable \
|
--default-branch="$FLATPAK_BRANCH" \
|
||||||
--install-deps-from=flathub \
|
--install-deps-from=flathub \
|
||||||
--repo="$PWD/repo" \
|
--repo="$PWD/repo" \
|
||||||
"$PWD/build-dir" "$MANIFEST"
|
"$PWD/build-dir" "$MANIFEST"
|
||||||
|
|
||||||
- name: Export single-file bundle
|
- name: Export single-file bundle
|
||||||
run: |
|
run: |
|
||||||
# Branch must be passed explicitly now that the repo ref is `stable` (--default-branch
|
# Branch must be passed explicitly (matches --default-branch above); build-bundle
|
||||||
# above); build-bundle otherwise defaults to `master` and errors "Refspec … not found".
|
# otherwise defaults to `master` and errors "Refspec … not found".
|
||||||
flatpak build-bundle "$PWD/repo" "$BUNDLE" "$APP_ID" stable
|
flatpak build-bundle "$PWD/repo" "$BUNDLE" "$APP_ID" "$FLATPAK_BRANCH"
|
||||||
ls -lh "$BUNDLE"
|
ls -lh "$BUNDLE"
|
||||||
|
|
||||||
- name: Publish to the Gitea generic registry
|
- name: Publish to the Gitea generic registry
|
||||||
@@ -132,14 +137,14 @@ jobs:
|
|||||||
curl -fsS --user "enricobuehler:$TOKEN" --upload-file "$BUNDLE" \
|
curl -fsS --user "enricobuehler:$TOKEN" --upload-file "$BUNDLE" \
|
||||||
"$BASE/$VERSION/$BUNDLE"
|
"$BASE/$VERSION/$BUNDLE"
|
||||||
echo "published $BASE/$VERSION/$BUNDLE"
|
echo "published $BASE/$VERSION/$BUNDLE"
|
||||||
# 2) Stable `latest/punktfunk-client.flatpak` alias for the Decky fallback + scripts.
|
# 2) Channel alias (stable release -> latest/, canary main build -> canary/) for the
|
||||||
# The generic registry rejects re-uploading an existing version/file (409), so
|
# Decky fallback + scripts. The generic registry rejects re-uploading an existing
|
||||||
# delete the prior `latest` file first (ignore 404 on the first ever run).
|
# version/file (409), so delete the prior alias file first (ignore 404 on run #1).
|
||||||
curl -fsS -o /dev/null --user "enricobuehler:$TOKEN" -X DELETE \
|
curl -fsS -o /dev/null --user "enricobuehler:$TOKEN" -X DELETE \
|
||||||
"$BASE/latest/punktfunk-client.flatpak" || true
|
"$BASE/$ALIAS/punktfunk-client.flatpak" || true
|
||||||
curl -fsS --user "enricobuehler:$TOKEN" --upload-file "$BUNDLE" \
|
curl -fsS --user "enricobuehler:$TOKEN" --upload-file "$BUNDLE" \
|
||||||
"$BASE/latest/punktfunk-client.flatpak"
|
"$BASE/$ALIAS/punktfunk-client.flatpak"
|
||||||
echo "published $BASE/latest/punktfunk-client.flatpak"
|
echo "published $BASE/$ALIAS/punktfunk-client.flatpak"
|
||||||
|
|
||||||
# Sign the OSTree repo flatpak-builder already produced and publish it to flatpak.unom.io on
|
# Sign the OSTree repo flatpak-builder already produced and publish it to flatpak.unom.io on
|
||||||
# unom-1, so users get `flatpak update` (the single-file bundle above has no remote). Mirrors
|
# unom-1, so users get `flatpak update` (the single-file bundle above has no remote). Mirrors
|
||||||
@@ -165,7 +170,7 @@ jobs:
|
|||||||
# build-sign signs the COMMIT objects; build-update-repo signs the SUMMARY. Both are
|
# build-sign signs the COMMIT objects; build-update-repo signs the SUMMARY. Both are
|
||||||
# required — clients with gpg-verify=true verify the commit, so summary-only signing
|
# required — clients with gpg-verify=true verify the commit, so summary-only signing
|
||||||
# fails the pull with "GPG verification enabled, but no signatures found".
|
# fails the pull with "GPG verification enabled, but no signatures found".
|
||||||
flatpak build-sign "$PWD/repo" "$APP_ID" stable \
|
flatpak build-sign "$PWD/repo" "$APP_ID" "$FLATPAK_BRANCH" \
|
||||||
--gpg-sign="$KEYID" --gpg-homedir="$GNUPGHOME"
|
--gpg-sign="$KEYID" --gpg-homedir="$GNUPGHOME"
|
||||||
flatpak build-update-repo --generate-static-deltas \
|
flatpak build-update-repo --generate-static-deltas \
|
||||||
--gpg-sign="$KEYID" --gpg-homedir="$GNUPGHOME" "$PWD/repo"
|
--gpg-sign="$KEYID" --gpg-homedir="$GNUPGHOME" "$PWD/repo"
|
||||||
@@ -180,23 +185,33 @@ jobs:
|
|||||||
Comment=unom Flatpak applications
|
Comment=unom Flatpak applications
|
||||||
GPGKey=$GPGKEY
|
GPGKey=$GPGKEY
|
||||||
EOF
|
EOF
|
||||||
cat > "site/${APP_ID}.flatpakref" <<EOF
|
# Two refs, one per channel — both regenerated every run and rsync'd without --delete, so
|
||||||
|
# the server always offers both (the stable ref only resolves once a release has built the
|
||||||
|
# `stable` branch). A box installs ONE; `flatpak update` then tracks that channel's branch.
|
||||||
|
write_ref() { # <filename> <branch> <title>
|
||||||
|
cat > "site/$1" <<EOF
|
||||||
[Flatpak Ref]
|
[Flatpak Ref]
|
||||||
Name=$APP_ID
|
Name=$APP_ID
|
||||||
Branch=stable
|
Branch=$2
|
||||||
Url=$REPO_URL/repo/
|
Url=$REPO_URL/repo/
|
||||||
Title=Punktfunk
|
Title=$3
|
||||||
Homepage=https://punktfunk.unom.io
|
Homepage=https://punktfunk.unom.io
|
||||||
IsRuntime=false
|
IsRuntime=false
|
||||||
GPGKey=$GPGKEY
|
GPGKey=$GPGKEY
|
||||||
RuntimeRepo=https://dl.flathub.org/repo/flathub.flatpakrepo
|
RuntimeRepo=https://dl.flathub.org/repo/flathub.flatpakrepo
|
||||||
EOF
|
EOF
|
||||||
|
}
|
||||||
|
write_ref "${APP_ID}.flatpakref" stable "Punktfunk"
|
||||||
|
write_ref "${APP_ID}.Canary.flatpakref" canary "Punktfunk (Canary)"
|
||||||
cat > site/index.html <<EOF
|
cat > site/index.html <<EOF
|
||||||
<!doctype html><meta charset=utf-8><title>unom flatpak repo</title>
|
<!doctype html><meta charset=utf-8><title>unom flatpak repo</title>
|
||||||
<h1>unom Flatpak repository</h1>
|
<h1>unom Flatpak repository</h1>
|
||||||
<p>Install the Punktfunk Linux client (auto-adds Flathub for the GNOME runtime, then tracks updates):</p>
|
<p>Install the Punktfunk Linux client (auto-adds Flathub for the GNOME runtime, then tracks updates).</p>
|
||||||
|
<p><b>Stable</b> (recommended — only moves on releases):</p>
|
||||||
<pre>flatpak install --user $REPO_URL/${APP_ID}.flatpakref
|
<pre>flatpak install --user $REPO_URL/${APP_ID}.flatpakref
|
||||||
flatpak run $APP_ID</pre>
|
flatpak run $APP_ID</pre>
|
||||||
|
<p><b>Canary</b> (latest main build, unstable):</p>
|
||||||
|
<pre>flatpak install --user $REPO_URL/${APP_ID}.Canary.flatpakref</pre>
|
||||||
<p>Or add the whole remote: <code>flatpak remote-add --user --if-not-exists unom $REPO_URL/unom.flatpakrepo</code></p>
|
<p>Or add the whole remote: <code>flatpak remote-add --user --if-not-exists unom $REPO_URL/unom.flatpakrepo</code></p>
|
||||||
EOF
|
EOF
|
||||||
# 3) Ship to unom-1 and (re)start the static server. rsync WITHOUT --delete keeps old
|
# 3) Ship to unom-1 and (re)start the static server. rsync WITHOUT --delete keeps old
|
||||||
@@ -207,24 +222,16 @@ jobs:
|
|||||||
DEST="${DEPLOY_USER}@${DEPLOY_HOST}"
|
DEST="${DEPLOY_USER}@${DEPLOY_HOST}"
|
||||||
$SSH "$DEST" "mkdir -p ~/$DEPLOY_DIR/site/repo"
|
$SSH "$DEST" "mkdir -p ~/$DEPLOY_DIR/site/repo"
|
||||||
rsync -az --info=stats1 -e "$SSH" repo/ "$DEST:$DEPLOY_DIR/site/repo/"
|
rsync -az --info=stats1 -e "$SSH" repo/ "$DEST:$DEPLOY_DIR/site/repo/"
|
||||||
rsync -az -e "$SSH" site/unom.flatpakrepo "site/${APP_ID}.flatpakref" site/index.html "$DEST:$DEPLOY_DIR/site/"
|
rsync -az -e "$SSH" site/unom.flatpakrepo "site/${APP_ID}.flatpakref" "site/${APP_ID}.Canary.flatpakref" site/index.html "$DEST:$DEPLOY_DIR/site/"
|
||||||
rsync -az -e "$SSH" packaging/flatpak/server/compose.production.yml packaging/flatpak/server/Caddyfile "$DEST:$DEPLOY_DIR/"
|
rsync -az -e "$SSH" packaging/flatpak/server/compose.production.yml packaging/flatpak/server/Caddyfile "$DEST:$DEPLOY_DIR/"
|
||||||
$SSH "$DEST" "cd ~/$DEPLOY_DIR && docker compose -f compose.production.yml up -d"
|
$SSH "$DEST" "cd ~/$DEPLOY_DIR && docker compose -f compose.production.yml up -d"
|
||||||
echo "deployed → $REPO_URL/${APP_ID}.flatpakref"
|
echo "deployed → $REPO_URL/${APP_ID}.flatpakref"
|
||||||
|
|
||||||
- name: Attach bundle to the Gitea release (tags only)
|
- name: Attach bundle to the Gitea release (stable tags only)
|
||||||
if: startsWith(gitea.ref, 'refs/tags/')
|
if: startsWith(gitea.ref, 'refs/tags/v')
|
||||||
env:
|
env:
|
||||||
TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITEA_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
API="${{ gitea.server_url }}/api/v1/repos/${{ gitea.repository }}"
|
. scripts/ci/gitea-release.sh
|
||||||
ID=$(curl -sf -X POST "$API/releases" \
|
RID=$(ensure_release "$GITHUB_REF_NAME" "$GITHUB_REF_NAME" auto)
|
||||||
-H "Authorization: token $TOKEN" -H 'Content-Type: application/json' \
|
upsert_asset "$RID" "$BUNDLE"
|
||||||
-d "{\"tag_name\":\"$GITHUB_REF_NAME\",\"name\":\"$GITHUB_REF_NAME\"}" \
|
|
||||||
| python3 -c 'import json,sys;print(json.load(sys.stdin)["id"])' \
|
|
||||||
|| curl -sf "$API/releases/tags/$GITHUB_REF_NAME" -H "Authorization: token $TOKEN" \
|
|
||||||
| python3 -c 'import json,sys;print(json.load(sys.stdin)["id"])')
|
|
||||||
curl -sf -X POST "$API/releases/$ID/assets?name=$BUNDLE" \
|
|
||||||
-H "Authorization: token $TOKEN" \
|
|
||||||
-F "attachment=@$BUNDLE" >/dev/null
|
|
||||||
echo "attached $BUNDLE to release $GITHUB_REF_NAME"
|
|
||||||
|
|||||||
@@ -0,0 +1,67 @@
|
|||||||
|
# Native Linux client screenshots for the app/marketing listings. The client renders
|
||||||
|
# host-free mock scenes (PUNKTFUNK_SHOT_SCENE) under a virtual X display; the driver
|
||||||
|
# (clients/linux/tools/screenshots.sh) grabs each one — no host, GPU, or Wayland. The
|
||||||
|
# Linux analogue of apple.yml's `screenshots` job, gated to STABLE RELEASE tags only.
|
||||||
|
# Standalone + best-effort: a failure here reds nothing else. PNGs land as a 30-day
|
||||||
|
# artifact; they are not committed or published.
|
||||||
|
name: linux-client-screenshots
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags: ["v*"]
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
screenshots:
|
||||||
|
if: startsWith(github.ref, 'refs/tags/v') || github.event_name == 'workflow_dispatch'
|
||||||
|
runs-on: ubuntu-24.04
|
||||||
|
# Same image as ci.yml/deb.yml — already carries the Rust toolchain + GTK/SDL build deps.
|
||||||
|
container:
|
||||||
|
image: git.unom.io/unom/punktfunk-rust-ci:latest
|
||||||
|
timeout-minutes: 90
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
# Client link deps (baked into the image; kept here so the job is green across image
|
||||||
|
# rebuilds — a no-op once present) PLUS the headless-render extras: a virtual X server,
|
||||||
|
# software GL+Vulkan (llvmpipe/lavapipe), the icon theme + fonts the UI draws with, and a
|
||||||
|
# root-window grab tool.
|
||||||
|
- name: Client link + headless-render deps
|
||||||
|
run: |
|
||||||
|
apt-get update
|
||||||
|
apt-get install -y --no-install-recommends \
|
||||||
|
libgtk-4-dev libadwaita-1-dev libsdl3-dev \
|
||||||
|
xvfb x11-utils imagemagick scrot \
|
||||||
|
libgl1-mesa-dri mesa-vulkan-drivers \
|
||||||
|
adwaita-icon-theme fonts-cantarell fonts-dejavu-core
|
||||||
|
|
||||||
|
# Reuse the workspace cargo caches (same keys as ci.yml/deb.yml).
|
||||||
|
- name: Cache keys
|
||||||
|
run: echo "rustc=$(rustc --version | cut -d' ' -f2)" >> "$GITHUB_ENV"
|
||||||
|
- uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
/usr/local/cargo/registry
|
||||||
|
/usr/local/cargo/git
|
||||||
|
key: cargo-home-${{ hashFiles('Cargo.lock') }}
|
||||||
|
restore-keys: cargo-home-
|
||||||
|
- uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: target
|
||||||
|
key: cargo-target-v3-${{ env.rustc }}-${{ hashFiles('Cargo.lock') }}
|
||||||
|
restore-keys: cargo-target-v3-${{ env.rustc }}-
|
||||||
|
|
||||||
|
- name: Build client
|
||||||
|
run: cargo build --release -p punktfunk-client-linux --locked
|
||||||
|
|
||||||
|
- name: Capture screenshots
|
||||||
|
run: bash clients/linux/tools/screenshots.sh
|
||||||
|
|
||||||
|
- name: Upload screenshots
|
||||||
|
if: always()
|
||||||
|
# v3: Gitea's API rejects upload-artifact@v4 (see apple.yml). Download is a zip.
|
||||||
|
uses: actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: punktfunk-linux-client-screenshots
|
||||||
|
path: clients/linux/screenshots
|
||||||
|
retention-days: 30
|
||||||
@@ -46,6 +46,19 @@ name: release
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
|
# Canary: a relevant main push uploads the iOS + macOS + tvOS builds to TestFlight (Apple's
|
||||||
|
# own canary channel) — no notarized DMG (that's stable-only; see the per-step gates).
|
||||||
|
# Heavy on the shared mac-mini runner, so paths-filtered; the TestFlight steps are
|
||||||
|
# continue-on-error until the App Store Connect record exists, so this no-ops until then.
|
||||||
|
branches: [main]
|
||||||
|
paths:
|
||||||
|
- 'clients/apple/**'
|
||||||
|
- 'crates/punktfunk-core/**'
|
||||||
|
- 'scripts/build-xcframework.sh'
|
||||||
|
- 'Cargo.lock'
|
||||||
|
- '.gitea/workflows/release.yml'
|
||||||
|
# Stable: a `vX.Y.Z` tag is THE release — notarized DMG attached to the unified Gitea Release
|
||||||
|
# + macOS/iOS/tvOS to TestFlight for manual promotion to the App Store.
|
||||||
tags: ['v*']
|
tags: ['v*']
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
inputs:
|
inputs:
|
||||||
@@ -87,8 +100,8 @@ jobs:
|
|||||||
- name: Version from tag
|
- name: Version from tag
|
||||||
run: |
|
run: |
|
||||||
case "$GITHUB_REF" in
|
case "$GITHUB_REF" in
|
||||||
refs/tags/v*) V="${GITHUB_REF_NAME#v}" ;;
|
refs/tags/v*) V="${GITHUB_REF_NAME#v}"; V="${V%%-*}" ;; # App Store marketing version is numeric X.Y.Z (drop -rc)
|
||||||
*) V="0.0.${GITHUB_RUN_NUMBER}" ;;
|
*) V="0.3.0" ;; # canary marketing version; the build number disambiguates
|
||||||
esac
|
esac
|
||||||
echo "VERSION=$V" >> "$GITHUB_ENV"
|
echo "VERSION=$V" >> "$GITHUB_ENV"
|
||||||
echo "BUILD_NUM=$GITHUB_RUN_NUMBER" >> "$GITHUB_ENV"
|
echo "BUILD_NUM=$GITHUB_RUN_NUMBER" >> "$GITHUB_ENV"
|
||||||
@@ -105,7 +118,27 @@ jobs:
|
|||||||
"$RUSTUP" toolchain install nightly --profile minimal
|
"$RUSTUP" toolchain install nightly --profile minimal
|
||||||
"$RUSTUP" component add rust-src --toolchain nightly
|
"$RUSTUP" component add rust-src --toolchain nightly
|
||||||
|
|
||||||
|
# The in-core Opus decode (surround) pulls audiopus_sys, which builds a vendored static libopus
|
||||||
|
# via CMake — keep the xcframework self-contained (no runtime libopus.dylib on end-user devices).
|
||||||
|
- name: CMake (for the vendored libopus audiopus_sys builds)
|
||||||
|
run: |
|
||||||
|
# Runner steps run with `bash --noprofile --norc`, so Homebrew's bin dir isn't on PATH —
|
||||||
|
# locate brew explicitly, install cmake if missing, and export its bin dir to GITHUB_PATH so
|
||||||
|
# the xcframework build step (audiopus_sys → vendored libopus) finds `cmake`.
|
||||||
|
for B in /opt/homebrew/bin/brew /usr/local/bin/brew; do [ -x "$B" ] && BREW="$B" && break; done
|
||||||
|
if [ -z "$BREW" ]; then echo "::error::Homebrew not found on the runner"; exit 1; fi
|
||||||
|
BREW_BIN="$(dirname "$BREW")"; export PATH="$BREW_BIN:$PATH"
|
||||||
|
command -v cmake >/dev/null || "$BREW" install cmake
|
||||||
|
echo "$BREW_BIN" >> "$GITHUB_PATH"
|
||||||
|
# Homebrew's CMake 4 dropped compatibility with the vendored libopus's pre-3.5
|
||||||
|
# `cmake_minimum_required`; treat 3.5 as the policy minimum (the cmake crate's child cmake
|
||||||
|
# inherits this from the env during the xcframework build).
|
||||||
|
echo "CMAKE_POLICY_VERSION_MINIMUM=3.5" >> "$GITHUB_ENV"
|
||||||
|
|
||||||
- name: Build PunktfunkCore.xcframework (mac + iOS + tvOS)
|
- name: Build PunktfunkCore.xcframework (mac + iOS + tvOS)
|
||||||
|
# tvOS is a tier-3 target (nightly -Zbuild-std): slow on the first build, then cached on
|
||||||
|
# the self-hosted runner. Built on canary too so the tvOS archive/upload below runs on the
|
||||||
|
# same track as iOS/macOS (the nightly toolchain is installed unconditionally above).
|
||||||
run: BUILD_IOS=1 BUILD_TVOS=1 bash scripts/build-xcframework.sh
|
run: BUILD_IOS=1 BUILD_TVOS=1 bash scripts/build-xcframework.sh
|
||||||
|
|
||||||
- name: Stage App Store Connect API key
|
- name: Stage App Store Connect API key
|
||||||
@@ -116,6 +149,9 @@ jobs:
|
|||||||
chmod 600 "$RUNNER_TEMP/asc.p8"
|
chmod 600 "$RUNNER_TEMP/asc.p8"
|
||||||
|
|
||||||
- name: macOS — archive, codesign Developer ID, notarize, DMG
|
- name: macOS — archive, codesign Developer ID, notarize, DMG
|
||||||
|
# Stable releases only — the notarized DMG is a Gatekeeper/direct-download artifact, not
|
||||||
|
# relevant to TestFlight testers (the canary channel). Skipped on canary main pushes.
|
||||||
|
if: startsWith(gitea.ref, 'refs/tags/v')
|
||||||
run: |
|
run: |
|
||||||
# Archive UNSIGNED, then codesign with the Developer ID Application identity from the
|
# Archive UNSIGNED, then codesign with the Developer ID Application identity from the
|
||||||
# login keychain. Unsigned archive sidesteps Xcode's keychain-access-groups
|
# login keychain. Unsigned archive sidesteps Xcode's keychain-access-groups
|
||||||
@@ -154,23 +190,14 @@ jobs:
|
|||||||
DEVELOPER_DIR="$XCODE_DEV_DIR" xcrun stapler staple "$DMG"
|
DEVELOPER_DIR="$XCODE_DEV_DIR" xcrun stapler staple "$DMG"
|
||||||
echo "DMG=$DMG" >> "$GITHUB_ENV"
|
echo "DMG=$DMG" >> "$GITHUB_ENV"
|
||||||
|
|
||||||
- name: Attach DMG to Gitea release
|
- name: Attach DMG to the Gitea release (stable tags only)
|
||||||
if: startsWith(gitea.ref, 'refs/tags/')
|
if: startsWith(gitea.ref, 'refs/tags/v')
|
||||||
env:
|
env:
|
||||||
TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITEA_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
API="${{ gitea.server_url }}/api/v1/repos/${{ gitea.repository }}"
|
. scripts/ci/gitea-release.sh
|
||||||
# Create the release (409 -> already exists, fetch it instead).
|
RID=$(ensure_release "$GITHUB_REF_NAME" "$GITHUB_REF_NAME" auto)
|
||||||
ID=$(curl -sf -X POST "$API/releases" \
|
upsert_asset "$RID" "$DMG" "Punktfunk-$VERSION.dmg"
|
||||||
-H "Authorization: token $TOKEN" -H 'Content-Type: application/json' \
|
|
||||||
-d "{\"tag_name\":\"$GITHUB_REF_NAME\",\"name\":\"$GITHUB_REF_NAME\"}" \
|
|
||||||
| python3 -c 'import json,sys;print(json.load(sys.stdin)["id"])' \
|
|
||||||
|| curl -sf "$API/releases/tags/$GITHUB_REF_NAME" -H "Authorization: token $TOKEN" \
|
|
||||||
| python3 -c 'import json,sys;print(json.load(sys.stdin)["id"])')
|
|
||||||
curl -sf -X POST "$API/releases/$ID/assets?name=Punktfunk-$VERSION.dmg" \
|
|
||||||
-H "Authorization: token $TOKEN" \
|
|
||||||
-F "attachment=@$DMG" >/dev/null
|
|
||||||
echo "attached Punktfunk-$VERSION.dmg to release $GITHUB_REF_NAME"
|
|
||||||
|
|
||||||
- name: macOS App Store — archive + upload to TestFlight
|
- name: macOS App Store — archive + upload to TestFlight
|
||||||
if: gitea.event_name != 'workflow_dispatch' || inputs.testflight == 'true'
|
if: gitea.event_name != 'workflow_dispatch' || inputs.testflight == 'true'
|
||||||
@@ -278,6 +305,8 @@ jobs:
|
|||||||
-authenticationKeyIssuerID "${{ secrets.ASC_API_ISSUER_ID }}"
|
-authenticationKeyIssuerID "${{ secrets.ASC_API_ISSUER_ID }}"
|
||||||
|
|
||||||
- name: tvOS — archive + upload to TestFlight
|
- name: tvOS — archive + upload to TestFlight
|
||||||
|
# Canary + stable, the same track as iOS/macOS — the tvOS xcframework slice is now built
|
||||||
|
# on every apple push (above), so this matches the iOS step's gate exactly.
|
||||||
if: gitea.event_name != 'workflow_dispatch' || inputs.testflight == 'true'
|
if: gitea.event_name != 'workflow_dispatch' || inputs.testflight == 'true'
|
||||||
# Needs tvOS added to the App Store Connect app record + the tvOS platform installed
|
# Needs tvOS added to the App Store Connect app record + the tvOS platform installed
|
||||||
# on the runner (xcodebuild -downloadPlatform tvOS).
|
# on the runner (xcodebuild -downloadPlatform tvOS).
|
||||||
|
|||||||
+32
-13
@@ -13,9 +13,10 @@ name: rpm
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [main]
|
branches: [main]
|
||||||
# HOST-scoped tags only — the Apple client's `v*` tags (release.yml) must NOT publish a host
|
# Single project version: a `vX.Y.Z` tag is THE release. main publishes to the `*-canary` rpm
|
||||||
# RPM (a `v0.1.1` client tag previously shipped a host 0.1.1 that shadowed every rolling build).
|
# groups, tags to the base groups (`bazzite`/`fedora-44`) — separate repos, so the old
|
||||||
tags: ['host-v*']
|
# version-shadow (a release outranking rolling builds in one group) is structurally gone.
|
||||||
|
tags: ['v*']
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
env:
|
env:
|
||||||
@@ -66,20 +67,22 @@ jobs:
|
|||||||
key: cargo-home-${{ hashFiles('Cargo.lock') }}
|
key: cargo-home-${{ hashFiles('Cargo.lock') }}
|
||||||
restore-keys: cargo-home-
|
restore-keys: cargo-home-
|
||||||
|
|
||||||
- name: Version
|
- name: Version + channel
|
||||||
# host-vX.Y.Z tag -> X.Y.Z-1 (a real host release); main push -> 0.2.0-0.ciN.g<sha>, whose
|
# vX.Y.Z tag -> X.Y.Z-1 in the base group (a real release); main push -> 0.3.0-0.ciN.g<sha>
|
||||||
# "0." release sorts BELOW the eventual 0.2.0-1 yet climbs by run number AND outranks the
|
# in the `<base>-canary` group, whose "0." release sorts below the eventual 0.3.0-1 yet
|
||||||
# stray 0.1.1, so `rpm-ostree upgrade` truly moves to the newest build. The spec %build
|
# climbs by run number. The canary base stays one minor ahead of the latest stable so a
|
||||||
# stamps PUNKTFUNK_BUILD_VERSION from these macros into the binary (--version provenance).
|
# stable->canary box re-point still moves forward. The spec %build stamps
|
||||||
|
# PUNKTFUNK_BUILD_VERSION from these macros into the binary (--version provenance).
|
||||||
run: |
|
run: |
|
||||||
SHORT=$(echo "$GITHUB_SHA" | cut -c1-8)
|
SHORT=$(echo "$GITHUB_SHA" | cut -c1-8)
|
||||||
case "$GITHUB_REF" in
|
case "$GITHUB_REF" in
|
||||||
refs/tags/host-v*) V="${GITHUB_REF_NAME#host-v}"; R="1" ;;
|
refs/tags/v*) V="${GITHUB_REF_NAME#v}"; R="1"; GROUP="${{ matrix.group }}" ;;
|
||||||
*) V="0.2.0"; R="0.ci${GITHUB_RUN_NUMBER}.g${SHORT}" ;;
|
*) V="0.3.0"; R="0.ci${GITHUB_RUN_NUMBER}.g${SHORT}"; GROUP="${{ matrix.group }}-canary" ;;
|
||||||
esac
|
esac
|
||||||
echo "PF_VERSION=$V" >> "$GITHUB_ENV"
|
echo "PF_VERSION=$V" >> "$GITHUB_ENV"
|
||||||
echo "PF_RELEASE=$R" >> "$GITHUB_ENV"
|
echo "PF_RELEASE=$R" >> "$GITHUB_ENV"
|
||||||
echo "rpm $V-$R"
|
echo "GROUP=$GROUP" >> "$GITHUB_ENV"
|
||||||
|
echo "rpm $V-$R -> group '$GROUP'"
|
||||||
|
|
||||||
- name: Build RPM
|
- name: Build RPM
|
||||||
# PF_WITH_WEB=1 → also build the noarch punktfunk-web subpackage (the publish loop below
|
# PF_WITH_WEB=1 → also build the noarch punktfunk-web subpackage (the publish loop below
|
||||||
@@ -101,6 +104,22 @@ jobs:
|
|||||||
case "$rpm" in *debuginfo*|*debugsource*) echo "skip $rpm"; continue;; esac
|
case "$rpm" in *debuginfo*|*debugsource*) echo "skip $rpm"; continue;; esac
|
||||||
echo "uploading $rpm"
|
echo "uploading $rpm"
|
||||||
curl -fsS --user "enricobuehler:$TOKEN" --upload-file "$rpm" \
|
curl -fsS --user "enricobuehler:$TOKEN" --upload-file "$rpm" \
|
||||||
"https://$REGISTRY/api/packages/$OWNER/rpm/${{ matrix.group }}/upload"
|
"https://$REGISTRY/api/packages/$OWNER/rpm/$GROUP/upload"
|
||||||
|
done
|
||||||
|
echo "published to $OWNER/rpm/$GROUP"
|
||||||
|
|
||||||
|
# On a real release, also attach the .rpms to the unified Gitea Release. Both Fedora bases
|
||||||
|
# (bazzite=F43, fedora-44) build the SAME filename, so suffix the asset with the base to keep
|
||||||
|
# both on the release; canary builds live in the `*-canary` rpm groups (no release page).
|
||||||
|
- name: Attach .rpms to the Gitea release (stable tags only)
|
||||||
|
if: startsWith(gitea.ref, 'refs/tags/v')
|
||||||
|
env:
|
||||||
|
GITEA_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
|
||||||
|
run: |
|
||||||
|
. scripts/ci/gitea-release.sh
|
||||||
|
RID=$(ensure_release "$GITHUB_REF_NAME" "$GITHUB_REF_NAME" auto)
|
||||||
|
for rpm in dist/*.rpm; do
|
||||||
|
case "$rpm" in *debuginfo*|*debugsource*) continue;; esac
|
||||||
|
base="$(basename "$rpm" .rpm)"
|
||||||
|
upsert_asset "$RID" "$rpm" "${base}.${{ matrix.group }}.rpm"
|
||||||
done
|
done
|
||||||
echo "published to $OWNER/rpm/${{ matrix.group }}"
|
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
# Management-console screenshots for the app/marketing listings. Captured from the
|
||||||
|
# built Storybook with headless Chromium (web/tools/screenshots.mjs) — the page
|
||||||
|
# stories render from fixtures, so no live mgmt API, login, or GPU is needed. This
|
||||||
|
# is the web analogue of apple.yml's `screenshots` job, but gated to STABLE RELEASE
|
||||||
|
# tags only (the console has no release workflow of its own — it ships inside the
|
||||||
|
# host packaging). Best-effort: a standalone workflow, so a failure here reds
|
||||||
|
# nothing else. PNGs land as a 30-day artifact; they are not committed or published.
|
||||||
|
name: web-screenshots
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags: ["v*"]
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
screenshots:
|
||||||
|
if: startsWith(github.ref, 'refs/tags/v') || github.event_name == 'workflow_dispatch'
|
||||||
|
runs-on: ubuntu-24.04
|
||||||
|
container:
|
||||||
|
image: oven/bun:1
|
||||||
|
timeout-minutes: 30
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
working-directory: web
|
||||||
|
steps:
|
||||||
|
# oven/bun ships neither git nor a real node (the driver runs under node), and
|
||||||
|
# the slim Debian base lacks a CA bundle — without it actions/checkout's HTTPS
|
||||||
|
# fetch dies with "Problem with the SSL CA cert" (same as ci.yml's web job).
|
||||||
|
- name: Install git + node + CA certs
|
||||||
|
working-directory: /
|
||||||
|
run: apt-get update && apt-get install -y --no-install-recommends ca-certificates git nodejs
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
# --ignore-scripts skips the prepare→codegen hook (mirrors ci.yml); run codegen
|
||||||
|
# explicitly since build-storybook has no prebuild hook of its own.
|
||||||
|
- name: Install dependencies
|
||||||
|
run: bun install --frozen-lockfile --ignore-scripts
|
||||||
|
- name: Generate API client + i18n messages
|
||||||
|
run: bun run codegen
|
||||||
|
# Pulls the matching Chromium build + the apt libs it needs (root in-container).
|
||||||
|
- name: Install Chromium
|
||||||
|
run: bunx playwright install --with-deps chromium
|
||||||
|
- name: Build Storybook
|
||||||
|
run: bun run build-storybook
|
||||||
|
- name: Capture screenshots
|
||||||
|
run: bun run screenshots
|
||||||
|
- name: Upload screenshots
|
||||||
|
if: always()
|
||||||
|
# v3: Gitea's API rejects upload-artifact@v4 (see apple.yml). Download is a zip.
|
||||||
|
uses: actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: punktfunk-web-console-screenshots
|
||||||
|
path: web/screenshots
|
||||||
|
retention-days: 30
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
# One-shot provisioning of the WDK + cargo-wdk onto the persistent self-hosted windows-amd64 runner, so
|
||||||
|
# the all-Rust UMDF drivers can build there (design/windows-host-rewrite.md, M0). The runner has the base
|
||||||
|
# Windows SDK + MSVC + LLVM + Rust but NOT the WDK (no km/wdf/iddcx headers) or cargo-wdk.
|
||||||
|
#
|
||||||
|
# Dispatch manually (workflow_dispatch). Idempotent: re-running is a near no-op once provisioned. The
|
||||||
|
# install persists on the runner (real box, not an ephemeral container), so this runs once, not per build.
|
||||||
|
name: windows-drivers-provision
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
paths:
|
||||||
|
- 'scripts/ci/provision-windows-wdk.ps1'
|
||||||
|
- '.gitea/workflows/windows-drivers-provision.yml'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
provision:
|
||||||
|
runs-on: windows-amd64
|
||||||
|
timeout-minutes: 60
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
shell: pwsh
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- name: Install WDK + cargo-wdk on the runner
|
||||||
|
run: ./scripts/ci/provision-windows-wdk.ps1
|
||||||
@@ -0,0 +1,150 @@
|
|||||||
|
# Windows driver workspace CI — runs on the self-hosted Windows runner (home-windows-1, host mode;
|
||||||
|
# label windows-amd64). Part of the Windows-host rewrite (design/windows-host-rewrite.md, M0).
|
||||||
|
#
|
||||||
|
# Stage 1 (this file): PROBE the runner's driver toolchain (WDK / EWDK / cargo-make / LLVM / the
|
||||||
|
# inf2cat/stampinf/devgen/signtool tools) so we know what's provisioned BEFORE writing driver code,
|
||||||
|
# and build+test the owned ABI crate (pf-driver-proto) on MSVC to prove it compiles cross-OS and the
|
||||||
|
# CI wiring works. The runner has no RTX GPU — that's fine: builds, the IddCx bindgen/link, the
|
||||||
|
# /INTEGRITYCHECK self-sign-load, and (later) IDD-push frame flow on the basic display do not need one;
|
||||||
|
# only live NVENC encode does, which defers to the RTX box.
|
||||||
|
#
|
||||||
|
# shell: pwsh deliberately (PowerShell 5.1's Out-File -Encoding utf8 prepends a BOM that corrupts the
|
||||||
|
# first GITHUB_ENV line — see windows.yml).
|
||||||
|
name: windows-drivers
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
paths:
|
||||||
|
- '.gitea/workflows/windows-drivers.yml'
|
||||||
|
- 'crates/pf-driver-proto/**'
|
||||||
|
- 'packaging/windows/drivers/**'
|
||||||
|
pull_request:
|
||||||
|
paths:
|
||||||
|
- '.gitea/workflows/windows-drivers.yml'
|
||||||
|
- 'crates/pf-driver-proto/**'
|
||||||
|
- 'packaging/windows/drivers/**'
|
||||||
|
|
||||||
|
# Driver builds need the WDK on the runner (provision once via windows-drivers-provision.yml).
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
probe-and-proto:
|
||||||
|
runs-on: windows-amd64
|
||||||
|
timeout-minutes: 30
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
shell: pwsh
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Probe driver toolchain (informational — never fails the job)
|
||||||
|
continue-on-error: true
|
||||||
|
run: |
|
||||||
|
$ErrorActionPreference = 'Continue'
|
||||||
|
function head($t) { Write-Host ""; Write-Host "===== $t =====" }
|
||||||
|
|
||||||
|
head "Windows Kits roots"
|
||||||
|
$kits = @('C:\Program Files (x86)\Windows Kits\10', 'C:\Program Files\Windows Kits\10')
|
||||||
|
foreach ($k in $kits) { if (Test-Path $k) { Write-Host "found: $k" } }
|
||||||
|
|
||||||
|
head "SDK Include versions (um vs km — km => WDK present)"
|
||||||
|
foreach ($k in $kits) {
|
||||||
|
$inc = Join-Path $k 'Include'
|
||||||
|
if (Test-Path $inc) {
|
||||||
|
Get-ChildItem $inc -Directory | ForEach-Object {
|
||||||
|
$hasUm = Test-Path (Join-Path $_.FullName 'um')
|
||||||
|
$hasKm = Test-Path (Join-Path $_.FullName 'km')
|
||||||
|
$wdf = Test-Path (Join-Path $_.FullName 'km\wdf\umdf\2.31')
|
||||||
|
$iddcx = (Get-ChildItem (Join-Path $_.FullName 'um\iddcx') -Directory -ErrorAction SilentlyContinue | ForEach-Object { $_.Name }) -join ','
|
||||||
|
Write-Host ("{0,-16} um={1,-5} km={2,-5} wdf2.31={3,-5} iddcx=[{4}]" -f $_.Name, $hasUm, $hasKm, $wdf, $iddcx)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
head "Driver tooling (inf2cat / stampinf / signtool / devgen / InfVerif)"
|
||||||
|
foreach ($tool in 'inf2cat.exe','stampinf.exe','signtool.exe','devgen.exe','InfVerif.exe','makecat.exe') {
|
||||||
|
$hits = @()
|
||||||
|
foreach ($k in $kits) {
|
||||||
|
$hits += Get-ChildItem -Path $k -Filter $tool -Recurse -ErrorAction SilentlyContinue |
|
||||||
|
Where-Object { $_.FullName -match '\\x64\\' } | Select-Object -First 1 -ExpandProperty FullName
|
||||||
|
}
|
||||||
|
$hits = $hits | Where-Object { $_ } | Select-Object -First 1
|
||||||
|
Write-Host ("{0,-14} -> {1}" -f $tool, ($(if ($hits) { $hits } else { 'NOT FOUND' })))
|
||||||
|
}
|
||||||
|
|
||||||
|
head "EWDK"
|
||||||
|
Write-Host ("EWDKROOT = " + ($env:EWDKROOT ?? '<unset>'))
|
||||||
|
|
||||||
|
head "LLVM / clang (bindgen 0.72 builds on the runner default clang)"
|
||||||
|
Write-Host ("LIBCLANG_PATH = " + ($env:LIBCLANG_PATH ?? '<unset>'))
|
||||||
|
$clang = Get-Command clang -ErrorAction SilentlyContinue
|
||||||
|
if ($clang) { & clang --version } else { Write-Host "clang: NOT on PATH" }
|
||||||
|
|
||||||
|
head "cargo-make (the gamepad drivers' build driver)"
|
||||||
|
$cm = & cargo make --version 2>&1; Write-Host $cm
|
||||||
|
|
||||||
|
head "Rust + targets"
|
||||||
|
& rustc -V; & cargo -V
|
||||||
|
Write-Host "installed targets:"; & rustup target list --installed
|
||||||
|
|
||||||
|
head "Env knobs the WDK build cares about"
|
||||||
|
Write-Host ("Version_Number = " + ($env:Version_Number ?? '<unset>'))
|
||||||
|
Write-Host ("CARGO_HOME = " + ($env:CARGO_HOME ?? '<unset>'))
|
||||||
|
Write-Host ("CARGO_TARGET_DIR (daemon) = " + ($env:CARGO_TARGET_DIR ?? '<unset>'))
|
||||||
|
|
||||||
|
- name: Build + test pf-driver-proto (MSVC)
|
||||||
|
run: |
|
||||||
|
# Short target dir to dodge MAX_PATH inside the deep act host workdir (see windows.yml).
|
||||||
|
$env:CARGO_TARGET_DIR = "C:\t\drv"
|
||||||
|
cargo build -p pf-driver-proto
|
||||||
|
cargo test -p pf-driver-proto
|
||||||
|
cargo clippy -p pf-driver-proto --all-targets -- -D warnings
|
||||||
|
cargo fmt -p pf-driver-proto -- --check
|
||||||
|
|
||||||
|
# Build the UMDF driver workspace (wdk-probe) on windows-drivers-rs: proves wdk-sys bindgen/link works
|
||||||
|
# on the runner's WDK + LLVM, that pf-driver-proto path-deps into a driver, and exposes the produced
|
||||||
|
# DLL's FORCE_INTEGRITY (/INTEGRITYCHECK) bit — the M0 self-signed-load question.
|
||||||
|
driver-build:
|
||||||
|
runs-on: windows-amd64
|
||||||
|
timeout-minutes: 45
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
shell: pwsh
|
||||||
|
# In-tree target dir on purpose: wdk-build's find_top_level_cargo_manifest() walks UP from OUT_DIR
|
||||||
|
# to the first ancestor with a Cargo.lock, so a relocated CARGO_TARGET_DIR (C:\t\…) hides the
|
||||||
|
# workspace lock and it panics. The driver deps have no deep CMake-from-source crates, so the
|
||||||
|
# default in-tree target stays well under MAX_PATH (unlike the SDL3/audiopus client build).
|
||||||
|
working-directory: packaging/windows/drivers
|
||||||
|
env:
|
||||||
|
# wdk-build otherwise picks 10.0.28000.0 (no km/crt) and bindgen fails — pin the WDK SDK version.
|
||||||
|
Version_Number: '10.0.26100.0'
|
||||||
|
# No LIBCLANG_PATH pin: the vendored bindgen 0.72 builds clean on the runner's default clang 22
|
||||||
|
# (the shipping pack proves it). A 0.71-era layout-test overflow once needed LLVM 21; the 0.72 bump
|
||||||
|
# retired that — see design/windows-build-and-packaging.md.
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- name: Ensure WDK + cargo-wdk (idempotent self-provision)
|
||||||
|
# Run the provisioning script here too so driver-build is self-sufficient and never races a
|
||||||
|
# separate provision run on the single runner. Path is relative to the job working-directory
|
||||||
|
# (packaging/windows/drivers). Near-noop once the toolchain is present.
|
||||||
|
run: ../../../scripts/ci/provision-windows-wdk.ps1
|
||||||
|
- name: cargo build the driver workspace (wdk-probe + wdk-iddcx + pf-vdisplay)
|
||||||
|
# Whole workspace: wdk-probe (toolchain/surface-assert probe) + wdk-iddcx (DDI wrappers) +
|
||||||
|
# pf-vdisplay (the real IddCx driver). pf-vdisplay linking proves the IddCx call sites resolve
|
||||||
|
# against IddCxStub end-to-end (M1 step 2 gate).
|
||||||
|
run: cargo build -v
|
||||||
|
- name: Inspect /INTEGRITYCHECK (before) — expect FORCE_INTEGRITY set by wdk-build
|
||||||
|
run: |
|
||||||
|
# explicit --target (.cargo/config.toml) -> output under the triple subdir.
|
||||||
|
$dll = "target\x86_64-pc-windows-msvc\debug\pf_vdisplay.dll"
|
||||||
|
if (-not (Test-Path $dll)) { throw "pf_vdisplay.dll not produced at $dll" }
|
||||||
|
$b = [IO.File]::ReadAllBytes($dll)
|
||||||
|
$pe = [BitConverter]::ToInt32($b, 0x3c)
|
||||||
|
$dllchar = [BitConverter]::ToUInt16($b, $pe + 0x5e) # OptionalHeader.DllCharacteristics
|
||||||
|
Write-Host ("pf_vdisplay.dll built OK ({0:N0} bytes)" -f (Get-Item $dll).Length)
|
||||||
|
Write-Host ("BEFORE: DllCharacteristics = 0x{0:X4}; FORCE_INTEGRITY = {1}" -f $dllchar, (($dllchar -band 0x0080) -ne 0))
|
||||||
|
- name: Clear FORCE_INTEGRITY (self-signed-load fix) + verify
|
||||||
|
# wdk-build sets /INTEGRITYCHECK unconditionally -> a self-signed driver won't load. Clear the PE
|
||||||
|
# bit deterministically (the reusable packaging step; signing/.cat happen later for real drivers).
|
||||||
|
run: ../clear-force-integrity.ps1 -Path target\x86_64-pc-windows-msvc\debug\pf_vdisplay.dll
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
# Build the punktfunk Windows HOST as a signed Inno Setup installer and publish it to Gitea's generic
|
# Build the punktfunk Windows HOST as a signed Inno Setup installer and publish it to Gitea's generic
|
||||||
# package registry, so a Windows GPU box can install the streaming host (SYSTEM service + bundled
|
# package registry, so a Windows GPU box can install the streaming host (SYSTEM service + bundled
|
||||||
# SudoVDA virtual-display driver) from one signed setup.exe. Runs on the self-hosted Windows runner
|
# pf-vdisplay virtual-display driver + the web management console, run by a scheduled task on a bundled
|
||||||
|
# bun) from one signed setup.exe. Runs on the self-hosted Windows runner
|
||||||
# (host mode; scripts/ci/setup-windows-runner.ps1) — same MSVC/Windows-SDK/LLVM env as windows.yml.
|
# (host mode; scripts/ci/setup-windows-runner.ps1) — same MSVC/Windows-SDK/LLVM env as windows.yml.
|
||||||
#
|
#
|
||||||
# Why an installer and not MSIX (like the client): the host installs a LocalSystem SCM service that
|
# Why an installer and not MSIX (like the client): the host installs a LocalSystem SCM service that
|
||||||
@@ -11,18 +12,22 @@
|
|||||||
#
|
#
|
||||||
# Registry (public reads, unom org): https://git.unom.io/unom/-/packages (generic group)
|
# Registry (public reads, unom org): https://git.unom.io/unom/-/packages (generic group)
|
||||||
#
|
#
|
||||||
# Versioning (free-form; not MSIX's 4-part rule):
|
# Versioning (free-form; not MSIX's 4-part rule) — single project version:
|
||||||
# host-win-vX.Y.Z tag -> X.Y.Z (a real host release; own tag namespace, off host-v*/win-v*/v*
|
# vX.Y.Z tag -> X.Y.Z (THE release; published + stable `latest/` alias + attached to the
|
||||||
# to avoid the version-shadow bug class — see deb.yml).
|
# unified Gitea Release).
|
||||||
# main push / dispatch -> 0.2.<run_number> (rolling; climbs monotonically by run number).
|
# main push / dispatch -> 0.3.<run_number> (canary; `canary/` alias; climbs by run number).
|
||||||
#
|
#
|
||||||
# Signing reuses the client's MSIX_CERT_PFX_B64 / MSIX_CERT_PASSWORD secrets (CN=unom). Without them
|
# Signing reuses the client's MSIX_CERT_PFX_B64 / MSIX_CERT_PASSWORD secrets (CN=unom). Without them
|
||||||
# an ephemeral self-signed cert is generated and its public .cer published next to the installer
|
# an ephemeral self-signed cert is generated and its public .cer published next to the installer
|
||||||
# (import once to LocalMachine\TrustedPublisher). See packaging/windows/pack-host-installer.ps1.
|
# (import once to LocalMachine\TrustedPublisher). See packaging/windows/pack-host-installer.ps1.
|
||||||
#
|
#
|
||||||
# NVENC: the host builds with --features nvenc; the only link need is nvencodeapi.lib, synthesised
|
# GPU backends: the host builds with --features nvenc,amf-qsv = all three vendors in one installer.
|
||||||
# from a 2-export .def with llvm-dlltool (no GPU/SDK at build time). The resulting exe is NVIDIA-only
|
# - NVENC (NVIDIA, direct SDK): the only link need is nvencodeapi.lib, synthesised from a 2-export
|
||||||
# by design — CI never launches it, so no GPU is needed here.
|
# .def with llvm-dlltool (no GPU/SDK at build time).
|
||||||
|
# - AMF/QSV (AMD/Intel, libavcodec): link-imports the FFmpeg libs from FFMPEG_DIR (the BtbN lgpl-shared
|
||||||
|
# tree the client uses; includes the *_amf/*_qsv encoders) and bundles its DLLs into the installer.
|
||||||
|
# lgpl-shared (not gpl-shared) keeps those bundled DLLs LGPL (we never use the GPL-only x264/x265).
|
||||||
|
# CI never launches the exe, so no GPU is needed here — this is build + Windows clippy coverage only.
|
||||||
name: windows-host
|
name: windows-host
|
||||||
|
|
||||||
on:
|
on:
|
||||||
@@ -32,11 +37,12 @@ on:
|
|||||||
- 'crates/punktfunk-host/**'
|
- 'crates/punktfunk-host/**'
|
||||||
- 'crates/punktfunk-core/**'
|
- 'crates/punktfunk-core/**'
|
||||||
- 'packaging/windows/**'
|
- 'packaging/windows/**'
|
||||||
- 'scripts/windows/host.env.example'
|
- 'scripts/windows/**'
|
||||||
|
- 'web/**'
|
||||||
- 'Cargo.lock'
|
- 'Cargo.lock'
|
||||||
- 'Cargo.toml'
|
- 'Cargo.toml'
|
||||||
- '.gitea/workflows/windows-host.yml'
|
- '.gitea/workflows/windows-host.yml'
|
||||||
tags: ['host-win-v*']
|
tags: ['v*']
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
env:
|
env:
|
||||||
@@ -51,6 +57,22 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Locale-safety gate (installer-run scripts must be ASCII)
|
||||||
|
shell: pwsh
|
||||||
|
# The installer runs these via powershell.exe (Windows PowerShell 5.1) and cmd.exe on the END
|
||||||
|
# USER's box. PS 5.1 reads a BOM-less script in the active ANSI codepage, so on a non-UTF-8 locale
|
||||||
|
# (e.g. German Windows-1252) a stray em-dash mis-decodes into a curly quote and the script aborts
|
||||||
|
# with "unterminated string" - exactly how the pf-vdisplay driver install silently failed in the
|
||||||
|
# field. Keep every installer-run script pure ASCII (matches install-gamepad-drivers.ps1).
|
||||||
|
run: |
|
||||||
|
$bad = Get-ChildItem packaging/windows/*.ps1, scripts/windows/*.ps1, scripts/windows/*.cmd -ErrorAction SilentlyContinue |
|
||||||
|
Where-Object { [IO.File]::ReadAllText($_.FullName) -match '[^\x00-\x7F]' }
|
||||||
|
if ($bad) {
|
||||||
|
$bad.FullName | ForEach-Object { Write-Output "::error::non-ASCII in installer-run script: $_" }
|
||||||
|
throw "installer-run scripts must be pure ASCII (PS 5.1 mis-parses them on non-UTF-8 locales)"
|
||||||
|
}
|
||||||
|
Write-Output "installer-run scripts are ASCII-clean"
|
||||||
|
|
||||||
- name: Configure + version
|
- name: Configure + version
|
||||||
shell: pwsh
|
shell: pwsh
|
||||||
run: |
|
run: |
|
||||||
@@ -59,10 +81,17 @@ jobs:
|
|||||||
# (pwsh Out-File utf8 = no BOM, unlike Windows PowerShell 5.1 — keeps the first line clean).
|
# (pwsh Out-File utf8 = no BOM, unlike Windows PowerShell 5.1 — keeps the first line clean).
|
||||||
"CARGO_TARGET_DIR=C:\t" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
|
"CARGO_TARGET_DIR=C:\t" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
|
||||||
"CARGO_WORKSPACE_DIR=$env:GITHUB_WORKSPACE" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
|
"CARGO_WORKSPACE_DIR=$env:GITHUB_WORKSPACE" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
|
||||||
$v = if ($env:GITHUB_REF -like 'refs/tags/host-win-v*') {
|
# FFMPEG_DIR: the same BtbN lgpl-shared x64 tree the Windows CLIENT links against (provisioned
|
||||||
$env:GITHUB_REF_NAME -replace '^host-win-v', ''
|
# by scripts/ci/setup-windows-runner.ps1). The host's AMD/Intel AMF/QSV encode backend
|
||||||
|
# (--features amf-qsv) link-imports avcodec/avutil/swscale from it; pack-host-installer.ps1
|
||||||
|
# then bundles its bin\*.dll into the installer. LIBCLANG_PATH is in the runner daemon env.
|
||||||
|
if (-not $env:FFMPEG_DIR) {
|
||||||
|
"FFMPEG_DIR=C:\Users\Public\ffmpeg" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
|
||||||
|
}
|
||||||
|
$v = if ($env:GITHUB_REF -like 'refs/tags/v*') {
|
||||||
|
$env:GITHUB_REF_NAME -replace '^v', ''
|
||||||
} else {
|
} else {
|
||||||
"0.2.$($env:GITHUB_RUN_NUMBER)"
|
"0.3.$($env:GITHUB_RUN_NUMBER)"
|
||||||
}
|
}
|
||||||
"HOST_VERSION=$v" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
|
"HOST_VERSION=$v" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
|
||||||
"PUNKTFUNK_BUILD_VERSION=$v" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
|
"PUNKTFUNK_BUILD_VERSION=$v" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
|
||||||
@@ -74,14 +103,27 @@ jobs:
|
|||||||
& packaging/windows/nvenc/gen-nvenc-importlib.ps1 -OutDir C:\t\nvenc
|
& packaging/windows/nvenc/gen-nvenc-importlib.ps1 -OutDir C:\t\nvenc
|
||||||
"PUNKTFUNK_NVENC_LIB_DIR=C:\t\nvenc" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
|
"PUNKTFUNK_NVENC_LIB_DIR=C:\t\nvenc" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
|
||||||
|
|
||||||
- name: Build (release, nvenc)
|
- name: Build (release, nvenc + amf-qsv)
|
||||||
shell: pwsh
|
shell: pwsh
|
||||||
run: cargo build --release -p punktfunk-host --features nvenc
|
# All-vendor host: NVENC (NVIDIA, direct SDK) + AMF/QSV (AMD/Intel, libavcodec via FFMPEG_DIR).
|
||||||
|
run: cargo build --release -p punktfunk-host --features nvenc,amf-qsv
|
||||||
|
|
||||||
- name: Clippy (host, Windows)
|
- name: Clippy (host, Windows)
|
||||||
shell: pwsh
|
shell: pwsh
|
||||||
# First-ever Windows lint coverage for the host (Linux CI never lints the windows-cfg code).
|
# First-ever Windows lint coverage for the host (Linux CI never lints the windows-cfg code).
|
||||||
run: cargo clippy -p punktfunk-host --features nvenc -- -D warnings
|
run: cargo clippy -p punktfunk-host --features nvenc,amf-qsv -- -D warnings
|
||||||
|
|
||||||
|
- name: Build + lint the HDR Vulkan layer (pf-vkhdr-layer)
|
||||||
|
shell: pwsh
|
||||||
|
# Standalone cdylib (own [workspace]) the installer bundles + registers (it lets Vulkan games
|
||||||
|
# like Doom use HDR on the virtual display). Lint here so a regression fails CI instead of
|
||||||
|
# silently shipping the host without the layer (pack-host-installer.ps1 builds it non-fatally).
|
||||||
|
# Windows-only FFI (user32 + the vk_layer loader glue) → can't be linted on the Linux CI.
|
||||||
|
run: |
|
||||||
|
Push-Location packaging/windows/pf-vkhdr-layer
|
||||||
|
cargo fmt --check; if ($LASTEXITCODE) { throw "pf-vkhdr-layer rustfmt" }
|
||||||
|
cargo clippy --release -- -D warnings; if ($LASTEXITCODE) { throw "pf-vkhdr-layer clippy" }
|
||||||
|
Pop-Location
|
||||||
|
|
||||||
- name: Ensure Inno Setup
|
- name: Ensure Inno Setup
|
||||||
shell: pwsh
|
shell: pwsh
|
||||||
@@ -91,6 +133,59 @@ jobs:
|
|||||||
choco install innosetup -y --no-progress
|
choco install innosetup -y --no-progress
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- name: Fetch portable bun runtime (build tool + bundled to run the console)
|
||||||
|
shell: pwsh
|
||||||
|
run: |
|
||||||
|
# ONE pinned bun, used both to BUILD the console and shipped in the installer to RUN it. The
|
||||||
|
# .output is self-contained (Nitro noExternals — deps bundled + tree-shaken, no node_modules),
|
||||||
|
# so the installer ships just bun + a ~75-file .output instead of node + a node_modules forest.
|
||||||
|
$ver = 'bun-v1.3.14'
|
||||||
|
$url = "https://github.com/oven-sh/bun/releases/download/$ver/bun-windows-x64.zip"
|
||||||
|
New-Item -ItemType Directory -Force -Path C:\t | Out-Null
|
||||||
|
$zip = 'C:\t\bun.zip'; $dst = 'C:\t\bundist'
|
||||||
|
Invoke-WebRequest -Uri $url -OutFile $zip
|
||||||
|
if (Test-Path $dst) { Remove-Item $dst -Recurse -Force }
|
||||||
|
Expand-Archive -Path $zip -DestinationPath $dst -Force
|
||||||
|
$bun = (Get-ChildItem -Path $dst -Recurse -Filter bun.exe | Select-Object -First 1).FullName
|
||||||
|
if (-not $bun) { throw "bun.exe not found in $url" }
|
||||||
|
"BUN_EXE=$bun" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
|
||||||
|
& $bun --version
|
||||||
|
|
||||||
|
- name: Build + smoke-boot web console (bun)
|
||||||
|
shell: pwsh
|
||||||
|
env:
|
||||||
|
# PAT with read access to the unom org packages — the @unom npm registry needs auth to BUILD.
|
||||||
|
REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
|
||||||
|
# The bun fetched above builds the Nitro server AND runs it. noExternals (vite.config) makes the
|
||||||
|
# output self-contained, so there's no .output/server install — the installer ships bun + the
|
||||||
|
# ~75-file .output. The runner is SYSTEM with no ~/.npmrc, so supply the private @unom token in
|
||||||
|
# the SYSTEM home .npmrc to BUILD (kept OUT of the shipped bundle — web\.npmrc has only the
|
||||||
|
# registry mapping, and nothing copies it into .output).
|
||||||
|
run: |
|
||||||
|
$bun = $env:BUN_EXE
|
||||||
|
if ($env:REGISTRY_TOKEN) {
|
||||||
|
$rc = Join-Path $env:USERPROFILE '.npmrc'
|
||||||
|
Add-Content -Path $rc -Value '@unom:registry=https://git.unom.io/api/packages/unom/npm/'
|
||||||
|
Add-Content -Path $rc -Value "//git.unom.io/api/packages/unom/npm/:_authToken=$env:REGISTRY_TOKEN"
|
||||||
|
}
|
||||||
|
Push-Location web
|
||||||
|
& $bun install --frozen-lockfile; if ($LASTEXITCODE) { throw "bun install failed ($LASTEXITCODE)" }
|
||||||
|
& $bun run build; if ($LASTEXITCODE) { throw "web build failed ($LASTEXITCODE)" }
|
||||||
|
if (Select-String -Path .output\server\index.mjs -Pattern 'Bun\.serve' -Quiet) {
|
||||||
|
throw "web build is a bun bundle (Bun.serve) - need the node-server preset"
|
||||||
|
}
|
||||||
|
Pop-Location
|
||||||
|
# Gate the installer on a real boot under the BUNDLED bun (the runtime it ships), serving /login.
|
||||||
|
$env:PORT = '3009'; $env:HOST = '127.0.0.1'; $env:PUNKTFUNK_UI_PASSWORD = 'ci'
|
||||||
|
$server = (Resolve-Path 'web\.output\server\index.mjs').Path
|
||||||
|
$p = Start-Process -FilePath $bun -ArgumentList $server -PassThru -WindowStyle Hidden
|
||||||
|
Start-Sleep -Seconds 4
|
||||||
|
try { $code = (Invoke-WebRequest -Uri 'http://127.0.0.1:3009/login' -UseBasicParsing -TimeoutSec 10).StatusCode } catch { $code = 0 }
|
||||||
|
Stop-Process -Id $p.Id -Force -ErrorAction SilentlyContinue
|
||||||
|
Write-Output "web console smoke (bun): /login -> $code"
|
||||||
|
if ($code -ne 200) { throw "web console failed to boot under bun" }
|
||||||
|
"WEB_OUTPUT_DIR=$((Resolve-Path 'web\.output').Path)" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
|
||||||
|
|
||||||
- name: Pack + sign installer
|
- name: Pack + sign installer
|
||||||
shell: pwsh
|
shell: pwsh
|
||||||
env:
|
env:
|
||||||
@@ -116,13 +211,25 @@ jobs:
|
|||||||
if (-not $files) { throw "pack produced no artifacts to publish" }
|
if (-not $files) { throw "pack produced no artifacts to publish" }
|
||||||
$base = "https://$($env:REGISTRY)/api/packages/$($env:OWNER)/generic/$($env:PKG)"
|
$base = "https://$($env:REGISTRY)/api/packages/$($env:OWNER)/generic/$($env:PKG)"
|
||||||
foreach ($f in $files) { Publish-File $f "$base/$($env:HOST_VERSION)/$(Split-Path $f -Leaf)" }
|
foreach ($f in $files) { Publish-File $f "$base/$($env:HOST_VERSION)/$(Split-Path $f -Leaf)" }
|
||||||
# On a tagged release, also refresh the stable `latest/` alias (delete-then-reupload, like
|
# Refresh the channel alias (delete-then-reupload, like flatpak.yml/decky.yml) for a
|
||||||
# flatpak.yml/decky.yml) so there's a predictable download URL.
|
# predictable download URL: stable release -> `latest/`, canary main build -> `canary/`.
|
||||||
if ($env:GITHUB_REF -like 'refs/tags/host-win-v*') {
|
$alias = if ($env:GITHUB_REF -like 'refs/tags/v*') { 'latest' } else { 'canary' }
|
||||||
$aliases = @{ $env:HOST_SETUP_PATH = 'punktfunk-host-setup.exe'; $env:HOST_CER_PATH = 'punktfunk-host-windows.cer' }
|
$aliasNames = @{ $env:HOST_SETUP_PATH = 'punktfunk-host-setup.exe'; $env:HOST_CER_PATH = 'punktfunk-host-windows.cer' }
|
||||||
foreach ($f in $files) {
|
foreach ($f in $files) {
|
||||||
$alias = $aliases[$f]; if (-not $alias) { continue }
|
$an = $aliasNames[$f]; if (-not $an) { continue }
|
||||||
curl.exe -fsS -o NUL --user "enricobuehler:$($env:REGISTRY_TOKEN)" -X DELETE "$base/latest/$alias" 2>$null
|
curl.exe -fsS -o NUL --user "enricobuehler:$($env:REGISTRY_TOKEN)" -X DELETE "$base/$alias/$an" 2>$null
|
||||||
Publish-File $f "$base/latest/$alias"
|
Publish-File $f "$base/$alias/$an"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# On a real release, also attach the signed installer (+ its .cer) to the unified Gitea Release.
|
||||||
|
- name: Attach host installer to the Gitea release (stable tags only)
|
||||||
|
if: startsWith(gitea.ref, 'refs/tags/v')
|
||||||
|
shell: pwsh
|
||||||
|
env:
|
||||||
|
GITEA_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
|
||||||
|
run: |
|
||||||
|
. scripts/ci/gitea-release.ps1
|
||||||
|
$rid = Ensure-GiteaRelease -Tag $env:GITHUB_REF_NAME -Name $env:GITHUB_REF_NAME -Prerelease 'auto'
|
||||||
|
foreach ($f in @($env:HOST_SETUP_PATH, $env:HOST_CER_PATH)) {
|
||||||
|
if ($f -and (Test-Path $f)) { Upsert-GiteaAsset -ReleaseId $rid -File $f }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,11 +11,12 @@
|
|||||||
# Registry (public, unom org): https://git.unom.io/unom/-/packages (generic group)
|
# Registry (public, unom org): https://git.unom.io/unom/-/packages (generic group)
|
||||||
# Packaging internals: clients/windows/packaging/README.md.
|
# Packaging internals: clients/windows/packaging/README.md.
|
||||||
#
|
#
|
||||||
# Versioning — MSIX requires a strictly 4-part numeric version (no ~/- suffixes), so:
|
# Versioning — single project version; MSIX requires a strictly 4-part numeric version, so:
|
||||||
# win-vX.Y.Z tag -> X.Y.Z.0 (a real Windows-client release; `win-v*` is its own tag namespace,
|
# vX.Y.Z tag -> X.Y.Z.0 (THE release; any -rc/+meta pre-release suffix is dropped for MSIX).
|
||||||
# kept off the host's `host-v*` and the Apple `v*` to avoid the
|
# Published to the generic registry + the stable `latest/` alias + attached to the
|
||||||
# version-shadow class of bug — see deb.yml).
|
# unified Gitea Release alongside every other platform's artifact.
|
||||||
# main push / dispatch -> 0.2.<run_number>.0 (rolling; climbs monotonically by run number).
|
# main push / dispatch -> 0.3.<run_number>.0 (canary; climbs monotonically by run number).
|
||||||
|
# Published to the generic registry + the `canary/` alias.
|
||||||
# Both arches share the version; artifacts are arch-suffixed (..._x64.msix / ..._arm64.msix).
|
# Both arches share the version; artifacts are arch-suffixed (..._x64.msix / ..._arm64.msix).
|
||||||
#
|
#
|
||||||
# Signing (packaging/pack-msix.ps1): if the MSIX_CERT_PFX_B64 / MSIX_CERT_PASSWORD Actions secrets
|
# Signing (packaging/pack-msix.ps1): if the MSIX_CERT_PFX_B64 / MSIX_CERT_PASSWORD Actions secrets
|
||||||
@@ -34,7 +35,7 @@ on:
|
|||||||
- 'Cargo.lock'
|
- 'Cargo.lock'
|
||||||
- 'Cargo.toml'
|
- 'Cargo.toml'
|
||||||
- '.gitea/workflows/windows-msix.yml'
|
- '.gitea/workflows/windows-msix.yml'
|
||||||
tags: ['win-v*']
|
tags: ['v*']
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
env:
|
env:
|
||||||
@@ -72,10 +73,11 @@ jobs:
|
|||||||
"CARGO_TARGET_DIR=${{ matrix.td }}" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
|
"CARGO_TARGET_DIR=${{ matrix.td }}" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
|
||||||
"FFMPEG_DIR=${{ matrix.ffmpeg }}" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
|
"FFMPEG_DIR=${{ matrix.ffmpeg }}" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
|
||||||
rustup target add ${{ matrix.target }}
|
rustup target add ${{ matrix.target }}
|
||||||
$parts = if ($env:GITHUB_REF -like 'refs/tags/win-v*') {
|
$parts = if ($env:GITHUB_REF -like 'refs/tags/v*') {
|
||||||
($env:GITHUB_REF_NAME -replace '^win-v', '').Split('.')
|
# MSIX needs a purely-numeric 4-part version: drop any -rc/+meta pre-release suffix.
|
||||||
|
(($env:GITHUB_REF_NAME -replace '^v', '') -replace '[-+].*$', '').Split('.')
|
||||||
} else {
|
} else {
|
||||||
@('0', '2', $env:GITHUB_RUN_NUMBER)
|
@('0', '3', $env:GITHUB_RUN_NUMBER)
|
||||||
}
|
}
|
||||||
while ($parts.Count -lt 4) { $parts += '0' }
|
while ($parts.Count -lt 4) { $parts += '0' }
|
||||||
$v = ($parts[0..3] -join '.')
|
$v = ($parts[0..3] -join '.')
|
||||||
@@ -101,11 +103,43 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
|
REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
|
$PSNativeCommandUseErrorActionPreference = $false
|
||||||
|
$base = "https://$($env:REGISTRY)/api/packages/$($env:OWNER)/generic/$($env:PKG)"
|
||||||
|
# stable release -> `latest/` alias; canary main build -> `canary/` alias.
|
||||||
|
$alias = if ($env:GITHUB_REF -like 'refs/tags/v*') { 'latest' } else { 'canary' }
|
||||||
|
# version-less, arch-suffixed alias names so each channel keeps one predictable URL.
|
||||||
|
$aliasNames = @{
|
||||||
|
"$($env:MSIX_PATH)" = "$($env:PKG)_${{ matrix.arch }}.msix"
|
||||||
|
"$($env:MSIX_CER_PATH)" = "$($env:PKG)_${{ matrix.arch }}.cer"
|
||||||
|
}
|
||||||
$files = @($env:MSIX_PATH, $env:MSIX_CER_PATH) | Where-Object { $_ -and (Test-Path $_) }
|
$files = @($env:MSIX_PATH, $env:MSIX_CER_PATH) | Where-Object { $_ -and (Test-Path $_) }
|
||||||
if (-not $files) { throw "pack produced no artifacts to publish" }
|
if (-not $files) { throw "pack produced no artifacts to publish" }
|
||||||
|
function Put($f, $url) {
|
||||||
|
curl.exe -fsS --user "enricobuehler:$($env:REGISTRY_TOKEN)" --upload-file "$f" "$url"
|
||||||
|
if ($LASTEXITCODE -ne 0) { throw "upload failed ($LASTEXITCODE): $url" }
|
||||||
|
Write-Output "published $url"
|
||||||
|
}
|
||||||
foreach ($f in $files) {
|
foreach ($f in $files) {
|
||||||
$name = Split-Path $f -Leaf
|
$name = Split-Path $f -Leaf
|
||||||
$url = "https://$($env:REGISTRY)/api/packages/$($env:OWNER)/generic/$($env:PKG)/$($env:MSIX_VERSION)/$name"
|
# 1) immutable, versioned path
|
||||||
curl.exe -fsS --user "enricobuehler:$($env:REGISTRY_TOKEN)" --upload-file "$f" "$url"
|
Put $f "$base/$($env:MSIX_VERSION)/$name"
|
||||||
Write-Output "published $name -> $url"
|
# 2) channel alias (delete-then-reupload; the generic registry 409s on an existing file)
|
||||||
|
$an = $aliasNames["$f"]
|
||||||
|
curl.exe -fsS -o NUL --user "enricobuehler:$($env:REGISTRY_TOKEN)" -X DELETE "$base/$alias/$an" 2>$null
|
||||||
|
Put $f "$base/$alias/$an"
|
||||||
|
}
|
||||||
|
|
||||||
|
# On a real release, also attach the MSIX (+ its .cer) to the unified Gitea Release. Both
|
||||||
|
# arch legs attach to the same release concurrently — the helper's create-or-fetch handles
|
||||||
|
# the race, and x64/arm64 filenames differ so the assets don't collide.
|
||||||
|
- name: Attach MSIX to the Gitea release (stable tags only)
|
||||||
|
if: startsWith(gitea.ref, 'refs/tags/v')
|
||||||
|
shell: pwsh
|
||||||
|
env:
|
||||||
|
GITEA_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
|
||||||
|
run: |
|
||||||
|
. scripts/ci/gitea-release.ps1
|
||||||
|
$rid = Ensure-GiteaRelease -Tag $env:GITHUB_REF_NAME -Name $env:GITHUB_REF_NAME -Prerelease 'auto'
|
||||||
|
foreach ($f in @($env:MSIX_PATH, $env:MSIX_CER_PATH)) {
|
||||||
|
if ($f -and (Test-Path $f)) { Upsert-GiteaAsset -ReleaseId $rid -File $f }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,9 @@ dist/
|
|||||||
clients/apple/.build/
|
clients/apple/.build/
|
||||||
clients/apple/PunktfunkCore.xcframework/
|
clients/apple/PunktfunkCore.xcframework/
|
||||||
clients/apple/.swiftpm/
|
clients/apple/.swiftpm/
|
||||||
|
# Generated App Store screenshots (tools/screenshots.sh output; uploaded as a CI artifact)
|
||||||
|
clients/apple/screenshots/
|
||||||
|
clients/linux/screenshots/
|
||||||
# Xcode per-user state
|
# Xcode per-user state
|
||||||
xcuserdata/
|
xcuserdata/
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
Low-latency desktop/game streaming stack, Linux-first, with a shared Rust protocol core
|
Low-latency desktop/game streaming stack, Linux-first, with a shared Rust protocol core
|
||||||
(`punktfunk-core`) exposed over a C ABI and native clients per platform. Full design:
|
(`punktfunk-core`) exposed over a C ABI and native clients per platform. Full design:
|
||||||
[`docs/implementation-plan.md`](docs/implementation-plan.md). Status table: `README.md`.
|
[`design/implementation-plan.md`](design/implementation-plan.md). Status table: `README.md`.
|
||||||
|
|
||||||
## Where the work stands
|
## Where the work stands
|
||||||
|
|
||||||
@@ -27,7 +27,15 @@ Low-latency desktop/game streaming stack, Linux-first, with a shared Rust protoc
|
|||||||
Input: mouse/keyboard (libei via RemoteDesktop portal on KWin/GNOME, gamescope's own EIS
|
Input: mouse/keyboard (libei via RemoteDesktop portal on KWin/GNOME, gamescope's own EIS
|
||||||
socket, wlr protocols on Sway) and **gamepads** (uinput X-Box-360 pads + rumble
|
socket, wlr protocols on Sway) and **gamepads** (uinput X-Box-360 pads + rumble
|
||||||
back-channel; validated live — pad created/destroyed with the session). Management REST API +
|
back-channel; validated live — pad created/destroyed with the session). Management REST API +
|
||||||
checked-in OpenAPI doc (`mgmt.rs`).
|
checked-in OpenAPI doc (`mgmt.rs`). **Web-console performance capture** (`stats_recorder.rs`,
|
||||||
|
design: [`design/stats-capture-plan.md`](design/stats-capture-plan.md)): the operator arms stats
|
||||||
|
recording from the web console, plays, stops, and reviews the run as graphs (per-stage latency
|
||||||
|
breakdown · fps new/repeat · goodput · loss/FEC). A shared `Arc<StatsRecorder>` ring (the hot-path
|
||||||
|
gate is a runtime `AtomicBool`, replacing the startup-only `PUNKTFUNK_PERF`) is fed by **both** the
|
||||||
|
native `virtual_stream` and the GameStream encode loop at their existing ~2 s/~1 s aggregation
|
||||||
|
boundary, and finished captures are saved as on-disk recordings
|
||||||
|
(`~/.config/punktfunk/captures/*.json`) browsable/exportable from the console's **Performance** page
|
||||||
|
(recharts). Endpoints `/api/v1/stats/*` (bearer-only). *Implemented; not yet on-glass validated.*
|
||||||
- **Native protocol (`punktfunk/1`): full session planes, validated live.** QUIC
|
- **Native protocol (`punktfunk/1`): full session planes, validated live.** QUIC
|
||||||
control plane (`punktfunk-core` `quic` feature: Hello{mode}/Welcome{full Config}/Start), data
|
control plane (`punktfunk-core` `quic` feature: Hello{mode}/Welcome{full Config}/Start), data
|
||||||
plane = the hardened core `Session` over raw UDP with **GF(2¹⁶) Leopard FEC + AES-GCM**
|
plane = the hardened core `Session` over raw UDP with **GF(2¹⁶) Leopard FEC + AES-GCM**
|
||||||
@@ -65,18 +73,55 @@ Low-latency desktop/game streaming stack, Linux-first, with a shared Rust protoc
|
|||||||
`send_rich_input`. **Client-negotiated virtual pad type**: the Hello carries a gamepad
|
`send_rich_input`. **Client-negotiated virtual pad type**: the Hello carries a gamepad
|
||||||
preference byte (same trailing-byte back-compat pattern as the compositor), the Welcome
|
preference byte (same trailing-byte back-compat pattern as the compositor), the Welcome
|
||||||
echoes the resolved backend — precedence: explicit client choice > `PUNKTFUNK_GAMEPAD`
|
echoes the resolved backend — precedence: explicit client choice > `PUNKTFUNK_GAMEPAD`
|
||||||
env > uinput Xbox 360; DualSense (UHID) only on Linux hosts.
|
env > uinput Xbox 360. Backends: **Xbox 360** (uinput / ViGEm), **Xbox One/Series** (the same
|
||||||
- **Windows host: implemented and shipping (NVIDIA-only, x64-only).** `#[cfg(windows)]` backends
|
XInput backend with the One/Series USB identity for matching glyphs — no extra game-visible
|
||||||
|
capability; impulse-trigger rumble is unreachable through a virtual pad), and the UHID
|
||||||
|
`hid-playstation` pads — **DualSense** (adaptive triggers, lightbar, touchpad, motion) and
|
||||||
|
**DualShock 4** (lightbar, touchpad, motion, rumble; DualSense minus adaptive triggers / player
|
||||||
|
LEDs / mute). DualSense and DualShock 4 each have a Linux (UHID `hid-playstation`) **and a Windows
|
||||||
|
(UMDF minidriver)** backend — `inject/dualsense_windows.rs` + `inject/dualshock4_windows.rs`, one
|
||||||
|
driver serving either identity per a `device_type` byte the host stamps into shared memory (the DS4
|
||||||
|
reuses the same SwDeviceCreate game-detection identity fix as the DualSense). One/Series stays
|
||||||
|
Linux-only and folds into Xbox 360 off it. Clients auto-resolve the type from the physical controller
|
||||||
|
(DS5→DualSense, DS4→DualShock 4, Xbox One→Xbox One). **Windows uses ZERO external gamepad
|
||||||
|
dependencies — ViGEmBus is gone.** Xbox 360 (XInput) runs on a UMDF2 **XUSB companion** driver
|
||||||
|
(`packaging/windows/xusb-driver/`, `inject/gamepad_windows.rs`) that registers `GUID_DEVINTERFACE_XUSB`
|
||||||
|
and answers the buffered XInput IOCTLs from a shared section, so classic `XInputGetState`/`SetState`
|
||||||
|
work with no kernel bus driver (validated live: slot connected, state + rumble round-trip; Xbox One
|
||||||
|
folds to this 360 path). All three UMDF drivers (DualSense/DS4 + XUSB) are bundled + pnputil-installed
|
||||||
|
by the Inno Setup installer (`packaging/windows/gamepad-drivers/` + `install-gamepad-drivers.ps1`).
|
||||||
|
**Multi-pad ready**: the host stamps each pad's index into the device Location (`pszDeviceLocation`),
|
||||||
|
the driver reads it (`WdfDeviceAllocAndQueryProperty`) to map its own `*-shm-<index>`, and
|
||||||
|
`UmdfHostProcessSharing=ProcessSharingDisabled` gives each pad its own host (per-pad statics) —
|
||||||
|
validated live with 2 distinct XInput slots + 2 DualSense pads. (Client-side multi-pad forwarding is
|
||||||
|
the remaining piece.)
|
||||||
|
- **Windows host: implemented and shipping (all-vendor, x64-only).** `#[cfg(windows)]` backends
|
||||||
behind the same traits as Linux — DXGI Desktop Duplication capture (`capture/dxgi.rs`), **SudoVDA**
|
behind the same traits as Linux — DXGI Desktop Duplication capture (`capture/dxgi.rs`), **SudoVDA**
|
||||||
virtual display per session (`vdisplay/sudovda.rs`), NVENC encode (`--features nvenc`), SendInput +
|
virtual display per session (`vdisplay/sudovda.rs`), GPU encode (NVENC `--features nvenc`; AMD/Intel
|
||||||
**ViGEm** gamepads (`inject/gamepad_windows.rs`), WASAPI loopback + virtual mic (`audio/wasapi_*`).
|
`--features amf-qsv`), SendInput + **ViGEm** gamepads (`inject/gamepad_windows.rs`), WASAPI loopback
|
||||||
Ships as a **signed Inno Setup installer** that registers a `LocalSystem` SCM service launching into
|
+ virtual mic (`audio/wasapi_*`). Ships as a **signed Inno Setup installer** that registers a
|
||||||
the interactive session for secure-desktop (UAC/lock-screen) capture (`service.rs`), bundles the
|
`LocalSystem` SCM service launching into the interactive session for secure-desktop (UAC/lock-screen)
|
||||||
SudoVDA driver, and is published by `windows-host.yml`. **HDR (10-bit)**: WGC captures the HDR
|
capture (`service.rs`), bundles the SudoVDA driver + the FFmpeg DLLs, and is published by
|
||||||
desktop as FP16/Rgb10a2 (DDA FP16 for the secure desktop), NVENC forces HEVC Main10 + BT.2020 PQ,
|
`windows-host.yml`. **Encoder is GPU-aware** (`encode.rs` `open_video` + `windows_resolved_backend`):
|
||||||
the client auto-detects PQ from the HEVC VUI — gated by `PUNKTFUNK_10BIT` + client `VIDEO_CAP_10BIT`;
|
`PUNKTFUNK_ENCODER=auto` (the host.env default) detects the DXGI adapter vendor → **NVENC** (NVIDIA,
|
||||||
**Windows host only** (the Linux host stays 8-bit, blocked upstream). Newer/less battle-tested than
|
direct SDK, `encode/nvenc.rs`), **AMF** (AMD) / **QSV** (Intel) via libavcodec
|
||||||
the Linux host; no AMD/Intel/software encode path. Packaging: `packaging/windows/`.
|
(`encode/ffmpeg_win.rs`, the Windows analogue of the Linux VAAPI backend — `WinVendor{Amf,Qsv}`,
|
||||||
|
system-memory NV12/P010 readback default + opt-in zero-copy D3D11 behind `PUNKTFUNK_ZEROCOPY` with a
|
||||||
|
system fallback), or software H.264 (`encode/sw.rs`, GPU-less). GameStream codec advertisement is
|
||||||
|
probed per-GPU on AMF/QSV (`windows_codec_support` → `serverinfo`, AV1 gated). **HDR (10-bit)**: WGC
|
||||||
|
captures the HDR desktop as FP16/Rgb10a2 (DDA FP16 for the secure desktop), the encoder forces HEVC
|
||||||
|
Main10 + BT.2020 PQ (NVENC ABGR10/P010; AMF/QSV P010 + a swscale Rgb10a2→P010 fallback), the client
|
||||||
|
auto-detects PQ from the HEVC VUI — gated by `PUNKTFUNK_10BIT` + client `VIDEO_CAP_10BIT`; **Windows
|
||||||
|
host only** (the Linux host stays 8-bit, blocked upstream). **Vulkan-game HDR over the virtual
|
||||||
|
display**: NVIDIA/AMD Vulkan ICDs refuse to *advertise* an HDR color space for a surface on an IddCx
|
||||||
|
indirect display (so Vulkan games — Doom: The Dark Ages, id Tech, etc. — say "device does not support
|
||||||
|
HDR"), even though the ICD happily *accepts + presents* a forced HDR swapchain there. A tiny always-on
|
||||||
|
Vulkan **implicit layer** (`packaging/windows/pf-vkhdr-layer/`, `VK_LAYER_PUNKTFUNK_hdr_inject`)
|
||||||
|
injects the `HDR10_ST2084`/scRGB surface formats into `vkGetPhysicalDeviceSurfaceFormats[2]KHR`,
|
||||||
|
self-gated on the display's actual advanced-color state (no-op on SDR / real monitors); bundled +
|
||||||
|
HKLM-registered by the installer. **Live-validated: Doom: The Dark Ages enables HDR over the virtual
|
||||||
|
display.** **AMF/QSV is CI-green but not yet on-glass validated** (no AMD/Intel Windows box in the
|
||||||
|
lab); NVENC is live-validated. Newer/less battle-tested than the Linux host. Packaging: `packaging/windows/`.
|
||||||
|
|
||||||
## What's left
|
## What's left
|
||||||
|
|
||||||
@@ -169,7 +214,9 @@ Low-latency desktop/game streaming stack, Linux-first, with a shared Rust protoc
|
|||||||
`punktfunk-core`; phone + Android TV): NDK `AMediaCodec` hardware HEVC decode → `SurfaceView` incl.
|
`punktfunk-core`; phone + Android TV): NDK `AMediaCodec` hardware HEVC decode → `SurfaceView` incl.
|
||||||
**HDR10** (Main10/BT.2020 PQ) with low-latency tuning + a live stats HUD (`decode.rs`/`stats.rs`),
|
**HDR10** (Main10/BT.2020 PQ) with low-latency tuning + a live stats HUD (`decode.rs`/`stats.rs`),
|
||||||
Opus/Oboe audio + mic uplink (`audio.rs`/`mic.rs`), gamepad input with rumble/HID feedback
|
Opus/Oboe audio + mic uplink (`audio.rs`/`mic.rs`), gamepad input with rumble/HID feedback
|
||||||
(`feedback.rs`), `NsdManager` mDNS discovery, SPAKE2 PIN pairing + TOFU (Keystore identity +
|
(`feedback.rs`), **native `mdns-sd` mDNS discovery** (`discovery.rs`, polled over JNI — the same
|
||||||
|
browse the Linux/Windows clients use, replacing the flaky per-OEM `NsdManager`; Kotlin keeps only
|
||||||
|
the `MulticastLock` + permission UX), SPAKE2 PIN pairing + TOFU (Keystore identity +
|
||||||
known-host store), Compose UI (Connect/Settings/Stream) with D-pad/controller focus nav. Built for
|
known-host store), Compose UI (Connect/Settings/Stream) with D-pad/controller focus nav. Built for
|
||||||
`arm64-v8a` + `x86_64`; published to Google Play (Internal Testing) via `android.yml`
|
`arm64-v8a` + `x86_64`; published to Google Play (Internal Testing) via `android.yml`
|
||||||
(`ci/play-upload.py`). Next: real-device gamepad/HDR live-verify, presenter/latency polish.
|
(`ci/play-upload.py`). Next: real-device gamepad/HDR live-verify, presenter/latency polish.
|
||||||
@@ -213,8 +260,8 @@ bash crates/punktfunk-core/tests/c/run.sh # standalone C-ABI link + round-trip
|
|||||||
```
|
```
|
||||||
|
|
||||||
Generated artifacts are **checked in** and CI fails on drift: `include/punktfunk_core.h`
|
Generated artifacts are **checked in** and CI fails on drift: `include/punktfunk_core.h`
|
||||||
(cbindgen from `punktfunk-core/src/abi.rs`) and `docs/api/openapi.json` (regenerate with
|
(cbindgen from `punktfunk-core/src/abi.rs`) and `api/openapi.json` (regenerate with
|
||||||
`cargo run -p punktfunk-host -- openapi > docs/api/openapi.json`; spec lives in `mgmt.rs`).
|
`cargo run -p punktfunk-host -- openapi > api/openapi.json`; spec lives in `mgmt.rs`).
|
||||||
|
|
||||||
CI is Gitea Actions (`.gitea/workflows/`, guide: docs-site `ci.md`): `ci.yml` runs the
|
CI is Gitea Actions (`.gitea/workflows/`, guide: docs-site `ci.md`): `ci.yml` runs the
|
||||||
workspace checks inside the `git.unom.io/unom/punktfunk-rust-ci` image plus web/docs-site
|
workspace checks inside the `git.unom.io/unom/punktfunk-rust-ci` image plus web/docs-site
|
||||||
@@ -235,15 +282,16 @@ crates/punktfunk-host/
|
|||||||
vdisplay/{kwin,gamescope,mutter,wlroots}.rs per-compositor client-sized virtual outputs
|
vdisplay/{kwin,gamescope,mutter,wlroots}.rs per-compositor client-sized virtual outputs
|
||||||
zerocopy/{egl,cuda,vulkan}.rs dmabuf → CUDA → NVENC (tiled via EGL/GL, LINEAR via Vulkan)
|
zerocopy/{egl,cuda,vulkan}.rs dmabuf → CUDA → NVENC (tiled via EGL/GL, LINEAR via Vulkan)
|
||||||
inject/{libei,wlr,gamepad,dualsense}.rs input backends (uinput xpad + UHID DualSense)
|
inject/{libei,wlr,gamepad,dualsense}.rs input backends (uinput xpad + UHID DualSense)
|
||||||
capture.rs · encode.rs · audio.rs · spike.rs · punktfunk1.rs · mgmt.rs · native_pairing.rs
|
encode/{nvenc,linux,vaapi,ffmpeg_win,sw}.rs per-GPU encoders (NVENC · Linux NVENC/CUDA · VAAPI · AMF/QSV · openh264)
|
||||||
|
capture.rs · encode.rs · audio.rs · spike.rs · punktfunk1.rs · mgmt.rs · native_pairing.rs · stats_recorder.rs
|
||||||
clients/probe/ punktfunk/1 reference/probe client (headless test/measurement tool)
|
clients/probe/ punktfunk/1 reference/probe client (headless test/measurement tool)
|
||||||
clients/linux/ native Linux client (GTK4/libadwaita · FFmpeg · PipeWire · SDL3)
|
clients/linux/ native Linux client (GTK4/libadwaita · FFmpeg · PipeWire · SDL3)
|
||||||
clients/windows/ native Windows client (WinUI 3 via windows-reactor · D3D11 · WASAPI · SDL3)
|
clients/windows/ native Windows client (WinUI 3 via windows-reactor · D3D11 · WASAPI · SDL3)
|
||||||
clients/apple/ native macOS/iOS/tvOS client (Swift · VideoToolbox · GameController)
|
clients/apple/ native macOS/iOS/tvOS client (Swift · VideoToolbox · GameController)
|
||||||
clients/android/ native Android client (Kotlin app + native/ Rust JNI core over punktfunk-core)
|
clients/android/ native Android client (Kotlin app + native/ Rust JNI core over punktfunk-core)
|
||||||
clients/decky/ Steam Deck Decky plugin
|
clients/decky/ Steam Deck Decky plugin
|
||||||
crates/punktfunk-host/src/{capture/dxgi,vdisplay/sudovda,inject/gamepad_windows,audio/wasapi_*,service}.rs Windows host backends
|
crates/punktfunk-host/src/{capture/dxgi,vdisplay/sudovda,encode/ffmpeg_win,inject/gamepad_windows,audio/wasapi_*,service}.rs Windows host backends
|
||||||
web/ TanStack web console over the mgmt API (status · devices · pairing)
|
web/ TanStack web console over the mgmt API (status · devices · pairing · performance graphs)
|
||||||
packaging/ apt(deb) · RPM/COPR · Arch/sysext · Flatpak · Bazzite bootc · Windows host installer (per-dir READMEs)
|
packaging/ apt(deb) · RPM/COPR · Arch/sysext · Flatpak · Bazzite bootc · Windows host installer (per-dir READMEs)
|
||||||
tools/{loss-harness,latency-probe}/ measurement (plan §10)
|
tools/{loss-harness,latency-probe}/ measurement (plan §10)
|
||||||
scripts/ 60-punktfunk.rules · punktfunk-host.service · host.env.example · headless/
|
scripts/ 60-punktfunk.rules · punktfunk-host.service · host.env.example · headless/
|
||||||
@@ -298,7 +346,23 @@ FFI also link-needs `libGL`/`libgbm`/`libcuda` at build time). Env knobs: `PUNKT
|
|||||||
`PUNKTFUNK_COMPOSITOR=kwin|gamescope|mutter`, `PUNKTFUNK_ZEROCOPY=1`, `PUNKTFUNK_GAMESCOPE_APP=...`,
|
`PUNKTFUNK_COMPOSITOR=kwin|gamescope|mutter`, `PUNKTFUNK_ZEROCOPY=1`, `PUNKTFUNK_GAMESCOPE_APP=...`,
|
||||||
`PUNKTFUNK_INPUT_BACKEND=...`, `PUNKTFUNK_PERF=1` (per-stage timing), `PUNKTFUNK_VIDEO_DROP=N` (FEC
|
`PUNKTFUNK_INPUT_BACKEND=...`, `PUNKTFUNK_PERF=1` (per-stage timing), `PUNKTFUNK_VIDEO_DROP=N` (FEC
|
||||||
test), `PUNKTFUNK_FEC_PCT=N`, `PUNKTFUNK_DSCP=1` (opt-in DSCP/SO_PRIORITY media QoS on the data +
|
test), `PUNKTFUNK_FEC_PCT=N`, `PUNKTFUNK_DSCP=1` (opt-in DSCP/SO_PRIORITY media QoS on the data +
|
||||||
GameStream video/audio sockets; no-op on the wire on Windows without a qWAVE policy).
|
GameStream video/audio sockets; no-op on the wire on Windows without a qWAVE policy),
|
||||||
|
`PUNKTFUNK_444=1` (full-chroma HEVC 4:4:4, see below).
|
||||||
|
|
||||||
|
**HEVC 4:4:4 (full chroma, Range Extensions)**: opt-in via `PUNKTFUNK_444`, negotiated like 10-bit —
|
||||||
|
the host emits 4:4:4 only when the client advertised `VIDEO_CAP_444` (wire bit `0x04` + ABI
|
||||||
|
`PUNKTFUNK_VIDEO_CAP_444`), the codec is HEVC, the session is single-process, **and** a GPU probe
|
||||||
|
(`encode::can_encode_444`, run before the Welcome) confirms support — else it resolves to 4:2:0 and
|
||||||
|
`Welcome::chroma_format` reflects the real value (honest downgrade; the client reads it via
|
||||||
|
`punktfunk_connection_chroma_format`). **punktfunk/1-native only** — GameStream/Moonlight stays 4:2:0
|
||||||
|
(stock clients can't decode 4:4:4). **NVENC is the implemented path**: Linux `hevc_nvenc` feeds a
|
||||||
|
swscale'd `yuv444p` (RGB-in is always 4:2:0 — verified on the RTX 5070 Ti — so the session forces CPU
|
||||||
|
RGB capture for 4:4:4); Windows NVENC keeps ARGB input + FREXT profile + `chromaFormatIDC=3` and the
|
||||||
|
DDA capturer delivers RGB. VAAPI / AMF / QSV **decline** (probe returns false — no validated 4:4:4
|
||||||
|
hardware in the lab; they'd produce 4:2:0). Software (openh264) is 4:2:0-only. Test with
|
||||||
|
`PUNKTFUNK_CLIENT_444=1 punktfunk-probe --out x.h265` then `ffprobe x.h265` (expect `pix_fmt yuv444p`).
|
||||||
|
*Linux NVENC mechanism validated on the RTX 5070 Ti (ffmpeg CLI); Windows NVENC + 10-bit-4:4:4 not yet
|
||||||
|
on-glass validated.*
|
||||||
|
|
||||||
## Conventions
|
## Conventions
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
# Contributing to punktfunk
|
||||||
|
|
||||||
|
Thanks for your interest in contributing!
|
||||||
|
|
||||||
|
## Licensing of contributions (inbound = outbound)
|
||||||
|
|
||||||
|
punktfunk is dual-licensed under **MIT OR Apache-2.0**.
|
||||||
|
|
||||||
|
> Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in
|
||||||
|
> the work by you, as defined in the Apache-2.0 license, shall be dual licensed as **MIT OR
|
||||||
|
> Apache-2.0**, without any additional terms or conditions.
|
||||||
|
|
||||||
|
By opening a pull request you agree to license your contribution under these terms. This is the
|
||||||
|
standard Rust-ecosystem "inbound = outbound" model; it keeps the project's licensing unambiguous
|
||||||
|
(including the Apache-2.0 §5 contributor patent grant) and any future relicensing clean. You retain
|
||||||
|
the copyright to your contributions.
|
||||||
|
|
||||||
|
### Do not paste copyleft (or otherwise incompatibly-licensed) code
|
||||||
|
|
||||||
|
The single thing that could poison the permissive license is **copied source from a copyleft
|
||||||
|
project**. Several adjacent projects (Sunshine, Apollo, Moonlight) are GPL-3.0. You may study them
|
||||||
|
and reimplement a *technique*, protocol, or wire format — those are not copyrightable — but **never
|
||||||
|
paste their code**, and do not translate a GPL implementation line-by-line. When a comment credits
|
||||||
|
prior art, make clear it is an independent reimplementation, not a copy. The same applies to any
|
||||||
|
third party's code under a license incompatible with MIT/Apache.
|
||||||
|
|
||||||
|
If you add a new third-party dependency, it must be permissive (MIT / Apache-2.0 / BSD / ISC / Zlib /
|
||||||
|
Unicode-3.0 / etc.). `about.toml` holds the accepted-license allow-list; regenerate the attribution
|
||||||
|
file with `scripts/gen-third-party-notices.sh` when the dependency tree changes.
|
||||||
|
|
||||||
|
## Before you push
|
||||||
|
|
||||||
|
```sh
|
||||||
|
cargo fmt --all --check
|
||||||
|
cargo clippy --workspace --all-targets -- -D warnings
|
||||||
|
cargo test --workspace
|
||||||
|
```
|
||||||
|
|
||||||
|
Generated artifacts are checked in and CI fails on drift: `include/punktfunk_core.h` (cbindgen) and
|
||||||
|
`api/openapi.json` (`cargo run -p punktfunk-host -- openapi`). Match the surrounding code's comment
|
||||||
|
density and naming. Commit messages end with the `Co-Authored-By` trailer (see `git log`).
|
||||||
|
|
||||||
|
See [`CLAUDE.md`](CLAUDE.md) for the full build/test/run guide and design invariants.
|
||||||
Generated
+513
-304
File diff suppressed because it is too large
Load Diff
+2
-1
@@ -3,6 +3,7 @@ resolver = "2"
|
|||||||
members = [
|
members = [
|
||||||
"crates/punktfunk-core",
|
"crates/punktfunk-core",
|
||||||
"crates/punktfunk-host",
|
"crates/punktfunk-host",
|
||||||
|
"crates/pf-driver-proto",
|
||||||
"clients/probe",
|
"clients/probe",
|
||||||
"clients/linux",
|
"clients/linux",
|
||||||
"clients/windows",
|
"clients/windows",
|
||||||
@@ -12,7 +13,7 @@ members = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
version = "0.0.1"
|
version = "0.3.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
rust-version = "1.82"
|
rust-version = "1.82"
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
|
|||||||
@@ -1,13 +1,20 @@
|
|||||||
# punktfunk
|
<p align="center">
|
||||||
|
<img src="assets/punktfunk-logo.svg" alt="punktfunk" width="320" />
|
||||||
|
</p>
|
||||||
|
|
||||||
**Low-latency desktop and game streaming, Linux-first.** Run the host on a Linux machine — or a
|
<p align="center"><b>Low-latency desktop and game streaming with first-class Linux and Windows hosts.</b></p>
|
||||||
Windows PC — with an NVIDIA GPU, connect from a Mac, PC, phone, tablet, or TV, and stream your desktop
|
|
||||||
or games — each device at its **own native resolution and refresh rate**, over your local network.
|
Run the host on a Linux machine or a Windows PC, connect from a Mac, PC, phone, tablet, or TV, and
|
||||||
|
stream your desktop or games — each device at its **own native resolution and refresh rate**, over
|
||||||
|
your local network.
|
||||||
|
|
||||||
📖 **Documentation: [docs.punktfunk.unom.io](https://docs.punktfunk.unom.io)** — start with
|
📖 **Documentation: [docs.punktfunk.unom.io](https://docs.punktfunk.unom.io)** — start with
|
||||||
[How It Works](https://docs.punktfunk.unom.io/docs/how-it-works) or the
|
[How It Works](https://docs.punktfunk.unom.io/docs/how-it-works) or the
|
||||||
[Quick Start](https://docs.punktfunk.unom.io/docs/quickstart).
|
[Quick Start](https://docs.punktfunk.unom.io/docs/quickstart).
|
||||||
|
|
||||||
|
💬 **Community: [Discord](https://discord.gg/kaPNvzMuGU)** — chat, support, and **Android beta
|
||||||
|
access** · **[r/Punktfunk](https://www.reddit.com/r/Punktfunk/)**.
|
||||||
|
|
||||||
punktfunk pairs a **virtual-display streaming host** with native clients on every platform. It speaks
|
punktfunk pairs a **virtual-display streaming host** with native clients on every platform. It speaks
|
||||||
the existing **GameStream** protocol, so any [Moonlight](https://moonlight-stream.org/) client works
|
the existing **GameStream** protocol, so any [Moonlight](https://moonlight-stream.org/) client works
|
||||||
day one — and adds its own faster **`punktfunk/1`** protocol that breaks the ~1 Gbps FEC wall with a
|
day one — and adds its own faster **`punktfunk/1`** protocol that breaks the ~1 Gbps FEC wall with a
|
||||||
@@ -19,6 +26,11 @@ protocol, FEC, and crypto, linked into the host and every client over a stable C
|
|||||||
- **Your device's exact mode.** For each client that connects, the host spins up a virtual display
|
- **Your device's exact mode.** For each client that connects, the host spins up a virtual display
|
||||||
sized to that device — 1080p60 to a laptop, 1440p120 to a desktop, 4K to a TV, all at once. No
|
sized to that device — 1080p60 to a laptop, 1440p120 to a desktop, 4K to a TV, all at once. No
|
||||||
letterboxing, no scaling, no rearranging your real monitors.
|
letterboxing, no scaling, no rearranging your real monitors.
|
||||||
|
- **A real virtual display on Windows, too.** On Linux the host uses per-compositor virtual outputs;
|
||||||
|
on Windows you get the same on-the-fly virtual display — at the client's exact mode, no physical
|
||||||
|
monitor or dummy HDMI plug, even on the secure desktop (UAC / lock screen). It also has **its own
|
||||||
|
indirect display driver (IDD)** the host pushes finished frames straight into, rather than scraping
|
||||||
|
a screen — tight, push-based integration that's unusual for a Windows streaming host.
|
||||||
- **Low latency, GPU end to end.** Frames go straight from the compositor to the NVENC encoder with
|
- **Low latency, GPU end to end.** Frames go straight from the compositor to the NVENC encoder with
|
||||||
zero CPU copies (dmabuf → CUDA/Vulkan → NVENC), over a transport tuned for responsiveness rather
|
zero CPU copies (dmabuf → CUDA/Vulkan → NVENC), over a transport tuned for responsiveness rather
|
||||||
than throughput. Stable 240 fps at 5120×1440; sub-millisecond capture-to-reassembly on a LAN.
|
than throughput. Stable 240 fps at 5120×1440; sub-millisecond capture-to-reassembly on a LAN.
|
||||||
@@ -35,7 +47,7 @@ protocol, FEC, and crypto, linked into the host and every client over a stable C
|
|||||||
| **Core** — `punktfunk-core` + C ABI (protocol · FEC · crypto · QUIC) | ✅ Complete & hardened |
|
| **Core** — `punktfunk-core` + C ABI (protocol · FEC · crypto · QUIC) | ✅ Complete & hardened |
|
||||||
| **GameStream host** → stock Moonlight | ✅ Live end-to-end: pairing, RTSP, audio, per-client virtual output at native resolution, GPU zero-copy NVENC, gamepads |
|
| **GameStream host** → stock Moonlight | ✅ Live end-to-end: pairing, RTSP, audio, per-client virtual output at native resolution, GPU zero-copy NVENC, gamepads |
|
||||||
| **Native protocol** — `punktfunk/1` | ✅ Validated live: QUIC control + GF(2¹⁶) FEC/AES-GCM data plane, PIN pairing, mDNS discovery, mid-stream mode renegotiation |
|
| **Native protocol** — `punktfunk/1` | ✅ Validated live: QUIC control + GF(2¹⁶) FEC/AES-GCM data plane, PIN pairing, mDNS discovery, mid-stream mode renegotiation |
|
||||||
| **Windows host** (NVIDIA, x64) | 🟡 Implemented & shipping as a signed installer (DXGI capture · SudoVDA virtual display · NVENC · WASAPI · ViGEm); NVIDIA-only, newer than the Linux host |
|
| **Windows host** (x64) | 🟡 Implemented & shipping as a signed installer: DXGI/WGC capture · its own all-Rust IddCx **virtual display** (secure-desktop capable) · GPU encode (NVENC on NVIDIA, AMF/QSV on AMD/Intel) · WASAPI audio · bundled virtual-gamepad drivers (no ViGEmBus) · HDR incl. Vulkan-game HDR. NVIDIA live-validated; AMD/Intel CI-green |
|
||||||
| **macOS / iOS / tvOS client** (`clients/apple`) | ✅ Streaming live: VideoToolbox decode, controllers incl. DualSense, discovery, pairing, speed test |
|
| **macOS / iOS / tvOS client** (`clients/apple`) | ✅ Streaming live: VideoToolbox decode, controllers incl. DualSense, discovery, pairing, speed test |
|
||||||
| **Linux client** (`clients/linux`, GTK4) | ✅ Streaming live: FFmpeg + VAAPI zero-copy decode, PipeWire audio, SDL3 controllers; ships as Flatpak/apt/rpm/Arch |
|
| **Linux client** (`clients/linux`, GTK4) | ✅ Streaming live: FFmpeg + VAAPI zero-copy decode, PipeWire audio, SDL3 controllers; ships as Flatpak/apt/rpm/Arch |
|
||||||
| **Android client** (`clients/android`, phone + TV) | ✅ Streaming live: AMediaCodec decode + HDR10, Oboe audio, controllers, discovery, pairing |
|
| **Android client** (`clients/android`, phone + TV) | ✅ Streaming live: AMediaCodec decode + HDR10, Oboe audio, controllers, discovery, pairing |
|
||||||
@@ -61,14 +73,14 @@ roadmap: **[/docs/roadmap](https://docs.punktfunk.unom.io/docs/roadmap)**.
|
|||||||
|
|
||||||
Pick your platform and install from its package registry — the per-platform guide covers adding the
|
Pick your platform and install from its package registry — the per-platform guide covers adding the
|
||||||
repo, first run, and the web console. The Linux host is the primary, most battle-tested path; a
|
repo, first run, and the web console. The Linux host is the primary, most battle-tested path; a
|
||||||
Windows host (NVIDIA-only) also ships as a signed installer.
|
Windows host also ships as a signed installer (all-vendor: NVIDIA, AMD, Intel).
|
||||||
|
|
||||||
| Platform | Install | Guide |
|
| Platform | Install | Guide |
|
||||||
|--------|---------|-------|
|
|--------|---------|-------|
|
||||||
| **Ubuntu / Debian** (apt) | `sudo apt install punktfunk-host` *(after adding the repo)* | [Ubuntu — GNOME](https://docs.punktfunk.unom.io/docs/ubuntu-gnome) · [KDE](https://docs.punktfunk.unom.io/docs/ubuntu-kde) |
|
| **Ubuntu / Debian** (apt) | `sudo apt install punktfunk-host` *(after adding the repo)* | [Ubuntu — GNOME](https://docs.punktfunk.unom.io/docs/ubuntu-gnome) · [KDE](https://docs.punktfunk.unom.io/docs/ubuntu-kde) |
|
||||||
| **Fedora / Bazzite** (rpm-ostree) | `rpm-ostree install punktfunk punktfunk-web` *(or the bootc image)* | [Fedora — KDE](https://docs.punktfunk.unom.io/docs/fedora-kde) · [Bazzite](https://docs.punktfunk.unom.io/docs/bazzite) |
|
| **Fedora / Bazzite** (rpm-ostree) | `rpm-ostree install punktfunk punktfunk-web` *(or the bootc image)* | [Fedora — KDE](https://docs.punktfunk.unom.io/docs/fedora-kde) · [Bazzite](https://docs.punktfunk.unom.io/docs/bazzite) |
|
||||||
| **Arch / Steam Deck** (PKGBUILD / sysext) | `makepkg -si` *(Arch)* · sysext `.raw` *(SteamOS)* | [packaging/arch](packaging/arch/README.md) |
|
| **Arch / Steam Deck** (PKGBUILD / sysext) | `makepkg -si` *(Arch)* · sysext `.raw` *(SteamOS)* | [packaging/arch](packaging/arch/README.md) |
|
||||||
| **Windows** (NVIDIA, x64) | signed `setup.exe` from the package registry | [Windows Host](https://docs.punktfunk.unom.io/docs/windows-host) |
|
| **Windows** (x64) | signed `setup.exe` from the package registry | [Windows Host](https://docs.punktfunk.unom.io/docs/windows-host) |
|
||||||
|
|
||||||
`punktfunk-host` is the streaming host; `punktfunk-web` is the browser console (pairing + status).
|
`punktfunk-host` is the streaming host; `punktfunk-web` is the browser console (pairing + status).
|
||||||
After install, run `punktfunk-host serve` inside your desktop session (the secure native default;
|
After install, run `punktfunk-host serve` inside your desktop session (the secure native default;
|
||||||
@@ -113,7 +125,7 @@ and the [docs site](https://docs.punktfunk.unom.io).
|
|||||||
```
|
```
|
||||||
crates/
|
crates/
|
||||||
punktfunk-core/ protocol · FEC · pacing · crypto · QUIC control plane — the C ABI (lib + cdylib + staticlib)
|
punktfunk-core/ protocol · FEC · pacing · crypto · QUIC control plane — the C ABI (lib + cdylib + staticlib)
|
||||||
punktfunk-host/ Linux host: virtual displays · capture · encode · input · GameStream · punktfunk/1 · mgmt
|
punktfunk-host/ the host (Linux + Windows): virtual displays · capture · encode · input · GameStream · punktfunk/1 · mgmt
|
||||||
clients/
|
clients/
|
||||||
apple/ macOS / iOS / tvOS app (Swift · VideoToolbox · Metal · GameController)
|
apple/ macOS / iOS / tvOS app (Swift · VideoToolbox · Metal · GameController)
|
||||||
linux/ Linux desktop app (Rust · GTK4/libadwaita · FFmpeg/VAAPI · PipeWire · SDL3)
|
linux/ Linux desktop app (Rust · GTK4/libadwaita · FFmpeg/VAAPI · PipeWire · SDL3)
|
||||||
@@ -124,7 +136,7 @@ clients/
|
|||||||
web/ web console (TanStack) over the management API — status · devices · pairing
|
web/ web console (TanStack) over the management API — status · devices · pairing
|
||||||
packaging/ apt · rpm / COPR · Arch · Flatpak · Bazzite bootc image
|
packaging/ apt · rpm / COPR · Arch · Flatpak · Bazzite bootc image
|
||||||
docs-site/ public documentation site (Fumadocs) — https://docs.punktfunk.unom.io
|
docs-site/ public documentation site (Fumadocs) — https://docs.punktfunk.unom.io
|
||||||
docs/ design notes & deep-dive plans
|
design/ design notes & deep-dive plans (index: design/README.md)
|
||||||
include/punktfunk_core.h cbindgen-generated C header (checked in)
|
include/punktfunk_core.h cbindgen-generated C header (checked in)
|
||||||
tools/ latency-probe · loss-harness (measurement)
|
tools/ latency-probe · loss-harness (measurement)
|
||||||
```
|
```
|
||||||
@@ -143,4 +155,31 @@ tools/ latency-probe · loss-harness (measurement)
|
|||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
MIT OR Apache-2.0.
|
Licensed under either of
|
||||||
|
|
||||||
|
- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or
|
||||||
|
<https://www.apache.org/licenses/LICENSE-2.0>)
|
||||||
|
- MIT license ([LICENSE-MIT](LICENSE-MIT) or <https://opensource.org/licenses/MIT>)
|
||||||
|
|
||||||
|
at your option — `SPDX-License-Identifier: MIT OR Apache-2.0`.
|
||||||
|
|
||||||
|
### Contribution
|
||||||
|
|
||||||
|
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in
|
||||||
|
the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any
|
||||||
|
additional terms or conditions. See [CONTRIBUTING.md](CONTRIBUTING.md).
|
||||||
|
|
||||||
|
### Third-party components
|
||||||
|
|
||||||
|
punktfunk's own source is MIT/Apache-2.0. Shipped binaries additionally link third-party components
|
||||||
|
under their own (permissive) licenses — see [`THIRD-PARTY-NOTICES.txt`](THIRD-PARTY-NOTICES.txt)
|
||||||
|
(regenerate with `scripts/gen-third-party-notices.sh`). The Windows host and client builds also
|
||||||
|
bundle FFmpeg under the **LGPL v2.1+** (dynamically linked, replaceable DLLs; the license text and
|
||||||
|
notice ship in the installed `licenses/` folder).
|
||||||
|
|
||||||
|
### Trademarks
|
||||||
|
|
||||||
|
punktfunk is an independent project and is **not affiliated with, endorsed by, or sponsored by**
|
||||||
|
NVIDIA, Microsoft, Sony, Valve, or the Moonlight project. "GameStream", "Moonlight", "Xbox",
|
||||||
|
"DualSense", "DualShock", and "PlayStation" are trademarks of their respective owners and are used
|
||||||
|
here only to describe interoperability.
|
||||||
|
|||||||
+16154
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,23 @@
|
|||||||
|
THIRD-PARTY SOFTWARE NOTICES
|
||||||
|
============================================================================
|
||||||
|
|
||||||
|
punktfunk (https://git.unom.io/unom/punktfunk) is licensed under MIT OR Apache-2.0.
|
||||||
|
The binaries it ships statically/dynamically link the third-party Rust crates below.
|
||||||
|
Each is distributed under its own permissive license; full texts follow.
|
||||||
|
Generated by `cargo about generate about.hbs` (see about.toml) — do not edit by hand.
|
||||||
|
|
||||||
|
Overview:
|
||||||
|
{{#each overview}}
|
||||||
|
{{name}} ({{id}}): {{count}} crate(s)
|
||||||
|
{{/each}}
|
||||||
|
|
||||||
|
{{#each licenses}}
|
||||||
|
----------------------------------------------------------------------------
|
||||||
|
{{name}} ({{id}})
|
||||||
|
Used by:
|
||||||
|
{{#each used_by}} - {{crate.name}} {{crate.version}}{{#if crate.repository}} ({{crate.repository}}){{/if}}
|
||||||
|
{{/each}}
|
||||||
|
----------------------------------------------------------------------------
|
||||||
|
{{text}}
|
||||||
|
|
||||||
|
{{/each}}
|
||||||
+49
@@ -0,0 +1,49 @@
|
|||||||
|
# cargo-about config — full-fidelity third-party license harvest for CI.
|
||||||
|
#
|
||||||
|
# cargo install cargo-about
|
||||||
|
# cargo about generate about.hbs > THIRD-PARTY-NOTICES.txt # (or use scripts/gen-third-party-notices.sh)
|
||||||
|
#
|
||||||
|
# `accepted` is the allow-list of SPDX licenses permitted in the dependency tree. CI fails if a crate
|
||||||
|
# carries anything not listed here — which is exactly the regression guard we want against a copyleft
|
||||||
|
# dependency silently entering the linked set. All entries
|
||||||
|
# below are permissive / attribution-only; deliberately NO GPL/LGPL/AGPL/MPL-link/SSPL/EPL.
|
||||||
|
#
|
||||||
|
# The dependency-free fallback is scripts/gen-third-party-notices.py (reads the cargo registry cache),
|
||||||
|
# which is what produced the committed baseline when cargo-about is unavailable offline.
|
||||||
|
|
||||||
|
accepted = [
|
||||||
|
"MIT",
|
||||||
|
"MIT-0",
|
||||||
|
"Apache-2.0",
|
||||||
|
"Apache-2.0 WITH LLVM-exception",
|
||||||
|
"BSD-2-Clause",
|
||||||
|
"BSD-3-Clause",
|
||||||
|
"ISC",
|
||||||
|
"Zlib",
|
||||||
|
"0BSD",
|
||||||
|
"BSL-1.0",
|
||||||
|
"Unicode-3.0",
|
||||||
|
"Unicode-DFS-2016",
|
||||||
|
"CDLA-Permissive-2.0",
|
||||||
|
"CC0-1.0",
|
||||||
|
"Unlicense",
|
||||||
|
"WTFPL",
|
||||||
|
"OpenSSL",
|
||||||
|
]
|
||||||
|
|
||||||
|
# cbindgen is MPL-2.0 but it is a BUILD-ONLY codegen tool that never links into a shipped artifact
|
||||||
|
# (its generated header is not a derivative work), so it is excluded from the notices rather than
|
||||||
|
# accepted as a linked license.
|
||||||
|
ignore-build-dependencies = true
|
||||||
|
ignore-dev-dependencies = true
|
||||||
|
|
||||||
|
# r-efi offers an LGPL-2.1-or-later arm but is tri-licensed; take a permissive arm. (It is also
|
||||||
|
# UEFI-target-gated out of every shipped build.)
|
||||||
|
[r-efi.clarify]
|
||||||
|
license = "MIT OR Apache-2.0"
|
||||||
|
|
||||||
|
[ring.clarify]
|
||||||
|
license = "MIT AND ISC AND OpenSSL"
|
||||||
|
|
||||||
|
[aws-lc-sys.clarify]
|
||||||
|
license = "ISC AND Apache-2.0 AND MIT AND BSD-3-Clause AND OpenSSL"
|
||||||
@@ -978,6 +978,309 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/api/v1/stats/capture/live": {
|
||||||
|
"get": {
|
||||||
|
"tags": [
|
||||||
|
"stats"
|
||||||
|
],
|
||||||
|
"summary": "Live in-progress capture",
|
||||||
|
"description": "The full sample time-series of the capture currently recording, for live graphing. `404` when\nnothing is armed.",
|
||||||
|
"operationId": "statsCaptureLive",
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "The in-progress capture (meta + samples so far)",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/Capture"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"401": {
|
||||||
|
"description": "Missing or invalid bearer token",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/ApiError"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"404": {
|
||||||
|
"description": "No capture is currently recording",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/ApiError"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/api/v1/stats/capture/start": {
|
||||||
|
"post": {
|
||||||
|
"tags": [
|
||||||
|
"stats"
|
||||||
|
],
|
||||||
|
"summary": "Start a stats capture",
|
||||||
|
"description": "Arms a new performance-stats capture. Idempotent: if a capture is already running this returns\nthe current status unchanged. While armed, the streaming loops emit aggregated samples (~ every\n1–2 s) into the in-progress capture, readable live via `GET /stats/capture/live`.",
|
||||||
|
"operationId": "statsCaptureStart",
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Capture armed (or already running)",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/StatsStatus"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"401": {
|
||||||
|
"description": "Missing or invalid bearer token",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/ApiError"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/api/v1/stats/capture/status": {
|
||||||
|
"get": {
|
||||||
|
"tags": [
|
||||||
|
"stats"
|
||||||
|
],
|
||||||
|
"summary": "Stats capture status",
|
||||||
|
"description": "Whether a capture is armed, its sample count, and start time. Poll this (e.g. every 2 s) to\ndrive the capture-control UI.",
|
||||||
|
"operationId": "statsCaptureStatus",
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "In-progress capture status (idle when not armed)",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/StatsStatus"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"401": {
|
||||||
|
"description": "Missing or invalid bearer token",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/ApiError"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/api/v1/stats/capture/stop": {
|
||||||
|
"post": {
|
||||||
|
"tags": [
|
||||||
|
"stats"
|
||||||
|
],
|
||||||
|
"summary": "Stop the stats capture",
|
||||||
|
"description": "Disarms the in-progress capture and writes it to disk atomically, returning its summary. If\nnothing was recording, returns `204 No Content`.",
|
||||||
|
"operationId": "statsCaptureStop",
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Capture stopped and saved",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/CaptureMeta"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"204": {
|
||||||
|
"description": "Nothing was recording"
|
||||||
|
},
|
||||||
|
"401": {
|
||||||
|
"description": "Missing or invalid bearer token",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/ApiError"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "Could not write the recording to disk",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/ApiError"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/api/v1/stats/recordings": {
|
||||||
|
"get": {
|
||||||
|
"tags": [
|
||||||
|
"stats"
|
||||||
|
],
|
||||||
|
"summary": "List saved recordings",
|
||||||
|
"description": "Every saved capture's summary (the `meta` head only — not the sample body), newest first.",
|
||||||
|
"operationId": "statsRecordingsList",
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Saved capture summaries, newest first",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/components/schemas/CaptureMeta"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"401": {
|
||||||
|
"description": "Missing or invalid bearer token",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/ApiError"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/api/v1/stats/recordings/{id}": {
|
||||||
|
"get": {
|
||||||
|
"tags": [
|
||||||
|
"stats"
|
||||||
|
],
|
||||||
|
"summary": "Get a saved recording",
|
||||||
|
"description": "The full capture (meta + samples) for `id`, for graphing or download.",
|
||||||
|
"operationId": "statsRecordingGet",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"name": "id",
|
||||||
|
"in": "path",
|
||||||
|
"description": "The recording id (its filename stem)",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "The full capture",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/Capture"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"401": {
|
||||||
|
"description": "Missing or invalid bearer token",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/ApiError"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"404": {
|
||||||
|
"description": "No recording with that id",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/ApiError"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "The recording file is unreadable",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/ApiError"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"delete": {
|
||||||
|
"tags": [
|
||||||
|
"stats"
|
||||||
|
],
|
||||||
|
"summary": "Delete a saved recording",
|
||||||
|
"description": "Removes the recording `id` from disk. `404` if there is no such recording.",
|
||||||
|
"operationId": "statsRecordingDelete",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"name": "id",
|
||||||
|
"in": "path",
|
||||||
|
"description": "The recording id (its filename stem)",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"204": {
|
||||||
|
"description": "Recording deleted"
|
||||||
|
},
|
||||||
|
"401": {
|
||||||
|
"description": "Missing or invalid bearer token",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/ApiError"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"404": {
|
||||||
|
"description": "No recording with that id",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/ApiError"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "Could not delete the recording",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/ApiError"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/api/v1/status": {
|
"/api/v1/status": {
|
||||||
"get": {
|
"get": {
|
||||||
"tags": [
|
"tags": [
|
||||||
@@ -1125,6 +1428,89 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"Capture": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "A full capture: summary + the sample time-series. The wire + on-disk shape.",
|
||||||
|
"required": [
|
||||||
|
"meta",
|
||||||
|
"samples"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"meta": {
|
||||||
|
"$ref": "#/components/schemas/CaptureMeta"
|
||||||
|
},
|
||||||
|
"samples": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/components/schemas/StatsSample"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"CaptureMeta": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "Capture summary — the filename stem plus the negotiated mode/codec/client. Stored at the head\nof each on-disk recording and listed standalone (without the sample body) by\n[`StatsRecorder::list`].",
|
||||||
|
"required": [
|
||||||
|
"id",
|
||||||
|
"started_unix_ms",
|
||||||
|
"duration_ms",
|
||||||
|
"kind",
|
||||||
|
"width",
|
||||||
|
"height",
|
||||||
|
"fps",
|
||||||
|
"codec",
|
||||||
|
"client",
|
||||||
|
"sample_count"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"client": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "Short label / fingerprint prefix, or `\"\"` if unknown."
|
||||||
|
},
|
||||||
|
"codec": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "`\"h264\" | \"hevc\" | \"av1\"`."
|
||||||
|
},
|
||||||
|
"duration_ms": {
|
||||||
|
"type": "integer",
|
||||||
|
"format": "int64",
|
||||||
|
"minimum": 0
|
||||||
|
},
|
||||||
|
"fps": {
|
||||||
|
"type": "integer",
|
||||||
|
"format": "int32",
|
||||||
|
"minimum": 0
|
||||||
|
},
|
||||||
|
"height": {
|
||||||
|
"type": "integer",
|
||||||
|
"format": "int32",
|
||||||
|
"minimum": 0
|
||||||
|
},
|
||||||
|
"id": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "e.g. `\"2026-06-26T20-14-03Z_5120x1440\"` — also the filename stem."
|
||||||
|
},
|
||||||
|
"kind": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "`\"native\" | \"gamestream\"`."
|
||||||
|
},
|
||||||
|
"sample_count": {
|
||||||
|
"type": "integer",
|
||||||
|
"format": "int32",
|
||||||
|
"minimum": 0
|
||||||
|
},
|
||||||
|
"started_unix_ms": {
|
||||||
|
"type": "integer",
|
||||||
|
"format": "int64",
|
||||||
|
"minimum": 0
|
||||||
|
},
|
||||||
|
"width": {
|
||||||
|
"type": "integer",
|
||||||
|
"format": "int32",
|
||||||
|
"minimum": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"CustomEntry": {
|
"CustomEntry": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"description": "A user-added title, persisted in `~/.config/punktfunk/library.json`. Same shape the API\nreturns and the web console edits.",
|
"description": "A user-added title, persisted in `~/.config/punktfunk/library.json`. Same shape the API\nreturns and the web console edits.",
|
||||||
@@ -1595,6 +1981,144 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"StageTiming": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "One pipeline stage's latency in an aggregation window (microseconds).",
|
||||||
|
"required": [
|
||||||
|
"name",
|
||||||
|
"p50_us",
|
||||||
|
"p99_us"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"name": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "`\"capture\" | \"submit\" | \"encode\" | \"packetize\" | \"send\"` (path-dependent)."
|
||||||
|
},
|
||||||
|
"p50_us": {
|
||||||
|
"type": "number",
|
||||||
|
"format": "float"
|
||||||
|
},
|
||||||
|
"p99_us": {
|
||||||
|
"type": "number",
|
||||||
|
"format": "float"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"StatsSample": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "One aggregated sample (~ every 2 s native, ~ every 1 s GameStream).",
|
||||||
|
"required": [
|
||||||
|
"t_ms",
|
||||||
|
"session_id",
|
||||||
|
"stages",
|
||||||
|
"fps",
|
||||||
|
"repeat_fps",
|
||||||
|
"mbps",
|
||||||
|
"bitrate_kbps",
|
||||||
|
"frames_dropped",
|
||||||
|
"packets_dropped",
|
||||||
|
"send_dropped",
|
||||||
|
"fec_recovered"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"bitrate_kbps": {
|
||||||
|
"type": "integer",
|
||||||
|
"format": "int32",
|
||||||
|
"description": "Configured target bitrate.",
|
||||||
|
"minimum": 0
|
||||||
|
},
|
||||||
|
"fec_recovered": {
|
||||||
|
"type": "integer",
|
||||||
|
"format": "int32",
|
||||||
|
"description": "FEC shards recovered this window (delta).",
|
||||||
|
"minimum": 0
|
||||||
|
},
|
||||||
|
"fps": {
|
||||||
|
"type": "number",
|
||||||
|
"format": "float",
|
||||||
|
"description": "Genuine NEW frames/s from the source."
|
||||||
|
},
|
||||||
|
"frames_dropped": {
|
||||||
|
"type": "integer",
|
||||||
|
"format": "int32",
|
||||||
|
"description": "Frames dropped this window (delta).",
|
||||||
|
"minimum": 0
|
||||||
|
},
|
||||||
|
"mbps": {
|
||||||
|
"type": "number",
|
||||||
|
"format": "float",
|
||||||
|
"description": "Transmit goodput (Mb/s)."
|
||||||
|
},
|
||||||
|
"packets_dropped": {
|
||||||
|
"type": "integer",
|
||||||
|
"format": "int32",
|
||||||
|
"description": "Packets dropped this window (receiver-side / reassembler, where known).",
|
||||||
|
"minimum": 0
|
||||||
|
},
|
||||||
|
"repeat_fps": {
|
||||||
|
"type": "number",
|
||||||
|
"format": "float",
|
||||||
|
"description": "Re-encoded holds/s (source-starvation indicator)."
|
||||||
|
},
|
||||||
|
"send_dropped": {
|
||||||
|
"type": "integer",
|
||||||
|
"format": "int32",
|
||||||
|
"description": "Host send-buffer overflow / EAGAIN this window (delta).",
|
||||||
|
"minimum": 0
|
||||||
|
},
|
||||||
|
"session_id": {
|
||||||
|
"type": "integer",
|
||||||
|
"format": "int32",
|
||||||
|
"description": "Disambiguates concurrent sessions (usually constant).",
|
||||||
|
"minimum": 0
|
||||||
|
},
|
||||||
|
"stages": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/components/schemas/StageTiming"
|
||||||
|
},
|
||||||
|
"description": "Ordered pipeline stages for this path."
|
||||||
|
},
|
||||||
|
"t_ms": {
|
||||||
|
"type": "integer",
|
||||||
|
"format": "int64",
|
||||||
|
"description": "Milliseconds since capture start (monotonic; stamped by [`StatsRecorder::push_sample`]).",
|
||||||
|
"minimum": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"StatsStatus": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "Snapshot of the in-progress capture for the management API.",
|
||||||
|
"required": [
|
||||||
|
"armed",
|
||||||
|
"sample_count",
|
||||||
|
"started_unix_ms",
|
||||||
|
"kind"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"armed": {
|
||||||
|
"type": "boolean",
|
||||||
|
"description": "Capture currently running."
|
||||||
|
},
|
||||||
|
"kind": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "Path of the in-progress capture (`\"\"` if idle)."
|
||||||
|
},
|
||||||
|
"sample_count": {
|
||||||
|
"type": "integer",
|
||||||
|
"format": "int32",
|
||||||
|
"description": "Samples in the in-progress capture.",
|
||||||
|
"minimum": 0
|
||||||
|
},
|
||||||
|
"started_unix_ms": {
|
||||||
|
"type": "integer",
|
||||||
|
"format": "int64",
|
||||||
|
"description": "Unix start time of the in-progress capture (`0` if idle).",
|
||||||
|
"minimum": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"StreamInfo": {
|
"StreamInfo": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"description": "RTSP-negotiated stream parameters.",
|
"description": "RTSP-negotiated stream parameters.",
|
||||||
@@ -1696,6 +2220,10 @@
|
|||||||
{
|
{
|
||||||
"name": "library",
|
"name": "library",
|
||||||
"description": "Game library: installed-store titles (Steam) plus user-curated custom entries"
|
"description": "Game library: installed-store titles (Steam) plus user-curated custom entries"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "stats",
|
||||||
|
"description": "Streaming performance-stats capture: arm/stop a recording, read the live + saved time-series for graphing"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<svg width="100%" height="100%" viewBox="0 0 579 298" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">
|
||||||
|
<style>
|
||||||
|
/* Theme-adaptive so the logo stays readable on both light and dark README
|
||||||
|
backgrounds: deep violet (the brand-mark palette) on light, the original
|
||||||
|
light violet on dark. Evaluated by the viewer's color scheme. */
|
||||||
|
.pf-wm { fill: #6c5bf3; }
|
||||||
|
.pf-back { fill: #a79ff8; }
|
||||||
|
.pf-deep { fill: #6c5bf3; }
|
||||||
|
@media (prefers-color-scheme: dark) {
|
||||||
|
.pf-wm { fill: #cec9fb; }
|
||||||
|
.pf-back { fill: #f2f1fe; }
|
||||||
|
.pf-deep { fill: #8c7ef5; }
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<g>
|
||||||
|
<g>
|
||||||
|
<path class="pf-wm" style="fill-rule:nonzero;" d="M21.144,176.635l0,102.687l31.253,0l0,-35.563l73.436,0l0,-23.555l-73.436,0l0,-19.398l77.285,0l0,-24.171l-108.537,0Z"/>
|
||||||
|
<path class="pf-wm" style="fill-rule:nonzero;" d="M136.148,176.635l0,47.264c0.154,16.627 0.154,16.627 0.308,20.014c0.77,15.087 2.463,21.4 7.544,26.634c7.698,8.16 20.014,10.315 59.272,10.315c23.863,0 34.178,-0.616 43.415,-2.463c11.7,-2.463 19.552,-10.623 21.246,-22.323c0.924,-7.236 1.078,-8.929 1.54,-32.176l0,-47.264l-31.253,0l0,47.264c0,2.155 -0.154,7.082 -0.308,10.623c-0.462,9.699 -1.232,12.47 -3.695,15.087c-3.387,3.695 -9.853,4.619 -31.407,4.619c-26.634,0 -32.638,-1.693 -34.332,-9.853c-0.77,-4.157 -0.77,-4.311 -1.078,-20.476l0,-47.264l-31.253,0Z"/>
|
||||||
|
<path class="pf-wm" style="fill-rule:nonzero;" d="M275.938,176.527l0,102.687l31.868,0l-0.77,-76.669l3.387,0l54.038,76.669l54.346,0l0,-102.687l-31.868,0l0.77,76.515l-3.233,0l-53.73,-76.515l-54.808,0Z"/>
|
||||||
|
<path class="pf-wm" style="fill-rule:nonzero;" d="M425.273,176.527l0,102.687l31.253,0l0,-39.258l17.089,0l46.032,39.258l47.418,0l-64.353,-52.344l59.426,-50.959l-47.88,0l-40.644,37.873l-17.089,0l0,-37.257l-31.253,0Z"/>
|
||||||
|
</g>
|
||||||
|
<path class="pf-back" style="fill-rule:nonzero;" d="M65.442,150.143c24.514,0 44.298,-19.784 44.298,-44.298c0,-24.514 -19.784,-44.298 -44.298,-44.298c-24.514,0 -44.298,19.784 -44.298,44.298c0,24.514 19.784,44.298 44.298,44.298Z"/>
|
||||||
|
<path class="pf-deep" style="fill-rule:nonzero;" d="M141.063,92.871c17.334,-17.334 17.334,-45.312 0,-62.647c-17.334,-17.334 -45.312,-17.334 -62.647,-0c-17.334,17.334 -17.334,45.312 0,62.647c17.334,17.334 45.312,17.334 62.647,-0Z"/>
|
||||||
|
<path style="fill:url(#_Linear1);" d="M121.228,104.359c-14.777,3.965 -31.187,0.136 -42.811,-11.488c-11.624,-11.624 -15.453,-28.034 -11.488,-42.811c14.777,-3.965 31.187,-0.136 42.811,11.488c11.624,11.624 15.453,28.034 11.488,42.811Z"/>
|
||||||
|
</g>
|
||||||
|
<defs>
|
||||||
|
<linearGradient id="_Linear1" x1="0" y1="0" x2="1" y2="0" gradientUnits="userSpaceOnUse" gradientTransform="matrix(31.323323,-31.323323,31.323323,31.323323,78.416832,92.870811)">
|
||||||
|
<stop offset="0" style="stop-color:#cec9fb;stop-opacity:0"/>
|
||||||
|
<stop offset="1" style="stop-color:#fcfcff;stop-opacity:1"/>
|
||||||
|
</linearGradient>
|
||||||
|
</defs>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 3.0 KiB |
@@ -11,8 +11,8 @@ machine, trust logic) instead of re-porting it into Kotlin.
|
|||||||
|
|
||||||
| Side | Owns |
|
| Side | Owns |
|
||||||
|------|------|
|
|------|------|
|
||||||
| **Rust** (`clients/android/native` → `libpunktfunk_android.so`) | the JNI seam, `NativeClient` (QUIC control + UDP data plane), AnnexB→`AMediaCodec` decode, Opus+Oboe audio, VK keymap, latency math, trust/pairing |
|
| **Rust** (`clients/android/native` → `libpunktfunk_android.so`) | the JNI seam, `NativeClient` (QUIC control + UDP data plane), AnnexB→`AMediaCodec` decode, Opus+Oboe audio, VK keymap, latency math, trust/pairing, **mDNS discovery** (`mdns-sd`, the same browse the Linux/Windows clients use) |
|
||||||
| **Kotlin** (`clients/android`) | Compose UI (host grid / settings / stream), `SurfaceView` lifecycle, input capture, `NsdManager` discovery, Keystore identity, permissions |
|
| **Kotlin** (`clients/android`) | Compose UI (host grid / settings / stream), `SurfaceView` lifecycle, input capture, the Wi-Fi `MulticastLock` + permission UX, Keystore identity, permissions |
|
||||||
|
|
||||||
The single seam is `io.unom.punktfunk.kit.NativeBridge` ⇄ `Java_io_unom_punktfunk_kit_NativeBridge_*`.
|
The single seam is `io.unom.punktfunk.kit.NativeBridge` ⇄ `Java_io_unom_punktfunk_kit_NativeBridge_*`.
|
||||||
|
|
||||||
@@ -30,7 +30,7 @@ clients/android/native/ Rust cdylib (workspace member) — links punktf
|
|||||||
clients/android/ Gradle project (this dir)
|
clients/android/ Gradle project (this dir)
|
||||||
settings.gradle.kts · build.gradle.kts · gradle.properties · gradlew
|
settings.gradle.kts · build.gradle.kts · gradle.properties · gradlew
|
||||||
app/ :app — Compose UI: Connect / Settings / Stream screens (phone + TV)
|
app/ :app — Compose UI: Connect / Settings / Stream screens (phone + TV)
|
||||||
kit/ :kit — NativeBridge · discovery (NsdManager) · Gamepad · Keymap ·
|
kit/ :kit — NativeBridge · discovery (native mdns-sd, polled) · Gamepad · Keymap ·
|
||||||
security (Keystore identity + known-host store) · cargo-ndk build
|
security (Keystore identity + known-host store) · cargo-ndk build
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -74,7 +74,8 @@ streaming experience:
|
|||||||
- **Audio** — Opus + Oboe playback with a jitter ring, plus mic uplink to the host.
|
- **Audio** — Opus + Oboe playback with a jitter ring, plus mic uplink to the host.
|
||||||
- **Input** — game controllers (buttons + axes) with rumble and HID feedback; D-pad /
|
- **Input** — game controllers (buttons + axes) with rumble and HID feedback; D-pad /
|
||||||
game-controller focus navigation for the couch (TV + phone).
|
game-controller focus navigation for the couch (TV + phone).
|
||||||
- **Discovery & trust** — `NsdManager` mDNS host list, SPAKE2 PIN pairing and TOFU, with a
|
- **Discovery & trust** — native `mdns-sd` mDNS host list (polled over JNI; the same browse the
|
||||||
|
Linux/Windows clients use, not `NsdManager`), SPAKE2 PIN pairing and TOFU, with a
|
||||||
Keystore-wrapped client identity and a known-host store.
|
Keystore-wrapped client identity and a known-host store.
|
||||||
- **UI** — Compose host list / settings / stream screens, Material You theming.
|
- **UI** — Compose host list / settings / stream screens, Material You theming.
|
||||||
- **Shipping** — built for `arm64-v8a` + `x86_64`; published to Google Play (Internal Testing).
|
- **Shipping** — built for `arm64-v8a` + `x86_64`; published to Google Play (Internal Testing).
|
||||||
|
|||||||
@@ -26,7 +26,9 @@ android {
|
|||||||
targetSdk = 36
|
targetSdk = 36
|
||||||
val vCode = (props.getProperty("VERSION_CODE") ?: System.getenv("VERSION_CODE"))
|
val vCode = (props.getProperty("VERSION_CODE") ?: System.getenv("VERSION_CODE"))
|
||||||
versionCode = vCode?.toInt() ?: 1
|
versionCode = vCode?.toInt() ?: 1
|
||||||
versionName = "0.0.2" // bumped for first Play Store release
|
// versionName is the single project version, threaded from CI (a vX.Y.Z release or a
|
||||||
|
// canary string). versionCode stays the monotonic run number (Play rejects regressions).
|
||||||
|
versionName = (props.getProperty("VERSION_NAME") ?: System.getenv("VERSION_NAME")) ?: "0.0.2"
|
||||||
ndk { abiFilters += listOf("arm64-v8a", "x86_64") }
|
ndk { abiFilters += listOf("arm64-v8a", "x86_64") }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,6 +62,10 @@ android {
|
|||||||
|
|
||||||
buildFeatures { compose = true }
|
buildFeatures { compose = true }
|
||||||
|
|
||||||
|
// Roborazzi/Robolectric render Compose on the host JVM (the CI screenshot harness) and need the
|
||||||
|
// merged Android resources + the app's manifest/theme available to the unit tests.
|
||||||
|
testOptions { unitTests { isIncludeAndroidResources = true } }
|
||||||
|
|
||||||
compileOptions {
|
compileOptions {
|
||||||
sourceCompatibility = JavaVersion.VERSION_21
|
sourceCompatibility = JavaVersion.VERSION_21
|
||||||
targetCompatibility = JavaVersion.VERSION_21
|
targetCompatibility = JavaVersion.VERSION_21
|
||||||
@@ -97,4 +103,21 @@ dependencies {
|
|||||||
// Android TV components (we target phone + TV) land in the TV-UI milestone:
|
// Android TV components (we target phone + TV) land in the TV-UI milestone:
|
||||||
// implementation("androidx.tv:tv-material:1.1.0")
|
// implementation("androidx.tv:tv-material:1.1.0")
|
||||||
// The manifest already declares leanback so the scaffold installs on TV.
|
// The manifest already declares leanback so the scaffold installs on TV.
|
||||||
|
|
||||||
|
// --- CI screenshot harness (Roborazzi on the JVM via Robolectric — no emulator/GPU). The
|
||||||
|
// screenshot tests render the real Compose UI with mock state; never load the JNI core, so the
|
||||||
|
// job runs `:app:testDebugUnitTest -PskipRustBuild` (see kit/build.gradle.kts). ---
|
||||||
|
testImplementation(composeBom)
|
||||||
|
testImplementation("androidx.compose.ui:ui-test-junit4")
|
||||||
|
debugImplementation("androidx.compose.ui:ui-test-manifest") // the ComponentActivity test host
|
||||||
|
testImplementation("junit:junit:4.13.2")
|
||||||
|
testImplementation("org.robolectric:robolectric:4.16.1")
|
||||||
|
testImplementation("io.github.takahirom.roborazzi:roborazzi:1.64.0")
|
||||||
|
testImplementation("io.github.takahirom.roborazzi:roborazzi-compose:1.64.0")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Record (write) the screenshots when the unit tests run. These tests exist to GENERATE marketing
|
||||||
|
// images, not to diff goldens, so always capture rather than verify.
|
||||||
|
tasks.withType<Test>().configureEach {
|
||||||
|
systemProperty("roborazzi.test.record", "true")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,11 +4,13 @@
|
|||||||
<!-- punktfunk/1 QUIC/UDP data plane. -->
|
<!-- punktfunk/1 QUIC/UDP data plane. -->
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||||
<!-- mDNS discovery of _punktfunk._udp on the LAN (NsdManager). -->
|
<!-- mDNS discovery of _punktfunk._udp on the LAN (native mdns-sd browse). Requested
|
||||||
|
opportunistically — raw multicast reception needs only the MulticastLock, not this. -->
|
||||||
<uses-permission
|
<uses-permission
|
||||||
android:name="android.permission.NEARBY_WIFI_DEVICES"
|
android:name="android.permission.NEARBY_WIFI_DEVICES"
|
||||||
android:usesPermissionFlags="neverForLocation" />
|
android:usesPermissionFlags="neverForLocation" />
|
||||||
<!-- Hold a MulticastLock while NsdManager discovery runs (OEM Wi-Fi power-save hedge). -->
|
<!-- HostDiscovery holds a MulticastLock while the native mDNS browse runs — raw multicast
|
||||||
|
reception needs it (also an OEM Wi-Fi power-save hedge). -->
|
||||||
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
|
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
|
||||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||||
<!-- Enforced from Android 17 (SDK 37) for ALL local-network traffic incl. the QUIC socket.
|
<!-- Enforced from Android 17 (SDK 37) for ALL local-network traffic incl. the QUIC socket.
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -63,6 +63,7 @@ import androidx.core.content.ContextCompat
|
|||||||
import io.unom.punktfunk.components.EmptyHostsState
|
import io.unom.punktfunk.components.EmptyHostsState
|
||||||
import io.unom.punktfunk.components.HostCard
|
import io.unom.punktfunk.components.HostCard
|
||||||
import io.unom.punktfunk.components.SectionLabel
|
import io.unom.punktfunk.components.SectionLabel
|
||||||
|
import io.unom.punktfunk.kit.Gamepad
|
||||||
import io.unom.punktfunk.kit.NativeBridge
|
import io.unom.punktfunk.kit.NativeBridge
|
||||||
import io.unom.punktfunk.kit.discovery.DiscoveredHost
|
import io.unom.punktfunk.kit.discovery.DiscoveredHost
|
||||||
import io.unom.punktfunk.kit.discovery.HostDiscovery
|
import io.unom.punktfunk.kit.discovery.HostDiscovery
|
||||||
@@ -73,40 +74,64 @@ import io.unom.punktfunk.kit.security.KnownHostStore
|
|||||||
import io.unom.punktfunk.kit.security.obtainIdentity
|
import io.unom.punktfunk.kit.security.obtainIdentity
|
||||||
import io.unom.punktfunk.models.HostStatus
|
import io.unom.punktfunk.models.HostStatus
|
||||||
import io.unom.punktfunk.models.PendingTrust
|
import io.unom.punktfunk.models.PendingTrust
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
|
/** Handshake budget for a normal connect (the prior hardcoded value, now passed explicitly). */
|
||||||
|
private const val CONNECT_TIMEOUT_MS = 10_000
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handshake budget for the no-PIN "request access" connect. Must exceed the host's approval-park
|
||||||
|
* window (~180 s) so a slow operator approval still lands on this same parked connection rather than
|
||||||
|
* timing the client out first. Mirrors the Linux client's 185 s.
|
||||||
|
*/
|
||||||
|
private const val REQUEST_ACCESS_TIMEOUT_MS = 185_000
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A no-PIN "request access" connect in flight — the host being requested (drives the cancelable
|
||||||
|
* "Waiting for approval…" dialog) and a per-attempt flag the Cancel button trips. The connect is a
|
||||||
|
* blocking call with no abort, so Cancel returns the UI immediately and a late result checks
|
||||||
|
* [cancelled] and tears the (possibly just-approved) session down silently rather than navigating.
|
||||||
|
*/
|
||||||
|
private class RequestAccessState(val target: PendingTrust) {
|
||||||
|
val cancelled = AtomicBoolean(false)
|
||||||
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun ConnectScreen(settings: Settings, onConnected: (Long) -> Unit) {
|
fun ConnectScreen(settings: Settings, onConnected: (Long) -> Unit) {
|
||||||
val scope = rememberCoroutineScope()
|
val scope = rememberCoroutineScope()
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
var host by remember { mutableStateOf("") }
|
var host by remember { mutableStateOf("") }
|
||||||
|
var hostName by remember { mutableStateOf("") }
|
||||||
var port by remember { mutableStateOf("9777") }
|
var port by remember { mutableStateOf("9777") }
|
||||||
var connecting by remember { mutableStateOf(false) }
|
var connecting by remember { mutableStateOf(false) }
|
||||||
var status by remember { mutableStateOf<String?>(null) }
|
var status by remember { mutableStateOf<String?>(null) }
|
||||||
// The host streams at exactly this mode; "Native" settings resolve from the device display.
|
// The host streams at exactly this mode; "Native" settings resolve from the device display.
|
||||||
val (w, h, hz) = settings.effectiveMode(context)
|
val (w, h, hz) = settings.effectiveMode(context)
|
||||||
|
|
||||||
// mDNS discovery scoped to this screen; NsdManager callbacks arrive on the main thread, so the
|
// mDNS discovery scoped to this screen, via the native mdns-sd browse (HostDiscovery) — its
|
||||||
// onChange callback can set Compose state directly. (Emulator SLIRP drops multicast → empty.)
|
// onChange fires on the main thread, so it can set Compose state directly. (Emulator SLIRP drops
|
||||||
// NsdManager discovery needs NEARBY_WIFI_DEVICES on Android 13+ (a runtime permission) — without
|
// multicast → empty; that's the network, not the API.) Raw multicast reception only needs the
|
||||||
// it discoverServices silently finds nothing. Request it once, then (re)start discovery on grant.
|
// Wi-Fi MulticastLock (HostDiscovery holds it), NOT NEARBY_WIFI_DEVICES — that gated the old
|
||||||
|
// NsdManager path. We still request NEARBY_WIFI_DEVICES opportunistically (some OEMs filter
|
||||||
|
// multicast without it; harmless where it isn't), but never block discovery on the grant — a
|
||||||
|
// denial used to leave discovery dead forever.
|
||||||
val discovery = remember { HostDiscovery(context) }
|
val discovery = remember { HostDiscovery(context) }
|
||||||
var discovered by remember { mutableStateOf<List<DiscoveredHost>>(emptyList()) }
|
var discovered by remember { mutableStateOf<List<DiscoveredHost>>(emptyList()) }
|
||||||
var nearbyGranted by remember { mutableStateOf(hasNearbyPermission(context)) }
|
|
||||||
val nearbyLauncher = rememberLauncherForActivityResult(
|
val nearbyLauncher = rememberLauncherForActivityResult(
|
||||||
ActivityResultContracts.RequestPermission(),
|
ActivityResultContracts.RequestPermission(),
|
||||||
) { granted -> nearbyGranted = granted }
|
) { _ -> /* best-effort hint; discovery runs regardless of the result */ }
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
if (!nearbyGranted && Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU && !hasNearbyPermission(context)) {
|
||||||
nearbyLauncher.launch(Manifest.permission.NEARBY_WIFI_DEVICES)
|
nearbyLauncher.launch(Manifest.permission.NEARBY_WIFI_DEVICES)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DisposableEffect(nearbyGranted) {
|
DisposableEffect(Unit) {
|
||||||
discovery.onChange = { discovered = it }
|
discovery.onChange = { discovered = it }
|
||||||
if (nearbyGranted) discovery.start()
|
discovery.start()
|
||||||
onDispose {
|
onDispose {
|
||||||
discovery.onChange = null
|
discovery.onChange = null
|
||||||
discovery.stop()
|
discovery.stop()
|
||||||
@@ -124,8 +149,18 @@ fun ConnectScreen(settings: Settings, onConnected: (Long) -> Unit) {
|
|||||||
.onSuccess { identity = it }
|
.onSuccess { identity = it }
|
||||||
.onFailure { status = "Identity unavailable: ${it.message} — re-pair may be required" }
|
.onFailure { status = "Identity unavailable: ${it.message} — re-pair may be required" }
|
||||||
}
|
}
|
||||||
// A trust decision awaiting the user (first-connect TOFU / fp changed / PIN pairing).
|
// A trust decision awaiting the user (first-connect TOFU / fp changed / PIN pairing / the
|
||||||
|
// request-access-or-PIN choice).
|
||||||
var pendingTrust by remember { mutableStateOf<PendingTrust?>(null) }
|
var pendingTrust by remember { mutableStateOf<PendingTrust?>(null) }
|
||||||
|
// A no-PIN "request access" connect in flight (the cancelable "Waiting for approval…" dialog).
|
||||||
|
var awaiting by remember { mutableStateOf<RequestAccessState?>(null) }
|
||||||
|
// A saved host whose label is being edited (the Rename dialog).
|
||||||
|
var renameTarget by remember { mutableStateOf<KnownHost?>(null) }
|
||||||
|
|
||||||
|
// Discovered hosts not already saved — a saved host (paired or TOFU) belongs in "Saved hosts",
|
||||||
|
// not also in "Discovered", so we hide the overlap (matched by fingerprint when both carry it, so
|
||||||
|
// it survives a DHCP address change; else by address:port). Mirrors the Apple client.
|
||||||
|
val discoveredUnsaved = discovered.filter { dh -> savedHosts.none { it.matches(dh) } }
|
||||||
|
|
||||||
// Issue the actual connect with identity + (optional) pin. On a TOFU connect (pinHex null),
|
// Issue the actual connect with identity + (optional) pin. On a TOFU connect (pinHex null),
|
||||||
// pin the fingerprint the host presented (as an unpaired known host) so the next connect goes
|
// pin the fingerprint the host presented (as an unpaired known host) so the next connect goes
|
||||||
@@ -143,12 +178,16 @@ fun ConnectScreen(settings: Settings, onConnected: (Long) -> Unit) {
|
|||||||
// Advertise HDR only when this device's display can present it (else the host sends a
|
// Advertise HDR only when this device's display can present it (else the host sends a
|
||||||
// proper SDR stream rather than PQ the panel would mis-tone-map).
|
// proper SDR stream rather than PQ the panel would mis-tone-map).
|
||||||
val hdrEnabled = displaySupportsHdr(context)
|
val hdrEnabled = displaySupportsHdr(context)
|
||||||
|
// "Automatic" resolves to a concrete pad type from the connected controller's VID/PID
|
||||||
|
// (Android exposes no controller-type enum) — parity with the Linux/Apple clients. An
|
||||||
|
// explicit choice is passed through unchanged.
|
||||||
|
val gamepadPref = Gamepad.resolvePref(settings.gamepad)
|
||||||
val handle = withContext(Dispatchers.IO) {
|
val handle = withContext(Dispatchers.IO) {
|
||||||
NativeBridge.nativeConnect(
|
NativeBridge.nativeConnect(
|
||||||
targetHost, targetPort, w, h, hz,
|
targetHost, targetPort, w, h, hz,
|
||||||
id.certPem, id.privateKeyPem, pinHex ?: "",
|
id.certPem, id.privateKeyPem, pinHex ?: "",
|
||||||
settings.bitrateKbps, settings.compositor, settings.gamepad,
|
settings.bitrateKbps, settings.compositor, gamepadPref,
|
||||||
hdrEnabled,
|
hdrEnabled, settings.audioChannels, CONNECT_TIMEOUT_MS,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
connecting = false
|
connecting = false
|
||||||
@@ -167,14 +206,77 @@ fun ConnectScreen(settings: Settings, onConnected: (Long) -> Unit) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decide pinned-reconnect vs fp-changed vs TOFU vs PIN pairing before connecting. Trust state is
|
// The no-PIN "request access" path (delegated approval): open a normal identified connect that
|
||||||
|
// the host PARKS until the operator clicks Approve in its console/web UI, showing a cancelable
|
||||||
|
// "Waiting for approval…" dialog meanwhile. The SAME connection is admitted on approval (no
|
||||||
|
// reconnect), so on success we record the host as PAIRED — the operator's approval IS the pairing.
|
||||||
|
// The connect can't be aborted, so Cancel returns the UI immediately and a late result is torn
|
||||||
|
// down silently via the per-attempt flag (mirrors the Linux client's request-access flow).
|
||||||
|
fun requestAccess(target: PendingTrust) {
|
||||||
|
val id = identity
|
||||||
|
if (id == null) {
|
||||||
|
status = "Identity not ready yet — try again in a moment"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val req = RequestAccessState(target)
|
||||||
|
awaiting = req
|
||||||
|
connecting = true
|
||||||
|
status = null
|
||||||
|
discovery.stop() // free the Wi-Fi radio before the (parked) stream session
|
||||||
|
scope.launch {
|
||||||
|
val hdrEnabled = displaySupportsHdr(context)
|
||||||
|
val gamepadPref = Gamepad.resolvePref(settings.gamepad)
|
||||||
|
// Pin the advertised fingerprint for a discovered host (defence against an impostor while
|
||||||
|
// we wait); a manually-typed host has none, so trust-on-first-use.
|
||||||
|
val pinHex = target.advertisedFp ?: ""
|
||||||
|
val handle = withContext(Dispatchers.IO) {
|
||||||
|
NativeBridge.nativeConnect(
|
||||||
|
target.host, target.port, w, h, hz,
|
||||||
|
id.certPem, id.privateKeyPem, pinHex,
|
||||||
|
settings.bitrateKbps, settings.compositor, gamepadPref,
|
||||||
|
hdrEnabled, settings.audioChannels, REQUEST_ACCESS_TIMEOUT_MS,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
// Cancelled while we were parked: tear the (possibly just-approved) session down and
|
||||||
|
// don't touch UI a fresh action may now own.
|
||||||
|
if (req.cancelled.get()) {
|
||||||
|
if (handle != 0L) withContext(Dispatchers.IO) { NativeBridge.nativeClose(handle) }
|
||||||
|
return@launch
|
||||||
|
}
|
||||||
|
awaiting = null
|
||||||
|
connecting = false
|
||||||
|
if (handle != 0L) {
|
||||||
|
// Approved — save the host as PAIRED, pinning the fingerprint it presented, so
|
||||||
|
// future connects are silent (exactly like after a PIN ceremony).
|
||||||
|
val fp = NativeBridge.nativeHostFingerprint(handle)
|
||||||
|
if (fp.isNotEmpty()) {
|
||||||
|
knownHostStore.save(KnownHost(target.host, target.port, target.name, fp, paired = true))
|
||||||
|
savedHosts = knownHostStore.all()
|
||||||
|
}
|
||||||
|
onConnected(handle)
|
||||||
|
} else {
|
||||||
|
status = "Request timed out — approve this device in the host's console, then retry."
|
||||||
|
discovery.start()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Decide pinned-reconnect vs fp-changed vs TOFU vs pairing before connecting. Trust state is
|
||||||
// keyed by address:port, so a discovered and a manually-typed connection to the same host share
|
// keyed by address:port, so a discovered and a manually-typed connection to the same host share
|
||||||
// one record. Trust-on-first-use is permitted ONLY when the host advertised pair=optional; a
|
// one record. Trust-on-first-use is permitted ONLY when the host advertised pair=optional; a
|
||||||
// pair=required host, or a manual/unknown-policy host, must pair by PIN.
|
// pair=required host, or a manual/unknown-policy host, must pair — either by no-PIN request
|
||||||
fun connect(targetHost: String, targetPort: Int, dh: DiscoveredHost? = null) {
|
// access (approve in the console) or by the SPAKE2 PIN ceremony.
|
||||||
|
fun connect(
|
||||||
|
targetHost: String,
|
||||||
|
targetPort: Int,
|
||||||
|
dh: DiscoveredHost? = null,
|
||||||
|
manualName: String? = null,
|
||||||
|
) {
|
||||||
val known = knownHostStore.get(targetHost, targetPort)
|
val known = knownHostStore.get(targetHost, targetPort)
|
||||||
val adv = dh?.fingerprint?.lowercase()
|
val adv = dh?.fingerprint?.lowercase()
|
||||||
val name = dh?.name ?: targetHost
|
// Label precedence: a saved host keeps its (possibly user-renamed) name; else the discovered
|
||||||
|
// mDNS name; else the name typed in the Add-host sheet; else the bare address.
|
||||||
|
val name = known?.name ?: dh?.name ?: manualName?.trim()?.takeIf { it.isNotEmpty() } ?: targetHost
|
||||||
when {
|
when {
|
||||||
// Known host whose advertised fp still matches the pin → silent pinned reconnect.
|
// Known host whose advertised fp still matches the pin → silent pinned reconnect.
|
||||||
known != null && (adv == null || adv == known.fpHex) ->
|
known != null && (adv == null || adv == known.fpHex) ->
|
||||||
@@ -186,9 +288,10 @@ fun ConnectScreen(settings: Settings, onConnected: (Long) -> Unit) {
|
|||||||
// clearly labeled, alongside PIN pairing). Smart-cast: this branch ⇒ dh != null.
|
// clearly labeled, alongside PIN pairing). Smart-cast: this branch ⇒ dh != null.
|
||||||
dh?.pairingRequired == false -> pendingTrust =
|
dh?.pairingRequired == false -> pendingTrust =
|
||||||
PendingTrust(targetHost, targetPort, name, dh.fingerprint, PendingTrust.Kind.TRUST_NEW)
|
PendingTrust(targetHost, targetPort, name, dh.fingerprint, PendingTrust.Kind.TRUST_NEW)
|
||||||
// pair=required, or a manual/unknown-policy host → PIN pairing is mandatory.
|
// pair=required, or a manual/unknown-policy host → offer the two ways in: a no-PIN
|
||||||
|
// "request access" (approve in the console) or the SPAKE2 PIN ceremony.
|
||||||
else -> pendingTrust =
|
else -> pendingTrust =
|
||||||
PendingTrust(targetHost, targetPort, name, adv, PendingTrust.Kind.PAIR)
|
PendingTrust(targetHost, targetPort, name, adv, PendingTrust.Kind.REQUEST_ACCESS)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -255,7 +358,7 @@ fun ConnectScreen(settings: Settings, onConnected: (Long) -> Unit) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (savedHosts.isEmpty() && discovered.isEmpty()) {
|
if (savedHosts.isEmpty() && discoveredUnsaved.isEmpty()) {
|
||||||
item(span = { GridItemSpan(maxLineSpan) }) {
|
item(span = { GridItemSpan(maxLineSpan) }) {
|
||||||
EmptyHostsState()
|
EmptyHostsState()
|
||||||
}
|
}
|
||||||
@@ -276,16 +379,17 @@ fun ConnectScreen(settings: Settings, onConnected: (Long) -> Unit) {
|
|||||||
knownHostStore.remove(kh.address, kh.port)
|
knownHostStore.remove(kh.address, kh.port)
|
||||||
savedHosts = knownHostStore.all()
|
savedHosts = knownHostStore.all()
|
||||||
},
|
},
|
||||||
|
onRename = { renameTarget = kh },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (discovered.isNotEmpty()) {
|
if (discoveredUnsaved.isNotEmpty()) {
|
||||||
item(span = { GridItemSpan(maxLineSpan) }) {
|
item(span = { GridItemSpan(maxLineSpan) }) {
|
||||||
Spacer(Modifier.height(12.dp))
|
Spacer(Modifier.height(12.dp))
|
||||||
SectionLabel("Discovered on the network")
|
SectionLabel("Discovered on the network")
|
||||||
}
|
}
|
||||||
items(discovered, key = { "disc-${it.host}-${it.port}" }) { dh ->
|
items(discoveredUnsaved, key = { "disc-${it.host}-${it.port}" }) { dh ->
|
||||||
HostCard(
|
HostCard(
|
||||||
name = dh.name,
|
name = dh.name,
|
||||||
address = "${dh.host}:${dh.port}",
|
address = "${dh.host}:${dh.port}",
|
||||||
@@ -297,9 +401,10 @@ fun ConnectScreen(settings: Settings, onConnected: (Long) -> Unit) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Active-discovery hint: when we're scanning but nothing's turned up yet, show it's
|
// Active-discovery hint: discovery runs whenever this screen is up, so while it's
|
||||||
// working rather than looking idle/empty.
|
// scanning but nothing's turned up yet (and we're not mid-connect), show it's working
|
||||||
if (nearbyGranted && discovered.isEmpty()) {
|
// rather than looking idle/empty.
|
||||||
|
if (!connecting && discovered.isEmpty()) {
|
||||||
item(span = { GridItemSpan(maxLineSpan) }) {
|
item(span = { GridItemSpan(maxLineSpan) }) {
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.fillMaxWidth().padding(vertical = 12.dp),
|
modifier = Modifier.fillMaxWidth().padding(vertical = 12.dp),
|
||||||
@@ -358,6 +463,15 @@ fun ConnectScreen(settings: Settings, onConnected: (Long) -> Unit) {
|
|||||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
)
|
)
|
||||||
Spacer(Modifier.height(20.dp))
|
Spacer(Modifier.height(20.dp))
|
||||||
|
OutlinedTextField(
|
||||||
|
value = hostName,
|
||||||
|
onValueChange = { hostName = it },
|
||||||
|
label = { Text("Name (optional)") },
|
||||||
|
placeholder = { Text("e.g. Living Room") },
|
||||||
|
singleLine = true,
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
)
|
||||||
|
Spacer(Modifier.height(16.dp))
|
||||||
OutlinedTextField(
|
OutlinedTextField(
|
||||||
value = host,
|
value = host,
|
||||||
onValueChange = { host = it },
|
onValueChange = { host = it },
|
||||||
@@ -365,7 +479,7 @@ fun ConnectScreen(settings: Settings, onConnected: (Long) -> Unit) {
|
|||||||
singleLine = true,
|
singleLine = true,
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
)
|
)
|
||||||
Spacer(Modifier.height(8.dp))
|
Spacer(Modifier.height(16.dp))
|
||||||
OutlinedTextField(
|
OutlinedTextField(
|
||||||
value = port,
|
value = port,
|
||||||
onValueChange = { v -> port = v.filter { it.isDigit() }.take(5) },
|
onValueChange = { v -> port = v.filter { it.isDigit() }.take(5) },
|
||||||
@@ -380,9 +494,10 @@ fun ConnectScreen(settings: Settings, onConnected: (Long) -> Unit) {
|
|||||||
onClick = {
|
onClick = {
|
||||||
val h = host.trim()
|
val h = host.trim()
|
||||||
val p = port.toIntOrNull() ?: 9777
|
val p = port.toIntOrNull() ?: 9777
|
||||||
|
val n = hostName
|
||||||
scope.launch { sheetState.hide() }.invokeOnCompletion {
|
scope.launch { sheetState.hide() }.invokeOnCompletion {
|
||||||
showManualSheet = false
|
showManualSheet = false
|
||||||
connect(h, p)
|
connect(h, p, manualName = n)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
@@ -437,6 +552,33 @@ fun ConnectScreen(settings: Settings, onConnected: (Long) -> Unit) {
|
|||||||
TextButton({ pendingTrust = null }) { Text("Cancel") }
|
TextButton({ pendingTrust = null }) { Text("Cancel") }
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
// A fresh pair=required (or manual/unknown-policy) host: offer the two ways in. "Request
|
||||||
|
// access" is the no-PIN path — connect and wait for the operator to click Approve in the
|
||||||
|
// host's console; "Use a PIN…" switches to the SPAKE2 ceremony.
|
||||||
|
PendingTrust.Kind.REQUEST_ACCESS -> AlertDialog(
|
||||||
|
onDismissRequest = { pendingTrust = null },
|
||||||
|
title = { Text("Pairing required") },
|
||||||
|
text = {
|
||||||
|
Column {
|
||||||
|
Text("${pt.host}:${pt.port} requires pairing before it will stream.")
|
||||||
|
Text(
|
||||||
|
"Request access and approve this device in the host's console (or web " +
|
||||||
|
"UI) — no PIN needed. Or pair with the 4-digit PIN the host displays.",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
confirmButton = {
|
||||||
|
TextButton({ pendingTrust = null; requestAccess(pt) }) { Text("Request access") }
|
||||||
|
},
|
||||||
|
dismissButton = {
|
||||||
|
Row {
|
||||||
|
TextButton({ pendingTrust = pt.copy(kind = PendingTrust.Kind.PAIR) }) {
|
||||||
|
Text("Use a PIN…")
|
||||||
|
}
|
||||||
|
TextButton({ pendingTrust = null }) { Text("Cancel") }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
PendingTrust.Kind.PAIR -> {
|
PendingTrust.Kind.PAIR -> {
|
||||||
var pin by remember(pt) { mutableStateOf("") }
|
var pin by remember(pt) { mutableStateOf("") }
|
||||||
var name by remember(pt) { mutableStateOf(Build.MODEL ?: "Android") }
|
var name by remember(pt) { mutableStateOf(Build.MODEL ?: "Android") }
|
||||||
@@ -502,10 +644,95 @@ fun ConnectScreen(settings: Settings, onConnected: (Long) -> Unit) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The no-PIN "request access" wait: the connect is parked on the host until the operator
|
||||||
|
// approves this device. Cancel returns the UI immediately — it trips the per-attempt flag so a
|
||||||
|
// late approval is torn down silently (see requestAccess) and resumes discovery.
|
||||||
|
awaiting?.let { req ->
|
||||||
|
fun cancel() {
|
||||||
|
req.cancelled.set(true)
|
||||||
|
awaiting = null
|
||||||
|
connecting = false
|
||||||
|
discovery.start() // the request may still be pending on the host; keep scanning
|
||||||
|
}
|
||||||
|
AlertDialog(
|
||||||
|
onDismissRequest = { cancel() },
|
||||||
|
title = { Text("Waiting for approval") },
|
||||||
|
text = {
|
||||||
|
val deviceName = Build.MODEL ?: "this device"
|
||||||
|
Column(verticalArrangement = Arrangement.spacedBy(12.dp)) {
|
||||||
|
Row(
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
||||||
|
) {
|
||||||
|
CircularProgressIndicator(modifier = Modifier.size(20.dp), strokeWidth = 2.dp)
|
||||||
|
Text("Approve this device on ${req.target.name}.")
|
||||||
|
}
|
||||||
|
Text(
|
||||||
|
"Open the host's console (or web UI) and approve “$deviceName”. It connects " +
|
||||||
|
"automatically once you approve — no PIN needed.",
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
confirmButton = {},
|
||||||
|
dismissButton = {
|
||||||
|
TextButton(onClick = { cancel() }) { Text("Cancel") }
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rename a saved host's label (discovered hosts are named by mDNS; this is how you give one a
|
||||||
|
// friendly name like "Living Room" after pairing). Keyed by the host so reopening resets the field.
|
||||||
|
renameTarget?.let { kh ->
|
||||||
|
var newName by remember(kh) { mutableStateOf(kh.name) }
|
||||||
|
AlertDialog(
|
||||||
|
onDismissRequest = { renameTarget = null },
|
||||||
|
title = { Text("Rename host") },
|
||||||
|
text = {
|
||||||
|
OutlinedTextField(
|
||||||
|
value = newName,
|
||||||
|
onValueChange = { newName = it },
|
||||||
|
label = { Text("Name") },
|
||||||
|
placeholder = { Text(kh.address) },
|
||||||
|
singleLine = true,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
confirmButton = {
|
||||||
|
TextButton(
|
||||||
|
enabled = newName.isNotBlank(),
|
||||||
|
onClick = {
|
||||||
|
knownHostStore.rename(kh.address, kh.port, newName.trim())
|
||||||
|
savedHosts = knownHostStore.all()
|
||||||
|
renameTarget = null
|
||||||
|
},
|
||||||
|
) { Text("Save") }
|
||||||
|
},
|
||||||
|
dismissButton = {
|
||||||
|
TextButton(onClick = { renameTarget = null }) { Text("Cancel") }
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** NsdManager discovery needs NEARBY_WIFI_DEVICES on API 33+; below that it doesn't apply. */
|
/**
|
||||||
|
* Whether NEARBY_WIFI_DEVICES is held (API 33+; not applicable below). We request it opportunistically
|
||||||
|
* as a multicast-reception hedge on OEMs that filter multicast without it, but discovery (raw mDNS via
|
||||||
|
* the native core + MulticastLock) does not depend on it.
|
||||||
|
*/
|
||||||
fun hasNearbyPermission(context: Context): Boolean =
|
fun hasNearbyPermission(context: Context): Boolean =
|
||||||
Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU ||
|
Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU ||
|
||||||
ContextCompat.checkSelfPermission(context, Manifest.permission.NEARBY_WIFI_DEVICES) ==
|
ContextCompat.checkSelfPermission(context, Manifest.permission.NEARBY_WIFI_DEVICES) ==
|
||||||
PackageManager.PERMISSION_GRANTED
|
PackageManager.PERMISSION_GRANTED
|
||||||
|
|
||||||
|
/**
|
||||||
|
* True when a saved host and a discovered advert are the same machine — matched by certificate
|
||||||
|
* fingerprint when both carry it (so it survives a DHCP address change), else by address:port.
|
||||||
|
* Mirrors the Apple client's `StoredHost.matches`; de-dupes "Discovered" against "Saved hosts".
|
||||||
|
*/
|
||||||
|
private fun KnownHost.matches(dh: DiscoveredHost): Boolean {
|
||||||
|
val advFp = dh.fingerprint?.lowercase()
|
||||||
|
if (!advFp.isNullOrEmpty() && fpHex.isNotEmpty() && fpHex.lowercase() == advFp) return true
|
||||||
|
return address == dh.host && port == dh.port
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package io.unom.punktfunk
|
||||||
|
|
||||||
|
import androidx.activity.compose.BackHandler
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.rememberScrollState
|
||||||
|
import androidx.compose.foundation.verticalScroll
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import androidx.compose.ui.text.font.FontFamily
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Open-source licenses: punktfunk's own license (MIT OR Apache-2.0) plus the third-party software
|
||||||
|
* notices, read from the bundled `THIRD-PARTY-NOTICES.txt` asset (generated by
|
||||||
|
* scripts/gen-third-party-notices.sh). Reached from [SettingsScreen]; Back returns there.
|
||||||
|
*/
|
||||||
|
@Composable
|
||||||
|
fun LicensesScreen(onBack: () -> Unit) {
|
||||||
|
val context = LocalContext.current
|
||||||
|
BackHandler(onBack = onBack)
|
||||||
|
|
||||||
|
val notices = remember {
|
||||||
|
runCatching {
|
||||||
|
context.assets.open("THIRD-PARTY-NOTICES.txt").bufferedReader().use { it.readText() }
|
||||||
|
}.getOrDefault("Third-party notices unavailable.")
|
||||||
|
}
|
||||||
|
val version = remember {
|
||||||
|
runCatching {
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
context.packageManager.getPackageInfo(context.packageName, 0).versionName
|
||||||
|
}.getOrNull()
|
||||||
|
}
|
||||||
|
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.verticalScroll(rememberScrollState())
|
||||||
|
.padding(horizontal = 20.dp, vertical = 24.dp),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(16.dp),
|
||||||
|
) {
|
||||||
|
Text("Open-source licenses", style = MaterialTheme.typography.headlineMedium)
|
||||||
|
if (version != null) {
|
||||||
|
Text(
|
||||||
|
"punktfunk $version",
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Text(
|
||||||
|
"punktfunk is licensed under MIT OR Apache-2.0, at your option. It uses the open-source " +
|
||||||
|
"components below, each under its own license.",
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
notices,
|
||||||
|
style = MaterialTheme.typography.bodySmall.copy(fontFamily = FontFamily.Monospace),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,9 +16,18 @@ data class Settings(
|
|||||||
val bitrateKbps: Int = 0,
|
val bitrateKbps: Int = 0,
|
||||||
val compositor: Int = 0,
|
val compositor: Int = 0,
|
||||||
val gamepad: Int = 0,
|
val gamepad: Int = 0,
|
||||||
|
/** Requested audio channel count: 2 (stereo), 6 (5.1) or 8 (7.1). The host clamps to what it
|
||||||
|
* can capture; the resolved count drives the decoder + AAudio layout. */
|
||||||
|
val audioChannels: Int = 2,
|
||||||
val micEnabled: Boolean = false,
|
val micEnabled: Boolean = false,
|
||||||
/** Show the live stats overlay (FPS / throughput / latency) during a stream. */
|
/** Show the live stats overlay (FPS / throughput / latency) during a stream. */
|
||||||
val statsHudEnabled: Boolean = true,
|
val statsHudEnabled: Boolean = true,
|
||||||
|
/**
|
||||||
|
* Touch input model. `true` (default) = trackpad: the cursor stays put on touch-down and moves
|
||||||
|
* by the finger's relative delta (swipe to nudge, lift and re-swipe to walk it across), tap to
|
||||||
|
* click where it is. `false` = direct pointing: the cursor jumps to the finger (the old behaviour).
|
||||||
|
*/
|
||||||
|
val trackpadMode: Boolean = true,
|
||||||
)
|
)
|
||||||
|
|
||||||
/** Loads/saves [Settings] in the app-private `punktfunk_settings` prefs. */
|
/** Loads/saves [Settings] in the app-private `punktfunk_settings` prefs. */
|
||||||
@@ -33,8 +42,10 @@ class SettingsStore(context: Context) {
|
|||||||
bitrateKbps = prefs.getInt(K_BITRATE, 0),
|
bitrateKbps = prefs.getInt(K_BITRATE, 0),
|
||||||
compositor = prefs.getInt(K_COMPOSITOR, 0),
|
compositor = prefs.getInt(K_COMPOSITOR, 0),
|
||||||
gamepad = prefs.getInt(K_GAMEPAD, 0),
|
gamepad = prefs.getInt(K_GAMEPAD, 0),
|
||||||
|
audioChannels = prefs.getInt(K_AUDIO_CH, 2),
|
||||||
micEnabled = prefs.getBoolean(K_MIC, false),
|
micEnabled = prefs.getBoolean(K_MIC, false),
|
||||||
statsHudEnabled = prefs.getBoolean(K_HUD, true),
|
statsHudEnabled = prefs.getBoolean(K_HUD, true),
|
||||||
|
trackpadMode = prefs.getBoolean(K_TRACKPAD, true),
|
||||||
)
|
)
|
||||||
|
|
||||||
fun save(s: Settings) {
|
fun save(s: Settings) {
|
||||||
@@ -45,8 +56,10 @@ class SettingsStore(context: Context) {
|
|||||||
.putInt(K_BITRATE, s.bitrateKbps)
|
.putInt(K_BITRATE, s.bitrateKbps)
|
||||||
.putInt(K_COMPOSITOR, s.compositor)
|
.putInt(K_COMPOSITOR, s.compositor)
|
||||||
.putInt(K_GAMEPAD, s.gamepad)
|
.putInt(K_GAMEPAD, s.gamepad)
|
||||||
|
.putInt(K_AUDIO_CH, s.audioChannels)
|
||||||
.putBoolean(K_MIC, s.micEnabled)
|
.putBoolean(K_MIC, s.micEnabled)
|
||||||
.putBoolean(K_HUD, s.statsHudEnabled)
|
.putBoolean(K_HUD, s.statsHudEnabled)
|
||||||
|
.putBoolean(K_TRACKPAD, s.trackpadMode)
|
||||||
.apply()
|
.apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,8 +70,10 @@ class SettingsStore(context: Context) {
|
|||||||
const val K_BITRATE = "bitrate_kbps"
|
const val K_BITRATE = "bitrate_kbps"
|
||||||
const val K_COMPOSITOR = "compositor"
|
const val K_COMPOSITOR = "compositor"
|
||||||
const val K_GAMEPAD = "gamepad"
|
const val K_GAMEPAD = "gamepad"
|
||||||
|
const val K_AUDIO_CH = "audio_channels"
|
||||||
const val K_MIC = "mic_enabled"
|
const val K_MIC = "mic_enabled"
|
||||||
const val K_HUD = "stats_hud_enabled"
|
const val K_HUD = "stats_hud_enabled"
|
||||||
|
const val K_TRACKPAD = "trackpad_mode"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,6 +139,13 @@ val REFRESH_OPTIONS = listOf(
|
|||||||
240 to "240 Hz",
|
240 to "240 Hz",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/** (channel count, label). 2 = stereo (default), 6 = 5.1, 8 = 7.1. */
|
||||||
|
val AUDIO_CHANNEL_OPTIONS = listOf(
|
||||||
|
2 to "Stereo",
|
||||||
|
6 to "5.1 Surround",
|
||||||
|
8 to "7.1 Surround",
|
||||||
|
)
|
||||||
|
|
||||||
/** (kbps, label). `0` = host default. */
|
/** (kbps, label). `0` = host default. */
|
||||||
val BITRATE_OPTIONS = listOf(
|
val BITRATE_OPTIONS = listOf(
|
||||||
0 to "Automatic",
|
0 to "Automatic",
|
||||||
@@ -142,9 +164,11 @@ val COMPOSITOR_OPTIONS = listOf(
|
|||||||
"gamescope",
|
"gamescope",
|
||||||
)
|
)
|
||||||
|
|
||||||
/** index = GamepadPref wire byte. */
|
/** index = GamepadPref wire byte (0=Auto 1=Xbox360 2=DualSense 3=XboxOne 4=DualShock4). */
|
||||||
val GAMEPAD_OPTIONS = listOf(
|
val GAMEPAD_OPTIONS = listOf(
|
||||||
"Automatic",
|
"Automatic",
|
||||||
"Xbox 360",
|
"Xbox 360",
|
||||||
"DualSense",
|
"DualSense",
|
||||||
|
"Xbox One",
|
||||||
|
"DualShock 4",
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -5,9 +5,8 @@ import android.content.pm.PackageManager
|
|||||||
import androidx.activity.compose.BackHandler
|
import androidx.activity.compose.BackHandler
|
||||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.compose.foundation.BorderStroke
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Box
|
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.ColumnScope
|
import androidx.compose.foundation.layout.ColumnScope
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
@@ -16,14 +15,14 @@ import androidx.compose.foundation.layout.fillMaxWidth
|
|||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.rememberScrollState
|
import androidx.compose.foundation.rememberScrollState
|
||||||
import androidx.compose.foundation.verticalScroll
|
import androidx.compose.foundation.verticalScroll
|
||||||
import androidx.compose.material.icons.Icons
|
|
||||||
import androidx.compose.material.icons.filled.ArrowDropDown
|
|
||||||
import androidx.compose.material3.DropdownMenu
|
|
||||||
import androidx.compose.material3.DropdownMenuItem
|
import androidx.compose.material3.DropdownMenuItem
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
|
import androidx.compose.material3.ExposedDropdownMenuBox
|
||||||
|
import androidx.compose.material3.ExposedDropdownMenuAnchorType
|
||||||
|
import androidx.compose.material3.ExposedDropdownMenuDefaults
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.OutlinedCard
|
import androidx.compose.material3.OutlinedCard
|
||||||
import androidx.compose.material3.Surface
|
import androidx.compose.material3.OutlinedTextField
|
||||||
import androidx.compose.material3.Switch
|
import androidx.compose.material3.Switch
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
@@ -33,7 +32,6 @@ import androidx.compose.runtime.remember
|
|||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.focus.onFocusChanged
|
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
@@ -47,6 +45,7 @@ import androidx.core.content.ContextCompat
|
|||||||
fun SettingsScreen(initial: Settings, onChange: (Settings) -> Unit, onBack: () -> Unit) {
|
fun SettingsScreen(initial: Settings, onChange: (Settings) -> Unit, onBack: () -> Unit) {
|
||||||
var s by remember { mutableStateOf(initial) }
|
var s by remember { mutableStateOf(initial) }
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
|
var showLicenses by remember { mutableStateOf(false) }
|
||||||
fun update(next: Settings) {
|
fun update(next: Settings) {
|
||||||
s = next
|
s = next
|
||||||
onChange(next)
|
onChange(next)
|
||||||
@@ -59,6 +58,11 @@ fun SettingsScreen(initial: Settings, onChange: (Settings) -> Unit, onBack: () -
|
|||||||
ActivityResultContracts.RequestPermission(),
|
ActivityResultContracts.RequestPermission(),
|
||||||
) { granted -> update(s.copy(micEnabled = granted)) }
|
) { granted -> update(s.copy(micEnabled = granted)) }
|
||||||
|
|
||||||
|
if (showLicenses) {
|
||||||
|
LicensesScreen(onBack = { showLicenses = false })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
@@ -107,6 +111,12 @@ fun SettingsScreen(initial: Settings, onChange: (Settings) -> Unit, onBack: () -
|
|||||||
}
|
}
|
||||||
|
|
||||||
SettingsGroup("Audio") {
|
SettingsGroup("Audio") {
|
||||||
|
SettingDropdown(
|
||||||
|
label = "Audio channels",
|
||||||
|
options = AUDIO_CHANNEL_OPTIONS,
|
||||||
|
selected = s.audioChannels,
|
||||||
|
) { ch -> update(s.copy(audioChannels = ch)) }
|
||||||
|
|
||||||
ToggleRow(
|
ToggleRow(
|
||||||
title = "Microphone",
|
title = "Microphone",
|
||||||
subtitle = "Send your mic to the host's virtual microphone",
|
subtitle = "Send your mic to the host's virtual microphone",
|
||||||
@@ -122,6 +132,16 @@ fun SettingsScreen(initial: Settings, onChange: (Settings) -> Unit, onBack: () -
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SettingsGroup("Pointer") {
|
||||||
|
ToggleRow(
|
||||||
|
title = "Trackpad mode",
|
||||||
|
subtitle = "Relative cursor like a laptop touchpad — swipe to nudge, tap to click. " +
|
||||||
|
"Off = the cursor jumps to your finger.",
|
||||||
|
checked = s.trackpadMode,
|
||||||
|
onCheckedChange = { on -> update(s.copy(trackpadMode = on)) },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
SettingsGroup("Overlay") {
|
SettingsGroup("Overlay") {
|
||||||
ToggleRow(
|
ToggleRow(
|
||||||
title = "Stats overlay",
|
title = "Stats overlay",
|
||||||
@@ -130,6 +150,14 @@ fun SettingsScreen(initial: Settings, onChange: (Settings) -> Unit, onBack: () -
|
|||||||
onCheckedChange = { on -> update(s.copy(statsHudEnabled = on)) },
|
onCheckedChange = { on -> update(s.copy(statsHudEnabled = on)) },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SettingsGroup("About") {
|
||||||
|
ClickableRow(
|
||||||
|
title = "Open-source licenses",
|
||||||
|
subtitle = "Third-party notices and credits",
|
||||||
|
onClick = { showLicenses = true },
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,12 +202,26 @@ private fun ToggleRow(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** A title + subtitle on the left; the whole row is clickable (opens a sub-screen). */
|
||||||
* A labelled value that opens a menu on click. Uses a clickable [Surface] + [DropdownMenu] rather
|
@Composable
|
||||||
* than `ExposedDropdownMenuBox` — that component's read-only text field traps D-pad / controller
|
private fun ClickableRow(title: String, subtitle: String, onClick: () -> Unit) {
|
||||||
* focus (directional keys never leave it), so you can't navigate past it on a TV. Calls [onSelect]
|
Row(
|
||||||
* on a pick. A primary-colour border marks D-pad focus.
|
modifier = Modifier.fillMaxWidth().clickable(onClick = onClick),
|
||||||
*/
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
) {
|
||||||
|
Column(Modifier.weight(1f)) {
|
||||||
|
Text(title, style = MaterialTheme.typography.bodyLarge)
|
||||||
|
Text(
|
||||||
|
subtitle,
|
||||||
|
style = MaterialTheme.typography.bodySmall,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A labelled read-only dropdown over [options] (value → label); calls [onSelect] on a pick. */
|
||||||
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
private fun <T> SettingDropdown(
|
private fun <T> SettingDropdown(
|
||||||
label: String,
|
label: String,
|
||||||
@@ -188,35 +230,20 @@ private fun <T> SettingDropdown(
|
|||||||
onSelect: (T) -> Unit,
|
onSelect: (T) -> Unit,
|
||||||
) {
|
) {
|
||||||
var expanded by remember { mutableStateOf(false) }
|
var expanded by remember { mutableStateOf(false) }
|
||||||
var focused by remember { mutableStateOf(false) }
|
|
||||||
val selectedLabel = options.firstOrNull { it.first == selected }?.second
|
val selectedLabel = options.firstOrNull { it.first == selected }?.second
|
||||||
?: options.firstOrNull()?.second.orEmpty()
|
?: options.firstOrNull()?.second.orEmpty()
|
||||||
Box(modifier = Modifier.fillMaxWidth()) {
|
ExposedDropdownMenuBox(expanded = expanded, onExpandedChange = { expanded = it }) {
|
||||||
Surface(
|
OutlinedTextField(
|
||||||
onClick = { expanded = true },
|
value = selectedLabel,
|
||||||
shape = MaterialTheme.shapes.small,
|
onValueChange = {},
|
||||||
color = MaterialTheme.colorScheme.surfaceVariant,
|
readOnly = true,
|
||||||
border = if (focused) BorderStroke(2.dp, MaterialTheme.colorScheme.primary) else null,
|
label = { Text(label) },
|
||||||
|
trailingIcon = { ExposedDropdownMenuDefaults.TrailingIcon(expanded = expanded) },
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.menuAnchor(ExposedDropdownMenuAnchorType.PrimaryNotEditable)
|
||||||
.onFocusChanged { focused = it.isFocused },
|
.fillMaxWidth(),
|
||||||
) {
|
)
|
||||||
Row(
|
ExposedDropdownMenu(expanded = expanded, onDismissRequest = { expanded = false }) {
|
||||||
modifier = Modifier.padding(horizontal = 16.dp, vertical = 12.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
) {
|
|
||||||
Column(Modifier.weight(1f)) {
|
|
||||||
Text(
|
|
||||||
label,
|
|
||||||
style = MaterialTheme.typography.labelMedium,
|
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
|
||||||
)
|
|
||||||
Text(selectedLabel, style = MaterialTheme.typography.bodyLarge)
|
|
||||||
}
|
|
||||||
Icon(Icons.Filled.ArrowDropDown, contentDescription = null)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
DropdownMenu(expanded = expanded, onDismissRequest = { expanded = false }) {
|
|
||||||
options.forEach { (value, lbl) ->
|
options.forEach { (value, lbl) ->
|
||||||
DropdownMenuItem(
|
DropdownMenuItem(
|
||||||
text = { Text(lbl) },
|
text = { Text(lbl) },
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ import androidx.compose.ui.Alignment
|
|||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.input.pointer.pointerInput
|
import androidx.compose.ui.input.pointer.pointerInput
|
||||||
import androidx.compose.ui.input.pointer.positionChange
|
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.text.font.FontFamily
|
import androidx.compose.ui.text.font.FontFamily
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
@@ -42,8 +41,25 @@ import io.unom.punktfunk.kit.NativeBridge
|
|||||||
import java.util.concurrent.atomic.AtomicBoolean
|
import java.util.concurrent.atomic.AtomicBoolean
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
|
import kotlin.math.hypot
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
|
// Touch-gesture tuning (px / ms). TAP_SLOP: movement under this still counts as a tap, not a drag.
|
||||||
|
// TAP_DRAG_MS: a new touch within this long after a tap starts a left-button drag. SCROLL_DIV: px of
|
||||||
|
// two-finger pan per wheel notch (smaller = faster scroll).
|
||||||
|
private const val TAP_SLOP = 12f
|
||||||
|
private const val TAP_DRAG_MS = 250L
|
||||||
|
private const val SCROLL_DIV = 4f
|
||||||
|
|
||||||
|
// Trackpad-mode pointer ballistics (relative one-finger motion). POINTER_SENS: base finger-px →
|
||||||
|
// host-px gain (~1:1, never twitchy). The rest is mild acceleration so a flick crosses the screen
|
||||||
|
// while a slow drag stays precise: above ACCEL_SPEED_FLOOR px/ms the gain ramps by ACCEL_GAIN per
|
||||||
|
// px/ms, capped at ACCEL_MAX (so a fast swipe can't fling the cursor uncontrollably).
|
||||||
|
private const val POINTER_SENS = 1.3f
|
||||||
|
private const val ACCEL_GAIN = 0.6f
|
||||||
|
private const val ACCEL_SPEED_FLOOR = 0.3f
|
||||||
|
private const val ACCEL_MAX = 3.0f
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun StreamScreen(handle: Long, micEnabled: Boolean, onDisconnect: () -> Unit) {
|
fun StreamScreen(handle: Long, micEnabled: Boolean, onDisconnect: () -> Unit) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
@@ -62,8 +78,11 @@ fun StreamScreen(handle: Long, micEnabled: Boolean, onDisconnect: () -> Unit) {
|
|||||||
// Live decode stats for the HUD. Poll once a second for the whole stream (cheap, and each call
|
// Live decode stats for the HUD. Poll once a second for the whole stream (cheap, and each call
|
||||||
// drains+resets the native window so it never grows unbounded even while the overlay is hidden);
|
// drains+resets the native window so it never grows unbounded even while the overlay is hidden);
|
||||||
// `showStats` only gates rendering. A 3-finger tap toggles it live; the default comes from Settings.
|
// `showStats` only gates rendering. A 3-finger tap toggles it live; the default comes from Settings.
|
||||||
|
val initialSettings = remember { SettingsStore(context).load() }
|
||||||
var stats by remember { mutableStateOf<DoubleArray?>(null) }
|
var stats by remember { mutableStateOf<DoubleArray?>(null) }
|
||||||
var showStats by remember { mutableStateOf(SettingsStore(context).load().statsHudEnabled) }
|
var showStats by remember { mutableStateOf(initialSettings.statsHudEnabled) }
|
||||||
|
// Touch model is fixed per session (re-keys the gesture handler below if it ever changes).
|
||||||
|
val trackpad = initialSettings.trackpadMode
|
||||||
LaunchedEffect(handle) {
|
LaunchedEffect(handle) {
|
||||||
while (true) {
|
while (true) {
|
||||||
delay(1000)
|
delay(1000)
|
||||||
@@ -139,41 +158,154 @@ fun StreamScreen(handle: Long, micEnabled: Boolean, onDisconnect: () -> Unit) {
|
|||||||
if (showStats) {
|
if (showStats) {
|
||||||
stats?.let { StatsOverlay(it, Modifier.align(Alignment.TopStart).padding(12.dp)) }
|
stats?.let { StatsOverlay(it, Modifier.align(Alignment.TopStart).padding(12.dp)) }
|
||||||
}
|
}
|
||||||
// Touch virtual-trackpad overlay: 1-finger drag → relative mouse move; tap → left click;
|
// Touch → mouse. Two models, chosen by the Trackpad-mode setting:
|
||||||
// 2-finger drag → scroll; 3-finger tap → toggle the stats HUD. (Physical-mouse pointer
|
// • trackpad (default): the cursor STAYS where it is on touch-down and moves by the finger's
|
||||||
// capture comes in a later increment.)
|
// relative delta (MouseMove) with mild pointer acceleration — swipe to nudge, lift and
|
||||||
|
// re-swipe to walk it across, tap to click where it is. This is what makes the cursor
|
||||||
|
// reachable on a small screen.
|
||||||
|
// • direct (opt-out): the cursor jumps to the finger and follows it (MouseMoveAbs,
|
||||||
|
// host-normalized against the overlay size), the old "direct pointing" behaviour.
|
||||||
|
// Both share the same gesture vocabulary: tap = left click; two-finger tap = right click;
|
||||||
|
// two-finger drag = scroll; tap-then-press-and-drag = left-drag (text selection / moving
|
||||||
|
// windows); three-finger tap = toggle the stats HUD.
|
||||||
Box(
|
Box(
|
||||||
Modifier.fillMaxSize().pointerInput(handle) {
|
Modifier.fillMaxSize().pointerInput(handle, trackpad) {
|
||||||
|
var lastTapUp = 0L
|
||||||
|
var lastTapX = 0f
|
||||||
|
var lastTapY = 0f
|
||||||
|
fun moveAbs(x: Float, y: Float) {
|
||||||
|
val sw = size.width
|
||||||
|
val sh = size.height
|
||||||
|
if (sw <= 0 || sh <= 0) return
|
||||||
|
NativeBridge.nativeSendPointerAbs(
|
||||||
|
handle,
|
||||||
|
x.coerceIn(0f, (sw - 1).toFloat()).roundToInt(),
|
||||||
|
y.coerceIn(0f, (sh - 1).toFloat()).roundToInt(),
|
||||||
|
sw,
|
||||||
|
sh,
|
||||||
|
)
|
||||||
|
}
|
||||||
awaitEachGesture {
|
awaitEachGesture {
|
||||||
val first = awaitFirstDown(requireUnconsumed = false)
|
val down = awaitFirstDown(requireUnconsumed = false)
|
||||||
|
val startX = down.position.x
|
||||||
|
val startY = down.position.y
|
||||||
|
// A touch landing just after a quick tap nearby = tap-and-drag: hold the left
|
||||||
|
// button for this whole gesture (laptop-trackpad convention).
|
||||||
|
val isDrag = down.uptimeMillis - lastTapUp < TAP_DRAG_MS &&
|
||||||
|
abs(startX - lastTapX) < TAP_SLOP && abs(startY - lastTapY) < TAP_SLOP
|
||||||
|
lastTapUp = 0L // consume the arming either way
|
||||||
|
// Direct mode jumps the cursor to the finger; trackpad mode leaves it put (the
|
||||||
|
// whole point — you nudge it with swipes instead).
|
||||||
|
if (!trackpad) moveAbs(startX, startY)
|
||||||
|
if (isDrag) NativeBridge.nativeSendPointerButton(handle, 1, true)
|
||||||
|
|
||||||
var moved = false
|
var moved = false
|
||||||
var maxFingers = 1
|
var maxFingers = 1
|
||||||
|
var scrolling = false
|
||||||
|
var prevCx = startX
|
||||||
|
var prevCy = startY
|
||||||
|
var upTime = down.uptimeMillis
|
||||||
|
// Trackpad relative-motion state: the tracked finger, its last position/time, and
|
||||||
|
// the sub-pixel remainder so a slow drag isn't lost to Int truncation.
|
||||||
|
var trackId = down.id
|
||||||
|
var prevX = startX
|
||||||
|
var prevY = startY
|
||||||
|
var prevT = down.uptimeMillis
|
||||||
|
var accX = 0f
|
||||||
|
var accY = 0f
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
val ev = awaitPointerEvent()
|
val ev = awaitPointerEvent()
|
||||||
val fingers = ev.changes.count { it.pressed }
|
val pressed = ev.changes.filter { it.pressed }
|
||||||
if (fingers == 0) break
|
if (pressed.isEmpty()) {
|
||||||
if (fingers > maxFingers) maxFingers = fingers
|
upTime = ev.changes.firstOrNull()?.uptimeMillis ?: upTime
|
||||||
val primary = ev.changes.firstOrNull { it.id == first.id } ?: ev.changes.first()
|
break
|
||||||
val d = primary.positionChange()
|
}
|
||||||
if (abs(d.x) > 0.5f || abs(d.y) > 0.5f) {
|
if (pressed.size > maxFingers) maxFingers = pressed.size
|
||||||
moved = true
|
|
||||||
if (fingers >= 2) {
|
if (pressed.size >= 2) {
|
||||||
// screen +y down → wire +up, so negate y. Coarse divisor; tune live.
|
// Two fingers → scroll by the centroid delta; never move the cursor.
|
||||||
val sy = (-d.y / 4f).toInt()
|
val cx = (pressed.sumOf { it.position.x.toDouble() } / pressed.size).toFloat()
|
||||||
val sx = (d.x / 4f).toInt()
|
val cy = (pressed.sumOf { it.position.y.toDouble() } / pressed.size).toFloat()
|
||||||
if (sy != 0) NativeBridge.nativeSendScroll(handle, 0, sy * 120)
|
if (!scrolling) {
|
||||||
if (sx != 0) NativeBridge.nativeSendScroll(handle, 1, sx * 120)
|
scrolling = true
|
||||||
|
prevCx = cx
|
||||||
|
prevCy = cy
|
||||||
|
}
|
||||||
|
val sy = ((prevCy - cy) / SCROLL_DIV).toInt() // finger up → wheel up
|
||||||
|
val sx = ((cx - prevCx) / SCROLL_DIV).toInt()
|
||||||
|
if (sy != 0) {
|
||||||
|
NativeBridge.nativeSendScroll(handle, 0, sy * 120)
|
||||||
|
prevCy = cy
|
||||||
|
moved = true
|
||||||
|
}
|
||||||
|
if (sx != 0) {
|
||||||
|
NativeBridge.nativeSendScroll(handle, 1, sx * 120)
|
||||||
|
prevCx = cx
|
||||||
|
moved = true
|
||||||
|
}
|
||||||
|
} else if (!scrolling) {
|
||||||
|
// One finger (skipped once a gesture turned into a scroll, so dropping
|
||||||
|
// back to one finger doesn't jerk the cursor).
|
||||||
|
val p = pressed.firstOrNull { it.id == down.id } ?: pressed.first()
|
||||||
|
if (abs(p.position.x - startX) > TAP_SLOP ||
|
||||||
|
abs(p.position.y - startY) > TAP_SLOP
|
||||||
|
) {
|
||||||
|
moved = true
|
||||||
|
}
|
||||||
|
if (trackpad) {
|
||||||
|
// Relative: move by the finger delta × (sensitivity × acceleration),
|
||||||
|
// carrying the sub-pixel remainder. Re-anchor (zero delta this frame)
|
||||||
|
// if the tracked finger changed, so lifting one of several fingers
|
||||||
|
// never jumps the cursor.
|
||||||
|
if (p.id != trackId) {
|
||||||
|
trackId = p.id
|
||||||
|
prevX = p.position.x
|
||||||
|
prevY = p.position.y
|
||||||
|
prevT = p.uptimeMillis
|
||||||
|
}
|
||||||
|
val dx = p.position.x - prevX
|
||||||
|
val dy = p.position.y - prevY
|
||||||
|
val dt = (p.uptimeMillis - prevT).coerceAtLeast(1L)
|
||||||
|
prevX = p.position.x
|
||||||
|
prevY = p.position.y
|
||||||
|
prevT = p.uptimeMillis
|
||||||
|
val speed = hypot(dx, dy) / dt // finger px per ms
|
||||||
|
val accel = (1f + ACCEL_GAIN * (speed - ACCEL_SPEED_FLOOR).coerceAtLeast(0f))
|
||||||
|
.coerceAtMost(ACCEL_MAX)
|
||||||
|
accX += dx * POINTER_SENS * accel
|
||||||
|
accY += dy * POINTER_SENS * accel
|
||||||
|
val outX = accX.toInt() // truncates toward zero → remainder kept w/ sign
|
||||||
|
val outY = accY.toInt()
|
||||||
|
if (outX != 0 || outY != 0) {
|
||||||
|
NativeBridge.nativeSendPointerMove(handle, outX, outY)
|
||||||
|
accX -= outX
|
||||||
|
accY -= outY
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
NativeBridge.nativeSendPointerMove(handle, d.x.toInt(), d.y.toInt())
|
moveAbs(p.position.x, p.position.y) // direct: cursor follows the finger
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ev.changes.forEach { it.consume() }
|
ev.changes.forEach { it.consume() }
|
||||||
}
|
}
|
||||||
if (!moved && maxFingers == 1) {
|
|
||||||
NativeBridge.nativeSendPointerButton(handle, 1, true)
|
if (isDrag) {
|
||||||
NativeBridge.nativeSendPointerButton(handle, 1, false)
|
NativeBridge.nativeSendPointerButton(handle, 1, false) // end the drag
|
||||||
} else if (!moved && maxFingers >= 3) {
|
} else if (!moved) {
|
||||||
showStats = !showStats // quick in-stream HUD toggle
|
when {
|
||||||
|
maxFingers >= 3 -> showStats = !showStats // in-stream HUD toggle
|
||||||
|
maxFingers == 2 -> { // two-finger tap → right click
|
||||||
|
NativeBridge.nativeSendPointerButton(handle, 3, true)
|
||||||
|
NativeBridge.nativeSendPointerButton(handle, 3, false)
|
||||||
|
}
|
||||||
|
else -> { // tap → left click (at the cursor's current spot), arm tap-drag
|
||||||
|
NativeBridge.nativeSendPointerButton(handle, 1, true)
|
||||||
|
NativeBridge.nativeSendPointerButton(handle, 1, false)
|
||||||
|
lastTapUp = upTime
|
||||||
|
lastTapX = startX
|
||||||
|
lastTapY = startY
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -187,7 +319,7 @@ fun StreamScreen(handle: Long, micEnabled: Boolean, onDisconnect: () -> Unit) {
|
|||||||
* `[fps, mbps, latP50Ms, latP95Ms, latValid, skew, w, h, hz, dropped]`.
|
* `[fps, mbps, latP50Ms, latP95Ms, latValid, skew, w, h, hz, dropped]`.
|
||||||
*/
|
*/
|
||||||
@Composable
|
@Composable
|
||||||
private fun StatsOverlay(s: DoubleArray, modifier: Modifier = Modifier) {
|
internal fun StatsOverlay(s: DoubleArray, modifier: Modifier = Modifier) {
|
||||||
if (s.size < 10) return
|
if (s.size < 10) return
|
||||||
val w = s[6].toInt()
|
val w = s[6].toInt()
|
||||||
val h = s[7].toInt()
|
val h = s[7].toInt()
|
||||||
|
|||||||
@@ -10,7 +10,9 @@ import androidx.compose.ui.platform.LocalContext
|
|||||||
|
|
||||||
// punktfunk brand violets (from the app icon: #6C5BF3 / #A79FF8 / #D2C9FB on a #16132A indigo).
|
// punktfunk brand violets (from the app icon: #6C5BF3 / #A79FF8 / #D2C9FB on a #16132A indigo).
|
||||||
// Used as the fallback dark scheme on pre-Android-12 devices; on 12+ we defer to Material You.
|
// Used as the fallback dark scheme on pre-Android-12 devices; on 12+ we defer to Material You.
|
||||||
private val BrandDark = darkColorScheme(
|
// `internal` (not private) so the CI screenshot tests can force the deterministic brand palette —
|
||||||
|
// Material You dynamic colour has no wallpaper to seed from under the Robolectric JVM renderer.
|
||||||
|
internal val BrandDark = darkColorScheme(
|
||||||
primary = Color(0xFFA79FF8),
|
primary = Color(0xFFA79FF8),
|
||||||
onPrimary = Color(0xFF1B1442),
|
onPrimary = Color(0xFF1B1442),
|
||||||
primaryContainer = Color(0xFF4C3FB3),
|
primaryContainer = Color(0xFF4C3FB3),
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ fun SectionLabel(text: String) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* A host as an Apple-style card: a colored letter-avatar, name + address, a trust pill, and (for
|
* A host as an Apple-style card: a colored letter-avatar, name + address, a trust pill, and (for
|
||||||
* saved hosts) an overflow menu with Forget. Tapping the card connects.
|
* saved hosts) an overflow menu with Rename / Forget. Tapping the card connects.
|
||||||
*/
|
*/
|
||||||
@Composable
|
@Composable
|
||||||
fun HostCard(
|
fun HostCard(
|
||||||
@@ -59,6 +59,7 @@ fun HostCard(
|
|||||||
enabled: Boolean,
|
enabled: Boolean,
|
||||||
onConnect: () -> Unit,
|
onConnect: () -> Unit,
|
||||||
onForget: (() -> Unit)?,
|
onForget: (() -> Unit)?,
|
||||||
|
onRename: (() -> Unit)? = null,
|
||||||
) {
|
) {
|
||||||
// D-pad / controller focus highlight: a clickable card is focusable, but the default state
|
// D-pad / controller focus highlight: a clickable card is focusable, but the default state
|
||||||
// layer is too subtle on a TV across a room — draw a clear primary-colour border when focused.
|
// layer is too subtle on a TV across a room — draw a clear primary-colour border when focused.
|
||||||
@@ -106,7 +107,7 @@ fun HostCard(
|
|||||||
StatusPill(status)
|
StatusPill(status)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (onForget != null) {
|
if (onForget != null || onRename != null) {
|
||||||
var menu by remember { mutableStateOf(false) }
|
var menu by remember { mutableStateOf(false) }
|
||||||
Box(modifier = Modifier.align(Alignment.TopEnd)) {
|
Box(modifier = Modifier.align(Alignment.TopEnd)) {
|
||||||
IconButton(enabled = enabled, onClick = { menu = true }) {
|
IconButton(enabled = enabled, onClick = { menu = true }) {
|
||||||
@@ -118,13 +119,24 @@ fun HostCard(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
DropdownMenu(expanded = menu, onDismissRequest = { menu = false }) {
|
DropdownMenu(expanded = menu, onDismissRequest = { menu = false }) {
|
||||||
DropdownMenuItem(
|
if (onRename != null) {
|
||||||
text = { Text("Forget") },
|
DropdownMenuItem(
|
||||||
onClick = {
|
text = { Text("Rename") },
|
||||||
menu = false
|
onClick = {
|
||||||
onForget()
|
menu = false
|
||||||
},
|
onRename()
|
||||||
)
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (onForget != null) {
|
||||||
|
DropdownMenuItem(
|
||||||
|
text = { Text("Forget") },
|
||||||
|
onClick = {
|
||||||
|
menu = false
|
||||||
|
onForget()
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,8 +14,10 @@ enum class Tab(val label: String, val icon: ImageVector) {
|
|||||||
/**
|
/**
|
||||||
* A trust decision awaiting the user before a connect proceeds. [name] is the label to save the
|
* A trust decision awaiting the user before a connect proceeds. [name] is the label to save the
|
||||||
* host under. Trust-on-first-use ([Kind.TRUST_NEW]) is only ever offered when the host ADVERTISED
|
* host under. Trust-on-first-use ([Kind.TRUST_NEW]) is only ever offered when the host ADVERTISED
|
||||||
* pair=optional; a pair=required host or a manually-typed/unknown-policy host goes straight to PIN
|
* pair=optional; a pair=required host or a manually-typed/unknown-policy host is offered the
|
||||||
* pairing ([Kind.PAIR]), and a changed fingerprint forces re-pairing — never a silent re-trust.
|
* two ways in ([Kind.REQUEST_ACCESS]): a no-PIN "request access" connect the operator approves in
|
||||||
|
* the host's console, or the SPAKE2 PIN ceremony ([Kind.PAIR]). A changed fingerprint forces
|
||||||
|
* re-pairing by PIN ([Kind.FP_CHANGED]) — never a silent re-trust.
|
||||||
*/
|
*/
|
||||||
data class PendingTrust(
|
data class PendingTrust(
|
||||||
val host: String,
|
val host: String,
|
||||||
@@ -24,7 +26,7 @@ data class PendingTrust(
|
|||||||
val advertisedFp: String?,
|
val advertisedFp: String?,
|
||||||
val kind: Kind,
|
val kind: Kind,
|
||||||
) {
|
) {
|
||||||
enum class Kind { TRUST_NEW, FP_CHANGED, PAIR }
|
enum class Kind { TRUST_NEW, FP_CHANGED, PAIR, REQUEST_ACCESS }
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Trust state of a host, shown as a colored pill on its card. */
|
/** Trust state of a host, shown as a colored pill on its card. */
|
||||||
|
|||||||
@@ -0,0 +1,74 @@
|
|||||||
|
package io.unom.punktfunk.screenshots
|
||||||
|
|
||||||
|
import androidx.activity.ComponentActivity
|
||||||
|
import androidx.compose.ui.test.junit4.createAndroidComposeRule
|
||||||
|
import androidx.compose.ui.test.onRoot
|
||||||
|
import com.github.takahirom.roborazzi.captureRoboImage
|
||||||
|
import com.github.takahirom.roborazzi.captureScreenRoboImage
|
||||||
|
import org.junit.Rule
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
import org.robolectric.RobolectricTestRunner
|
||||||
|
import org.robolectric.annotation.Config
|
||||||
|
import org.robolectric.annotation.GraphicsMode
|
||||||
|
|
||||||
|
/**
|
||||||
|
* App-store / marketing screenshots of the native Android client, rendered on the JVM by Roborazzi
|
||||||
|
* (Robolectric Native Graphics) — no emulator, GPU, host, or JNI core. The scenes (ShotScenes.kt)
|
||||||
|
* render the REAL Compose UI with mock state.
|
||||||
|
*
|
||||||
|
* `sdk = [36]` is mandatory: Robolectric ships android-all jars only up to API 36 (Android 16), and
|
||||||
|
* the app's compileSdk is 37. PNGs land in build/outputs/roborazzi/.
|
||||||
|
*/
|
||||||
|
@RunWith(RobolectricTestRunner::class)
|
||||||
|
@GraphicsMode(GraphicsMode.Mode.NATIVE)
|
||||||
|
@Config(sdk = [36], qualifiers = "w360dp-h800dp-xxhdpi")
|
||||||
|
class ScreenshotTest {
|
||||||
|
@get:Rule
|
||||||
|
val compose = createAndroidComposeRule<ComponentActivity>()
|
||||||
|
|
||||||
|
private val out = "build/outputs/roborazzi"
|
||||||
|
|
||||||
|
// Pausing the animation clock before composing (then advancing once past the entrance animation
|
||||||
|
// and freezing) is what makes a text-field-bearing scene capturable: a focused field blinks its
|
||||||
|
// cursor via an infinite animation that otherwise keeps Compose perpetually "busy", so
|
||||||
|
// setContent's wait-for-idle never returns. Frozen, the capture is also deterministic.
|
||||||
|
|
||||||
|
/** Full-screen content scenes: the compose root fills the device, so a root capture is the shot. */
|
||||||
|
private fun shootRoot(name: String, content: @androidx.compose.runtime.Composable () -> Unit) {
|
||||||
|
compose.mainClock.autoAdvance = false
|
||||||
|
compose.setContent { ShotTheme(content) }
|
||||||
|
compose.mainClock.advanceTimeBy(800)
|
||||||
|
compose.onRoot().captureRoboImage("$out/phone-$name.png")
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Dialog scenes: the AlertDialog is a separate window, so capture the whole screen (all windows). */
|
||||||
|
private fun shootScreen(name: String, content: @androidx.compose.runtime.Composable () -> Unit) {
|
||||||
|
compose.mainClock.autoAdvance = false
|
||||||
|
compose.setContent { ShotTheme(content) }
|
||||||
|
compose.mainClock.advanceTimeBy(800)
|
||||||
|
captureScreenRoboImage("$out/phone-$name.png")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun hosts() = shootRoot("hosts") { HostsScene() }
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun settings() = shootRoot("settings") { SettingsScene() }
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Config(sdk = [36], qualifiers = "w800dp-h360dp-xxhdpi") // landscape — the stream is immersive
|
||||||
|
fun stream() = shootRoot("stream") { StreamScene() }
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun trust() = shootScreen("trust") {
|
||||||
|
HostsScene()
|
||||||
|
TrustDialog()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun pair() = shootScreen("pair") {
|
||||||
|
HostsScene()
|
||||||
|
PairDialog()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,195 @@
|
|||||||
|
package io.unom.punktfunk.screenshots
|
||||||
|
|
||||||
|
import androidx.compose.foundation.background
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.Box
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.Spacer
|
||||||
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.height
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.lazy.grid.GridCells
|
||||||
|
import androidx.compose.foundation.lazy.grid.GridItemSpan
|
||||||
|
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
|
||||||
|
import androidx.compose.foundation.lazy.grid.items
|
||||||
|
import androidx.compose.material3.AlertDialog
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.Surface
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.TextButton
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.graphics.Brush
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import io.unom.punktfunk.BrandDark
|
||||||
|
import io.unom.punktfunk.Settings
|
||||||
|
import io.unom.punktfunk.SettingsScreen
|
||||||
|
import io.unom.punktfunk.StatsOverlay
|
||||||
|
import io.unom.punktfunk.components.HostCard
|
||||||
|
import io.unom.punktfunk.components.SectionLabel
|
||||||
|
import io.unom.punktfunk.models.HostStatus
|
||||||
|
|
||||||
|
// The CI screenshot scenes: the REAL app composables, fed embedded mock state, under the forced
|
||||||
|
// brand palette (Material You has no wallpaper to seed from on the JVM). The stream-video surface
|
||||||
|
// and ConnectScreen/App are intentionally absent — they require the live JNI core / a session.
|
||||||
|
|
||||||
|
/** Forces the deterministic punktfunk brand scheme (see Theme.kt) instead of dynamic colour. */
|
||||||
|
@Composable
|
||||||
|
internal fun ShotTheme(content: @Composable () -> Unit) {
|
||||||
|
MaterialTheme(colorScheme = BrandDark, content = content)
|
||||||
|
}
|
||||||
|
|
||||||
|
private data class MockHost(val name: String, val address: String, val status: HostStatus)
|
||||||
|
|
||||||
|
private val SAVED = listOf(
|
||||||
|
MockHost("Living Room PC", "192.168.1.42:9777", HostStatus.PAIRED),
|
||||||
|
MockHost("Office", "192.168.1.50:9777", HostStatus.TOFU),
|
||||||
|
)
|
||||||
|
private val DISCOVERED = listOf(
|
||||||
|
MockHost("studio-deck", "192.168.1.61:9777", HostStatus.PAIRING),
|
||||||
|
MockHost("HTPC", "192.168.1.70:9777", HostStatus.TOFU),
|
||||||
|
)
|
||||||
|
|
||||||
|
/** The connect screen's host grid, reconstructed from the real HostCard/SectionLabel components. */
|
||||||
|
@Composable
|
||||||
|
internal fun HostsScene() {
|
||||||
|
Surface(Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background) {
|
||||||
|
LazyVerticalGrid(
|
||||||
|
columns = GridCells.Adaptive(minSize = 160.dp),
|
||||||
|
modifier = Modifier.fillMaxSize(),
|
||||||
|
contentPadding = androidx.compose.foundation.layout.PaddingValues(16.dp),
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(8.dp),
|
||||||
|
) {
|
||||||
|
item(span = { GridItemSpan(maxLineSpan) }) {
|
||||||
|
Column(
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
) {
|
||||||
|
Spacer(Modifier.height(8.dp))
|
||||||
|
Text("Punktfunk", style = MaterialTheme.typography.headlineLarge)
|
||||||
|
Text(
|
||||||
|
"stream a remote desktop",
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
)
|
||||||
|
Spacer(Modifier.height(24.dp))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
item(span = { GridItemSpan(maxLineSpan) }) { SectionLabel("Saved hosts") }
|
||||||
|
items(SAVED) { h ->
|
||||||
|
HostCard(h.name, h.address, h.status, enabled = true, onConnect = {}, onForget = {}, onRename = {})
|
||||||
|
}
|
||||||
|
item(span = { GridItemSpan(maxLineSpan) }) {
|
||||||
|
Spacer(Modifier.height(12.dp))
|
||||||
|
SectionLabel("Discovered on the network")
|
||||||
|
}
|
||||||
|
items(DISCOVERED) { h ->
|
||||||
|
HostCard(h.name, h.address, h.status, enabled = true, onConnect = {}, onForget = null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The real SettingsScreen, fed a representative non-default Settings. */
|
||||||
|
@Composable
|
||||||
|
internal fun SettingsScene() {
|
||||||
|
Surface(Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background) {
|
||||||
|
SettingsScreen(
|
||||||
|
initial = Settings(
|
||||||
|
width = 1920,
|
||||||
|
height = 1080,
|
||||||
|
hz = 120,
|
||||||
|
bitrateKbps = 50_000,
|
||||||
|
compositor = 1,
|
||||||
|
gamepad = 2,
|
||||||
|
micEnabled = true,
|
||||||
|
statsHudEnabled = true,
|
||||||
|
trackpadMode = true,
|
||||||
|
),
|
||||||
|
onChange = {},
|
||||||
|
onBack = {},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The real TOFU AlertDialog (mirrors ConnectScreen's PendingTrust.Kind.TRUST_NEW), shown over the host grid. */
|
||||||
|
@Composable
|
||||||
|
internal fun TrustDialog() {
|
||||||
|
AlertDialog(
|
||||||
|
onDismissRequest = {},
|
||||||
|
title = { Text("Trust this host?") },
|
||||||
|
text = {
|
||||||
|
Column {
|
||||||
|
Text("First connection to 192.168.1.61:9777.")
|
||||||
|
Text("Fingerprint 9f8e7d6c5b4a3928…")
|
||||||
|
Text(
|
||||||
|
"This host allows trust-on-first-use, but that can't tell an impostor " +
|
||||||
|
"from the real host. Pairing with a PIN is stronger — it proves both sides.",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
confirmButton = { TextButton({}) { Text("Trust (TOFU)") } },
|
||||||
|
dismissButton = { TextButton({}) { Text("Pair with PIN…") } },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The PIN-pairing AlertDialog (mirrors ConnectScreen's PendingTrust.Kind.PAIR). The live screen
|
||||||
|
* uses OutlinedTextFields, but a TextField inside a Dialog window never reaches idle under
|
||||||
|
* Robolectric (its focus/cursor machinery animates forever) — so the PIN is shown as a static
|
||||||
|
* display here, which also reads better in a marketing shot. */
|
||||||
|
@Composable
|
||||||
|
internal fun PairDialog() {
|
||||||
|
AlertDialog(
|
||||||
|
onDismissRequest = {},
|
||||||
|
title = { Text("Pair with PIN") },
|
||||||
|
text = {
|
||||||
|
Column {
|
||||||
|
Text("Enter the 4-digit PIN shown on the host.")
|
||||||
|
Spacer(Modifier.height(16.dp))
|
||||||
|
Surface(
|
||||||
|
color = MaterialTheme.colorScheme.surfaceVariant,
|
||||||
|
shape = MaterialTheme.shapes.medium,
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
"4 8 2 7",
|
||||||
|
style = MaterialTheme.typography.headlineMedium,
|
||||||
|
textAlign = TextAlign.Center,
|
||||||
|
modifier = Modifier.fillMaxWidth().padding(vertical = 16.dp),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Spacer(Modifier.height(12.dp))
|
||||||
|
Text(
|
||||||
|
"This device: Pixel 9 Pro",
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
confirmButton = { TextButton({}) { Text("Pair") } },
|
||||||
|
dismissButton = { TextButton({}) { Text("Cancel") } },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The live stats HUD (the real StatsOverlay) over a synthetic "streamed frame" gradient. */
|
||||||
|
@Composable
|
||||||
|
internal fun StreamScene() {
|
||||||
|
Box(
|
||||||
|
Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.background(
|
||||||
|
Brush.linearGradient(listOf(Color(0xFF2A1E5C), Color(0xFF0E1B3D), Color(0xFF06122B))),
|
||||||
|
),
|
||||||
|
) {
|
||||||
|
// [fps, mbps, latP50, latP95, latValid, skew, w, h, hz, dropped]
|
||||||
|
StatsOverlay(
|
||||||
|
doubleArrayOf(238.0, 921.4, 1.3, 2.1, 1.0, 1.0, 5120.0, 1440.0, 240.0, 0.0),
|
||||||
|
Modifier.align(Alignment.TopStart).padding(12.dp),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -99,6 +99,12 @@ val cargoNdkDebug = registerCargoNdk("cargoNdkDebug", release = false)
|
|||||||
val cargoNdkRelease = registerCargoNdk("cargoNdkRelease", release = true)
|
val cargoNdkRelease = registerCargoNdk("cargoNdkRelease", release = true)
|
||||||
|
|
||||||
afterEvaluate {
|
afterEvaluate {
|
||||||
tasks.named("preDebugBuild").configure { dependsOn(cargoNdkDebug) }
|
// `-PskipRustBuild` skips the cargo-ndk native build — for JVM-only tasks (the Roborazzi
|
||||||
tasks.named("preReleaseBuild").configure { dependsOn(cargoNdkRelease) }
|
// screenshot unit tests render Compose on the JVM and never load libpunktfunk_android.so), so
|
||||||
|
// CI/local screenshot runs don't need the Rust toolchain or NDK. The native build stays wired
|
||||||
|
// for every normal APK/AAR build.
|
||||||
|
if (!project.hasProperty("skipRustBuild")) {
|
||||||
|
tasks.named("preDebugBuild").configure { dependsOn(cargoNdkDebug) }
|
||||||
|
tasks.named("preReleaseBuild").configure { dependsOn(cargoNdkRelease) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,6 +44,71 @@ object Gamepad {
|
|||||||
const val AXIS_LT = 4
|
const val AXIS_LT = 4
|
||||||
const val AXIS_RT = 5
|
const val AXIS_RT = 5
|
||||||
|
|
||||||
|
// GamepadPref wire bytes — must equal punktfunk-core `config.rs::GamepadPref::to_u8`.
|
||||||
|
const val PREF_AUTO = 0
|
||||||
|
const val PREF_XBOX360 = 1
|
||||||
|
const val PREF_DUALSENSE = 2
|
||||||
|
const val PREF_XBOXONE = 3
|
||||||
|
const val PREF_DUALSHOCK4 = 4
|
||||||
|
|
||||||
|
// USB vendor ids of the controllers we can identify by VID/PID.
|
||||||
|
private const val VID_SONY = 0x054C
|
||||||
|
private const val VID_MICROSOFT = 0x045E
|
||||||
|
|
||||||
|
// Sony product ids. DualSense (PS5) and DualShock 4 (PS4) map to distinct host pad types.
|
||||||
|
private val PID_DUALSENSE = setOf(0x0CE6, 0x0DF2)
|
||||||
|
private val PID_DUALSHOCK4 = setOf(0x05C4, 0x09CC)
|
||||||
|
|
||||||
|
// Microsoft Xbox One / Series product ids (wired + the common Bluetooth/dongle revisions). All
|
||||||
|
// behave like Xbox 360 on the host minus the glyph identity, so they share one pref byte.
|
||||||
|
private val PID_XBOXONE = setOf(
|
||||||
|
0x02D1, 0x02DD, 0x02E3, 0x02EA, 0x0B00, 0x0B12, 0x0B13, 0x0B20,
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolve a connected controller's [GamepadPref] wire byte from its USB VID/PID, mirroring the
|
||||||
|
* Linux client's `pref_for_type` (SDL3 `GamepadType`) and the Apple client's GameController type
|
||||||
|
* auto-resolution. Android exposes no controller-type enum, so we match `getVendorId()` /
|
||||||
|
* `getProductId()`. Used only when the user picked "Automatic" — an explicit choice is honored as
|
||||||
|
* is. An unrecognized pad (or none) falls back to [PREF_XBOX360], the safe XInput default the
|
||||||
|
* host always supports. Never returns [PREF_AUTO] (the host would then decide) — once we have a
|
||||||
|
* physical pad we resolve it concretely, matching the other native clients.
|
||||||
|
*/
|
||||||
|
fun prefFor(dev: InputDevice?): Int {
|
||||||
|
if (dev == null) return PREF_XBOX360
|
||||||
|
val vid = dev.vendorId
|
||||||
|
val pid = dev.productId
|
||||||
|
return when {
|
||||||
|
vid == VID_SONY && pid in PID_DUALSENSE -> PREF_DUALSENSE
|
||||||
|
vid == VID_SONY && pid in PID_DUALSHOCK4 -> PREF_DUALSHOCK4
|
||||||
|
vid == VID_MICROSOFT && pid in PID_XBOXONE -> PREF_XBOXONE
|
||||||
|
else -> PREF_XBOX360
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** First connected gamepad/joystick [InputDevice], or null when none is attached. */
|
||||||
|
fun firstPad(): InputDevice? {
|
||||||
|
for (id in InputDevice.getDeviceIds()) {
|
||||||
|
val d = InputDevice.getDevice(id) ?: continue
|
||||||
|
val s = d.sources
|
||||||
|
if (s and InputDevice.SOURCE_GAMEPAD == InputDevice.SOURCE_GAMEPAD ||
|
||||||
|
s and InputDevice.SOURCE_JOYSTICK == InputDevice.SOURCE_JOYSTICK
|
||||||
|
) {
|
||||||
|
return d
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The [GamepadPref] wire byte to send for the user's [setting] (the persisted gamepad index). A
|
||||||
|
* non-Auto setting is passed through unchanged; "Automatic" ([PREF_AUTO]) resolves to a concrete
|
||||||
|
* type from the first connected controller via [prefFor] (so the host gets the right pad even
|
||||||
|
* though Android can't tell it the controller type any other way).
|
||||||
|
*/
|
||||||
|
fun resolvePref(setting: Int): Int =
|
||||||
|
if (setting == PREF_AUTO) prefFor(firstPad()) else setting
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gamepad `KEYCODE_*` → BTN_* bit, or 0 if not a gamepad button we forward. A/B/X/Y are
|
* Gamepad `KEYCODE_*` → BTN_* bit, or 0 if not a gamepad button we forward. A/B/X/Y are
|
||||||
* positional (Xbox layout; Nintendo relabeling needs device-type detection, deferred).
|
* positional (Xbox layout; Nintendo relabeling needs device-type detection, deferred).
|
||||||
|
|||||||
@@ -81,8 +81,16 @@ class GamepadFeedback(private val handle: Long) {
|
|||||||
rumbleThread?.interrupt()
|
rumbleThread?.interrupt()
|
||||||
hidoutThread?.interrupt()
|
hidoutThread?.interrupt()
|
||||||
runCatching { vm?.cancel() } // drop any held rumble immediately
|
runCatching { vm?.cancel() } // drop any held rumble immediately
|
||||||
runCatching { rumbleThread?.join(200) }
|
// Join WITHOUT a timeout. These poll threads dereference the native session handle on every
|
||||||
runCatching { hidoutThread?.join(200) }
|
// pull (nativeNextRumble/nativeNextHidout), so they MUST be dead before StreamScreen's
|
||||||
|
// onDispose reaches nativeClose, which frees that handle. A *bounded* join that times out
|
||||||
|
// would let a thread survive into the freed handle → use-after-free SIGSEGV (the
|
||||||
|
// back-while-streaming crash, on the one path the main-thread `closed` guard can't cover).
|
||||||
|
// Safe to block unbounded: the native pulls are internally time-bounded (PULL_TIMEOUT ~100 ms)
|
||||||
|
// and rendering is a quick best-effort binder call, so each thread observes running=false and
|
||||||
|
// exits within ~one timeout — the join returns promptly (well under any ANR threshold).
|
||||||
|
runCatching { rumbleThread?.join() }
|
||||||
|
runCatching { hidoutThread?.join() }
|
||||||
rumbleThread = null
|
rumbleThread = null
|
||||||
hidoutThread = null
|
hidoutThread = null
|
||||||
runCatching { lightsSession?.close() }
|
runCatching { lightsSession?.close() }
|
||||||
@@ -94,18 +102,7 @@ class GamepadFeedback(private val handle: Long) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** First connected gamepad/joystick InputDevice, or null (→ logged no-op on the emulator). */
|
/** First connected gamepad/joystick InputDevice, or null (→ logged no-op on the emulator). */
|
||||||
private fun resolvePad(): InputDevice? {
|
private fun resolvePad(): InputDevice? = Gamepad.firstPad()
|
||||||
for (id in InputDevice.getDeviceIds()) {
|
|
||||||
val d = InputDevice.getDevice(id) ?: continue
|
|
||||||
val s = d.sources
|
|
||||||
if (s and InputDevice.SOURCE_GAMEPAD == InputDevice.SOURCE_GAMEPAD ||
|
|
||||||
s and InputDevice.SOURCE_JOYSTICK == InputDevice.SOURCE_JOYSTICK
|
|
||||||
) {
|
|
||||||
return d
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---- Rumble ----
|
// ---- Rumble ----
|
||||||
|
|
||||||
|
|||||||
@@ -29,8 +29,10 @@ object NativeBridge {
|
|||||||
* trust-on-first-use — read [nativeHostFingerprint] after; else 64-hex host SHA-256, mismatch →
|
* trust-on-first-use — read [nativeHostFingerprint] after; else 64-hex host SHA-256, mismatch →
|
||||||
* `0`). [width]/[height]/[refreshHz] are the requested virtual-output mode (the host streams at
|
* `0`). [width]/[height]/[refreshHz] are the requested virtual-output mode (the host streams at
|
||||||
* exactly this); [bitrateKbps] 0 = host default; [compositorPref]/[gamepadPref] are the
|
* exactly this); [bitrateKbps] 0 = host default; [compositorPref]/[gamepadPref] are the
|
||||||
* `CompositorPref`/`GamepadPref` wire bytes (0 = Auto). Returns an opaque session handle, or `0`
|
* `CompositorPref`/`GamepadPref` wire bytes (0 = Auto). [timeoutMs] is the handshake budget — the
|
||||||
* on failure. Pair with exactly one [nativeClose].
|
* normal path passes a short value, the no-PIN "request access" path a long one (≥ the host's
|
||||||
|
* approval-park window) so a slow operator approval lands on this same parked connection. Returns
|
||||||
|
* an opaque session handle, or `0` on failure. Pair with exactly one [nativeClose].
|
||||||
*/
|
*/
|
||||||
external fun nativeConnect(
|
external fun nativeConnect(
|
||||||
host: String,
|
host: String,
|
||||||
@@ -45,6 +47,8 @@ object NativeBridge {
|
|||||||
compositorPref: Int,
|
compositorPref: Int,
|
||||||
gamepadPref: Int,
|
gamepadPref: Int,
|
||||||
hdrEnabled: Boolean,
|
hdrEnabled: Boolean,
|
||||||
|
audioChannels: Int,
|
||||||
|
timeoutMs: Int,
|
||||||
): Long
|
): Long
|
||||||
|
|
||||||
/** 64-hex SHA-256 of the cert the host presented on [handle]; valid after a successful connect. */
|
/** 64-hex SHA-256 of the cert the host presented on [handle]; valid after a successful connect. */
|
||||||
@@ -67,6 +71,27 @@ object NativeBridge {
|
|||||||
/** Tear down a session handle returned by [nativeConnect]. No-op on `0`. */
|
/** Tear down a session handle returned by [nativeConnect]. No-op on `0`. */
|
||||||
external fun nativeClose(handle: Long)
|
external fun nativeClose(handle: Long)
|
||||||
|
|
||||||
|
// ---- LAN discovery: mDNS browse of `_punktfunk._udp` in Rust (mdns-sd), polled by Kotlin ----
|
||||||
|
// Replaces NsdManager. The caller holds the Wi-Fi MulticastLock for the browse lifetime; raw
|
||||||
|
// multicast *reception* needs it. See io.unom.punktfunk.kit.discovery.HostDiscovery.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start browsing `_punktfunk._udp` on the LAN. Returns an opaque discovery handle, or `0` on
|
||||||
|
* failure. Pair with exactly one [nativeDiscoveryStop]. Cheap + non-blocking (spawns the mDNS
|
||||||
|
* daemon + a fold thread).
|
||||||
|
*/
|
||||||
|
external fun nativeDiscoveryStart(): Long
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The current resolved-host snapshot for [handle]: newline-joined records, each
|
||||||
|
* `key␟name␟addr␟port␟fp␟pair` (`␟` = U+001F). Empty string = no hosts / `0` handle. Poll ~1 Hz;
|
||||||
|
* cheap (a lock + string build), safe to call on the main thread.
|
||||||
|
*/
|
||||||
|
external fun nativeDiscoveryPoll(handle: Long): String
|
||||||
|
|
||||||
|
/** Stop the browse, shut the mDNS daemon down and join its thread. No-op on `0`. */
|
||||||
|
external fun nativeDiscoveryStop(handle: Long)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start the HEVC decode thread rendering onto [surface] (a SurfaceView's surface). Decode runs
|
* Start the HEVC decode thread rendering onto [surface] (a SurfaceView's surface). Decode runs
|
||||||
* entirely in Rust (NDK AMediaCodec → ANativeWindow) — no per-frame JNI. No-op if already started.
|
* entirely in Rust (NDK AMediaCodec → ANativeWindow) — no per-frame JNI. No-op if already started.
|
||||||
@@ -108,6 +133,13 @@ object NativeBridge {
|
|||||||
/** Relative mouse move; dx/dy are device-pixel deltas (screen +y down). */
|
/** Relative mouse move; dx/dy are device-pixel deltas (screen +y down). */
|
||||||
external fun nativeSendPointerMove(handle: Long, dx: Int, dy: Int)
|
external fun nativeSendPointerMove(handle: Long, dx: Int, dy: Int)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Absolute mouse position — the host moves the cursor to (x, y) in a [surfaceWidth]×[surfaceHeight]
|
||||||
|
* pixel space (it normalizes against that size and maps into the output region). Touch
|
||||||
|
* "direct pointing": the cursor jumps to the finger. Parity with the Apple client's absolute touch.
|
||||||
|
*/
|
||||||
|
external fun nativeSendPointerAbs(handle: Long, x: Int, y: Int, surfaceWidth: Int, surfaceHeight: Int)
|
||||||
|
|
||||||
/** One mouse-button transition. button: 1=left 2=middle 3=right 4=X1 5=X2. */
|
/** One mouse-button transition. button: 1=left 2=middle 3=right 4=X1 5=X2. */
|
||||||
external fun nativeSendPointerButton(handle: Long, button: Int, down: Boolean)
|
external fun nativeSendPointerButton(handle: Long, button: Int, down: Boolean)
|
||||||
|
|
||||||
|
|||||||
+88
-138
@@ -1,17 +1,13 @@
|
|||||||
package io.unom.punktfunk.kit.discovery
|
package io.unom.punktfunk.kit.discovery
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.net.nsd.NsdManager
|
|
||||||
import android.net.nsd.NsdServiceInfo
|
|
||||||
import android.net.wifi.WifiManager
|
import android.net.wifi.WifiManager
|
||||||
import android.os.Build
|
import android.os.Handler
|
||||||
|
import android.os.Looper
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import io.unom.punktfunk.kit.NativeBridge
|
||||||
|
|
||||||
private const val TAG = "PunktfunkNsd"
|
private const val TAG = "PunktfunkMdns"
|
||||||
|
|
||||||
/** DNS-SD service type punktfunk hosts advertise (host: `_punktfunk._udp.local.`). */
|
|
||||||
const val PUNKTFUNK_SERVICE_TYPE = "_punktfunk._udp"
|
|
||||||
const val PUNKTFUNK_PROTO = "punktfunk/1"
|
|
||||||
|
|
||||||
/** One resolved host fit for the picker. [key] is the stable dedup id. */
|
/** One resolved host fit for the picker. [key] is the stable dedup id. */
|
||||||
data class DiscoveredHost(
|
data class DiscoveredHost(
|
||||||
@@ -23,165 +19,115 @@ data class DiscoveredHost(
|
|||||||
val pairingRequired: Boolean = false,
|
val pairingRequired: Boolean = false,
|
||||||
)
|
)
|
||||||
|
|
||||||
/** Parsed TXT fields. Pure — unit-testable without Android (see ParseTxtTest). */
|
/** Field separator the native browse uses inside one record (ASCII Unit Separator). */
|
||||||
data class TxtFields(
|
private const val FIELD_SEP = '\u001F'
|
||||||
val proto: String?,
|
|
||||||
val fp: String?,
|
|
||||||
val pair: String?,
|
|
||||||
val id: String?,
|
|
||||||
) {
|
|
||||||
val pairingRequired: Boolean get() = pair == "required"
|
|
||||||
val isPunktfunk: Boolean get() = proto == PUNKTFUNK_PROTO
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pure TXT parser. NSD hands TXT as a `Map<String, ByteArray?>` (a null/empty value = present-but-
|
* Parse one record from [NativeBridge.nativeDiscoveryPoll] (`key␟name␟addr␟port␟fp␟pair`), or null
|
||||||
* empty key). Decode UTF-8; missing keys are null, never an error.
|
* if it's malformed. Pure — unit-tested without Android (see ParseRecordTest). The native side
|
||||||
|
* already applied the protocol gate and address selection, so this is just field marshaling.
|
||||||
*/
|
*/
|
||||||
fun parseTxt(attrs: Map<String, ByteArray?>): TxtFields {
|
fun parseHostRecord(record: String): DiscoveredHost? {
|
||||||
fun s(k: String): String? = attrs[k]?.takeIf { it.isNotEmpty() }?.toString(Charsets.UTF_8)
|
val f = record.split(FIELD_SEP)
|
||||||
return TxtFields(proto = s("proto"), fp = s("fp"), pair = s("pair"), id = s("id"))
|
if (f.size < 6) return null
|
||||||
|
val addr = f[2]
|
||||||
|
val port = f[3].toIntOrNull() ?: return null
|
||||||
|
if (addr.isBlank() || port !in 1..65535) return null
|
||||||
|
return DiscoveredHost(
|
||||||
|
key = f[0].ifBlank { "$addr:$port" },
|
||||||
|
name = f[1].ifBlank { addr },
|
||||||
|
host = addr,
|
||||||
|
port = port,
|
||||||
|
fingerprint = f[4].ifBlank { null },
|
||||||
|
pairingRequired = f[5] == "required",
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Browses `_punktfunk._udp` via NsdManager, resolves each service (the reliable
|
* Browses `_punktfunk._udp` for punktfunk/1 hosts via the native `mdns-sd` core (the same browse the
|
||||||
* `registerServiceInfoCallback` path on API 34+, legacy `resolveService` on 31–33 where its TXT is
|
* Linux/Windows clients use), exposed over JNI — *not* `NsdManager`, whose per-OEM system daemon
|
||||||
* often empty), and pushes the live host set to [onChange] (invoked on the main thread).
|
* made discovery "mostly broken". [start] spins up the native browse and polls it ~1 Hz on the main
|
||||||
|
* thread, pushing the live host set to [onChange] (also on the main thread, only when it changes);
|
||||||
|
* [stop] tears it down.
|
||||||
*
|
*
|
||||||
* Lifecycle: [start] when the picker appears, [stop] when it leaves / on connect — holds a
|
* We hold a Wi-Fi [WifiManager.MulticastLock] for the browse lifetime — raw multicast *reception*
|
||||||
* MulticastLock while running (an OEM Wi-Fi power-save hedge). Note: the Android emulator's SLIRP
|
* needs it. (The Android emulator's SLIRP NAT drops multicast, so on the emulator discovery starts
|
||||||
* NAT drops multicast, so on the emulator discovery starts but never finds a LAN host.
|
* but never finds a LAN host — same as before; that's the network, not the API.)
|
||||||
*/
|
*/
|
||||||
class HostDiscovery(context: Context) {
|
class HostDiscovery(context: Context) {
|
||||||
private val appCtx = context.applicationContext
|
private val appCtx = context.applicationContext
|
||||||
private val nsd = appCtx.getSystemService(Context.NSD_SERVICE) as NsdManager
|
|
||||||
|
|
||||||
/** Invoked on the main thread whenever the resolved host set changes. */
|
/** Invoked on the main thread whenever the resolved host set changes. */
|
||||||
var onChange: ((List<DiscoveredHost>) -> Unit)? = null
|
var onChange: ((List<DiscoveredHost>) -> Unit)? = null
|
||||||
|
|
||||||
private val resolved = LinkedHashMap<String, DiscoveredHost>() // key -> host
|
private val handler = Handler(Looper.getMainLooper())
|
||||||
private var multicastLock: WifiManager.MulticastLock? = null
|
private var multicastLock: WifiManager.MulticastLock? = null
|
||||||
private var discoveryListener: NsdManager.DiscoveryListener? = null
|
private var nativeHandle = 0L
|
||||||
private val infoCallbacks = mutableListOf<NsdManager.ServiceInfoCallback>() // API 34+ registrations
|
|
||||||
private var running = false
|
private var running = false
|
||||||
|
private var last: List<DiscoveredHost> = emptyList()
|
||||||
|
|
||||||
@Synchronized
|
private val poll = object : Runnable {
|
||||||
fun start() {
|
override fun run() {
|
||||||
if (running) return
|
if (!running) return
|
||||||
running = true
|
val hosts = snapshot()
|
||||||
acquireMulticastLock()
|
if (hosts != last) {
|
||||||
val listener = makeDiscoveryListener()
|
last = hosts
|
||||||
discoveryListener = listener
|
onChange?.invoke(hosts)
|
||||||
runCatching {
|
}
|
||||||
nsd.discoverServices(PUNKTFUNK_SERVICE_TYPE, NsdManager.PROTOCOL_DNS_SD, listener)
|
handler.postDelayed(this, POLL_MS)
|
||||||
}.onFailure {
|
|
||||||
Log.e(TAG, "discoverServices failed", it)
|
|
||||||
stop()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Synchronized
|
fun start() {
|
||||||
fun stop() {
|
if (running) return
|
||||||
if (!running) return
|
acquireMulticastLock()
|
||||||
running = false
|
val h = runCatching { NativeBridge.nativeDiscoveryStart() }
|
||||||
discoveryListener?.let { runCatching { nsd.stopServiceDiscovery(it) } }
|
.onFailure { Log.e(TAG, "nativeDiscoveryStart threw", it) }
|
||||||
discoveryListener = null
|
.getOrDefault(0L)
|
||||||
if (Build.VERSION.SDK_INT >= 34) {
|
if (h == 0L) {
|
||||||
for (cb in infoCallbacks) runCatching { nsd.unregisterServiceInfoCallback(cb) }
|
Log.e(TAG, "native mDNS discovery failed to start")
|
||||||
|
releaseMulticastLock()
|
||||||
|
return
|
||||||
}
|
}
|
||||||
infoCallbacks.clear()
|
nativeHandle = h
|
||||||
|
running = true
|
||||||
|
last = emptyList()
|
||||||
|
handler.post(poll)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun stop() {
|
||||||
|
if (!running && nativeHandle == 0L) return
|
||||||
|
running = false
|
||||||
|
handler.removeCallbacks(poll)
|
||||||
|
val h = nativeHandle
|
||||||
|
nativeHandle = 0L
|
||||||
|
if (h != 0L) runCatching { NativeBridge.nativeDiscoveryStop(h) }
|
||||||
|
.onFailure { Log.e(TAG, "nativeDiscoveryStop threw", it) }
|
||||||
releaseMulticastLock()
|
releaseMulticastLock()
|
||||||
resolved.clear()
|
last = emptyList()
|
||||||
onChange?.invoke(emptyList())
|
onChange?.invoke(emptyList())
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun publish() {
|
private fun snapshot(): List<DiscoveredHost> {
|
||||||
onChange?.invoke(resolved.values.sortedBy { it.name.lowercase() })
|
val h = nativeHandle
|
||||||
}
|
if (h == 0L) return emptyList()
|
||||||
|
// getOrNull (not getOrDefault): the JNI returns a platform String!, so a (near-impossible)
|
||||||
private fun makeDiscoveryListener() = object : NsdManager.DiscoveryListener {
|
// native null is a *success* value here — coalesce it so the main-thread poll can't NPE.
|
||||||
override fun onDiscoveryStarted(type: String) {
|
val blob = runCatching { NativeBridge.nativeDiscoveryPoll(h) }
|
||||||
Log.d(TAG, "discovery started: $type")
|
.onFailure { Log.e(TAG, "nativeDiscoveryPoll threw", it) }
|
||||||
}
|
.getOrNull() ?: ""
|
||||||
override fun onDiscoveryStopped(type: String) {
|
if (blob.isEmpty()) return emptyList()
|
||||||
Log.d(TAG, "discovery stopped: $type")
|
return blob.split('\n')
|
||||||
}
|
.filter { it.isNotBlank() }
|
||||||
override fun onStartDiscoveryFailed(type: String, code: Int) {
|
.mapNotNull { parseHostRecord(it) }
|
||||||
Log.e(TAG, "start discovery failed: $code")
|
.associateBy { it.key } // dedup by stable key (id, or addr:port)
|
||||||
runCatching { nsd.stopServiceDiscovery(this) }
|
.values
|
||||||
}
|
.sortedBy { it.name.lowercase() }
|
||||||
override fun onStopDiscoveryFailed(type: String, code: Int) {
|
|
||||||
Log.e(TAG, "stop discovery failed: $code")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onServiceFound(info: NsdServiceInfo) {
|
|
||||||
Log.d(TAG, "found: ${info.serviceName}")
|
|
||||||
resolve(info)
|
|
||||||
}
|
|
||||||
override fun onServiceLost(info: NsdServiceInfo) {
|
|
||||||
Log.d(TAG, "lost: ${info.serviceName}")
|
|
||||||
// onServiceLost carries no TXT, so drop by the instance-name fallback key only.
|
|
||||||
if (resolved.remove(info.serviceName) != null) publish()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun resolve(found: NsdServiceInfo) {
|
|
||||||
if (Build.VERSION.SDK_INT >= 34) resolveViaCallback(found) else resolveViaLegacy(found)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun resolveViaCallback(found: NsdServiceInfo) {
|
|
||||||
val cb = object : NsdManager.ServiceInfoCallback {
|
|
||||||
override fun onServiceUpdated(info: NsdServiceInfo) = ingest(info)
|
|
||||||
override fun onServiceLost() {}
|
|
||||||
override fun onServiceInfoCallbackRegistrationFailed(code: Int) {
|
|
||||||
Log.e(TAG, "ServiceInfoCallback reg failed: $code")
|
|
||||||
}
|
|
||||||
override fun onServiceInfoCallbackUnregistered() {}
|
|
||||||
}
|
|
||||||
runCatching {
|
|
||||||
nsd.registerServiceInfoCallback(found, appCtx.mainExecutor, cb)
|
|
||||||
infoCallbacks.add(cb)
|
|
||||||
}.onFailure { Log.e(TAG, "registerServiceInfoCallback failed", it) }
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun resolveViaLegacy(found: NsdServiceInfo) {
|
|
||||||
// A ResolveListener can't be reused — allocate one per resolve. TXT may be empty pre-34.
|
|
||||||
val listener = object : NsdManager.ResolveListener {
|
|
||||||
override fun onServiceResolved(info: NsdServiceInfo) = ingest(info)
|
|
||||||
override fun onResolveFailed(info: NsdServiceInfo, code: Int) {
|
|
||||||
Log.e(TAG, "resolve failed: $code")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
runCatching { nsd.resolveService(found, listener) }
|
|
||||||
.onFailure { Log.e(TAG, "resolveService failed", it) }
|
|
||||||
}
|
|
||||||
|
|
||||||
@Suppress("DEPRECATION") // info.host is deprecated at API 34 (replaced by hostAddresses)
|
|
||||||
private fun ingest(info: NsdServiceInfo) {
|
|
||||||
val txt = parseTxt(info.attributes)
|
|
||||||
// Reject an incompatible protocol IF the host advertised one; tolerate empty TXT (pre-34).
|
|
||||||
if (txt.proto != null && !txt.isPunktfunk) {
|
|
||||||
Log.d(TAG, "skip non-punktfunk proto=${txt.proto}")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
val ip = (if (Build.VERSION.SDK_INT >= 34) info.hostAddresses.firstOrNull() else info.host)
|
|
||||||
?.hostAddress ?: return
|
|
||||||
val key = txt.id?.takeIf { it.isNotBlank() } ?: info.serviceName
|
|
||||||
resolved[key] = DiscoveredHost(
|
|
||||||
key = key,
|
|
||||||
name = info.serviceName.removeSuffix("."),
|
|
||||||
host = ip,
|
|
||||||
port = info.port,
|
|
||||||
fingerprint = txt.fp,
|
|
||||||
pairingRequired = txt.pairingRequired,
|
|
||||||
)
|
|
||||||
Log.d(TAG, "resolved: ${resolved[key]}")
|
|
||||||
publish()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun acquireMulticastLock() {
|
private fun acquireMulticastLock() {
|
||||||
val wifi = appCtx.getSystemService(Context.WIFI_SERVICE) as WifiManager
|
val wifi = appCtx.getSystemService(Context.WIFI_SERVICE) as WifiManager
|
||||||
multicastLock = wifi.createMulticastLock("punktfunk-nsd").apply {
|
multicastLock = wifi.createMulticastLock("punktfunk-mdns").apply {
|
||||||
setReferenceCounted(true)
|
setReferenceCounted(true)
|
||||||
runCatching { acquire() }
|
runCatching { acquire() }
|
||||||
}
|
}
|
||||||
@@ -191,4 +137,8 @@ class HostDiscovery(context: Context) {
|
|||||||
multicastLock?.takeIf { it.isHeld }?.let { runCatching { it.release() } }
|
multicastLock?.takeIf { it.isHeld }?.let { runCatching { it.release() } }
|
||||||
multicastLock = null
|
multicastLock = null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private companion object {
|
||||||
|
const val POLL_MS = 1000L
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,6 +50,12 @@ class KnownHostStore(context: Context) {
|
|||||||
prefs.edit().remove(key(address, port)).apply()
|
prefs.edit().remove(key(address, port)).apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Set a saved host's display name, keeping its pin + paired flag. No-op if not saved. */
|
||||||
|
fun rename(address: String, port: Int, newName: String) {
|
||||||
|
val h = get(address, port) ?: return
|
||||||
|
save(h.copy(name = newName))
|
||||||
|
}
|
||||||
|
|
||||||
/** All trusted hosts, name-sorted — backs the saved-hosts list. */
|
/** All trusted hosts, name-sorted — backs the saved-hosts list. */
|
||||||
fun all(): List<KnownHost> =
|
fun all(): List<KnownHost> =
|
||||||
prefs.all.values.mapNotNull { (it as? String)?.let(::parse) }.sortedBy { it.name.lowercase() }
|
prefs.all.values.mapNotNull { (it as? String)?.let(::parse) }.sortedBy { it.name.lowercase() }
|
||||||
|
|||||||
+62
@@ -0,0 +1,62 @@
|
|||||||
|
package io.unom.punktfunk.kit.discovery
|
||||||
|
|
||||||
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Assert.assertNull
|
||||||
|
import org.junit.Assert.assertTrue
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pure JVM test of the native-record parser (`key␟name␟addr␟port␟fp␟pair`), the Kotlin half of the
|
||||||
|
* discovery JNI seam. No Android types. Run: `./gradlew :kit:testDebugUnitTest`.
|
||||||
|
*/
|
||||||
|
class ParseRecordTest {
|
||||||
|
private val s = '\u001F' // field separator (must match the Rust side, discovery.rs FIELD_SEP)
|
||||||
|
|
||||||
|
private fun rec(vararg f: String) = f.joinToString(s.toString())
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun parsesFullRecord() {
|
||||||
|
val fp = "a".repeat(64)
|
||||||
|
val h = parseHostRecord(rec("host-123", "home-worker-2", "192.168.1.70", "9777", fp, "required"))!!
|
||||||
|
assertEquals("host-123", h.key)
|
||||||
|
assertEquals("home-worker-2", h.name)
|
||||||
|
assertEquals("192.168.1.70", h.host)
|
||||||
|
assertEquals(9777, h.port)
|
||||||
|
assertEquals(fp, h.fingerprint)
|
||||||
|
assertTrue(h.pairingRequired)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun optionalPairingAndEmptyFingerprint() {
|
||||||
|
val h = parseHostRecord(rec("id", "name", "10.0.0.5", "9777", "", "optional"))!!
|
||||||
|
assertNull(h.fingerprint)
|
||||||
|
assertEquals(false, h.pairingRequired)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun emptyKeyFallsBackToAddrPort() {
|
||||||
|
// Host advertised no `id` TXT → the native side leaves the key blank; we synthesize addr:port.
|
||||||
|
val h = parseHostRecord(rec("", "name", "10.0.0.5", "9777", "", "required"))!!
|
||||||
|
assertEquals("10.0.0.5:9777", h.key)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun emptyNameFallsBackToAddr() {
|
||||||
|
val h = parseHostRecord(rec("k", "", "10.0.0.5", "9777", "", "optional"))!!
|
||||||
|
assertEquals("10.0.0.5", h.name)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun rejectsTooFewFields() {
|
||||||
|
assertNull(parseHostRecord("only${'\u001F'}three${'\u001F'}fields"))
|
||||||
|
assertNull(parseHostRecord(""))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun rejectsBadPortOrAddress() {
|
||||||
|
assertNull(parseHostRecord(rec("k", "n", "10.0.0.5", "notaport", "", "required")))
|
||||||
|
assertNull(parseHostRecord(rec("k", "n", "10.0.0.5", "0", "", "required")))
|
||||||
|
assertNull(parseHostRecord(rec("k", "n", "10.0.0.5", "70000", "", "required")))
|
||||||
|
assertNull(parseHostRecord(rec("k", "n", "", "9777", "", "required")))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
package io.unom.punktfunk.kit.discovery
|
|
||||||
|
|
||||||
import org.junit.Assert.assertEquals
|
|
||||||
import org.junit.Assert.assertFalse
|
|
||||||
import org.junit.Assert.assertNull
|
|
||||||
import org.junit.Assert.assertTrue
|
|
||||||
import org.junit.Test
|
|
||||||
|
|
||||||
/** Pure JVM test of the mDNS TXT parser (no Android types). Run: `./gradlew :kit:testDebugUnitTest`. */
|
|
||||||
class ParseTxtTest {
|
|
||||||
private fun b(s: String): ByteArray = s.toByteArray(Charsets.UTF_8)
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun parsesFullRecord() {
|
|
||||||
val fp = "a".repeat(64)
|
|
||||||
val t = parseTxt(
|
|
||||||
mapOf(
|
|
||||||
"proto" to b("punktfunk/1"),
|
|
||||||
"fp" to b(fp),
|
|
||||||
"pair" to b("required"),
|
|
||||||
"id" to b("host-123"),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
assertEquals("punktfunk/1", t.proto)
|
|
||||||
assertEquals(fp, t.fp)
|
|
||||||
assertEquals("host-123", t.id)
|
|
||||||
assertTrue(t.isPunktfunk)
|
|
||||||
assertTrue(t.pairingRequired)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun optionalPairingAndMissingKeys() {
|
|
||||||
val t = parseTxt(mapOf("proto" to b("punktfunk/1"), "pair" to b("optional")))
|
|
||||||
assertFalse(t.pairingRequired)
|
|
||||||
assertNull(t.fp)
|
|
||||||
assertNull(t.id)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun emptyMapYieldsAllNull() {
|
|
||||||
val t = parseTxt(emptyMap())
|
|
||||||
assertNull(t.proto)
|
|
||||||
assertNull(t.fp)
|
|
||||||
assertNull(t.pair)
|
|
||||||
assertNull(t.id)
|
|
||||||
assertFalse(t.isPunktfunk)
|
|
||||||
assertFalse(t.pairingRequired)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun nullAndEmptyValuesTreatedAsAbsent() {
|
|
||||||
// NSD delivers present-but-empty TXT keys as null / empty ByteArray.
|
|
||||||
val t = parseTxt(mapOf("fp" to null, "id" to ByteArray(0), "proto" to b("punktfunk/1")))
|
|
||||||
assertNull(t.fp)
|
|
||||||
assertNull(t.id)
|
|
||||||
assertTrue(t.isPunktfunk)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun nonPunktfunkProtoIsNotAccepted() {
|
|
||||||
assertFalse(parseTxt(mapOf("proto" to b("moonlight/7"))).isPunktfunk)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -19,6 +19,12 @@ crate-type = ["cdylib"]
|
|||||||
punktfunk-core = { path = "../../../crates/punktfunk-core", features = ["quic"] }
|
punktfunk-core = { path = "../../../crates/punktfunk-core", features = ["quic"] }
|
||||||
jni = "0.21"
|
jni = "0.21"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
|
# LAN host discovery: browse the host's `_punktfunk._udp` mDNS advert — the SAME crate + service the
|
||||||
|
# Linux/Windows clients use (`clients/linux/src/discovery.rs`), replacing Android's per-OEM
|
||||||
|
# `NsdManager` system daemon with one tested browse path. Pure Rust (socket2/if-addrs/mio), so it
|
||||||
|
# cross-compiles to the Android targets AND builds on the host (the JNI seam links into
|
||||||
|
# `cargo build --workspace`). Kotlin keeps only the Wi-Fi `MulticastLock` + permission UX.
|
||||||
|
mdns-sd = "0.20"
|
||||||
|
|
||||||
# Android-only deps. Gated so `cargo build --workspace` on the Linux/macOS dev boxes + CI still
|
# Android-only deps. Gated so `cargo build --workspace` on the Linux/macOS dev boxes + CI still
|
||||||
# compiles this crate (as a host cdylib) — the Android-framework glue (logging now; AMediaCodec via
|
# compiles this crate (as a host cdylib) — the Android-framework glue (logging now; AMediaCodec via
|
||||||
|
|||||||
@@ -1,8 +1,21 @@
|
|||||||
//! Android audio playback (android-only): pull Opus packets from the connector, decode to
|
//! Android audio playback (android-only): pull Opus packets from the connector, decode to
|
||||||
//! interleaved f32 stereo, and feed AAudio (LowLatency) via its realtime data callback through a
|
//! interleaved f32 (stereo or 5.1/7.1 surround), and feed AAudio (LowLatency) via its realtime data
|
||||||
//! jitter ring. Mirrors [`crate::decode`]: one thread we own (the Opus decode producer) plus a
|
//! callback through a jitter ring. Mirrors [`crate::decode`]: one thread we own (the Opus decode
|
||||||
//! shutdown flag; the realtime callback thread is owned by AAudio. Ring logic ported from
|
//! producer) plus a shutdown flag; the realtime callback thread is owned by AAudio.
|
||||||
//! `punktfunk-client-linux/src/audio.rs` (prime ~3 quanta, drop-oldest cap, re-prime on drain).
|
//!
|
||||||
|
//! The layout is the host-RESOLVED channel count (`NativeClient::audio_channels`, negotiated at
|
||||||
|
//! connect), so an older/clamping host that can only capture stereo is decoded + played as stereo.
|
||||||
|
//! 2 = stereo / 6 = 5.1 / 8 = 7.1, in the canonical wire order FL FR FC LFE RL RR SL SR.
|
||||||
|
//!
|
||||||
|
//! The ring started as a port of `punktfunk-client-linux/src/audio.rs`, but AAudio — unlike
|
||||||
|
//! PipeWire, which adaptively rate-matches the stream and absorbs a shallow buffer — hands us a raw
|
||||||
|
//! realtime callback and makes us own the buffer. So this client diverges deliberately to stop the
|
||||||
|
//! Android-only crackle: (1) the callback is allocation/free-free — decoded buffers are recycled to
|
||||||
|
//! the producer via a free-list instead of being freed on the audio thread (Android's Scudo `free`
|
||||||
|
//! has unbounded tail latency); (2) the jitter ring is deeper (~40 ms prime / ~150 ms hard cap) and
|
||||||
|
//! decoupled from the tiny LowLatency burst size, with de-prime hysteresis so a transient drain
|
||||||
|
//! doesn't manufacture a silence; (3) the AAudio HW buffer is primed above its 2-burst default and
|
||||||
|
//! grown on XRuns (Google's anti-glitch technique).
|
||||||
|
|
||||||
use ndk::audio::{
|
use ndk::audio::{
|
||||||
AudioCallbackResult, AudioDirection, AudioFormat, AudioPerformanceMode, AudioSharingMode,
|
AudioCallbackResult, AudioDirection, AudioFormat, AudioPerformanceMode, AudioSharingMode,
|
||||||
@@ -13,16 +26,75 @@ use punktfunk_core::error::PunktfunkError;
|
|||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
use std::ffi::c_void;
|
use std::ffi::c_void;
|
||||||
use std::sync::atomic::{AtomicBool, AtomicU64, Ordering};
|
use std::sync::atomic::{AtomicBool, AtomicU64, Ordering};
|
||||||
use std::sync::mpsc::{sync_channel, SyncSender, TrySendError};
|
use std::sync::mpsc::{sync_channel, Receiver, SyncSender, TrySendError};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
const CHANNELS: usize = 2;
|
|
||||||
const SAMPLE_RATE: i32 = 48_000;
|
const SAMPLE_RATE: i32 = 48_000;
|
||||||
/// Decoded-chunk hand-off depth: 64 × 5 ms = 320 ms slack (matches the core's AUDIO_QUEUE).
|
/// Decoded-chunk hand-off depth: 64 × 5 ms = 320 ms slack (matches the core's AUDIO_QUEUE).
|
||||||
const RING_CHUNKS: usize = 64;
|
const RING_CHUNKS: usize = 64;
|
||||||
/// Opus decode scratch: worst-case 120 ms stereo frame (5760 samples/ch × 2 ch).
|
|
||||||
const PCM_SCRATCH: usize = 5760 * CHANNELS;
|
// --- Jitter-ring depths, in MILLISECONDS (scaled to interleaved-f32 samples at runtime). --------
|
||||||
|
// The channel count is negotiated, not a compile-time const, so these are kept in ms and multiplied
|
||||||
|
// by `ms` (interleaved-f32 samples per millisecond at the resolved layout) inside `start`.
|
||||||
|
// Unlike the Linux client (PipeWire adaptively rate-matches the stream to the graph clock, masking
|
||||||
|
// host↔DAC drift + a shallow ring), AAudio hands us a raw callback and we own the buffer: drift and
|
||||||
|
// WiFi power-save bunching land as underruns/overflows = crackle. So Android runs a deliberately
|
||||||
|
// deeper, smoothly-managed ring than Linux — keep the two clients' depths intentionally divergent.
|
||||||
|
/// Prime/target floor: fill to ~40 ms before playing (and after a sustained drain). Deep enough to
|
||||||
|
/// ride out WiFi arrival jitter + clock drift; the dominant Android-only anti-crackle lever.
|
||||||
|
const PRIME_FLOOR_MS: usize = 40;
|
||||||
|
/// Ceiling for the burst-scaled target (so a large quantum can't push the prime depth too high).
|
||||||
|
const PRIME_CEIL_MS: usize = 80;
|
||||||
|
/// Drop-oldest headroom above the target before trimming — a ~80 ms band swallows an arrival burst
|
||||||
|
/// without overflowing.
|
||||||
|
const JITTER_HEADROOM_MS: usize = 80;
|
||||||
|
/// Hard latency bound: never let the ring exceed ~150 ms (the only thing that caps added latency).
|
||||||
|
const HARD_CAP_MS: usize = 150;
|
||||||
|
/// Re-prime (go silent to refill) only after this many CONSECUTIVE empty callbacks, so one transient
|
||||||
|
/// drain doesn't manufacture a fresh 40 ms silence (the old `if ring.is_empty()` re-primed instantly).
|
||||||
|
const DEPRIME_AFTER_CALLBACKS: u32 = 5;
|
||||||
|
/// Throttle the AAudio XRun-driven HW-buffer grow check (cheap, but no need to poll every quantum).
|
||||||
|
const XRUN_CHECK_EVERY: u32 = 128;
|
||||||
|
|
||||||
|
/// Opus decoder for the audio plane: a plain stereo decoder (the validated path) or a multistream
|
||||||
|
/// decoder for 5.1/7.1, both behind one `decode_float`. Built from the host-RESOLVED channel count
|
||||||
|
/// via the shared layout table. Mirrors the Linux client's `AudioDec`.
|
||||||
|
enum AudioDec {
|
||||||
|
Stereo(opus::Decoder),
|
||||||
|
Surround(opus::MSDecoder),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AudioDec {
|
||||||
|
fn new(channels: u8) -> Result<AudioDec, opus::Error> {
|
||||||
|
if channels == 2 {
|
||||||
|
Ok(AudioDec::Stereo(opus::Decoder::new(
|
||||||
|
SAMPLE_RATE as u32,
|
||||||
|
opus::Channels::Stereo,
|
||||||
|
)?))
|
||||||
|
} else {
|
||||||
|
let l = punktfunk_core::audio::layout_for(channels, false);
|
||||||
|
Ok(AudioDec::Surround(opus::MSDecoder::new(
|
||||||
|
SAMPLE_RATE as u32,
|
||||||
|
l.streams,
|
||||||
|
l.coupled,
|
||||||
|
l.mapping,
|
||||||
|
)?))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn decode_float(
|
||||||
|
&mut self,
|
||||||
|
input: &[u8],
|
||||||
|
out: &mut [f32],
|
||||||
|
fec: bool,
|
||||||
|
) -> Result<usize, opus::Error> {
|
||||||
|
match self {
|
||||||
|
AudioDec::Stereo(d) => d.decode_float(input, out, fec),
|
||||||
|
AudioDec::Surround(d) => d.decode_float(input, out, fec),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Diagnostics — written by the decode thread + the realtime callback, logged periodically. The
|
/// Diagnostics — written by the decode thread + the realtime callback, logged periodically. The
|
||||||
/// audio analogue of the video `fed`/`rendered` counters (we can't "screenshot" sound).
|
/// audio analogue of the video `fed`/`rendered` counters (we can't "screenshot" sound).
|
||||||
@@ -42,27 +114,57 @@ pub struct AudioPlayback {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl AudioPlayback {
|
impl AudioPlayback {
|
||||||
/// Open AAudio (LowLatency, 48 kHz/stereo/f32) with a realtime callback draining a jitter ring,
|
/// Open AAudio (LowLatency, 48 kHz/f32, the host-resolved channel layout) with a realtime
|
||||||
/// then spawn the Opus decode thread. `None` on failure (the caller leaves video streaming).
|
/// callback draining a jitter ring, then spawn the Opus decode thread. `None` on failure (the
|
||||||
|
/// caller leaves video streaming).
|
||||||
pub fn start(client: Arc<NativeClient>) -> Option<AudioPlayback> {
|
pub fn start(client: Arc<NativeClient>) -> Option<AudioPlayback> {
|
||||||
|
// Build playback from the host-RESOLVED channel count (never the request): 2 = stereo /
|
||||||
|
// 6 = 5.1 / 8 = 7.1, canonical wire order FL FR FC LFE RL RR SL SR.
|
||||||
|
let channels = punktfunk_core::audio::normalize_channels(client.audio_channels) as usize;
|
||||||
|
// Interleaved f32 samples per millisecond at this layout (48 kHz × channels); the ms-
|
||||||
|
// denominated jitter-ring depths scale by it.
|
||||||
|
let ms = (SAMPLE_RATE as usize / 1000) * channels;
|
||||||
|
let prime_floor = PRIME_FLOOR_MS * ms;
|
||||||
|
let prime_ceil = PRIME_CEIL_MS * ms;
|
||||||
|
let jitter_headroom = JITTER_HEADROOM_MS * ms;
|
||||||
|
let hard_cap_max = HARD_CAP_MS * ms;
|
||||||
let counters = Arc::new(Counters::default());
|
let counters = Arc::new(Counters::default());
|
||||||
let (tx, rx) = sync_channel::<Vec<f32>>(RING_CHUNKS);
|
let (tx, rx) = sync_channel::<Vec<f32>>(RING_CHUNKS);
|
||||||
|
// Recycle free-list: drained PCM buffers go BACK to the decode thread to be refilled, so the
|
||||||
|
// realtime callback never frees heap (Android's Scudo allocator has unbounded free() tail
|
||||||
|
// latency — a free on the audio thread is an XRun = a click) and the decode thread rarely
|
||||||
|
// allocates. Same depth as the data channel.
|
||||||
|
let (free_tx, free_rx) = sync_channel::<Vec<f32>>(RING_CHUNKS);
|
||||||
|
|
||||||
// Realtime consumer state, owned by the callback (FnMut) — no lock: AAudio calls it from a
|
// Realtime consumer state, owned by the callback (FnMut) — no lock: AAudio calls it from a
|
||||||
// single high-priority thread, and the decode thread only touches `tx`.
|
// single high-priority thread, and the decode thread only touches `tx`/`free_rx`.
|
||||||
let cb_counters = counters.clone();
|
let cb_counters = counters.clone();
|
||||||
let mut ring: VecDeque<f32> = VecDeque::with_capacity(PCM_SCRATCH);
|
// Pre-reserve the ring so `extend` never reallocates on the realtime thread. Worst transient
|
||||||
|
// before the trim below = the hard cap plus one full channel of 5 ms (480-f32) frames — the
|
||||||
|
// punktfunk protocol always sends 5 ms Opus frames (host `audio_thread`); a larger frame
|
||||||
|
// would force a one-time realloc, asserted (not silently corrupted) in `decode_loop`.
|
||||||
|
let mut ring: VecDeque<f32> = VecDeque::with_capacity(hard_cap_max + RING_CHUNKS * 5 * ms);
|
||||||
let mut primed = false;
|
let mut primed = false;
|
||||||
let callback = move |_s: &AudioStream, data: *mut c_void, num_frames: i32| {
|
let mut empties: u32 = 0; // consecutive empty callbacks (de-prime hysteresis)
|
||||||
let want = num_frames as usize * CHANNELS;
|
let mut cb_count: u32 = 0; // callbacks since open (throttles the XRun grow check)
|
||||||
|
let mut last_xrun: i32 = 0; // last AAudio XRun count we grew the buffer for
|
||||||
|
let callback = move |s: &AudioStream, data: *mut c_void, num_frames: i32| {
|
||||||
|
let want = num_frames as usize * channels;
|
||||||
// SAFETY: AAudio provides `num_frames * channel_count` F32 slots at `data`.
|
// SAFETY: AAudio provides `num_frames * channel_count` F32 slots at `data`.
|
||||||
let out = unsafe { std::slice::from_raw_parts_mut(data as *mut f32, want) };
|
let out = unsafe { std::slice::from_raw_parts_mut(data as *mut f32, want) };
|
||||||
while let Ok(chunk) = rx.try_recv() {
|
// Drain decoded chunks into the ring WITHOUT freeing on the RT thread: `drain(..)` empties
|
||||||
ring.extend(chunk);
|
// each Vec but keeps its capacity, then the empty buffer is handed back for reuse. The
|
||||||
|
// only RT-thread free is the rare case where the recycle channel is momentarily full.
|
||||||
|
while let Ok(mut chunk) = rx.try_recv() {
|
||||||
|
ring.extend(chunk.drain(..));
|
||||||
|
let _ = free_tx.try_send(chunk);
|
||||||
}
|
}
|
||||||
// Prime to ~3 quanta (15 ms; floor 15 ms / ceiling 200 ms); drop OLDEST above the cap.
|
// Jitter buffer: prime to ~40 ms (prime_floor) before playing and after a sustained drain;
|
||||||
let target = (3 * want).clamp(720 * CHANNELS, 9600 * CHANNELS);
|
// drop-oldest only above a wide ~120 ms band. Decoupled from the AAudio burst `want` (tiny
|
||||||
while ring.len() > target.max(want) + want {
|
// on the LowLatency MMAP path) so the depth doesn't collapse to a single quantum.
|
||||||
|
let target = (3 * want).clamp(prime_floor, prime_ceil);
|
||||||
|
let hard_cap = (target + jitter_headroom).min(hard_cap_max);
|
||||||
|
while ring.len() > hard_cap {
|
||||||
ring.pop_front();
|
ring.pop_front();
|
||||||
}
|
}
|
||||||
if !primed && ring.len() >= target {
|
if !primed && ring.len() >= target {
|
||||||
@@ -79,12 +181,34 @@ impl AudioPlayback {
|
|||||||
out.fill(0.0);
|
out.fill(0.0);
|
||||||
cb_counters.underruns.fetch_add(1, Ordering::Relaxed);
|
cb_counters.underruns.fetch_add(1, Ordering::Relaxed);
|
||||||
}
|
}
|
||||||
|
// Re-prime only after a RUN of empty callbacks, not a single transient one — otherwise
|
||||||
|
// every momentary drain costs a fresh 40 ms silence (the old behaviour, self-inflicted
|
||||||
|
// crackle on any jitter spike).
|
||||||
if ring.is_empty() {
|
if ring.is_empty() {
|
||||||
primed = false; // re-prime after a genuine drain (avoids sustained crackle on loss)
|
empties += 1;
|
||||||
|
if empties >= DEPRIME_AFTER_CALLBACKS {
|
||||||
|
primed = false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
empties = 0;
|
||||||
}
|
}
|
||||||
cb_counters
|
cb_counters
|
||||||
.ring_depth
|
.ring_depth
|
||||||
.store(ring.len() as u64, Ordering::Relaxed);
|
.store(ring.len() as u64, Ordering::Relaxed);
|
||||||
|
// Google's AAudio anti-glitch technique: when the device reports new XRuns, grow the HW
|
||||||
|
// buffer by one burst (up to capacity). getXRunCount + setBufferSizeInFrames are both
|
||||||
|
// callback-safe / non-blocking, and set clamps to capacity so it self-limits. Throttled.
|
||||||
|
cb_count = cb_count.wrapping_add(1);
|
||||||
|
if cb_count % XRUN_CHECK_EVERY == 0 {
|
||||||
|
let xr = s.x_run_count();
|
||||||
|
if xr > last_xrun {
|
||||||
|
last_xrun = xr;
|
||||||
|
let burst = s.frames_per_burst().max(1);
|
||||||
|
let grown =
|
||||||
|
(s.buffer_size_in_frames() + burst).min(s.buffer_capacity_in_frames());
|
||||||
|
let _ = s.set_buffer_size_in_frames(grown);
|
||||||
|
}
|
||||||
|
}
|
||||||
AudioCallbackResult::Continue
|
AudioCallbackResult::Continue
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -93,7 +217,11 @@ impl AudioPlayback {
|
|||||||
.ok()?
|
.ok()?
|
||||||
.direction(AudioDirection::Output)
|
.direction(AudioDirection::Output)
|
||||||
.sample_rate(SAMPLE_RATE)
|
.sample_rate(SAMPLE_RATE)
|
||||||
.channel_count(CHANNELS as i32)
|
// The wire order (FL FR FC LFE RL RR SL SR) is the standard AAudio/Android channel
|
||||||
|
// order, so this is an IDENTITY mapping — no permute. AAudio infers the 5.1/7.1 mask
|
||||||
|
// from `channel_count` (the ndk crate's builder exposes no setChannelMask); the host
|
||||||
|
// captures + Opus-encodes in exactly this order.
|
||||||
|
.channel_count(channels as i32)
|
||||||
.format(AudioFormat::PCM_Float)
|
.format(AudioFormat::PCM_Float)
|
||||||
.performance_mode(AudioPerformanceMode::LowLatency)
|
.performance_mode(AudioPerformanceMode::LowLatency)
|
||||||
.sharing_mode(AudioSharingMode::Shared)
|
.sharing_mode(AudioSharingMode::Shared)
|
||||||
@@ -109,19 +237,31 @@ impl AudioPlayback {
|
|||||||
log::error!("audio: request_start: {e}");
|
log::error!("audio: request_start: {e}");
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
// Lift the AAudio HW buffer off its brittle ~2-burst LowLatency default so a single late
|
||||||
|
// callback doesn't immediately underrun; the in-callback XRun loop grows it further if the
|
||||||
|
// device still glitches. set_buffer_size_in_frames clamps to capacity.
|
||||||
|
let burst = stream.frames_per_burst().max(1);
|
||||||
|
let _ =
|
||||||
|
stream.set_buffer_size_in_frames((burst * 3).min(stream.buffer_capacity_in_frames()));
|
||||||
|
// perf != LowLatency or rate != 48000 means AAudio silently fell to a resampled legacy path
|
||||||
|
// (different burst behaviour) — surface it so the field can tell that apart from plain jitter.
|
||||||
log::info!(
|
log::info!(
|
||||||
"audio: AAudio started rate={} ch={} fmt={:?} burst={}",
|
"audio: AAudio started rate={} ch={} fmt={:?} perf={:?} share={:?} burst={} buf={}/{}",
|
||||||
stream.sample_rate(),
|
stream.sample_rate(),
|
||||||
stream.channel_count(),
|
stream.channel_count(),
|
||||||
stream.format(),
|
stream.format(),
|
||||||
|
stream.performance_mode(),
|
||||||
|
stream.sharing_mode(),
|
||||||
stream.frames_per_burst(),
|
stream.frames_per_burst(),
|
||||||
|
stream.buffer_size_in_frames(),
|
||||||
|
stream.buffer_capacity_in_frames(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let shutdown = Arc::new(AtomicBool::new(false));
|
let shutdown = Arc::new(AtomicBool::new(false));
|
||||||
let sd = shutdown.clone();
|
let sd = shutdown.clone();
|
||||||
let join = std::thread::Builder::new()
|
let join = std::thread::Builder::new()
|
||||||
.name("pf-audio".into())
|
.name("pf-audio".into())
|
||||||
.spawn(move || decode_loop(client, tx, sd, counters))
|
.spawn(move || decode_loop(client, tx, free_rx, sd, counters, channels))
|
||||||
.ok();
|
.ok();
|
||||||
|
|
||||||
Some(AudioPlayback {
|
Some(AudioPlayback {
|
||||||
@@ -143,31 +283,53 @@ impl Drop for AudioPlayback {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Producer: `next_audio` → Opus `decode_float` → push interleaved f32 into the ring channel.
|
/// Producer: `next_audio` → Opus `decode_float` → push interleaved f32 into the ring channel.
|
||||||
|
/// Buffers come from (and return to) the realtime callback's recycle free-list so the steady state
|
||||||
|
/// is allocation-free on both threads.
|
||||||
fn decode_loop(
|
fn decode_loop(
|
||||||
client: Arc<NativeClient>,
|
client: Arc<NativeClient>,
|
||||||
tx: SyncSender<Vec<f32>>,
|
tx: SyncSender<Vec<f32>>,
|
||||||
|
free_rx: Receiver<Vec<f32>>,
|
||||||
shutdown: Arc<AtomicBool>,
|
shutdown: Arc<AtomicBool>,
|
||||||
counters: Arc<Counters>,
|
counters: Arc<Counters>,
|
||||||
|
channels: usize,
|
||||||
) {
|
) {
|
||||||
let mut dec = match opus::Decoder::new(SAMPLE_RATE as u32, opus::Channels::Stereo) {
|
// Interleaved f32 samples per millisecond at this layout — the ring's 5 ms reserve check below.
|
||||||
|
let ms = (SAMPLE_RATE as usize / 1000) * channels;
|
||||||
|
// Opus decode scratch: worst-case 120 ms frame (5760 samples/ch) × channels.
|
||||||
|
let pcm_scratch = 5760 * channels;
|
||||||
|
let mut dec = match AudioDec::new(channels as u8) {
|
||||||
Ok(d) => d,
|
Ok(d) => d,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
log::error!("audio: opus decoder init: {e} — audio disabled");
|
log::error!("audio: opus decoder init: {e} — audio disabled");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let mut pcm = vec![0f32; PCM_SCRATCH];
|
let mut pcm = vec![0f32; pcm_scratch];
|
||||||
let mut window_peak = 0f32; // loudest |sample| since the last log — tells a tone from silence
|
let mut window_peak = 0f32; // loudest |sample| since the last log — tells a tone from silence
|
||||||
while !shutdown.load(Ordering::Relaxed) {
|
while !shutdown.load(Ordering::Relaxed) {
|
||||||
match client.next_audio(Duration::from_millis(5)) {
|
match client.next_audio(Duration::from_millis(5)) {
|
||||||
Ok(pkt) => match dec.decode_float(&pkt.data, &mut pcm, false) {
|
Ok(pkt) => match dec.decode_float(&pkt.data, &mut pcm, false) {
|
||||||
Ok(samples) => {
|
Ok(samples) => {
|
||||||
let n = samples * CHANNELS;
|
let n = samples * channels;
|
||||||
for &s in &pcm[..n] {
|
for &s in &pcm[..n] {
|
||||||
window_peak = window_peak.max(s.abs());
|
window_peak = window_peak.max(s.abs());
|
||||||
}
|
}
|
||||||
|
// The ring's pre-reservation in `start` assumes the protocol's 5 ms (≤480-f32/ch)
|
||||||
|
// frames; a larger frame would force a one-time realloc on the RT thread. Catch a
|
||||||
|
// future host frame-size change here in debug, not as a silent audio glitch.
|
||||||
|
debug_assert!(
|
||||||
|
n <= 5 * ms,
|
||||||
|
"audio frame {n} f32 exceeds the 5 ms ring reserve"
|
||||||
|
);
|
||||||
let count = counters.opus_decoded.fetch_add(1, Ordering::Relaxed) + 1;
|
let count = counters.opus_decoded.fetch_add(1, Ordering::Relaxed) + 1;
|
||||||
match tx.try_send(pcm[..n].to_vec()) {
|
// Reuse a recycled buffer if the callback handed one back; only allocate when the
|
||||||
|
// free-list is momentarily empty (startup / after a backpressure drop).
|
||||||
|
let mut buf = free_rx
|
||||||
|
.try_recv()
|
||||||
|
.unwrap_or_else(|_| Vec::with_capacity(pcm_scratch));
|
||||||
|
buf.clear();
|
||||||
|
buf.extend_from_slice(&pcm[..n]);
|
||||||
|
match tx.try_send(buf) {
|
||||||
Ok(()) | Err(TrySendError::Full(_)) => {} // drop-newest under backpressure
|
Ok(()) | Err(TrySendError::Full(_)) => {} // drop-newest under backpressure
|
||||||
Err(TrySendError::Disconnected(_)) => break,
|
Err(TrySendError::Disconnected(_)) => break,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,303 @@
|
|||||||
|
//! LAN host discovery over mDNS, in Rust via `mdns-sd` — the same crate + service type the
|
||||||
|
//! Linux/Windows clients use (`clients/linux/src/discovery.rs`), exposed to Kotlin over JNI.
|
||||||
|
//!
|
||||||
|
//! Why not `NsdManager`: that API delegates to a per-OEM system mDNS daemon whose reliability
|
||||||
|
//! varies wildly (the Android client's discovery was "mostly broken"). Browsing in our own Rust
|
||||||
|
//! core — the crate is already linked for the whole protocol — gives one tested code path across
|
||||||
|
//! every desktop + mobile client and removes the system-daemon dependency. Kotlin still holds the
|
||||||
|
//! Wi-Fi `MulticastLock` for the browse lifetime (raw multicast *reception* needs it) and owns the
|
||||||
|
//! permission UX; this module owns the socket + resolve.
|
||||||
|
//!
|
||||||
|
//! Shape: [`Java_io_unom_punktfunk_kit_NativeBridge_nativeDiscoveryStart`] spins up a
|
||||||
|
//! [`ServiceDaemon`] browsing `_punktfunk._udp.local.` on a background thread that folds
|
||||||
|
//! resolve/remove events into a shared map; Kotlin polls `nativeDiscoveryPoll` ~1 Hz for a
|
||||||
|
//! newline-joined snapshot and calls `nativeDiscoveryStop` to tear it down. Polling (not a JVM
|
||||||
|
//! callback) mirrors `nativeVideoStats`: no `AttachCurrentThread`/global-ref lifecycle to get
|
||||||
|
//! wrong, and 1 Hz is plenty for a host picker.
|
||||||
|
|
||||||
|
use crate::session::jni_guard;
|
||||||
|
use jni::objects::JObject;
|
||||||
|
use jni::sys::jlong;
|
||||||
|
use jni::JNIEnv;
|
||||||
|
use mdns_sd::{ResolvedService, ServiceDaemon, ServiceEvent};
|
||||||
|
use std::collections::HashMap;
|
||||||
|
use std::sync::{Arc, Mutex};
|
||||||
|
use std::thread::JoinHandle;
|
||||||
|
|
||||||
|
/// DNS-SD service type punktfunk hosts advertise (host side: `punktfunk_host::discovery`).
|
||||||
|
const SERVICE_TYPE: &str = "_punktfunk._udp.local.";
|
||||||
|
/// Wire protocol id in the `proto` TXT record; a host advertising anything else is skipped.
|
||||||
|
const PROTO: &str = "punktfunk/1";
|
||||||
|
/// Field separator inside one serialized record (ASCII Unit Separator — never in a field value).
|
||||||
|
const FIELD_SEP: char = '\u{1f}';
|
||||||
|
|
||||||
|
/// One resolved host, serialized to Kotlin as `key␟name␟addr␟port␟fp␟pair` (`␟` = [`FIELD_SEP`]).
|
||||||
|
/// Records are newline-joined in a poll snapshot; [`Host::encode`] strips the framing bytes from
|
||||||
|
/// every field so no value can break it.
|
||||||
|
#[derive(Clone, PartialEq)]
|
||||||
|
struct Host {
|
||||||
|
key: String,
|
||||||
|
name: String,
|
||||||
|
addr: String,
|
||||||
|
port: u16,
|
||||||
|
fp: String,
|
||||||
|
pair: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Host {
|
||||||
|
fn encode(&self) -> String {
|
||||||
|
// mDNS instance labels + TXT values are arbitrary UTF-8 from an UNauthenticated source, so
|
||||||
|
// strip the field/record separators: a rogue advert that smuggled '\n'/U+001F could otherwise
|
||||||
|
// inject or suppress picker rows. (Trust is still gated on connect — this only protects the
|
||||||
|
// list's integrity.)
|
||||||
|
fn clean(s: &str) -> String {
|
||||||
|
s.replace(['\n', '\r', FIELD_SEP], "")
|
||||||
|
}
|
||||||
|
format!(
|
||||||
|
"{}{FIELD_SEP}{}{FIELD_SEP}{}{FIELD_SEP}{}{FIELD_SEP}{}{FIELD_SEP}{}",
|
||||||
|
clean(&self.key),
|
||||||
|
clean(&self.name),
|
||||||
|
clean(&self.addr),
|
||||||
|
self.port,
|
||||||
|
clean(&self.fp),
|
||||||
|
clean(&self.pair),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A running browse behind the `jlong` handle: the daemon, the shared resolved-host map keyed by
|
||||||
|
/// mDNS fullname (stable across re-announce and present on both resolve *and* remove — which fixes
|
||||||
|
/// the old `NsdManager` key mismatch that leaked stale hosts), and the event-fold thread.
|
||||||
|
struct Discovery {
|
||||||
|
daemon: ServiceDaemon,
|
||||||
|
hosts: Arc<Mutex<HashMap<String, Host>>>,
|
||||||
|
thread: Option<JoinHandle<()>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Discovery {
|
||||||
|
fn start() -> Option<Discovery> {
|
||||||
|
let daemon = match ServiceDaemon::new() {
|
||||||
|
Ok(d) => d,
|
||||||
|
Err(e) => {
|
||||||
|
log::error!("mDNS daemon failed — discovery disabled: {e}");
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let rx = match daemon.browse(SERVICE_TYPE) {
|
||||||
|
Ok(r) => r,
|
||||||
|
Err(e) => {
|
||||||
|
log::error!("mDNS browse failed — discovery disabled: {e}");
|
||||||
|
let _ = daemon.shutdown();
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let hosts: Arc<Mutex<HashMap<String, Host>>> = Arc::new(Mutex::new(HashMap::new()));
|
||||||
|
let map = hosts.clone();
|
||||||
|
let spawned = std::thread::Builder::new()
|
||||||
|
.name("pf-mdns".into())
|
||||||
|
.spawn(move || {
|
||||||
|
// Exits when the daemon is shut down (the browse channel closes → recv errors).
|
||||||
|
while let Ok(event) = rx.recv() {
|
||||||
|
match event {
|
||||||
|
ServiceEvent::ServiceResolved(info) => {
|
||||||
|
if let Some(host) = resolve(&info) {
|
||||||
|
map.lock()
|
||||||
|
.unwrap()
|
||||||
|
.insert(info.get_fullname().to_string(), host);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ServiceEvent::ServiceRemoved(_ty, fullname) => {
|
||||||
|
map.lock().unwrap().remove(&fullname);
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
let thread = match spawned {
|
||||||
|
Ok(t) => t,
|
||||||
|
Err(e) => {
|
||||||
|
// The daemon thread + bound :5353 socket outlive a dropped handle (no Drop impl), so
|
||||||
|
// shut it down explicitly — same cleanup as the browse-failure path above.
|
||||||
|
log::error!("mDNS fold thread spawn failed: {e}");
|
||||||
|
let _ = daemon.shutdown();
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
log::info!("native mDNS discovery started ({SERVICE_TYPE})");
|
||||||
|
Some(Discovery {
|
||||||
|
daemon,
|
||||||
|
hosts,
|
||||||
|
thread: Some(thread),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Current resolved-host set, newline-joined (empty string = none). Sorted for a stable order
|
||||||
|
/// across polls; Kotlin re-sorts by display name.
|
||||||
|
fn snapshot(&self) -> String {
|
||||||
|
let mut records: Vec<String> = self
|
||||||
|
.hosts
|
||||||
|
.lock()
|
||||||
|
.unwrap()
|
||||||
|
.values()
|
||||||
|
.map(Host::encode)
|
||||||
|
.collect();
|
||||||
|
records.sort();
|
||||||
|
records.join("\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn stop(mut self) {
|
||||||
|
let _ = self.daemon.shutdown(); // closes the browse channel → the fold thread exits
|
||||||
|
if let Some(t) = self.thread.take() {
|
||||||
|
let _ = t.join();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Build a [`Host`] from a resolved mDNS record, or `None` if it isn't a usable punktfunk host
|
||||||
|
/// (incompatible advertised proto, or no IPv4 address). IPv4 only on purpose: the core dials with
|
||||||
|
/// `format!("{host}:{port}").parse::<SocketAddr>()`, which can't parse a bare/scoped IPv6 literal
|
||||||
|
/// (it needs the `[addr%scope]:port` form), so surfacing a v6-only host would present a card that
|
||||||
|
/// fails on every tap. Dropping it shows the honest "not found" instead.
|
||||||
|
fn resolve(info: &ResolvedService) -> Option<Host> {
|
||||||
|
let val = |k: &str| info.get_property_val_str(k).unwrap_or("").to_string();
|
||||||
|
let proto = val("proto");
|
||||||
|
if !proto.is_empty() && proto != PROTO {
|
||||||
|
return None; // some other DNS-SD service sharing the type — ignore
|
||||||
|
}
|
||||||
|
let addr = info
|
||||||
|
.get_addresses_v4()
|
||||||
|
.iter()
|
||||||
|
.next()
|
||||||
|
.map(|a| a.to_string())?;
|
||||||
|
let id = val("id");
|
||||||
|
let fullname = info.get_fullname();
|
||||||
|
Some(Host {
|
||||||
|
key: if id.is_empty() {
|
||||||
|
fullname.to_string()
|
||||||
|
} else {
|
||||||
|
id
|
||||||
|
},
|
||||||
|
name: fullname.split('.').next().unwrap_or("?").to_string(),
|
||||||
|
addr,
|
||||||
|
port: info.get_port(),
|
||||||
|
fp: val("fp"),
|
||||||
|
pair: val("pair"),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// `NativeBridge.nativeDiscoveryStart(): Long` — start browsing `_punktfunk._udp`; returns an opaque
|
||||||
|
/// handle, or `0` on failure (logged). Pair with exactly one [`nativeDiscoveryStop`]. Kotlin must
|
||||||
|
/// hold the Wi-Fi `MulticastLock` for the browse lifetime.
|
||||||
|
///
|
||||||
|
/// [`nativeDiscoveryStop`]: Java_io_unom_punktfunk_kit_NativeBridge_nativeDiscoveryStop
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "system" fn Java_io_unom_punktfunk_kit_NativeBridge_nativeDiscoveryStart(
|
||||||
|
_env: JNIEnv,
|
||||||
|
_this: JObject,
|
||||||
|
) -> jlong {
|
||||||
|
jni_guard(0, || match Discovery::start() {
|
||||||
|
Some(d) => Box::into_raw(Box::new(d)) as jlong,
|
||||||
|
None => 0,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// `NativeBridge.nativeDiscoveryPoll(handle): String` — the current resolved-host snapshot,
|
||||||
|
/// newline-joined records of `key␟name␟addr␟port␟fp␟pair` (`␟` = U+001F). Empty string = no hosts /
|
||||||
|
/// `0` handle. Poll ~1 Hz from the UI thread (cheap: a mutex lock + string build).
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "system" fn Java_io_unom_punktfunk_kit_NativeBridge_nativeDiscoveryPoll<'local>(
|
||||||
|
env: JNIEnv<'local>,
|
||||||
|
_this: JObject<'local>,
|
||||||
|
handle: jlong,
|
||||||
|
) -> jni::sys::jstring {
|
||||||
|
jni_guard(std::ptr::null_mut(), || {
|
||||||
|
let out = if handle == 0 {
|
||||||
|
String::new()
|
||||||
|
} else {
|
||||||
|
// SAFETY: live handle per the start/stop contract — Kotlin owns the lifecycle and never
|
||||||
|
// polls after stop (it nulls the handle first).
|
||||||
|
let d = unsafe { &*(handle as *const Discovery) };
|
||||||
|
d.snapshot()
|
||||||
|
};
|
||||||
|
match env.new_string(out) {
|
||||||
|
Ok(s) => s.into_raw(),
|
||||||
|
Err(_) => std::ptr::null_mut(),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// `NativeBridge.nativeDiscoveryStop(handle)` — stop the browse, shut the daemon down and join its
|
||||||
|
/// thread. No-op on `0`.
|
||||||
|
///
|
||||||
|
/// # Safety contract
|
||||||
|
/// `handle` must be `0` or a live handle from [`nativeDiscoveryStart`], stopped exactly once and not
|
||||||
|
/// concurrently with [`nativeDiscoveryPoll`] (Kotlin owns this; all calls are on the main thread).
|
||||||
|
///
|
||||||
|
/// [`nativeDiscoveryStart`]: Java_io_unom_punktfunk_kit_NativeBridge_nativeDiscoveryStart
|
||||||
|
/// [`nativeDiscoveryPoll`]: Java_io_unom_punktfunk_kit_NativeBridge_nativeDiscoveryPoll
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "system" fn Java_io_unom_punktfunk_kit_NativeBridge_nativeDiscoveryStop(
|
||||||
|
_env: JNIEnv,
|
||||||
|
_this: JObject,
|
||||||
|
handle: jlong,
|
||||||
|
) {
|
||||||
|
jni_guard((), || {
|
||||||
|
if handle != 0 {
|
||||||
|
// SAFETY: live handle from nativeDiscoveryStart, stopped exactly once per the contract.
|
||||||
|
let d = unsafe { Box::from_raw(handle as *mut Discovery) };
|
||||||
|
d.stop();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn encode_round_trips_all_fields_with_unit_separator() {
|
||||||
|
let h = Host {
|
||||||
|
key: "host-123".into(),
|
||||||
|
name: "home-worker-2".into(),
|
||||||
|
addr: "192.168.1.70".into(),
|
||||||
|
port: 9777,
|
||||||
|
fp: "ab".repeat(32),
|
||||||
|
pair: "required".into(),
|
||||||
|
};
|
||||||
|
let encoded = h.encode();
|
||||||
|
let fields: Vec<&str> = encoded.split(FIELD_SEP).collect();
|
||||||
|
assert_eq!(fields.len(), 6);
|
||||||
|
assert_eq!(fields[0], "host-123");
|
||||||
|
assert_eq!(fields[1], "home-worker-2");
|
||||||
|
assert_eq!(fields[2], "192.168.1.70");
|
||||||
|
assert_eq!(fields[3], "9777");
|
||||||
|
assert_eq!(fields[4], "ab".repeat(32));
|
||||||
|
assert_eq!(fields[5], "required");
|
||||||
|
assert!(
|
||||||
|
!encoded.contains('\n'),
|
||||||
|
"a record must never contain the record separator"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn encode_strips_injected_separators_from_a_hostile_advert() {
|
||||||
|
// A rogue advert could carry framing bytes in its instance label / TXT; encode must strip
|
||||||
|
// them so the snapshot stays exactly one record of exactly six fields.
|
||||||
|
let h = Host {
|
||||||
|
key: "k\u{1f}injected".into(),
|
||||||
|
name: "evil\nhost\r".into(),
|
||||||
|
addr: "10.0.0.5".into(),
|
||||||
|
port: 9777,
|
||||||
|
fp: "ab\u{1f}cd".into(),
|
||||||
|
pair: "required\n".into(),
|
||||||
|
};
|
||||||
|
let encoded = h.encode();
|
||||||
|
assert_eq!(encoded.matches(FIELD_SEP).count(), 5, "exactly six fields");
|
||||||
|
assert!(!encoded.contains('\n') && !encoded.contains('\r'));
|
||||||
|
let fields: Vec<&str> = encoded.split(FIELD_SEP).collect();
|
||||||
|
assert_eq!(fields[0], "kinjected");
|
||||||
|
assert_eq!(fields[1], "evilhost");
|
||||||
|
assert_eq!(fields[4], "abcd");
|
||||||
|
assert_eq!(fields[5], "required");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
//! Not android-gated: `next_rumble`/`next_hidout` are pure-Rust on the `quic` feature, so these
|
//! Not android-gated: `next_rumble`/`next_hidout` are pure-Rust on the `quic` feature, so these
|
||||||
//! compile on the host build too (parity with the input shims in [`crate::session`]).
|
//! compile on the host build too (parity with the input shims in [`crate::session`]).
|
||||||
|
|
||||||
use crate::session::SessionHandle;
|
use crate::session::{jni_guard, SessionHandle};
|
||||||
use jni::objects::{JByteBuffer, JObject};
|
use jni::objects::{JByteBuffer, JObject};
|
||||||
use jni::sys::{jint, jlong};
|
use jni::sys::{jint, jlong};
|
||||||
use jni::JNIEnv;
|
use jni::JNIEnv;
|
||||||
@@ -32,17 +32,20 @@ pub extern "system" fn Java_io_unom_punktfunk_kit_NativeBridge_nativeNextRumble(
|
|||||||
_this: JObject,
|
_this: JObject,
|
||||||
handle: jlong,
|
handle: jlong,
|
||||||
) -> jlong {
|
) -> jlong {
|
||||||
if handle == 0 {
|
// Runs on a Kotlin poll thread, so a panic here would abort the process; guard the boundary.
|
||||||
return -1;
|
jni_guard(-1, || {
|
||||||
}
|
if handle == 0 {
|
||||||
// SAFETY: live handle per the nativeConnect/nativeClose contract; next_rumble is &self on the
|
return -1;
|
||||||
// Sync connector — safe alongside the decode/audio/input threads. Kotlin stops these poll
|
}
|
||||||
// threads (and joins them) before nativeClose frees the handle.
|
// SAFETY: live handle per the nativeConnect/nativeClose contract; next_rumble is &self on the
|
||||||
let h = unsafe { &*(handle as *const SessionHandle) };
|
// Sync connector — safe alongside the decode/audio/input threads. Kotlin stops these poll
|
||||||
match h.client.next_rumble(PULL_TIMEOUT) {
|
// threads (and joins them — unbounded) before nativeClose frees the handle.
|
||||||
Ok((_pad, low, high)) => (jlong::from(low) << 16) | jlong::from(high),
|
let h = unsafe { &*(handle as *const SessionHandle) };
|
||||||
Err(_) => -1, // NoFrame (timeout) or Closed — Kotlin loops on its running flag
|
match h.client.next_rumble(PULL_TIMEOUT) {
|
||||||
}
|
Ok((_pad, low, high)) => (jlong::from(low) << 16) | jlong::from(high),
|
||||||
|
Err(_) => -1, // NoFrame (timeout) or Closed — Kotlin loops on its running flag
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `NativeBridge.nativeNextHidout(handle, buf): Int` — block up to ~100 ms for the next DualSense
|
/// `NativeBridge.nativeNextHidout(handle, buf): Int` — block up to ~100 ms for the next DualSense
|
||||||
@@ -58,57 +61,60 @@ pub extern "system" fn Java_io_unom_punktfunk_kit_NativeBridge_nativeNextHidout(
|
|||||||
handle: jlong,
|
handle: jlong,
|
||||||
buf: JByteBuffer,
|
buf: JByteBuffer,
|
||||||
) -> jint {
|
) -> jint {
|
||||||
if handle == 0 {
|
// Runs on a Kotlin poll thread, so a panic here would abort the process; guard the boundary.
|
||||||
return -1;
|
jni_guard(-1, || {
|
||||||
}
|
if handle == 0 {
|
||||||
// SAFETY: live handle per the contract; next_hidout is &self on the Sync connector.
|
return -1;
|
||||||
let h = unsafe { &*(handle as *const SessionHandle) };
|
}
|
||||||
let ev = match h.client.next_hidout(PULL_TIMEOUT) {
|
// SAFETY: live handle per the contract; next_hidout is &self on the Sync connector.
|
||||||
Ok(ev) => ev,
|
let h = unsafe { &*(handle as *const SessionHandle) };
|
||||||
Err(_) => return -1, // timeout or closed — Kotlin loops
|
let ev = match h.client.next_hidout(PULL_TIMEOUT) {
|
||||||
};
|
Ok(ev) => ev,
|
||||||
|
Err(_) => return -1, // timeout or closed — Kotlin loops
|
||||||
|
};
|
||||||
|
|
||||||
// The caller passes a direct ByteBuffer (allocateDirect) so we write its backing store directly.
|
// The caller passes a direct ByteBuffer (allocateDirect) so we write its backing store directly.
|
||||||
let cap = match env.get_direct_buffer_capacity(&buf) {
|
let cap = match env.get_direct_buffer_capacity(&buf) {
|
||||||
Ok(c) => c,
|
Ok(c) => c,
|
||||||
Err(_) => return -1,
|
Err(_) => return -1,
|
||||||
};
|
};
|
||||||
let ptr = match env.get_direct_buffer_address(&buf) {
|
let ptr = match env.get_direct_buffer_address(&buf) {
|
||||||
Ok(p) if !p.is_null() => p,
|
Ok(p) if !p.is_null() => p,
|
||||||
_ => return -1,
|
_ => return -1,
|
||||||
};
|
};
|
||||||
// SAFETY: `ptr`/`cap` describe the direct ByteBuffer's backing store, valid for this call.
|
// SAFETY: `ptr`/`cap` describe the direct ByteBuffer's backing store, valid for this call.
|
||||||
let out = unsafe { std::slice::from_raw_parts_mut(ptr, cap) };
|
let out = unsafe { std::slice::from_raw_parts_mut(ptr, cap) };
|
||||||
|
|
||||||
let n = match ev {
|
let n = match ev {
|
||||||
HidOutput::Led { r, g, b, .. } => {
|
HidOutput::Led { r, g, b, .. } => {
|
||||||
if cap < 4 {
|
if cap < 4 {
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
out[0] = TAG_LED;
|
||||||
|
out[1] = r;
|
||||||
|
out[2] = g;
|
||||||
|
out[3] = b;
|
||||||
|
4
|
||||||
}
|
}
|
||||||
out[0] = TAG_LED;
|
HidOutput::PlayerLeds { bits, .. } => {
|
||||||
out[1] = r;
|
if cap < 2 {
|
||||||
out[2] = g;
|
return -1;
|
||||||
out[3] = b;
|
}
|
||||||
4
|
out[0] = TAG_PLAYER_LEDS;
|
||||||
}
|
out[1] = bits;
|
||||||
HidOutput::PlayerLeds { bits, .. } => {
|
2
|
||||||
if cap < 2 {
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
out[0] = TAG_PLAYER_LEDS;
|
HidOutput::Trigger { which, effect, .. } => {
|
||||||
out[1] = bits;
|
let n = 2 + effect.len();
|
||||||
2
|
if cap < n {
|
||||||
}
|
return -1; // the raw DS5 trigger block is ~11 bytes; Kotlin allocates 64
|
||||||
HidOutput::Trigger { which, effect, .. } => {
|
}
|
||||||
let n = 2 + effect.len();
|
out[0] = TAG_TRIGGER;
|
||||||
if cap < n {
|
out[1] = which;
|
||||||
return -1; // the raw DS5 trigger block is ~11 bytes; Kotlin allocates 64
|
out[2..n].copy_from_slice(&effect);
|
||||||
|
n
|
||||||
}
|
}
|
||||||
out[0] = TAG_TRIGGER;
|
};
|
||||||
out[1] = which;
|
n as jint
|
||||||
out[2..n].copy_from_slice(&effect);
|
})
|
||||||
n
|
|
||||||
}
|
|
||||||
};
|
|
||||||
n as jint
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,13 +3,17 @@
|
|||||||
//! Architecture: the **Rust-heavy** client model (like `punktfunk-client-linux`, *not* the
|
//! Architecture: the **Rust-heavy** client model (like `punktfunk-client-linux`, *not* the
|
||||||
//! thin-native-over-C-ABI Apple model). This `cdylib` links `punktfunk-core` directly and drives
|
//! thin-native-over-C-ABI Apple model). This `cdylib` links `punktfunk-core` directly and drives
|
||||||
//! the whole `punktfunk/1` protocol through [`punktfunk_core::client::NativeClient`]; Kotlin owns
|
//! the whole `punktfunk/1` protocol through [`punktfunk_core::client::NativeClient`]; Kotlin owns
|
||||||
//! only the Android-framework surface (Compose UI, `SurfaceView` lifecycle, input capture,
|
//! only the Android-framework surface (Compose UI, `SurfaceView` lifecycle, input capture, the
|
||||||
//! `NsdManager` discovery, Keystore). The JNI seam below is the one place the two languages meet.
|
//! Wi-Fi `MulticastLock` + permission UX, Keystore). The JNI seam below is the one place the two
|
||||||
|
//! languages meet.
|
||||||
//!
|
//!
|
||||||
//! Why Rust-heavy: Kotlin cannot `import` the cbindgen C header the way Swift can, so a native
|
//! Why Rust-heavy: Kotlin cannot `import` the cbindgen C header the way Swift can, so a native
|
||||||
//! bridge is unavoidable. Writing it in Rust lets the Android client reuse the Linux client's
|
//! bridge is unavoidable. Writing it in Rust lets the Android client reuse the Linux client's
|
||||||
//! orchestration verbatim — audio jitter ring, the VK keymap inverse, latency/skew math, the
|
//! orchestration verbatim — audio jitter ring, the VK keymap inverse, latency/skew math, the
|
||||||
//! input capture state machine, trust/pairing logic — instead of re-porting it into Kotlin.
|
//! input capture state machine, trust/pairing logic, **mDNS discovery** ([`discovery`], the same
|
||||||
|
//! `mdns-sd` browse the Linux/Windows clients use) — instead of re-porting it into Kotlin. Kotlin
|
||||||
|
//! keeps only the Android-framework surface it must (Compose UI, `SurfaceView`, input capture, the
|
||||||
|
//! Wi-Fi `MulticastLock` + permission UX, Keystore identity).
|
||||||
//!
|
//!
|
||||||
//! JNI symbols map to `io.unom.punktfunk.kit.NativeBridge` in the `:kit` Gradle module
|
//! JNI symbols map to `io.unom.punktfunk.kit.NativeBridge` in the `:kit` Gradle module
|
||||||
//! (`clients/android`). The current surface is the scaffold's native-link proof
|
//! (`clients/android`). The current surface is the scaffold's native-link proof
|
||||||
@@ -25,6 +29,9 @@ use jni::JNIEnv;
|
|||||||
mod audio;
|
mod audio;
|
||||||
#[cfg(target_os = "android")]
|
#[cfg(target_os = "android")]
|
||||||
mod decode;
|
mod decode;
|
||||||
|
// Ungated: pure `mdns-sd` + `jni`, so the browse + its JNI seam link into the host workspace build
|
||||||
|
// (and its unit test runs there) exactly like `session`/`stats`. Kotlin only ever calls it on device.
|
||||||
|
mod discovery;
|
||||||
mod feedback;
|
mod feedback;
|
||||||
#[cfg(target_os = "android")]
|
#[cfg(target_os = "android")]
|
||||||
mod mic;
|
mod mic;
|
||||||
|
|||||||
@@ -19,11 +19,28 @@ use jni::JNIEnv;
|
|||||||
use punktfunk_core::client::NativeClient;
|
use punktfunk_core::client::NativeClient;
|
||||||
use punktfunk_core::config::{CompositorPref, GamepadPref, Mode};
|
use punktfunk_core::config::{CompositorPref, GamepadPref, Mode};
|
||||||
use punktfunk_core::input::{InputEvent, InputKind};
|
use punktfunk_core::input::{InputEvent, InputKind};
|
||||||
|
use std::panic::AssertUnwindSafe;
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use std::thread::JoinHandle;
|
use std::thread::JoinHandle;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
|
/// Run a JNI body, catching any panic at the FFI boundary and returning `default` instead.
|
||||||
|
///
|
||||||
|
/// A panic unwinding out of an `extern "system"` function aborts the whole process on Rust ≥ 1.81 —
|
||||||
|
/// a hard crash of the embedding Android app with no logcat trace. This mirrors the discipline the C
|
||||||
|
/// ABI already enforces (`punktfunk_core::abi` wraps every entry point in `catch_unwind`); the
|
||||||
|
/// `panic = "unwind"` profile in the workspace `Cargo.toml` exists precisely so these guards work.
|
||||||
|
/// We apply it to the teardown + background-thread shims (the "leaving a stream" path), where an
|
||||||
|
/// unexpected panic (e.g. a poisoned `Mutex` during concurrent teardown) must degrade to a logged
|
||||||
|
/// no-op rather than kill the app.
|
||||||
|
pub(crate) fn jni_guard<T>(default: T, f: impl FnOnce() -> T) -> T {
|
||||||
|
std::panic::catch_unwind(AssertUnwindSafe(f)).unwrap_or_else(|_| {
|
||||||
|
log::error!("punktfunk JNI: caught a panic at the FFI boundary (returning default)");
|
||||||
|
default
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/// A live session behind the `jlong` handle: the connector + the decode thread it feeds.
|
/// A live session behind the `jlong` handle: the connector + the decode thread it feeds.
|
||||||
pub(crate) struct SessionHandle {
|
pub(crate) struct SessionHandle {
|
||||||
// Read only by the android decode path (`nativeStartVideo` → `crate::decode`); on the host
|
// Read only by the android decode path (`nativeStartVideo` → `crate::decode`); on the host
|
||||||
@@ -123,11 +140,15 @@ pub extern "system" fn Java_io_unom_punktfunk_kit_NativeBridge_nativeGenerateIde
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// `NativeBridge.nativeConnect(host, port, w, h, hz, certPem, keyPem, pinHex, bitrateKbps,
|
/// `NativeBridge.nativeConnect(host, port, w, h, hz, certPem, keyPem, pinHex, bitrateKbps,
|
||||||
/// compositorPref, gamepadPref): Long`. `certPem`/`keyPem` empty = anonymous, else presented as the
|
/// compositorPref, gamepadPref, hdrEnabled, audioChannels, timeoutMs): Long`. `certPem`/`keyPem`
|
||||||
/// persistent identity. `pinHex` empty = TOFU (read `nativeHostFingerprint` after), else 64-hex
|
/// empty = anonymous, else presented as the persistent identity. `pinHex` empty = TOFU (read
|
||||||
/// SHA-256 to pin the host (mismatch → 0). `bitrateKbps` 0 = host default. `compositorPref`/
|
/// `nativeHostFingerprint` after), else 64-hex SHA-256 to pin the host (mismatch → 0). `bitrateKbps`
|
||||||
/// `gamepadPref` are `CompositorPref`/`GamepadPref` wire bytes (0 = Auto; unknown → Auto).
|
/// 0 = host default. `compositorPref`/`gamepadPref` are `CompositorPref`/`GamepadPref` wire bytes
|
||||||
/// Returns an opaque handle, or 0 on failure (logged).
|
/// (0 = Auto; unknown → Auto). `audioChannels` is the requested surround layout (2/6/8; normalized,
|
||||||
|
/// anything else → stereo) — the host clamps it and the resolved count drives playback. `timeoutMs`
|
||||||
|
/// is the handshake budget: the normal path passes a short value, the no-PIN "request access" path a
|
||||||
|
/// long one (≥ the host's approval-park window) so a slow operator approval lands on this same parked
|
||||||
|
/// connection rather than timing the client out first. Returns an opaque handle, or 0 on failure.
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub extern "system" fn Java_io_unom_punktfunk_kit_NativeBridge_nativeConnect<'local>(
|
pub extern "system" fn Java_io_unom_punktfunk_kit_NativeBridge_nativeConnect<'local>(
|
||||||
@@ -145,6 +166,8 @@ pub extern "system" fn Java_io_unom_punktfunk_kit_NativeBridge_nativeConnect<'lo
|
|||||||
compositor_pref: jint,
|
compositor_pref: jint,
|
||||||
gamepad_pref: jint,
|
gamepad_pref: jint,
|
||||||
hdr_enabled: jboolean,
|
hdr_enabled: jboolean,
|
||||||
|
audio_channels: jint,
|
||||||
|
timeout_ms: jint,
|
||||||
) -> jlong {
|
) -> jlong {
|
||||||
let host: String = match env.get_string(&host) {
|
let host: String = match env.get_string(&host) {
|
||||||
Ok(s) => s.into(),
|
Ok(s) => s.into(),
|
||||||
@@ -196,10 +219,17 @@ pub extern "system" fn Java_io_unom_punktfunk_kit_NativeBridge_nativeConnect<'lo
|
|||||||
} else {
|
} else {
|
||||||
0
|
0
|
||||||
},
|
},
|
||||||
|
// Requested surround layout (2 = stereo / 6 = 5.1 / 8 = 7.1). The host clamps to what it can
|
||||||
|
// capture and echoes the resolved count in `connector.audio_channels`, which drives the
|
||||||
|
// decoder + AAudio layout (read in `crate::audio::AudioPlayback::start`). Anything else
|
||||||
|
// normalizes to stereo here.
|
||||||
|
punktfunk_core::audio::normalize_channels(audio_channels.clamp(0, u8::MAX as jint) as u8),
|
||||||
None, // launch: default app
|
None, // launch: default app
|
||||||
pin, // Some → Crypto on host-fp mismatch
|
pin, // Some → Crypto on host-fp mismatch
|
||||||
identity, // owned (cert, key) PEM, or None (anonymous)
|
identity, // owned (cert, key) PEM, or None (anonymous)
|
||||||
Duration::from_secs(10),
|
// Handshake budget from Kotlin: ~10 s for a normal connect, ~185 s for "request access"
|
||||||
|
// (the host parks the connection until the operator approves the device — see ConnectScreen).
|
||||||
|
Duration::from_millis(timeout_ms.max(0) as u64),
|
||||||
) {
|
) {
|
||||||
Ok(client) => {
|
Ok(client) => {
|
||||||
let handle = SessionHandle {
|
let handle = SessionHandle {
|
||||||
@@ -231,10 +261,12 @@ pub extern "system" fn Java_io_unom_punktfunk_kit_NativeBridge_nativeClose(
|
|||||||
_this: JObject,
|
_this: JObject,
|
||||||
handle: jlong,
|
handle: jlong,
|
||||||
) {
|
) {
|
||||||
if handle != 0 {
|
jni_guard((), || {
|
||||||
// SAFETY: per the contract, `handle` is a live `Box<SessionHandle>` pointer.
|
if handle != 0 {
|
||||||
unsafe { drop(Box::from_raw(handle as *mut SessionHandle)) };
|
// SAFETY: per the contract, `handle` is a live `Box<SessionHandle>` pointer.
|
||||||
}
|
unsafe { drop(Box::from_raw(handle as *mut SessionHandle)) };
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `NativeBridge.nativeHostFingerprint(handle): String` — the SHA-256 (64-hex) of the cert the host
|
/// `NativeBridge.nativeHostFingerprint(handle): String` — the SHA-256 (64-hex) of the cert the host
|
||||||
@@ -367,11 +399,13 @@ pub extern "system" fn Java_io_unom_punktfunk_kit_NativeBridge_nativeStopVideo(
|
|||||||
_this: JObject,
|
_this: JObject,
|
||||||
handle: jlong,
|
handle: jlong,
|
||||||
) {
|
) {
|
||||||
if handle != 0 {
|
jni_guard((), || {
|
||||||
// SAFETY: live handle per the contract.
|
if handle != 0 {
|
||||||
let h = unsafe { &*(handle as *const SessionHandle) };
|
// SAFETY: live handle per the contract.
|
||||||
h.stop_video();
|
let h = unsafe { &*(handle as *const SessionHandle) };
|
||||||
}
|
h.stop_video();
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `NativeBridge.nativeVideoStats(handle): DoubleArray?` — drain ~1 s of decode stats for the HUD.
|
/// `NativeBridge.nativeVideoStats(handle): DoubleArray?` — drain ~1 s of decode stats for the HUD.
|
||||||
@@ -386,36 +420,38 @@ pub extern "system" fn Java_io_unom_punktfunk_kit_NativeBridge_nativeVideoStats(
|
|||||||
_this: JObject,
|
_this: JObject,
|
||||||
handle: jlong,
|
handle: jlong,
|
||||||
) -> jdoubleArray {
|
) -> jdoubleArray {
|
||||||
if handle == 0 {
|
jni_guard(std::ptr::null_mut(), || {
|
||||||
return std::ptr::null_mut();
|
if handle == 0 {
|
||||||
}
|
return std::ptr::null_mut();
|
||||||
// SAFETY: live handle per the nativeConnect/nativeClose contract.
|
}
|
||||||
let h = unsafe { &*(handle as *const SessionHandle) };
|
// SAFETY: live handle per the nativeConnect/nativeClose contract.
|
||||||
let snap = match h.video.lock().unwrap().as_ref() {
|
let h = unsafe { &*(handle as *const SessionHandle) };
|
||||||
Some(vt) => vt.stats.drain(),
|
let snap = match h.video.lock().unwrap().as_ref() {
|
||||||
None => return std::ptr::null_mut(), // not streaming → no stats
|
Some(vt) => vt.stats.drain(),
|
||||||
};
|
None => return std::ptr::null_mut(), // not streaming → no stats
|
||||||
let mode = h.client.mode();
|
};
|
||||||
let buf: [f64; 10] = [
|
let mode = h.client.mode();
|
||||||
snap.fps,
|
let buf: [f64; 10] = [
|
||||||
snap.mbps,
|
snap.fps,
|
||||||
snap.lat_p50_ms,
|
snap.mbps,
|
||||||
snap.lat_p95_ms,
|
snap.lat_p50_ms,
|
||||||
if snap.lat_valid { 1.0 } else { 0.0 },
|
snap.lat_p95_ms,
|
||||||
if snap.skew_corrected { 1.0 } else { 0.0 },
|
if snap.lat_valid { 1.0 } else { 0.0 },
|
||||||
mode.width as f64,
|
if snap.skew_corrected { 1.0 } else { 0.0 },
|
||||||
mode.height as f64,
|
mode.width as f64,
|
||||||
mode.refresh_hz as f64,
|
mode.height as f64,
|
||||||
h.client.frames_dropped() as f64,
|
mode.refresh_hz as f64,
|
||||||
];
|
h.client.frames_dropped() as f64,
|
||||||
let arr = match env.new_double_array(buf.len() as jsize) {
|
];
|
||||||
Ok(a) => a,
|
let arr = match env.new_double_array(buf.len() as jsize) {
|
||||||
Err(_) => return std::ptr::null_mut(),
|
Ok(a) => a,
|
||||||
};
|
Err(_) => return std::ptr::null_mut(),
|
||||||
if env.set_double_array_region(&arr, 0, &buf).is_err() {
|
};
|
||||||
return std::ptr::null_mut();
|
if env.set_double_array_region(&arr, 0, &buf).is_err() {
|
||||||
}
|
return std::ptr::null_mut();
|
||||||
arr.into_raw()
|
}
|
||||||
|
arr.into_raw()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `NativeBridge.nativeStartAudio(handle)` — start the Opus→AAudio playback thread. No-op if already
|
/// `NativeBridge.nativeStartAudio(handle)` — start the Opus→AAudio playback thread. No-op if already
|
||||||
@@ -451,11 +487,13 @@ pub extern "system" fn Java_io_unom_punktfunk_kit_NativeBridge_nativeStopAudio(
|
|||||||
_this: JObject,
|
_this: JObject,
|
||||||
handle: jlong,
|
handle: jlong,
|
||||||
) {
|
) {
|
||||||
if handle != 0 {
|
jni_guard((), || {
|
||||||
// SAFETY: live handle per the contract.
|
if handle != 0 {
|
||||||
let h = unsafe { &*(handle as *const SessionHandle) };
|
// SAFETY: live handle per the contract.
|
||||||
h.stop_audio();
|
let h = unsafe { &*(handle as *const SessionHandle) };
|
||||||
}
|
h.stop_audio();
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `NativeBridge.nativeStartMic(handle)` — start mic capture (AAudio input → Opus → host `send_mic`).
|
/// `NativeBridge.nativeStartMic(handle)` — start mic capture (AAudio input → Opus → host `send_mic`).
|
||||||
@@ -492,11 +530,13 @@ pub extern "system" fn Java_io_unom_punktfunk_kit_NativeBridge_nativeStopMic(
|
|||||||
_this: JObject,
|
_this: JObject,
|
||||||
handle: jlong,
|
handle: jlong,
|
||||||
) {
|
) {
|
||||||
if handle != 0 {
|
jni_guard((), || {
|
||||||
// SAFETY: live handle per the contract.
|
if handle != 0 {
|
||||||
let h = unsafe { &*(handle as *const SessionHandle) };
|
// SAFETY: live handle per the contract.
|
||||||
h.stop_mic();
|
let h = unsafe { &*(handle as *const SessionHandle) };
|
||||||
}
|
h.stop_mic();
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---- Input plane: Kotlin capture → NativeClient::send_input ----------------------------------
|
// ---- Input plane: Kotlin capture → NativeClient::send_input ----------------------------------
|
||||||
@@ -530,6 +570,38 @@ pub extern "system" fn Java_io_unom_punktfunk_kit_NativeBridge_nativeSendPointer
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// `NativeBridge.nativeSendPointerAbs(handle, x, y, surfaceWidth, surfaceHeight)` — absolute cursor
|
||||||
|
/// position: the host moves the pointer to `x`/`y` in a `surfaceWidth`×`surfaceHeight` pixel space,
|
||||||
|
/// normalizing against the size packed into `flags` as `(w << 16) | h` and mapping into the output
|
||||||
|
/// region (it drops the event if that size is zero). This is the touch "direct pointing" path — the
|
||||||
|
/// cursor jumps to the finger — and matches the Apple client's absolute touch forwarding.
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "system" fn Java_io_unom_punktfunk_kit_NativeBridge_nativeSendPointerAbs(
|
||||||
|
_env: JNIEnv,
|
||||||
|
_this: JObject,
|
||||||
|
handle: jlong,
|
||||||
|
x: jint,
|
||||||
|
y: jint,
|
||||||
|
surface_width: jint,
|
||||||
|
surface_height: jint,
|
||||||
|
) {
|
||||||
|
if handle == 0 {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// SAFETY: live handle per the contract.
|
||||||
|
let h = unsafe { &*(handle as *const SessionHandle) };
|
||||||
|
let w = (surface_width.max(0) as u32) & 0xffff;
|
||||||
|
let ht = (surface_height.max(0) as u32) & 0xffff;
|
||||||
|
let _ = h.client.send_input(&InputEvent {
|
||||||
|
kind: InputKind::MouseMoveAbs,
|
||||||
|
_pad: [0; 3],
|
||||||
|
code: 0,
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
flags: (w << 16) | ht,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/// `NativeBridge.nativeSendPointerButton(handle, button, down)` — one button transition.
|
/// `NativeBridge.nativeSendPointerButton(handle, button, down)` — one button transition.
|
||||||
/// `button`: GameStream id (1=left, 2=middle, 3=right, 4=X1, 5=X2). `down`: 1=press, 0=release.
|
/// `button`: GameStream id (1=left, 2=middle, 3=right, 4=X1, 5=X2). `down`: 1=press, 0=release.
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
|||||||
@@ -16,6 +16,15 @@ let package = Package(
|
|||||||
.target(
|
.target(
|
||||||
name: "PunktfunkKit",
|
name: "PunktfunkKit",
|
||||||
dependencies: ["PunktfunkCore"],
|
dependencies: ["PunktfunkCore"],
|
||||||
|
// OSS attribution shown by the app's Acknowledgements screen. Bundled here (not in the
|
||||||
|
// app target) so it rides along via Bundle.module in both `swift build` and the Xcode
|
||||||
|
// app, which links the PunktfunkKit product. Refresh with
|
||||||
|
// scripts/gen-third-party-notices.sh (it copies the generated file into Resources/).
|
||||||
|
resources: [
|
||||||
|
.copy("Resources/THIRD-PARTY-NOTICES.txt"),
|
||||||
|
.copy("Resources/LICENSE-MIT.txt"),
|
||||||
|
.copy("Resources/LICENSE-APACHE.txt"),
|
||||||
|
],
|
||||||
linkerSettings: [
|
linkerSettings: [
|
||||||
// Rust staticlib system deps.
|
// Rust staticlib system deps.
|
||||||
.linkedFramework("Security"),
|
.linkedFramework("Security"),
|
||||||
|
|||||||
+53
-1
@@ -174,6 +174,58 @@ signing, bundle id `io.unom.punktfunk`. Notes:
|
|||||||
in a simulator via `xcrun simctl install/launch` — `SIMCTL_CHILD_PUNKTFUNK_AUTOCONNECT=…`
|
in a simulator via `xcrun simctl install/launch` — `SIMCTL_CHILD_PUNKTFUNK_AUTOCONNECT=…`
|
||||||
passes the dev autoconnect env through).
|
passes the dev autoconnect env through).
|
||||||
|
|
||||||
|
## App Store screenshots
|
||||||
|
|
||||||
|
Automated, faithful screenshots of the real UI for App Store Connect — one set per platform at
|
||||||
|
exactly the accepted pixel sizes. Driver: **`tools/screenshots.sh`**.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
tools/screenshots.sh all # macOS + (if full Xcode) iOS, iPadOS, tvOS → ./screenshots
|
||||||
|
tools/screenshots.sh macos # just macOS
|
||||||
|
OUT=~/Desktop/shots tools/screenshots.sh ios ipad tvos
|
||||||
|
PUNKTFUNK_SHOT_HERO=~/frame.png tools/screenshots.sh ios # real captured frame behind the hero
|
||||||
|
```
|
||||||
|
|
||||||
|
How it works: the app has a DEBUG-only **shot mode** (`Sources/PunktfunkClient/Screenshots/`).
|
||||||
|
Launched with `PUNKTFUNK_SHOT_SCENE=<name>` it renders **one** mock-populated screen full-bleed
|
||||||
|
(`ScreenshotHostView`) instead of `ContentView`, then the OS screenshots the *real, fully-rendered*
|
||||||
|
window — `screencapture` on macOS, `xcrun simctl io booted screenshot` on the Simulators. The five
|
||||||
|
scenes (`ShotScenes.all`): `01-stream` (the stream hero — a synthetic frame + the glass HUD, since
|
||||||
|
`StreamView` needs a live connection), `02-hosts`, `03-pair`, `04-trust`, `05-settings`. Mock data
|
||||||
|
is in `ShotMock`; nothing touches a host.
|
||||||
|
|
||||||
|
Output pixels are App Store Connect's required/largest sizes (Apple auto-derives the smaller ones):
|
||||||
|
`mac` 2880×1800 · `iphone-6.9` 1320×2868 (hero 2868×1320) · `ipad-13` 2064×2752 (hero 2752×2064) ·
|
||||||
|
`appletv` 1920×1080.
|
||||||
|
|
||||||
|
Why not `ImageRenderer` (the obvious offscreen route)? It can't rasterize this app's chrome —
|
||||||
|
`NavigationStack`, `Form`/`TabView`, and Liquid-Glass/`NSVisualEffect` materials all render black or
|
||||||
|
SwiftUI's "can't render" placeholder. Capturing the live window/Simulator avoids that entirely.
|
||||||
|
|
||||||
|
Requirements / gotchas:
|
||||||
|
- **macOS**: only the Swift toolchain is needed, **plus a one-time Screen Recording grant** for
|
||||||
|
your terminal (System Settings → Privacy & Security → Screen Recording) — without it
|
||||||
|
`screencapture -l` fails with "could not create image from window". (A no-permission fallback,
|
||||||
|
`PUNKTFUNK_SHOT_SELFCAPTURE=<dir>`, uses `cacheDisplay` — but it omits material blur and can't
|
||||||
|
read `ScrollView` content, so it's for quick checks, not submission.)
|
||||||
|
- **iOS/iPadOS/tvOS**: needs **full Xcode** (xcodebuild + Simulators), not just Command Line Tools,
|
||||||
|
and the matching device Simulators installed (iPhone 16 Pro Max, iPad Pro 13", Apple TV). Run it
|
||||||
|
on a full-Xcode Mac (e.g. the `macos-arm64` CI mini).
|
||||||
|
- The hero defaults to a synthetic synthwave frame — set `PUNKTFUNK_SHOT_HERO` to a real captured
|
||||||
|
frame for a production-quality lead screenshot.
|
||||||
|
|
||||||
|
**CI**: the `apple` workflow's **`screenshots`** job runs on the `macos-arm64` runner on every main
|
||||||
|
push + manual dispatch (skipped on PRs), and attaches the result as a single zip artifact,
|
||||||
|
**`punktfunk-appstore-screenshots`** (download it from the run's Artifacts; `upload-artifact@v3` —
|
||||||
|
Gitea's backend rejects v4). It captures the two **required iOS sizes — iPhone 6.9" + iPad 13"** —
|
||||||
|
on the Simulator (auto-creating the device if the runner lacks it), and is isolated from the
|
||||||
|
build/test job so a capture hiccup never reds the build.
|
||||||
|
|
||||||
|
**macOS and tvOS are NOT in CI**, by design: the self-hosted runner is **headless** (no
|
||||||
|
window-server session), so the macOS window capture can't run there, and tvOS needs the Tier-3
|
||||||
|
build-std slice. Generate those on a GUI Mac: `tools/screenshots.sh macos tvos`. (If the runner is
|
||||||
|
ever switched to a logged-in GUI session, re-adding macOS to the job's capture step is one line.)
|
||||||
|
|
||||||
## Notes for whoever picks this up next
|
## Notes for whoever picks this up next
|
||||||
|
|
||||||
1. **cbindgen import quirk** (the predicted "small compile fixes", now fixed): the
|
1. **cbindgen import quirk** (the predicted "small compile fixes", now fixed): the
|
||||||
@@ -309,4 +361,4 @@ signing, bundle id `io.unom.punktfunk`. Notes:
|
|||||||
- Mid-stream renegotiation (resolution change without reconnect) is designed-for but not
|
- Mid-stream renegotiation (resolution change without reconnect) is designed-for but not
|
||||||
implemented (the Welcome is one-shot today).
|
implemented (the Welcome is one-shot today).
|
||||||
- Host-side gamepad injection needs `/dev/uinput` access on the box (udev rule from
|
- Host-side gamepad injection needs `/dev/uinput` access on the box (udev rule from
|
||||||
`docs/linux-setup.md`).
|
`design/linux-setup.md`).
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
import PunktfunkKit
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
/// Open-source acknowledgements: punktfunk's own license (MIT OR Apache-2.0) followed by the
|
||||||
|
/// third-party software notices. Used as a pushed view on iOS/tvOS and a preferences tab on macOS.
|
||||||
|
struct AcknowledgementsView: View {
|
||||||
|
private var version: String? {
|
||||||
|
Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
ScrollView {
|
||||||
|
VStack(alignment: .leading, spacing: 18) {
|
||||||
|
Text("punktfunk")
|
||||||
|
.font(.title2).bold()
|
||||||
|
if let version {
|
||||||
|
Text("Version \(version)")
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
}
|
||||||
|
Text(Licenses.appLicense)
|
||||||
|
.font(.caption.monospaced())
|
||||||
|
.modifier(SelectableText())
|
||||||
|
|
||||||
|
Divider()
|
||||||
|
|
||||||
|
Text("Third-party software")
|
||||||
|
.font(.headline)
|
||||||
|
Text(
|
||||||
|
"punktfunk uses the open-source components below, each under its own license. "
|
||||||
|
+ "On some platforms FFmpeg is additionally bundled under the LGPL v2.1+ "
|
||||||
|
+ "(dynamically linked, replaceable)."
|
||||||
|
)
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
Text(Licenses.thirdPartyNotices)
|
||||||
|
.font(.caption2.monospaced())
|
||||||
|
.modifier(SelectableText())
|
||||||
|
}
|
||||||
|
.frame(maxWidth: 900, alignment: .leading)
|
||||||
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
|
.padding()
|
||||||
|
#if os(tvOS)
|
||||||
|
.padding(40)
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
.navigationTitle("Acknowledgements")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// `textSelection(.enabled)` is unavailable on tvOS, so apply it only where it exists.
|
||||||
|
private struct SelectableText: ViewModifier {
|
||||||
|
func body(content: Content) -> some View {
|
||||||
|
#if os(tvOS)
|
||||||
|
content
|
||||||
|
#else
|
||||||
|
content.textSelection(.enabled)
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,10 +4,12 @@
|
|||||||
// (HomeView/HostCards), the trust prompt (TrustCardView), and the HUD (StreamHUDView) live in
|
// (HomeView/HostCards), the trust prompt (TrustCardView), and the HUD (StreamHUDView) live in
|
||||||
// their own files.
|
// their own files.
|
||||||
//
|
//
|
||||||
// Two ways to establish trust on first contact: the TOFU prompt (host fingerprint over the
|
// Ways to establish trust on first contact: the TOFU prompt (host fingerprint over the
|
||||||
// live-but-blurred stream, compared with the host's log) or the PIN pairing ceremony — pairing
|
// live-but-blurred stream, compared with the host's log; only for a host advertising pair=optional),
|
||||||
// verifies both sides at once and is the only way into hosts running --require-pairing. Once
|
// the PIN pairing ceremony (verifies both sides at once), or — for a host that requires pairing —
|
||||||
// pinned, reconnects are silent and a changed host identity refuses to connect.
|
// delegated approval ("Request Access": a plain identified connect the host parks until the operator
|
||||||
|
// approves this device in its console, no PIN). Once pinned, reconnects are silent and a changed
|
||||||
|
// host identity refuses to connect.
|
||||||
|
|
||||||
#if os(macOS)
|
#if os(macOS)
|
||||||
import AppKit
|
import AppKit
|
||||||
@@ -25,11 +27,18 @@ struct ContentView: View {
|
|||||||
@AppStorage(DefaultsKey.compositor) private var compositor = 0
|
@AppStorage(DefaultsKey.compositor) private var compositor = 0
|
||||||
@AppStorage(DefaultsKey.gamepadType) private var gamepadType = 0
|
@AppStorage(DefaultsKey.gamepadType) private var gamepadType = 0
|
||||||
@AppStorage(DefaultsKey.bitrateKbps) private var bitrateKbps = 0
|
@AppStorage(DefaultsKey.bitrateKbps) private var bitrateKbps = 0
|
||||||
|
@AppStorage(DefaultsKey.audioChannels) private var audioChannels = 2
|
||||||
@AppStorage(DefaultsKey.fullscreenWhileStreaming) private var fullscreenWhileStreaming = true
|
@AppStorage(DefaultsKey.fullscreenWhileStreaming) private var fullscreenWhileStreaming = true
|
||||||
@AppStorage(DefaultsKey.hudEnabled) private var hudEnabled = true
|
@AppStorage(DefaultsKey.hudEnabled) private var hudEnabled = true
|
||||||
@AppStorage(DefaultsKey.hudPlacement) private var hudPlacement = HUDPlacement.topTrailing.rawValue
|
@AppStorage(DefaultsKey.hudPlacement) private var hudPlacement = HUDPlacement.topTrailing.rawValue
|
||||||
@State private var showAddHost = false
|
@State private var showAddHost = false
|
||||||
@State private var pairingTarget: StoredHost?
|
@State private var pairingTarget: StoredHost?
|
||||||
|
/// A fresh `pair=required`/unknown host the user tapped: drives the choice between no-PIN
|
||||||
|
/// delegated approval ("Request Access") and the SPAKE2 PIN ceremony (rule 3b).
|
||||||
|
@State private var approvalChoice: ApprovalRequest?
|
||||||
|
/// A delegated-approval connect is in flight (host parks it until the operator approves):
|
||||||
|
/// drives the cancelable "Waiting for approval" prompt and the pin-as-paired on success.
|
||||||
|
@State private var awaitingApproval: ApprovalRequest?
|
||||||
@State private var speedTestTarget: StoredHost?
|
@State private var speedTestTarget: StoredHost?
|
||||||
@State private var libraryTarget: StoredHost?
|
@State private var libraryTarget: StoredHost?
|
||||||
#if !os(macOS)
|
#if !os(macOS)
|
||||||
@@ -54,10 +63,27 @@ struct ContentView: View {
|
|||||||
autoConnectIfAsked()
|
autoConnectIfAsked()
|
||||||
}
|
}
|
||||||
.onChange(of: model.phase) { _, phase in
|
.onChange(of: model.phase) { _, phase in
|
||||||
// A session actually started — remember it on the card ("Connected … ago"
|
switch phase {
|
||||||
// plus the accent ring on the most recent host).
|
case .streaming:
|
||||||
if case .streaming = phase, let host = model.activeHost {
|
// A session actually started — remember it on the card ("Connected … ago"
|
||||||
|
// plus the accent ring on the most recent host).
|
||||||
|
guard let host = model.activeHost else { break }
|
||||||
store.markConnected(host.id)
|
store.markConnected(host.id)
|
||||||
|
// Delegated approval just succeeded: the operator let this device in, so pin the
|
||||||
|
// host's observed fingerprint and remember it as paired — future connects are then
|
||||||
|
// silent (rule 1), exactly like after a PIN/TOFU success. Dismisses the wait prompt.
|
||||||
|
if awaitingApproval?.host.id == host.id {
|
||||||
|
if let fp = model.connection?.hostFingerprint {
|
||||||
|
store.pin(host.id, fingerprint: fp)
|
||||||
|
}
|
||||||
|
awaitingApproval = nil
|
||||||
|
}
|
||||||
|
case .idle:
|
||||||
|
// The delegated-approval connect failed, timed out, or was cancelled — drop the
|
||||||
|
// wait prompt (SessionModel surfaces any error via `errorMessage`).
|
||||||
|
if awaitingApproval != nil { awaitingApproval = nil }
|
||||||
|
default:
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.onDisappear { model.disconnect() } // window closed mid-session (Cmd+N spawns more)
|
.onDisappear { model.disconnect() } // window closed mid-session (Cmd+N spawns more)
|
||||||
@@ -89,6 +115,47 @@ struct ContentView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
// Fresh pair=required / unknown host: offer the two ways in. An action sheet (not an
|
||||||
|
// alert) so it never collides with the wait alert below. "Request Access" is the no-PIN
|
||||||
|
// delegated-approval path; "Pair with PIN…" runs the SPAKE2 ceremony. The follow-on
|
||||||
|
// presentation is deferred a tick so this dialog is fully dismissed first.
|
||||||
|
.confirmationDialog(
|
||||||
|
"Pairing required",
|
||||||
|
isPresented: Binding(
|
||||||
|
get: { approvalChoice != nil },
|
||||||
|
set: { if !$0 { approvalChoice = nil } }),
|
||||||
|
titleVisibility: .visible,
|
||||||
|
presenting: approvalChoice
|
||||||
|
) { req in
|
||||||
|
Button("Request Access") {
|
||||||
|
DispatchQueue.main.async { requestAccess(req) }
|
||||||
|
}
|
||||||
|
Button("Pair with PIN…") {
|
||||||
|
DispatchQueue.main.async { pairingTarget = req.host }
|
||||||
|
}
|
||||||
|
Button("Cancel", role: .cancel) {}
|
||||||
|
} message: { req in
|
||||||
|
Text("\(req.host.displayName) requires pairing. Request access and approve this "
|
||||||
|
+ "device in the host's web console (port 3000 → Pairing) — no PIN needed. Or "
|
||||||
|
+ "pair with the 4-digit PIN it can display.")
|
||||||
|
}
|
||||||
|
// The delegated-approval wait: the host holds the connection open until the operator
|
||||||
|
// approves it. Cancel returns the UI at once; the in-flight connect is left to time out
|
||||||
|
// and its late result is discarded by SessionModel's connect guard (disconnect resets the
|
||||||
|
// phase/host it checks).
|
||||||
|
.alert(
|
||||||
|
"Waiting for approval",
|
||||||
|
isPresented: Binding(
|
||||||
|
get: { awaitingApproval != nil },
|
||||||
|
set: { if !$0 { awaitingApproval = nil } }),
|
||||||
|
presenting: awaitingApproval
|
||||||
|
) { _ in
|
||||||
|
Button("Cancel", role: .cancel) { model.disconnect() }
|
||||||
|
} message: { req in
|
||||||
|
Text("Approve \u{201C}\(localDeviceName)\u{201D} in \(req.host.displayName)'s web "
|
||||||
|
+ "console (port 3000 → Pairing). This device connects automatically once you "
|
||||||
|
+ "approve it — no need to reconnect.")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private var home: some View {
|
private var home: some View {
|
||||||
@@ -229,19 +296,32 @@ struct ContentView: View {
|
|||||||
// A pinned host connects on its stored fingerprint; an unpinned host may only TOFU when
|
// A pinned host connects on its stored fingerprint; an unpinned host may only TOFU when
|
||||||
// the host's LIVE advert says `pair=optional` (rule 3a). When the caller doesn't already
|
// the host's LIVE advert says `pair=optional` (rule 3a). When the caller doesn't already
|
||||||
// know the policy (a saved-card tap / manual entry), resolve it from the current mDNS set:
|
// know the policy (a saved-card tap / manual entry), resolve it from the current mDNS set:
|
||||||
// an unpinned host with no matching `pair=optional` advert routes to PIN pairing instead
|
// an unpinned host with no matching `pair=optional` advert routes to the approval choice
|
||||||
// of silently entering the trust prompt (rules 3b + 4). A pinned host ignores all of this.
|
// (request access / pair with PIN) instead of silently entering the trust prompt (rules
|
||||||
|
// 3b + 4). A pinned host ignores all of this.
|
||||||
if host.pinnedSHA256 == nil {
|
if host.pinnedSHA256 == nil {
|
||||||
let tofuOK = allowTofu ?? discovery.hosts.contains {
|
let tofuOK = allowTofu ?? discovery.hosts.contains {
|
||||||
host.matches($0) && $0.allowsTofu
|
host.matches($0) && $0.allowsTofu
|
||||||
}
|
}
|
||||||
if !tofuOK {
|
if !tofuOK {
|
||||||
pairingTarget = host
|
// pair=required / unknown policy / manual entry (rule 3b): never a silent
|
||||||
|
// connect — offer no-PIN delegated approval or the PIN ceremony.
|
||||||
|
approvalChoice = ApprovalRequest(
|
||||||
|
host: host, advertisedFingerprint: advertisedFingerprint(for: host))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// The gamepad-type setting resolves NOW (Automatic → match the active physical
|
startSession(host, launchID: launchID, allowTofu: host.pinnedSHA256 == nil)
|
||||||
// controller): the host's virtual pad backend is fixed per session.
|
}
|
||||||
|
|
||||||
|
/// Resolve the @AppStorage stream mode + input prefs and hand off to the session model. The
|
||||||
|
/// gamepad-type setting resolves NOW (Automatic → match the active physical controller): the
|
||||||
|
/// host's virtual pad backend is fixed per session. `requestAccess` opens the no-PIN
|
||||||
|
/// delegated-approval connect (host parks it until the operator approves).
|
||||||
|
private func startSession(
|
||||||
|
_ host: StoredHost, launchID: String? = nil,
|
||||||
|
allowTofu: Bool, requestAccess: Bool = false
|
||||||
|
) {
|
||||||
model.connect(
|
model.connect(
|
||||||
to: host,
|
to: host,
|
||||||
width: UInt32(clamping: width), height: UInt32(clamping: height),
|
width: UInt32(clamping: width), height: UInt32(clamping: height),
|
||||||
@@ -252,8 +332,24 @@ struct ContentView: View {
|
|||||||
setting: PunktfunkConnection.GamepadType(
|
setting: PunktfunkConnection.GamepadType(
|
||||||
rawValue: UInt32(clamping: gamepadType)) ?? .auto),
|
rawValue: UInt32(clamping: gamepadType)) ?? .auto),
|
||||||
bitrateKbps: UInt32(clamping: bitrateKbps),
|
bitrateKbps: UInt32(clamping: bitrateKbps),
|
||||||
|
audioChannels: UInt8(clamping: audioChannels),
|
||||||
launchID: launchID,
|
launchID: launchID,
|
||||||
allowTofu: host.pinnedSHA256 == nil)
|
allowTofu: allowTofu,
|
||||||
|
requestAccess: requestAccess)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The no-PIN delegated-approval flow: open an identified connect the host parks until the
|
||||||
|
/// operator approves it in the console, showing the cancelable "Waiting for approval" prompt
|
||||||
|
/// meanwhile. On success the SAME connection is admitted (no reconnect) and the host is pinned
|
||||||
|
/// as paired (see the `.streaming` branch of `onChange`).
|
||||||
|
private func requestAccess(_ req: ApprovalRequest) {
|
||||||
|
guard !model.isBusy else { return }
|
||||||
|
awaitingApproval = req
|
||||||
|
// Pin the advertised certificate for a discovered host (impostor defence during the long
|
||||||
|
// wait); a manually-typed host has no advertised fingerprint, so trust-on-first-use.
|
||||||
|
var host = req.host
|
||||||
|
host.pinnedSHA256 = req.advertisedFingerprint
|
||||||
|
startSession(host, allowTofu: false, requestAccess: true)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Picked a title in the (experimental) library: dismiss the browser and start a session that
|
/// Picked a title in the (experimental) library: dismiss the browser and start a session that
|
||||||
@@ -266,8 +362,9 @@ struct ContentView: View {
|
|||||||
/// Tap a discovered host: save it (so the session has a stored identity and the trust pin
|
/// Tap a discovered host: save it (so the session has a stored identity and the trust pin
|
||||||
/// persists), then connect or pair per the host's advertised policy. The host is the policy
|
/// persists), then connect or pair per the host's advertised policy. The host is the policy
|
||||||
/// authority — TOFU is offered ONLY when it explicitly advertised `pair=optional` (rule 3a);
|
/// authority — TOFU is offered ONLY when it explicitly advertised `pair=optional` (rule 3a);
|
||||||
/// a `pair=required` host, or one with no/unknown `pair` field, goes straight to the PIN
|
/// a `pair=required` host, or one with no/unknown `pair` field, gets the approval choice
|
||||||
/// pairing ceremony (rule 3b). (A pinned discovered host connects silently inside `connect`.)
|
/// (request access / pair with PIN) (rule 3b). (A pinned discovered host connects silently
|
||||||
|
/// inside `connect`.)
|
||||||
private func connectDiscovered(_ d: DiscoveredHost) {
|
private func connectDiscovered(_ d: DiscoveredHost) {
|
||||||
guard !model.isBusy else { return }
|
guard !model.isBusy else { return }
|
||||||
let host = StoredHost(name: d.name, address: d.host, port: d.port)
|
let host = StoredHost(name: d.name, address: d.host, port: d.port)
|
||||||
@@ -275,7 +372,9 @@ struct ContentView: View {
|
|||||||
if d.allowsTofu {
|
if d.allowsTofu {
|
||||||
connect(host, allowTofu: true)
|
connect(host, allowTofu: true)
|
||||||
} else {
|
} else {
|
||||||
pairingTarget = host
|
// pair=required / unknown policy (rule 3b): offer no-PIN delegated approval or PIN.
|
||||||
|
approvalChoice = ApprovalRequest(
|
||||||
|
host: host, advertisedFingerprint: pinFingerprint(d.fingerprintHex))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -289,6 +388,30 @@ struct ContentView: View {
|
|||||||
connect(pinned)
|
connect(pinned)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The certificate fingerprint a live mDNS advert carries for this saved host (advisory — see
|
||||||
|
/// `HostDiscovery`), to pin during a delegated-approval wait. nil if the host isn't currently
|
||||||
|
/// advertising or advertised no/invalid `fp`.
|
||||||
|
private func advertisedFingerprint(for host: StoredHost) -> Data? {
|
||||||
|
pinFingerprint(discovery.hosts.first { host.matches($0) }?.fingerprintHex)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Parse an advertised cert fingerprint (lowercase hex) into the 32-byte pin the connect
|
||||||
|
/// expects; nil unless it's exactly a 32-byte (SHA-256) value, so a malformed advert falls
|
||||||
|
/// back to trust-on-first-use rather than failing the connect closed.
|
||||||
|
private func pinFingerprint(_ hex: String?) -> Data? {
|
||||||
|
guard let hex, let data = Data(hexString: hex), data.count == 32 else { return nil }
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
|
/// How the host lists this device in its approval prompt (matches PairSheet's client name).
|
||||||
|
private var localDeviceName: String {
|
||||||
|
#if os(macOS)
|
||||||
|
Host.current().localizedName ?? "Mac"
|
||||||
|
#else
|
||||||
|
UIDevice.current.name
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - First-run + dev hooks
|
// MARK: - First-run + dev hooks
|
||||||
|
|
||||||
/// First run on iOS: default the stream mode to this device's native screen so the
|
/// First run on iOS: default the stream mode to this device's native screen so the
|
||||||
@@ -351,6 +474,7 @@ struct ContentView: View {
|
|||||||
compositor: pref,
|
compositor: pref,
|
||||||
gamepad: pad,
|
gamepad: pad,
|
||||||
bitrateKbps: bitrate,
|
bitrateKbps: bitrate,
|
||||||
|
audioChannels: UInt8(clamping: audioChannels),
|
||||||
autoTrust: true)
|
autoTrust: true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -375,3 +499,31 @@ private struct FullscreenController: NSViewRepresentable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/// A fresh `pair=required`/unknown host pending a trust decision: drives both the "request access
|
||||||
|
/// vs. pair with PIN" choice and the subsequent approval wait. `advertisedFingerprint` is the
|
||||||
|
/// discovered host's advertised cert (nil for a manually-typed host → trust-on-first-use).
|
||||||
|
private struct ApprovalRequest {
|
||||||
|
let host: StoredHost
|
||||||
|
let advertisedFingerprint: Data?
|
||||||
|
}
|
||||||
|
|
||||||
|
private extension Data {
|
||||||
|
/// Parse an even-length hex string into bytes; nil on any non-hex character or odd length.
|
||||||
|
/// Used to turn an mDNS-advertised cert fingerprint into a connect pin.
|
||||||
|
init?(hexString: String) {
|
||||||
|
let chars = Array(hexString)
|
||||||
|
guard chars.count.isMultiple(of: 2) else { return nil }
|
||||||
|
var bytes = [UInt8]()
|
||||||
|
bytes.reserveCapacity(chars.count / 2)
|
||||||
|
var i = 0
|
||||||
|
while i < chars.count {
|
||||||
|
guard let hi = chars[i].hexDigitValue, let lo = chars[i + 1].hexDigitValue else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
bytes.append(UInt8(hi << 4 | lo))
|
||||||
|
i += 2
|
||||||
|
}
|
||||||
|
self = Data(bytes)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,387 @@
|
|||||||
|
// DEBUG-only controller test panel, reached from Settings → Controllers → "Test Controller…".
|
||||||
|
// It shows the live input of the active controller and lets you fire the host→client feedback
|
||||||
|
// channels — rumble, DualSense adaptive triggers, lightbar, player LEDs — straight at the
|
||||||
|
// physical pad (no host needed), so the rendering paths a session uses can be confirmed
|
||||||
|
// on-device. Driven by PunktfunkKit's `ControllerTester`, which reuses the real renderers.
|
||||||
|
//
|
||||||
|
// tvOS is excluded for now (it has no segmented picker / the panel wants a pointer-style
|
||||||
|
// layout); macOS + iOS/iPadOS cover the validation need.
|
||||||
|
|
||||||
|
#if DEBUG && !os(tvOS)
|
||||||
|
import GameController
|
||||||
|
import PunktfunkKit
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
@MainActor
|
||||||
|
struct ControllerTestView: View {
|
||||||
|
@Environment(\.dismiss) private var dismiss
|
||||||
|
@ObservedObject private var gamepads = GamepadManager.shared
|
||||||
|
@StateObject private var tester = ControllerTester()
|
||||||
|
|
||||||
|
@State private var heavyOn = false
|
||||||
|
@State private var lightOn = false
|
||||||
|
@State private var intensity = 0.75
|
||||||
|
@State private var triggerTarget = TriggerTarget.both
|
||||||
|
@State private var playerLED = -1
|
||||||
|
|
||||||
|
private enum TriggerTarget: String, CaseIterable, Identifiable {
|
||||||
|
case left = "L2", right = "R2", both = "Both"
|
||||||
|
var id: String { rawValue }
|
||||||
|
}
|
||||||
|
|
||||||
|
private struct TriggerDemo: Identifiable {
|
||||||
|
let label: String
|
||||||
|
let effect: DualSenseTriggerEffect
|
||||||
|
var id: String { label }
|
||||||
|
}
|
||||||
|
|
||||||
|
private static let triggerDemos: [TriggerDemo] = [
|
||||||
|
.init(label: "Off", effect: .off),
|
||||||
|
.init(label: "Resistance", effect: .feedback(start: 0.3, strength: 0.7)),
|
||||||
|
.init(label: "Weapon", effect: .weapon(start: 0.4, end: 0.7, strength: 0.9)),
|
||||||
|
.init(label: "Vibration", effect: .vibration(start: 0.1, amplitude: 0.8, frequency: 0.5)),
|
||||||
|
.init(label: "Bow", effect: .slope(start: 0.2, end: 0.9, startStrength: 0.2, endStrength: 0.9)),
|
||||||
|
]
|
||||||
|
|
||||||
|
// (display name, hardware colour, swatch colour)
|
||||||
|
private static let lightSwatches: [(String, GCColor, Color)] = [
|
||||||
|
("Red", GCColor(red: 1, green: 0, blue: 0), .red),
|
||||||
|
("Green", GCColor(red: 0, green: 1, blue: 0), .green),
|
||||||
|
("Blue", GCColor(red: 0, green: 0.2, blue: 1), .blue),
|
||||||
|
("White", GCColor(red: 1, green: 1, blue: 1), .white),
|
||||||
|
]
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
VStack(spacing: 0) {
|
||||||
|
HStack {
|
||||||
|
Text("Test Controller").font(.headline)
|
||||||
|
Spacer()
|
||||||
|
Button("Done") { dismiss() }.keyboardShortcut(.cancelAction)
|
||||||
|
}
|
||||||
|
.padding()
|
||||||
|
Divider()
|
||||||
|
ScrollView {
|
||||||
|
VStack(alignment: .leading, spacing: 16) {
|
||||||
|
if let active = gamepads.active {
|
||||||
|
header(active)
|
||||||
|
inputCard
|
||||||
|
rumbleCard()
|
||||||
|
triggerCard(active)
|
||||||
|
extrasCard(active)
|
||||||
|
} else {
|
||||||
|
ContentUnavailableView(
|
||||||
|
"No controller",
|
||||||
|
systemImage: "gamecontroller",
|
||||||
|
description: Text("Connect a controller and pick it under "
|
||||||
|
+ "Settings → Controllers → Use controller."))
|
||||||
|
.frame(maxWidth: .infinity, minHeight: 220)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.frame(minWidth: 420, minHeight: 540)
|
||||||
|
.onAppear { tester.target(gamepads.active?.controller) }
|
||||||
|
.onDisappear { tester.stop() }
|
||||||
|
.onChange(of: gamepads.active?.id) { _, _ in
|
||||||
|
heavyOn = false
|
||||||
|
lightOn = false
|
||||||
|
playerLED = -1
|
||||||
|
tester.target(gamepads.active?.controller)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: Header
|
||||||
|
|
||||||
|
private func header(_ c: GamepadManager.DiscoveredController) -> some View {
|
||||||
|
HStack(spacing: 10) {
|
||||||
|
Image(systemName: c.isDualSense ? "playstation.logo" : "gamecontroller.fill")
|
||||||
|
.font(.title2)
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
VStack(alignment: .leading, spacing: 2) {
|
||||||
|
Text(c.name).font(.headline)
|
||||||
|
Text(c.productCategory).font(.caption).foregroundStyle(.secondary)
|
||||||
|
}
|
||||||
|
Spacer()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: Input
|
||||||
|
|
||||||
|
private var inputCard: some View {
|
||||||
|
card("Input") {
|
||||||
|
// Poll the live controller at 30 Hz — no handlers installed, so nothing else's
|
||||||
|
// capture is disturbed.
|
||||||
|
TimelineView(.periodic(from: .now, by: 1.0 / 30.0)) { _ in
|
||||||
|
if let gp = gamepads.active?.controller.extendedGamepad {
|
||||||
|
inputReadout(gp, controller: gamepads.active?.controller)
|
||||||
|
} else {
|
||||||
|
Text("Not an extended gamepad").foregroundStyle(.secondary)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ViewBuilder
|
||||||
|
private func inputReadout(_ g: GCExtendedGamepad, controller: GCController?) -> some View {
|
||||||
|
VStack(alignment: .leading, spacing: 14) {
|
||||||
|
HStack(alignment: .top, spacing: 20) {
|
||||||
|
stick("L", x: g.leftThumbstick.xAxis.value, y: g.leftThumbstick.yAxis.value,
|
||||||
|
pressed: g.leftThumbstickButton?.isPressed ?? false)
|
||||||
|
stick("R", x: g.rightThumbstick.xAxis.value, y: g.rightThumbstick.yAxis.value,
|
||||||
|
pressed: g.rightThumbstickButton?.isPressed ?? false)
|
||||||
|
VStack(spacing: 8) {
|
||||||
|
triggerBar("L2", value: g.leftTrigger.value)
|
||||||
|
triggerBar("R2", value: g.rightTrigger.value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
buttonGrid(g)
|
||||||
|
if let tp = Self.touchpad(g) {
|
||||||
|
touchpadView(tp)
|
||||||
|
}
|
||||||
|
if let m = controller?.motion {
|
||||||
|
motionReadout(m)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func stick(_ label: String, x: Float, y: Float, pressed: Bool) -> some View {
|
||||||
|
VStack(spacing: 4) {
|
||||||
|
ZStack {
|
||||||
|
Circle().stroke(Color.secondary.opacity(0.3))
|
||||||
|
Circle()
|
||||||
|
.fill(pressed ? Color.accentColor : Color.secondary)
|
||||||
|
.frame(width: 12, height: 12)
|
||||||
|
.offset(x: CGFloat(x) * 22, y: CGFloat(-y) * 22) // GC y is +up
|
||||||
|
}
|
||||||
|
.frame(width: 56, height: 56)
|
||||||
|
Text("\(label) \(sgn(x)),\(sgn(y))").font(.caption2.monospaced()).foregroundStyle(.secondary)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func triggerBar(_ label: String, value: Float) -> some View {
|
||||||
|
HStack(spacing: 6) {
|
||||||
|
Text(label).font(.caption2.monospaced()).frame(width: 22, alignment: .leading)
|
||||||
|
GeometryReader { geo in
|
||||||
|
ZStack(alignment: .leading) {
|
||||||
|
Capsule().fill(Color.secondary.opacity(0.15))
|
||||||
|
Capsule().fill(Color.accentColor).frame(width: geo.size.width * CGFloat(value))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.frame(height: 10)
|
||||||
|
Text(mag(value)).font(.caption2.monospaced()).frame(width: 34, alignment: .trailing)
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
}
|
||||||
|
.frame(width: 150)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func buttonGrid(_ g: GCExtendedGamepad) -> some View {
|
||||||
|
var items: [(String, Bool)] = [
|
||||||
|
("A", g.buttonA.isPressed), ("B", g.buttonB.isPressed),
|
||||||
|
("X", g.buttonX.isPressed), ("Y", g.buttonY.isPressed),
|
||||||
|
("LB", g.leftShoulder.isPressed), ("RB", g.rightShoulder.isPressed),
|
||||||
|
("L3", g.leftThumbstickButton?.isPressed ?? false),
|
||||||
|
("R3", g.rightThumbstickButton?.isPressed ?? false),
|
||||||
|
("Menu", g.buttonMenu.isPressed),
|
||||||
|
("Opts", g.buttonOptions?.isPressed ?? false),
|
||||||
|
("↑", g.dpad.up.isPressed), ("↓", g.dpad.down.isPressed),
|
||||||
|
("←", g.dpad.left.isPressed), ("→", g.dpad.right.isPressed),
|
||||||
|
]
|
||||||
|
if let tp = Self.touchpad(g) { items.append(("Pad", tp.button.isPressed)) }
|
||||||
|
return LazyVGrid(
|
||||||
|
columns: Array(repeating: GridItem(.flexible(), spacing: 6), count: 5), spacing: 6
|
||||||
|
) {
|
||||||
|
ForEach(items.indices, id: \.self) { i in
|
||||||
|
Text(items[i].0)
|
||||||
|
.font(.caption.monospaced())
|
||||||
|
.frame(maxWidth: .infinity, minHeight: 24)
|
||||||
|
.background(
|
||||||
|
RoundedRectangle(cornerRadius: 6)
|
||||||
|
.fill(items[i].1 ? Color.accentColor : Color.secondary.opacity(0.15)))
|
||||||
|
.foregroundStyle(items[i].1 ? Color.white : Color.secondary)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func touchpadView(
|
||||||
|
_ tp: (primary: GCControllerDirectionPad, secondary: GCControllerDirectionPad,
|
||||||
|
button: GCControllerButtonInput)
|
||||||
|
) -> some View {
|
||||||
|
VStack(alignment: .leading, spacing: 4) {
|
||||||
|
Text("Touchpad\(tp.button.isPressed ? " — click" : "")")
|
||||||
|
.font(.caption2).foregroundStyle(.secondary)
|
||||||
|
ZStack {
|
||||||
|
RoundedRectangle(cornerRadius: 8).stroke(Color.secondary.opacity(0.3))
|
||||||
|
fingerDot(tp.primary, color: .accentColor)
|
||||||
|
fingerDot(tp.secondary, color: .orange)
|
||||||
|
}
|
||||||
|
.frame(width: 150, height: 74)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func fingerDot(_ pad: GCControllerDirectionPad, color: Color) -> some View {
|
||||||
|
let x = pad.xAxis.value, y = pad.yAxis.value
|
||||||
|
let active = !(x == 0 && y == 0) // GC snaps a lifted finger to exactly (0, 0)
|
||||||
|
return Circle().fill(color).frame(width: 10, height: 10)
|
||||||
|
.offset(x: CGFloat(x) * 71, y: CGFloat(-y) * 33)
|
||||||
|
.opacity(active ? 1 : 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func motionReadout(_ m: GCMotion) -> some View {
|
||||||
|
let a = Self.totalAccel(m)
|
||||||
|
return VStack(alignment: .leading, spacing: 2) {
|
||||||
|
Text("Motion").font(.caption2).foregroundStyle(.secondary)
|
||||||
|
Text(String(format: "gyro %+.2f %+.2f %+.2f",
|
||||||
|
m.rotationRate.x, m.rotationRate.y, m.rotationRate.z))
|
||||||
|
.font(.caption2.monospaced())
|
||||||
|
Text(String(format: "accel %+.2f %+.2f %+.2f", a.0, a.1, a.2))
|
||||||
|
.font(.caption2.monospaced())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: Rumble
|
||||||
|
|
||||||
|
private func rumbleCard() -> some View {
|
||||||
|
card("Rumble") {
|
||||||
|
VStack(alignment: .leading, spacing: 12) {
|
||||||
|
Picker("Strength", selection: $intensity) {
|
||||||
|
Text("25%").tag(0.25)
|
||||||
|
Text("50%").tag(0.5)
|
||||||
|
Text("75%").tag(0.75)
|
||||||
|
Text("100%").tag(1.0)
|
||||||
|
}
|
||||||
|
.pickerStyle(.segmented)
|
||||||
|
Toggle("Heavy motor (left)", isOn: $heavyOn)
|
||||||
|
Toggle("Light motor (right)", isOn: $lightOn)
|
||||||
|
Label("Backend: \(tester.rumbleBackend)", systemImage: "waveform")
|
||||||
|
.font(.caption).foregroundStyle(.secondary)
|
||||||
|
Text("Toggle a motor to feel it. The host maps a game's low/high-frequency "
|
||||||
|
+ "rumble onto these two. A DualSense is driven over raw HID (CoreHaptics "
|
||||||
|
+ "can't reach its motors on macOS).")
|
||||||
|
.font(.caption).foregroundStyle(.secondary)
|
||||||
|
}
|
||||||
|
.onChange(of: heavyOn) { _, _ in applyRumble() }
|
||||||
|
.onChange(of: lightOn) { _, _ in applyRumble() }
|
||||||
|
.onChange(of: intensity) { _, _ in applyRumble() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func applyRumble() {
|
||||||
|
tester.rumble(low: heavyOn ? Float(intensity) : 0, high: lightOn ? Float(intensity) : 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: Adaptive triggers
|
||||||
|
|
||||||
|
private func triggerCard(_ c: GamepadManager.DiscoveredController) -> some View {
|
||||||
|
card("Adaptive triggers") {
|
||||||
|
if c.hasAdaptiveTriggers {
|
||||||
|
VStack(alignment: .leading, spacing: 12) {
|
||||||
|
Picker("Apply to", selection: $triggerTarget) {
|
||||||
|
ForEach(TriggerTarget.allCases) { Text($0.rawValue).tag($0) }
|
||||||
|
}
|
||||||
|
.pickerStyle(.segmented)
|
||||||
|
LazyVGrid(
|
||||||
|
columns: [GridItem(.adaptive(minimum: 96), spacing: 8)], spacing: 8
|
||||||
|
) {
|
||||||
|
ForEach(Self.triggerDemos) { demo in
|
||||||
|
Button(demo.label) { applyTrigger(demo.effect) }
|
||||||
|
.buttonStyle(.bordered)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Text("Pick an effect, then pull L2/R2 to feel the resistance.")
|
||||||
|
.font(.caption).foregroundStyle(.secondary)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Text("Adaptive triggers need a DualSense.")
|
||||||
|
.font(.caption).foregroundStyle(.secondary)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func applyTrigger(_ e: DualSenseTriggerEffect) {
|
||||||
|
switch triggerTarget {
|
||||||
|
case .left: tester.applyTrigger(e, right: false)
|
||||||
|
case .right: tester.applyTrigger(e, right: true)
|
||||||
|
case .both:
|
||||||
|
tester.applyTrigger(e, right: false)
|
||||||
|
tester.applyTrigger(e, right: true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: Lightbar + player LED
|
||||||
|
|
||||||
|
@ViewBuilder
|
||||||
|
private func extrasCard(_ c: GamepadManager.DiscoveredController) -> some View {
|
||||||
|
if c.hasLight {
|
||||||
|
card("Lightbar & player LED") {
|
||||||
|
VStack(alignment: .leading, spacing: 12) {
|
||||||
|
HStack(spacing: 12) {
|
||||||
|
ForEach(Self.lightSwatches.indices, id: \.self) { i in
|
||||||
|
Button { tester.setLight(Self.lightSwatches[i].1) } label: {
|
||||||
|
Circle().fill(Self.lightSwatches[i].2)
|
||||||
|
.frame(width: 26, height: 26)
|
||||||
|
.overlay(Circle().stroke(Color.secondary.opacity(0.4)))
|
||||||
|
}
|
||||||
|
.buttonStyle(.plain)
|
||||||
|
}
|
||||||
|
Button("Off") { tester.setLight(nil) }.buttonStyle(.bordered)
|
||||||
|
}
|
||||||
|
Picker("Player LED", selection: $playerLED) {
|
||||||
|
Text("Off").tag(-1)
|
||||||
|
Text("1").tag(0)
|
||||||
|
Text("2").tag(1)
|
||||||
|
Text("3").tag(2)
|
||||||
|
Text("4").tag(3)
|
||||||
|
}
|
||||||
|
.pickerStyle(.segmented)
|
||||||
|
.onChange(of: playerLED) { _, v in
|
||||||
|
tester.setPlayerIndex(GCControllerPlayerIndex(rawValue: v) ?? .indexUnset)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: Helpers
|
||||||
|
|
||||||
|
private func card<Content: View>(
|
||||||
|
_ title: String, @ViewBuilder _ content: () -> Content
|
||||||
|
) -> some View {
|
||||||
|
VStack(alignment: .leading, spacing: 10) {
|
||||||
|
Text(title).font(.subheadline.weight(.semibold))
|
||||||
|
content()
|
||||||
|
}
|
||||||
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
|
.padding(14)
|
||||||
|
.background(RoundedRectangle(cornerRadius: 12).fill(Color.secondary.opacity(0.08)))
|
||||||
|
}
|
||||||
|
|
||||||
|
private func sgn(_ v: Float) -> String { String(format: "%+.2f", v) }
|
||||||
|
private func mag(_ v: Float) -> String { String(format: "%.2f", v) }
|
||||||
|
|
||||||
|
/// The touchpad surface of a PlayStation pad — `GCDualSenseGamepad` and `GCDualShockGamepad`
|
||||||
|
/// don't share a touchpad type, so downcast either. `nil` for any other controller.
|
||||||
|
private static func touchpad(
|
||||||
|
_ g: GCExtendedGamepad
|
||||||
|
) -> (primary: GCControllerDirectionPad, secondary: GCControllerDirectionPad,
|
||||||
|
button: GCControllerButtonInput)? {
|
||||||
|
if let ds = g as? GCDualSenseGamepad {
|
||||||
|
return (ds.touchpadPrimary, ds.touchpadSecondary, ds.touchpadButton)
|
||||||
|
}
|
||||||
|
if let ds4 = g as? GCDualShockGamepad {
|
||||||
|
return (ds4.touchpadPrimary, ds4.touchpadSecondary, ds4.touchpadButton)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Total acceleration in g: gravity + user when the pad splits them, else the raw vector.
|
||||||
|
private static func totalAccel(_ m: GCMotion) -> (Double, Double, Double) {
|
||||||
|
if m.hasGravityAndUserAcceleration {
|
||||||
|
return (m.gravity.x + m.userAcceleration.x,
|
||||||
|
m.gravity.y + m.userAcceleration.y,
|
||||||
|
m.gravity.z + m.userAcceleration.z)
|
||||||
|
}
|
||||||
|
return (m.acceleration.x, m.acceleration.y, m.acceleration.z)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -14,7 +14,18 @@ struct PunktfunkClientApp: App {
|
|||||||
|
|
||||||
var body: some Scene {
|
var body: some Scene {
|
||||||
WindowGroup("Punktfunk") {
|
WindowGroup("Punktfunk") {
|
||||||
|
#if DEBUG
|
||||||
|
// PUNKTFUNK_SHOT_SCENE=<name> → show that single mock-populated screen full-bleed for
|
||||||
|
// the App Store screenshot capture (tools/screenshots.sh). Normal launch otherwise;
|
||||||
|
// the whole path is absent from Release builds.
|
||||||
|
if let scene = ScreenshotMode.requestedScene {
|
||||||
|
ScreenshotHostView(scene: scene)
|
||||||
|
} else {
|
||||||
|
ContentView()
|
||||||
|
}
|
||||||
|
#else
|
||||||
ContentView()
|
ContentView()
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
// The Stream menu (Disconnect ⌘D, Show/Hide Statistics ⌘⇧S) — a real menu bar on
|
// The Stream menu (Disconnect ⌘D, Show/Hide Statistics ⌘⇧S) — a real menu bar on
|
||||||
// macOS, hardware-keyboard shortcuts on iPad. tvOS has neither.
|
// macOS, hardware-keyboard shortcuts on iPad. tvOS has neither.
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
// App Store screenshot harness — device catalog.
|
||||||
|
//
|
||||||
|
// The harness captures the REAL running UI (not an offscreen ImageRenderer snapshot, which can't
|
||||||
|
// rasterize NavigationStack / Form / Liquid-Glass — they come out black). The app is launched in
|
||||||
|
// "shot mode" (PUNKTFUNK_SHOT_SCENE=<name>, see ScreenshotHost) showing one mock-populated scene
|
||||||
|
// full-bleed, and the OS screenshots it: `xcrun simctl io booted screenshot` on the iOS/tvOS
|
||||||
|
// simulators (native pixels = the exact App Store size), `screencapture` for the mac window.
|
||||||
|
// tools/screenshots.sh drives it. DEBUG-only — none of this ships in Release.
|
||||||
|
//
|
||||||
|
// This catalog records the target App Store sizes; on Apple platforms only the mac size is read
|
||||||
|
// at runtime (to size the capture window) — the simulator IS the device, so iOS/tvOS pixels are
|
||||||
|
// whatever the booted device is.
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
import CoreGraphics
|
||||||
|
|
||||||
|
enum ShotOrientation { case natural, portrait, landscape }
|
||||||
|
|
||||||
|
/// A target App Store canvas: a natural-orientation pixel size + backing scale.
|
||||||
|
struct ShotDevice {
|
||||||
|
let id: String
|
||||||
|
let naturalWidth: Int
|
||||||
|
let naturalHeight: Int
|
||||||
|
let scale: CGFloat
|
||||||
|
|
||||||
|
func pixels(_ o: ShotOrientation) -> (w: Int, h: Int) {
|
||||||
|
let long = max(naturalWidth, naturalHeight)
|
||||||
|
let short = min(naturalWidth, naturalHeight)
|
||||||
|
switch o {
|
||||||
|
case .natural: return (naturalWidth, naturalHeight)
|
||||||
|
case .portrait: return (short, long)
|
||||||
|
case .landscape: return (long, short)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Logical point size (pixels / scale) — used to size the mac capture window so that a
|
||||||
|
/// `screencapture` on a 2× display yields exactly `pixels(_:)`.
|
||||||
|
func points(_ o: ShotOrientation) -> CGSize {
|
||||||
|
let (w, h) = pixels(o)
|
||||||
|
return CGSize(width: CGFloat(w) / scale, height: CGFloat(h) / scale)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Mac: 2880×1800 (16:10 Retina) — an accepted size; on a 1× display the window capture is
|
||||||
|
/// 1440×900, also accepted.
|
||||||
|
static let mac = ShotDevice(id: "mac", naturalWidth: 2880, naturalHeight: 1800, scale: 2)
|
||||||
|
|
||||||
|
/// iPhone 6.9" (required) — for reference / the driver script's simulator choice.
|
||||||
|
static let iphone69 = ShotDevice(id: "iphone-6.9", naturalWidth: 1320, naturalHeight: 2868,
|
||||||
|
scale: 3)
|
||||||
|
/// iPad 13" (required).
|
||||||
|
static let ipad13 = ShotDevice(id: "ipad-13", naturalWidth: 2064, naturalHeight: 2752,
|
||||||
|
scale: 2)
|
||||||
|
/// Apple TV (always landscape).
|
||||||
|
static let appleTV = ShotDevice(id: "appletv", naturalWidth: 1920, naturalHeight: 1080,
|
||||||
|
scale: 1)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,147 @@
|
|||||||
|
// App Store screenshot harness — the in-app "shot mode" root.
|
||||||
|
//
|
||||||
|
// Launched with PUNKTFUNK_SHOT_SCENE=<name> (one of ShotScenes.all), the app shows that single
|
||||||
|
// mock-populated scene full-bleed instead of ContentView, so the OS can screenshot the REAL,
|
||||||
|
// fully-rendered UI (materials, NavigationStack, glass — all the things ImageRenderer can't
|
||||||
|
// rasterize offscreen). tools/screenshots.sh drives one launch per scene per device.
|
||||||
|
//
|
||||||
|
// Capture per platform:
|
||||||
|
// • iOS / tvOS simulator → `xcrun simctl io booted screenshot` (native pixels = exact size).
|
||||||
|
// • macOS → `screencapture -l<windowID>` of the borderless capture window (the configurator
|
||||||
|
// prints `PF_SHOT_WINDOW=<id>`), or the no-permission self-capture fallback
|
||||||
|
// (PUNKTFUNK_SHOT_SELFCAPTURE=<dir> → cacheDisplay; renders the real hierarchy but, like all
|
||||||
|
// non-window-server capture, omits material blur).
|
||||||
|
//
|
||||||
|
// Every screen prints `PF_SHOT_READY scene=<name>` to stdout once it has settled, so the driver
|
||||||
|
// can wait for layout instead of guessing with a fixed sleep.
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
import SwiftUI
|
||||||
|
#if os(macOS)
|
||||||
|
import AppKit
|
||||||
|
import ImageIO
|
||||||
|
#endif
|
||||||
|
|
||||||
|
@MainActor
|
||||||
|
enum ScreenshotMode {
|
||||||
|
/// The scene requested via PUNKTFUNK_SHOT_SCENE, or nil for a normal launch.
|
||||||
|
static var requestedScene: ShotScene? {
|
||||||
|
let name = ProcessInfo.processInfo.environment["PUNKTFUNK_SHOT_SCENE"] ?? ""
|
||||||
|
guard !name.isEmpty else { return nil }
|
||||||
|
return ShotScenes.all.first { $0.name == name }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Full-bleed host for a single scene, with per-platform window sizing / orientation and a
|
||||||
|
/// readiness ping for the capture script.
|
||||||
|
struct ScreenshotHostView: View {
|
||||||
|
let scene: ShotScene
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
scene.make()
|
||||||
|
.environment(\.colorScheme, scene.colorScheme)
|
||||||
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||||
|
.background(Color.black)
|
||||||
|
.ignoresSafeArea()
|
||||||
|
#if os(macOS)
|
||||||
|
.background(MacShotWindowConfigurator(scene: scene))
|
||||||
|
#elseif os(iOS)
|
||||||
|
.background(IOSOrientationConfigurator(orientation: scene.orientation))
|
||||||
|
#endif
|
||||||
|
.task {
|
||||||
|
// Let layout + materials settle, then signal the driver.
|
||||||
|
try? await Task.sleep(nanoseconds: 900_000_000)
|
||||||
|
announceReady()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func announceReady() {
|
||||||
|
print("PF_SHOT_READY scene=\(scene.name)")
|
||||||
|
fflush(stdout)
|
||||||
|
#if os(macOS)
|
||||||
|
MacSelfCapture.captureIfRequested(scene: scene)
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if os(macOS)
|
||||||
|
/// Sizes the hosting window to the mac canvas, strips the title bar to a clean full-bleed
|
||||||
|
/// surface, and prints the CGWindowID for `screencapture -l`.
|
||||||
|
private struct MacShotWindowConfigurator: NSViewRepresentable {
|
||||||
|
let scene: ShotScene
|
||||||
|
|
||||||
|
func makeNSView(context: Context) -> NSView { NSView() }
|
||||||
|
|
||||||
|
func updateNSView(_ view: NSView, context: Context) {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
guard let window = view.window, !context.coordinator.configured else { return }
|
||||||
|
context.coordinator.configured = true
|
||||||
|
// NavigationStack / Form / material chrome follow the WINDOW's appearance, not the
|
||||||
|
// SwiftUI colorScheme — without this the dark scenes render on a light window (white
|
||||||
|
// background, washed-out materials).
|
||||||
|
window.appearance = NSAppearance(named: scene.colorScheme == .dark ? .darkAqua : .aqua)
|
||||||
|
let size = ShotDevice.mac.points(scene.orientation)
|
||||||
|
window.styleMask = [.titled, .fullSizeContentView]
|
||||||
|
window.titlebarAppearsTransparent = true
|
||||||
|
window.titleVisibility = .hidden
|
||||||
|
window.isMovable = false
|
||||||
|
for button in [NSWindow.ButtonType.closeButton, .miniaturizeButton, .zoomButton] {
|
||||||
|
window.standardWindowButton(button)?.isHidden = true
|
||||||
|
}
|
||||||
|
window.setContentSize(size)
|
||||||
|
window.center()
|
||||||
|
window.makeKeyAndOrderFront(nil)
|
||||||
|
NSApp.activate(ignoringOtherApps: true)
|
||||||
|
print("PF_SHOT_WINDOW=\(window.windowNumber) scene=\(scene.name) "
|
||||||
|
+ "size=\(Int(size.width))x\(Int(size.height))pt")
|
||||||
|
fflush(stdout)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func makeCoordinator() -> Coordinator { Coordinator() }
|
||||||
|
final class Coordinator { var configured = false }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// No-permission fallback: capture the window's view tree via cacheDisplay. Renders the real
|
||||||
|
/// hierarchy (NavigationStack/Form/cards — unlike ImageRenderer) but omits material blur, which
|
||||||
|
/// only the window server (screencapture) composites. Used when PUNKTFUNK_SHOT_SELFCAPTURE is set.
|
||||||
|
enum MacSelfCapture {
|
||||||
|
static func captureIfRequested(scene: ShotScene) {
|
||||||
|
guard let dir = ProcessInfo.processInfo.environment["PUNKTFUNK_SHOT_SELFCAPTURE"],
|
||||||
|
!dir.isEmpty,
|
||||||
|
let window = NSApp.windows.first(where: { $0.isVisible }),
|
||||||
|
let content = window.contentView else { return }
|
||||||
|
let outDir = URL(fileURLWithPath: (dir as NSString).expandingTildeInPath, isDirectory: true)
|
||||||
|
try? FileManager.default.createDirectory(at: outDir, withIntermediateDirectories: true)
|
||||||
|
guard let rep = content.bitmapImageRepForCachingDisplay(in: content.bounds) else { return }
|
||||||
|
content.cacheDisplay(in: content.bounds, to: rep)
|
||||||
|
let url = outDir.appendingPathComponent("\(ShotDevice.mac.id)-\(scene.name).png")
|
||||||
|
if let dest = CGImageDestinationCreateWithURL(
|
||||||
|
url as CFURL, "public.png" as CFString, 1, nil), let cg = rep.cgImage {
|
||||||
|
CGImageDestinationAddImage(dest, cg, nil)
|
||||||
|
CGImageDestinationFinalize(dest)
|
||||||
|
print("PF_SHOT_SAVED \(url.path) \(rep.pixelsWide)x\(rep.pixelsHigh)px")
|
||||||
|
}
|
||||||
|
fflush(stdout)
|
||||||
|
exit(0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if os(iOS)
|
||||||
|
/// Best-effort orientation lock for the requested scene (landscape for the stream hero, portrait
|
||||||
|
/// for chrome). Requires the app to allow those orientations in Info.plist.
|
||||||
|
private struct IOSOrientationConfigurator: UIViewControllerRepresentable {
|
||||||
|
let orientation: ShotOrientation
|
||||||
|
|
||||||
|
func makeUIViewController(context: Context) -> UIViewController { UIViewController() }
|
||||||
|
|
||||||
|
func updateUIViewController(_ vc: UIViewController, context: Context) {
|
||||||
|
guard let scene = vc.view.window?.windowScene else { return }
|
||||||
|
let mask: UIInterfaceOrientationMask = orientation == .landscape ? .landscapeRight : .portrait
|
||||||
|
scene.requestGeometryUpdate(.iOS(interfaceOrientations: mask))
|
||||||
|
vc.setNeedsUpdateOfSupportedInterfaceOrientations()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,284 @@
|
|||||||
|
// App Store screenshot scenes — the actual screens we render, each wired with mock data so it
|
||||||
|
// looks populated without a live host. Every scene is built from the REAL app views (HomeView,
|
||||||
|
// SettingsView, PairSheet, TrustCardView) so the screenshots track the shipping UI; only the
|
||||||
|
// live stream is faked (StreamView needs a real punktfunk/1 connection — see ShotStreamHero).
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
import PunktfunkKit
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
/// One screen to capture: a name (→ file suffix), the canvas orientation, a color scheme, and a
|
||||||
|
/// factory that builds the populated view on the main actor.
|
||||||
|
struct ShotScene {
|
||||||
|
let name: String
|
||||||
|
let orientation: ShotOrientation
|
||||||
|
let colorScheme: ColorScheme
|
||||||
|
let make: @MainActor () -> AnyView
|
||||||
|
}
|
||||||
|
|
||||||
|
@MainActor
|
||||||
|
enum ShotScenes {
|
||||||
|
static let all: [ShotScene] = [
|
||||||
|
ShotScene(name: "01-stream", orientation: .landscape, colorScheme: .dark) {
|
||||||
|
AnyView(ShotStreamHero())
|
||||||
|
},
|
||||||
|
ShotScene(name: "02-hosts", orientation: .natural, colorScheme: .dark) {
|
||||||
|
AnyView(ShotHome())
|
||||||
|
},
|
||||||
|
ShotScene(name: "03-pair", orientation: .natural, colorScheme: .dark) {
|
||||||
|
AnyView(ShotPair())
|
||||||
|
},
|
||||||
|
ShotScene(name: "04-trust", orientation: .landscape, colorScheme: .dark) {
|
||||||
|
AnyView(ShotTrust())
|
||||||
|
},
|
||||||
|
ShotScene(name: "05-settings", orientation: .natural, colorScheme: .dark) {
|
||||||
|
AnyView(ShotSettings())
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Mock data
|
||||||
|
|
||||||
|
@MainActor
|
||||||
|
enum ShotMock {
|
||||||
|
/// A populated saved-host grid: a pinned recent host, a couple more, mixed online state.
|
||||||
|
static func hostStore() -> HostStore {
|
||||||
|
let store = HostStore()
|
||||||
|
store.hosts = [
|
||||||
|
StoredHost(name: "Battlestation", address: "192.168.1.20", port: 9777,
|
||||||
|
pinnedSHA256: fingerprint, lastConnected: Date().addingTimeInterval(-420)),
|
||||||
|
StoredHost(name: "Living Room PC", address: "192.168.1.41", port: 9777,
|
||||||
|
pinnedSHA256: fingerprint),
|
||||||
|
StoredHost(name: "Workshop", address: "10.0.0.7", port: 9777),
|
||||||
|
]
|
||||||
|
return store
|
||||||
|
}
|
||||||
|
|
||||||
|
static let host = StoredHost(name: "Battlestation", address: "192.168.1.20", port: 9777,
|
||||||
|
pinnedSHA256: fingerprint)
|
||||||
|
|
||||||
|
/// A plausible-looking 32-byte SHA-256 for the trust card / pin lock glyphs.
|
||||||
|
static let fingerprint = Data((0..<32).map { UInt8(($0 &* 37 &+ 0x1d) & 0xff) })
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Home
|
||||||
|
|
||||||
|
private struct ShotHome: View {
|
||||||
|
@StateObject private var store = ShotMock.hostStore()
|
||||||
|
@StateObject private var model = SessionModel()
|
||||||
|
@StateObject private var discovery = HostDiscovery()
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
#if os(macOS)
|
||||||
|
HomeView(
|
||||||
|
store: store, model: model, discovery: discovery,
|
||||||
|
showAddHost: .constant(false), pairingTarget: .constant(nil),
|
||||||
|
speedTestTarget: .constant(nil), libraryTarget: .constant(nil),
|
||||||
|
connect: { _ in }, connectDiscovered: { _ in },
|
||||||
|
onPaired: { _, _ in }, onLaunchTitle: { _, _ in })
|
||||||
|
#else
|
||||||
|
HomeView(
|
||||||
|
store: store, model: model, discovery: discovery,
|
||||||
|
showAddHost: .constant(false), pairingTarget: .constant(nil),
|
||||||
|
speedTestTarget: .constant(nil), libraryTarget: .constant(nil),
|
||||||
|
showSettings: .constant(false),
|
||||||
|
connect: { _ in }, connectDiscovered: { _ in },
|
||||||
|
onPaired: { _, _ in }, onLaunchTitle: { _, _ in })
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Settings
|
||||||
|
|
||||||
|
private struct ShotSettings: View {
|
||||||
|
var body: some View {
|
||||||
|
#if os(macOS)
|
||||||
|
// The mac Settings window is a fixed-size tabbed panel — float it over a dimmed host
|
||||||
|
// grid so the shot reads as the preferences window over the running app.
|
||||||
|
ZStack {
|
||||||
|
ShotHome().blur(radius: 24).overlay(Color.black.opacity(0.45))
|
||||||
|
SettingsView()
|
||||||
|
.fixedSize()
|
||||||
|
.clipShape(RoundedRectangle(cornerRadius: 12))
|
||||||
|
.shadow(radius: 40, y: 16)
|
||||||
|
}
|
||||||
|
#elseif os(iOS)
|
||||||
|
NavigationStack {
|
||||||
|
SettingsView()
|
||||||
|
.navigationTitle("Settings")
|
||||||
|
.navigationBarTitleDisplayMode(.inline)
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
NavigationStack { SettingsView() }
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Pair (PIN ceremony)
|
||||||
|
|
||||||
|
private struct ShotPair: View {
|
||||||
|
var body: some View {
|
||||||
|
ZStack {
|
||||||
|
ShotHome().blur(radius: 28).overlay(Color.black.opacity(0.5))
|
||||||
|
PairSheet(host: ShotMock.host, onPaired: { _ in })
|
||||||
|
.frame(maxWidth: 460)
|
||||||
|
.background(.regularMaterial, in: RoundedRectangle(cornerRadius: 18))
|
||||||
|
.clipShape(RoundedRectangle(cornerRadius: 18))
|
||||||
|
.shadow(radius: 40, y: 16)
|
||||||
|
.padding(40)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Trust (TOFU card over the blurred live stream)
|
||||||
|
|
||||||
|
private struct ShotTrust: View {
|
||||||
|
var body: some View {
|
||||||
|
ZStack {
|
||||||
|
ShotDesktopFrame()
|
||||||
|
.blur(radius: 32)
|
||||||
|
.overlay(Color.black.opacity(0.45))
|
||||||
|
TrustCardView(
|
||||||
|
fingerprint: ShotMock.fingerprint, hostName: "Battlestation",
|
||||||
|
onCancel: {}, onTrust: {}, onPairInstead: {})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Stream hero
|
||||||
|
|
||||||
|
/// The marketing hero: a stand-in streamed frame with the real glass HUD chip on top.
|
||||||
|
/// StreamView can't render here (it needs a live punktfunk/1 connection), so the frame is
|
||||||
|
/// synthetic — set `PUNKTFUNK_SHOT_HERO=/path/to/frame.png` to drop in a real captured frame.
|
||||||
|
private struct ShotStreamHero: View {
|
||||||
|
var body: some View {
|
||||||
|
ZStack(alignment: .topTrailing) {
|
||||||
|
ShotDesktopFrame()
|
||||||
|
ShotHUD()
|
||||||
|
}
|
||||||
|
.background(Color.black)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A faithful copy of StreamHUDView's overlay (which needs a live PunktfunkConnection for the
|
||||||
|
/// mode line) with representative numbers, reusing the app's real `.glassBackground`.
|
||||||
|
private struct ShotHUD: View {
|
||||||
|
var body: some View {
|
||||||
|
VStack(alignment: .trailing, spacing: 4) {
|
||||||
|
HStack(spacing: 6) {
|
||||||
|
Circle().fill(Color.accentColor).frame(width: 7, height: 7)
|
||||||
|
Text("5120×1440@240 240 fps 812.4 Mb/s")
|
||||||
|
.font(.system(.caption, design: .monospaced))
|
||||||
|
}
|
||||||
|
Text("capture→client 1.3/2.1 ms p50/p95")
|
||||||
|
.font(.system(.caption2, design: .monospaced))
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
#if os(macOS)
|
||||||
|
Text("⌘⎋ releases the mouse")
|
||||||
|
.font(.caption2).foregroundStyle(.secondary)
|
||||||
|
#elseif os(tvOS)
|
||||||
|
Text("Press Menu to disconnect")
|
||||||
|
.font(.caption).foregroundStyle(.secondary)
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
.padding(10)
|
||||||
|
.glassBackground(RoundedRectangle(cornerRadius: 10))
|
||||||
|
.padding(10)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A synthetic "streamed frame" — a synthwave scene that reads as game content without shipping
|
||||||
|
/// any real art. Replaced wholesale when `PUNKTFUNK_SHOT_HERO` points at a real PNG.
|
||||||
|
private struct ShotDesktopFrame: View {
|
||||||
|
var body: some View {
|
||||||
|
if let image = Self.overrideImage {
|
||||||
|
image.resizable().scaledToFill()
|
||||||
|
} else {
|
||||||
|
synthetic
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private var synthetic: some View {
|
||||||
|
ZStack {
|
||||||
|
LinearGradient(
|
||||||
|
colors: [
|
||||||
|
Color(red: 0.05, green: 0.02, blue: 0.16),
|
||||||
|
Color(red: 0.35, green: 0.05, blue: 0.42),
|
||||||
|
Color(red: 0.95, green: 0.30, blue: 0.35),
|
||||||
|
Color(red: 0.99, green: 0.62, blue: 0.32),
|
||||||
|
],
|
||||||
|
startPoint: .top, endPoint: .bottom)
|
||||||
|
Canvas { ctx, size in
|
||||||
|
let horizon = size.height * 0.52
|
||||||
|
// Sun.
|
||||||
|
let sunR = size.height * 0.20
|
||||||
|
let sun = CGRect(x: size.width / 2 - sunR, y: horizon - sunR * 1.6,
|
||||||
|
width: sunR * 2, height: sunR * 2)
|
||||||
|
ctx.fill(Path(ellipseIn: sun),
|
||||||
|
with: .linearGradient(
|
||||||
|
Gradient(colors: [Color(red: 1, green: 0.95, blue: 0.5),
|
||||||
|
Color(red: 1, green: 0.35, blue: 0.45)]),
|
||||||
|
startPoint: CGPoint(x: sun.midX, y: sun.minY),
|
||||||
|
endPoint: CGPoint(x: sun.midX, y: sun.maxY)))
|
||||||
|
// Sun scanlines — clip a copy so the base context stays unclipped (GraphicsContext
|
||||||
|
// is a value type; there is no resetClip).
|
||||||
|
var sunCtx = ctx
|
||||||
|
sunCtx.clip(to: Path(ellipseIn: sun))
|
||||||
|
for i in 0..<7 {
|
||||||
|
let y = sun.minY + sun.height * (0.55 + Double(i) * 0.07)
|
||||||
|
let bar = CGRect(x: sun.minX, y: y, width: sun.width,
|
||||||
|
height: sun.height * (0.012 + Double(i) * 0.006))
|
||||||
|
sunCtx.fill(Path(bar), with: .color(.black.opacity(0.85)))
|
||||||
|
}
|
||||||
|
// Perspective grid below the horizon.
|
||||||
|
ctx.opacity = 0.55
|
||||||
|
let cx = size.width / 2
|
||||||
|
for col in -10...10 {
|
||||||
|
var p = Path()
|
||||||
|
p.move(to: CGPoint(x: cx, y: horizon))
|
||||||
|
p.addLine(to: CGPoint(x: cx + Double(col) * size.width * 0.11,
|
||||||
|
y: size.height))
|
||||||
|
ctx.stroke(p, with: .color(Color(red: 0.6, green: 0.95, blue: 1)),
|
||||||
|
lineWidth: 1.5)
|
||||||
|
}
|
||||||
|
var row = horizon
|
||||||
|
var step = size.height * 0.012
|
||||||
|
while row < size.height {
|
||||||
|
var p = Path()
|
||||||
|
p.move(to: CGPoint(x: 0, y: row))
|
||||||
|
p.addLine(to: CGPoint(x: size.width, y: row))
|
||||||
|
ctx.stroke(p, with: .color(Color(red: 0.6, green: 0.95, blue: 1)),
|
||||||
|
lineWidth: 1.5)
|
||||||
|
step *= 1.32
|
||||||
|
row += step
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.overlay(alignment: .bottomLeading) {
|
||||||
|
// A small "now playing" chip so the frame reads as live content, not a wallpaper.
|
||||||
|
HStack(spacing: 8) {
|
||||||
|
Image(systemName: "gamecontroller.fill")
|
||||||
|
Text("Streaming from Battlestation")
|
||||||
|
.font(.system(.callout, weight: .semibold))
|
||||||
|
}
|
||||||
|
.padding(.horizontal, 14).padding(.vertical, 9)
|
||||||
|
.glassBackground(Capsule())
|
||||||
|
.padding(18)
|
||||||
|
}
|
||||||
|
.ignoresSafeArea()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// `PUNKTFUNK_SHOT_HERO=/abs/path.png` → use a real captured frame as the hero background.
|
||||||
|
static var overrideImage: Image? {
|
||||||
|
guard let path = ProcessInfo.processInfo.environment["PUNKTFUNK_SHOT_HERO"],
|
||||||
|
!path.isEmpty, FileManager.default.fileExists(atPath: path) else { return nil }
|
||||||
|
#if os(macOS)
|
||||||
|
guard let ns = NSImage(contentsOfFile: path) else { return nil }
|
||||||
|
return Image(nsImage: ns)
|
||||||
|
#else
|
||||||
|
guard let ui = UIImage(contentsOfFile: path) else { return nil }
|
||||||
|
return Image(uiImage: ui)
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -95,14 +95,23 @@ final class SessionModel: ObservableObject {
|
|||||||
/// field — TOFU is forbidden (rule 3b): the connect refuses rather than offering trust, and
|
/// field — TOFU is forbidden (rule 3b): the connect refuses rather than offering trust, and
|
||||||
/// the user is routed to PIN pairing by the caller. (A pinned host connects regardless: its
|
/// the user is routed to PIN pairing by the caller. (A pinned host connects regardless: its
|
||||||
/// stored fingerprint is the trust decision.)
|
/// stored fingerprint is the trust decision.)
|
||||||
|
///
|
||||||
|
/// `requestAccess` is the no-PIN delegated-approval path: open an identified connect the host
|
||||||
|
/// PARKS until the operator clicks Approve in its console, then admits the SAME connection (no
|
||||||
|
/// reconnect). The handshake budget is widened to exceed the host's park window, and a
|
||||||
|
/// successful connect streams directly (the approval IS the trust decision) — the caller pins
|
||||||
|
/// the observed fingerprint as paired. `host.pinnedSHA256`, when set, pins the advertised cert
|
||||||
|
/// for the wait; nil = trust-on-first-use.
|
||||||
func connect(to host: StoredHost, width: UInt32, height: UInt32, hz: UInt32,
|
func connect(to host: StoredHost, width: UInt32, height: UInt32, hz: UInt32,
|
||||||
compositor: PunktfunkConnection.Compositor = .auto,
|
compositor: PunktfunkConnection.Compositor = .auto,
|
||||||
gamepad: PunktfunkConnection.GamepadType = .auto,
|
gamepad: PunktfunkConnection.GamepadType = .auto,
|
||||||
bitrateKbps: UInt32 = 0,
|
bitrateKbps: UInt32 = 0,
|
||||||
|
audioChannels: UInt8 = 2,
|
||||||
hdrEnabled: Bool = true,
|
hdrEnabled: Bool = true,
|
||||||
launchID: String? = nil,
|
launchID: String? = nil,
|
||||||
allowTofu: Bool = false,
|
allowTofu: Bool = false,
|
||||||
autoTrust: Bool = false) {
|
autoTrust: Bool = false,
|
||||||
|
requestAccess: Bool = false) {
|
||||||
guard phase == .idle else { return }
|
guard phase == .idle else { return }
|
||||||
phase = .connecting
|
phase = .connecting
|
||||||
activeHost = host
|
activeHost = host
|
||||||
@@ -137,7 +146,11 @@ final class SessionModel: ObservableObject {
|
|||||||
width: width, height: height, refreshHz: hz,
|
width: width, height: height, refreshHz: hz,
|
||||||
pinSHA256: pin, identity: identity, compositor: compositor,
|
pinSHA256: pin, identity: identity, compositor: compositor,
|
||||||
gamepad: gamepad, bitrateKbps: bitrateKbps, videoCaps: videoCaps,
|
gamepad: gamepad, bitrateKbps: bitrateKbps, videoCaps: videoCaps,
|
||||||
launchID: launchID) }
|
audioChannels: audioChannels, launchID: launchID,
|
||||||
|
// Delegated approval: the host holds this connect open until the operator approves
|
||||||
|
// it (~180 s) — outwait that window so a slow approval still lands here. Normal
|
||||||
|
// connects keep the snappy default.
|
||||||
|
timeoutMs: requestAccess ? 185_000 : 10_000) }
|
||||||
await MainActor.run { [weak self] in
|
await MainActor.run { [weak self] in
|
||||||
guard let self else { return }
|
guard let self else { return }
|
||||||
// The user may have abandoned this attempt (window closed, another host
|
// The user may have abandoned this attempt (window closed, another host
|
||||||
@@ -151,7 +164,9 @@ final class SessionModel: ObservableObject {
|
|||||||
}
|
}
|
||||||
switch result {
|
switch result {
|
||||||
case .success(let conn):
|
case .success(let conn):
|
||||||
if pin != nil || autoTrust {
|
if pin != nil || autoTrust || requestAccess {
|
||||||
|
// requestAccess: the operator approved this device on the host, so the
|
||||||
|
// session is trusted — stream directly (the caller pins it as paired).
|
||||||
self.connection = conn
|
self.connection = conn
|
||||||
self.startStatsTimer()
|
self.startStatsTimer()
|
||||||
self.beginStreaming()
|
self.beginStreaming()
|
||||||
@@ -173,16 +188,25 @@ final class SessionModel: ObservableObject {
|
|||||||
case .failure:
|
case .failure:
|
||||||
self.phase = .idle
|
self.phase = .idle
|
||||||
self.activeHost = nil
|
self.activeHost = nil
|
||||||
self.errorMessage = pin != nil
|
if requestAccess {
|
||||||
? "Could not connect to \(host.displayName) — host unreachable, "
|
// The delegated-approval connect ended without being admitted: the
|
||||||
+ "not running, its identity no longer matches the pinned "
|
// operator didn't approve it before the host's park window elapsed (or
|
||||||
+ "fingerprint, or it requires pairing and no longer "
|
// the host was unreachable).
|
||||||
+ "recognizes this Mac (right-click the host card to pair "
|
self.errorMessage = "\(host.displayName) didn't let this device in. "
|
||||||
+ "again)."
|
+ "Approve it in the host's web console (port 3000 → Pairing), then "
|
||||||
: "Could not connect to \(host.displayName) — is punktfunk-host "
|
+ "request access again — the request expires after a few minutes."
|
||||||
+ "running on \(host.address):\(host.port)? If it requires "
|
} else {
|
||||||
+ "pairing, right-click the host card and pair with its PIN "
|
self.errorMessage = pin != nil
|
||||||
+ "first."
|
? "Could not connect to \(host.displayName) — host unreachable, "
|
||||||
|
+ "not running, its identity no longer matches the pinned "
|
||||||
|
+ "fingerprint, or it requires pairing and no longer "
|
||||||
|
+ "recognizes this Mac (right-click the host card to pair "
|
||||||
|
+ "again)."
|
||||||
|
: "Could not connect to \(host.displayName) — is punktfunk-host "
|
||||||
|
+ "running on \(host.address):\(host.port)? If it requires "
|
||||||
|
+ "pairing, right-click the host card and pair with its PIN "
|
||||||
|
+ "first."
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,9 +25,13 @@ struct SettingsView: View {
|
|||||||
@AppStorage(DefaultsKey.libraryEnabled) private var libraryEnabled = false
|
@AppStorage(DefaultsKey.libraryEnabled) private var libraryEnabled = false
|
||||||
@AppStorage(DefaultsKey.fullscreenWhileStreaming) private var fullscreenWhileStreaming = true
|
@AppStorage(DefaultsKey.fullscreenWhileStreaming) private var fullscreenWhileStreaming = true
|
||||||
@AppStorage(DefaultsKey.micEnabled) private var micEnabled = true
|
@AppStorage(DefaultsKey.micEnabled) private var micEnabled = true
|
||||||
|
@AppStorage(DefaultsKey.audioChannels) private var audioChannels = 2
|
||||||
@AppStorage(DefaultsKey.hudEnabled) private var hudEnabled = true
|
@AppStorage(DefaultsKey.hudEnabled) private var hudEnabled = true
|
||||||
@AppStorage(DefaultsKey.hudPlacement) private var hudPlacement = HUDPlacement.topTrailing.rawValue
|
@AppStorage(DefaultsKey.hudPlacement) private var hudPlacement = HUDPlacement.topTrailing.rawValue
|
||||||
@ObservedObject private var gamepads = GamepadManager.shared
|
@ObservedObject private var gamepads = GamepadManager.shared
|
||||||
|
#if DEBUG && !os(tvOS)
|
||||||
|
@State private var showControllerTest = false
|
||||||
|
#endif
|
||||||
#if os(macOS)
|
#if os(macOS)
|
||||||
@AppStorage(DefaultsKey.speakerUID) private var speakerUID = ""
|
@AppStorage(DefaultsKey.speakerUID) private var speakerUID = ""
|
||||||
@AppStorage(DefaultsKey.micUID) private var micUID = ""
|
@AppStorage(DefaultsKey.micUID) private var micUID = ""
|
||||||
@@ -94,6 +98,9 @@ struct SettingsView: View {
|
|||||||
}
|
}
|
||||||
.formStyle(.grouped)
|
.formStyle(.grouped)
|
||||||
.tabItem { Label("Advanced", systemImage: "slider.horizontal.3") }
|
.tabItem { Label("Advanced", systemImage: "slider.horizontal.3") }
|
||||||
|
|
||||||
|
AcknowledgementsView()
|
||||||
|
.tabItem { Label("About", systemImage: "info.circle") }
|
||||||
}
|
}
|
||||||
.frame(width: 480, height: 460)
|
.frame(width: 480, height: 460)
|
||||||
}
|
}
|
||||||
@@ -111,6 +118,9 @@ struct SettingsView: View {
|
|||||||
statisticsSection
|
statisticsSection
|
||||||
experimentalSection
|
experimentalSection
|
||||||
controllersSection
|
controllersSection
|
||||||
|
Section {
|
||||||
|
NavigationLink("Acknowledgements") { AcknowledgementsView() }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.formStyle(.grouped)
|
.formStyle(.grouped)
|
||||||
.onAppear {
|
.onAppear {
|
||||||
@@ -170,6 +180,10 @@ struct SettingsView: View {
|
|||||||
TVSelectionRow(title: "Stream mode", options: options, selection: modeTag)
|
TVSelectionRow(title: "Stream mode", options: options, selection: modeTag)
|
||||||
TVSelectionRow(
|
TVSelectionRow(
|
||||||
title: "Bitrate", options: bitrateOptions, selection: $bitrateKbps)
|
title: "Bitrate", options: bitrateOptions, selection: $bitrateKbps)
|
||||||
|
TVSelectionRow(
|
||||||
|
title: "Audio channels",
|
||||||
|
options: [("Stereo", 2), ("5.1 Surround", 6), ("7.1 Surround", 8)],
|
||||||
|
selection: $audioChannels)
|
||||||
if bitrateKbps > 1_000_000 {
|
if bitrateKbps > 1_000_000 {
|
||||||
Label(Self.gigabitWarning, systemImage: "exclamationmark.triangle.fill")
|
Label(Self.gigabitWarning, systemImage: "exclamationmark.triangle.fill")
|
||||||
.font(.caption)
|
.font(.caption)
|
||||||
@@ -209,6 +223,8 @@ struct SettingsView: View {
|
|||||||
.foregroundStyle(.secondary)
|
.foregroundStyle(.secondary)
|
||||||
.multilineTextAlignment(.center)
|
.multilineTextAlignment(.center)
|
||||||
.padding(.top, 8)
|
.padding(.top, 8)
|
||||||
|
NavigationLink("Acknowledgements") { AcknowledgementsView() }
|
||||||
|
.padding(.top, 8)
|
||||||
}
|
}
|
||||||
.frame(maxWidth: 1000)
|
.frame(maxWidth: 1000)
|
||||||
.frame(maxWidth: .infinity)
|
.frame(maxWidth: .infinity)
|
||||||
@@ -268,6 +284,11 @@ struct SettingsView: View {
|
|||||||
|
|
||||||
@ViewBuilder private var audioSection: some View {
|
@ViewBuilder private var audioSection: some View {
|
||||||
Section {
|
Section {
|
||||||
|
Picker("Audio channels", selection: $audioChannels) {
|
||||||
|
Text("Stereo").tag(2)
|
||||||
|
Text("5.1 Surround").tag(6)
|
||||||
|
Text("7.1 Surround").tag(8)
|
||||||
|
}
|
||||||
#if os(macOS)
|
#if os(macOS)
|
||||||
Picker("Speaker", selection: $speakerUID) {
|
Picker("Speaker", selection: $speakerUID) {
|
||||||
Text("System default").tag("")
|
Text("System default").tag("")
|
||||||
@@ -411,6 +432,11 @@ struct SettingsView: View {
|
|||||||
Text(option.label).tag(option.tag)
|
Text(option.label).tag(option.tag)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#if DEBUG && !os(tvOS)
|
||||||
|
Button("Test Controller…") { showControllerTest = true }
|
||||||
|
.disabled(gamepads.active == nil)
|
||||||
|
.sheet(isPresented: $showControllerTest) { ControllerTestView() }
|
||||||
|
#endif
|
||||||
} header: {
|
} header: {
|
||||||
Text("Controllers")
|
Text("Controllers")
|
||||||
} footer: {
|
} footer: {
|
||||||
@@ -511,15 +537,18 @@ struct SettingsView: View {
|
|||||||
private static let padTypes: [(label: String, tag: Int)] = [
|
private static let padTypes: [(label: String, tag: Int)] = [
|
||||||
("Automatic", 0),
|
("Automatic", 0),
|
||||||
("Xbox 360", 1),
|
("Xbox 360", 1),
|
||||||
|
("Xbox One", 3),
|
||||||
("DualSense", 2),
|
("DualSense", 2),
|
||||||
|
("DualShock 4", 4),
|
||||||
]
|
]
|
||||||
|
|
||||||
private static let controllersFooter =
|
private static let controllersFooter =
|
||||||
"One controller is forwarded to the host, as player 1 — Automatic picks the most "
|
"One controller is forwarded to the host, as player 1 — Automatic picks the most "
|
||||||
+ "recently connected one. The type is the virtual pad the host creates: Automatic "
|
+ "recently connected one. The type is the virtual pad the host creates: Automatic "
|
||||||
+ "matches the controller (a DualSense gets adaptive triggers, lightbar, touchpad "
|
+ "matches the controller (a DualSense gets adaptive triggers, lightbar, touchpad "
|
||||||
+ "and motion), and changes apply from the next session. Two identical controllers "
|
+ "and motion; a DualShock 4 the same minus adaptive triggers), and changes apply "
|
||||||
+ "may swap a manual selection after reconnecting."
|
+ "from the next session. Two identical controllers may swap a manual selection "
|
||||||
|
+ "after reconnecting."
|
||||||
|
|
||||||
/// "Use controller" choices: Automatic, every forwardable controller, and — so a stale
|
/// "Use controller" choices: Automatic, every forwardable controller, and — so a stale
|
||||||
/// pin stays visible instead of leaving the Picker selection tag-less — any pinned id
|
/// pin stays visible instead of leaving the Picker selection tag-less — any pinned id
|
||||||
@@ -537,7 +566,7 @@ struct SettingsView: View {
|
|||||||
|
|
||||||
private func controllerRow(_ controller: GamepadManager.DiscoveredController) -> some View {
|
private func controllerRow(_ controller: GamepadManager.DiscoveredController) -> some View {
|
||||||
HStack(spacing: 10) {
|
HStack(spacing: 10) {
|
||||||
Image(systemName: controller.isDualSense ? "playstation.logo" : "gamecontroller.fill")
|
Image(systemName: controller.hasTouchpadAndMotion ? "playstation.logo" : "gamecontroller.fill")
|
||||||
.foregroundStyle(.secondary)
|
.foregroundStyle(.secondary)
|
||||||
VStack(alignment: .leading, spacing: 2) {
|
VStack(alignment: .leading, spacing: 2) {
|
||||||
Text(controller.name)
|
Text(controller.name)
|
||||||
|
|||||||
@@ -15,6 +15,9 @@ public enum DefaultsKey {
|
|||||||
public static let gamepadType = "punktfunk.gamepadType"
|
public static let gamepadType = "punktfunk.gamepadType"
|
||||||
public static let gamepadID = "punktfunk.gamepadID"
|
public static let gamepadID = "punktfunk.gamepadID"
|
||||||
public static let bitrateKbps = "punktfunk.bitrateKbps"
|
public static let bitrateKbps = "punktfunk.bitrateKbps"
|
||||||
|
/// Requested audio channel count: 2 (stereo), 6 (5.1) or 8 (7.1). The host clamps to what it
|
||||||
|
/// can capture; the resolved count drives the in-core decode + AVAudioEngine layout.
|
||||||
|
public static let audioChannels = "punktfunk.audioChannels"
|
||||||
public static let micEnabled = "punktfunk.micEnabled"
|
public static let micEnabled = "punktfunk.micEnabled"
|
||||||
public static let speakerUID = "punktfunk.speakerUID"
|
public static let speakerUID = "punktfunk.speakerUID"
|
||||||
public static let micUID = "punktfunk.micUID"
|
public static let micUID = "punktfunk.micUID"
|
||||||
|
|||||||
@@ -0,0 +1,153 @@
|
|||||||
|
// Raw-HID DualSense rumble for macOS.
|
||||||
|
//
|
||||||
|
// Apple's GameController/CHHapticEngine path does NOT drive the DualSense's rumble motors on
|
||||||
|
// macOS — a documented platform gap: adaptive triggers, lightbar and player LEDs all work
|
||||||
|
// (different APIs), but `CHHapticEngine` output never reaches the motors. So we write the motor
|
||||||
|
// amplitudes straight into the DualSense HID output report, exactly the way SDL and the Linux
|
||||||
|
// `hid-playstation` driver do (the same report that already rumbles this pad on a Linux host).
|
||||||
|
//
|
||||||
|
// USB (report 0x02, 48 bytes, no CRC) and Bluetooth (report 0x31, 78 bytes, trailing CRC32) are
|
||||||
|
// both handled. The App Sandbox permits the raw-HID access via the app's `device.usb` +
|
||||||
|
// `device.bluetooth` entitlements, and this coexists with GameController holding the same device
|
||||||
|
// (non-seized open). Output-only, so no run-loop scheduling is needed.
|
||||||
|
//
|
||||||
|
// macOS-only: IOKit HID device access isn't available to apps on iOS/tvOS.
|
||||||
|
|
||||||
|
#if os(macOS)
|
||||||
|
import Foundation
|
||||||
|
import IOKit
|
||||||
|
import IOKit.hid
|
||||||
|
import os
|
||||||
|
|
||||||
|
private let log = Logger(subsystem: "io.unom.punktfunk", category: "gamepad")
|
||||||
|
|
||||||
|
/// Opens the first connected Sony DualSense and forwards motor rumble to it over raw HID.
|
||||||
|
/// Single-pad model (we forward exactly one controller), so the first match is the right one.
|
||||||
|
final class DualSenseHID {
|
||||||
|
private let manager: IOHIDManager
|
||||||
|
private var device: IOHIDDevice?
|
||||||
|
private var bluetooth = false
|
||||||
|
private var closed = false
|
||||||
|
|
||||||
|
private static let vendorSony = 0x054C
|
||||||
|
// DualSense (0x0CE6) and DualSense Edge (0x0DF2). The DualShock 4 uses a different report
|
||||||
|
// layout and is intentionally not handled here.
|
||||||
|
private static let productIDs = [0x0CE6, 0x0DF2]
|
||||||
|
|
||||||
|
/// "USB" or "Bluetooth" — for logs / the debug panel. Valid after a successful `open()`.
|
||||||
|
var transport: String { bluetooth ? "Bluetooth" : "USB" }
|
||||||
|
|
||||||
|
init() {
|
||||||
|
manager = IOHIDManagerCreate(kCFAllocatorDefault, IOOptionBits(kIOHIDOptionsTypeNone))
|
||||||
|
}
|
||||||
|
|
||||||
|
deinit { close() }
|
||||||
|
|
||||||
|
/// Find and open the first connected DualSense. Returns false if none is present or it can't
|
||||||
|
/// be opened (caller then falls back to CoreHaptics).
|
||||||
|
func open() -> Bool {
|
||||||
|
let matches = Self.productIDs.map { pid in
|
||||||
|
[kIOHIDVendorIDKey: Self.vendorSony, kIOHIDProductIDKey: pid] as CFDictionary
|
||||||
|
}
|
||||||
|
IOHIDManagerSetDeviceMatchingMultiple(manager, matches as CFArray)
|
||||||
|
guard IOHIDManagerOpen(manager, IOOptionBits(kIOHIDOptionsTypeNone)) == kIOReturnSuccess else {
|
||||||
|
log.info("rumble: DualSense HID manager open failed — falling back to CoreHaptics")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
guard let devices = IOHIDManagerCopyDevices(manager) as? Set<IOHIDDevice>,
|
||||||
|
let dev = devices.first
|
||||||
|
else {
|
||||||
|
log.info("rumble: no DualSense HID device found — falling back to CoreHaptics")
|
||||||
|
IOHIDManagerClose(manager, IOOptionBits(kIOHIDOptionsTypeNone))
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
device = dev
|
||||||
|
let transport = IOHIDDeviceGetProperty(dev, kIOHIDTransportKey as CFString) as? String
|
||||||
|
bluetooth = transport?.lowercased().contains("bluetooth") ?? false
|
||||||
|
log.info("rumble: DualSense raw-HID rumble active (transport=\(self.transport, privacy: .public))")
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Drive the motors. `low` = left/heavy (low-frequency), `high` = right/light (high-frequency),
|
||||||
|
/// each 0...255. (0, 0) stops.
|
||||||
|
func rumble(low: UInt8, high: UInt8) {
|
||||||
|
guard let dev = device else { return }
|
||||||
|
let report = bluetooth
|
||||||
|
? Self.bluetoothReport(low: low, high: high)
|
||||||
|
: Self.usbReport(low: low, high: high)
|
||||||
|
let rc = report.withUnsafeBufferPointer { buf in
|
||||||
|
IOHIDDeviceSetReport(
|
||||||
|
dev, kIOHIDReportTypeOutput, CFIndex(report[0]), buf.baseAddress!, buf.count)
|
||||||
|
}
|
||||||
|
if rc != kIOReturnSuccess {
|
||||||
|
log.error("rumble: IOHIDDeviceSetReport failed (0x\(String(format: "%08x", rc), privacy: .public))")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func close() {
|
||||||
|
guard !closed else { return }
|
||||||
|
closed = true
|
||||||
|
if device != nil { rumble(low: 0, high: 0) } // silence the motors before releasing
|
||||||
|
device = nil
|
||||||
|
IOHIDManagerClose(manager, IOOptionBits(kIOHIDOptionsTypeNone))
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Report builders
|
||||||
|
|
||||||
|
// DualSense effects payload (DS5EffectsState_t / hid-playstation `common`) — offsets relative
|
||||||
|
// to the payload start:
|
||||||
|
// 0 flag0 (enable bits) 2 motor_right (high-freq) 3 motor_left (low-freq)
|
||||||
|
// 1 flag1 38 flag2 (enhanced enable)
|
||||||
|
// We mirror the Linux driver: flag0 = COMPATIBLE_VIBRATION | HAPTICS_SELECT, flag2 =
|
||||||
|
// COMPATIBLE_VIBRATION2 (the enhanced-firmware path), motors sent directly. valid_flag1 stays
|
||||||
|
// 0 so this rumble-only report leaves the lightbar / triggers / player LEDs (driven by
|
||||||
|
// GameController) untouched.
|
||||||
|
private static func fillEffects(_ data: inout [UInt8], at base: Int, low: UInt8, high: UInt8) {
|
||||||
|
data[base + 0] = 0x03 // COMPATIBLE_VIBRATION (0x01) | HAPTICS_SELECT (0x02)
|
||||||
|
data[base + 2] = high // motor_right
|
||||||
|
data[base + 3] = low // motor_left
|
||||||
|
data[base + 38] = 0x04 // COMPATIBLE_VIBRATION2 (enhanced rumble, firmware ≥ 0x0224)
|
||||||
|
}
|
||||||
|
|
||||||
|
// `usbReport` / `bluetoothReport` / `crc32` are internal (not private) so the unit tests can
|
||||||
|
// pin the exact wire layout against the SDL / hid-playstation spec without a physical pad.
|
||||||
|
static func usbReport(low: UInt8, high: UInt8) -> [UInt8] {
|
||||||
|
var d = [UInt8](repeating: 0, count: 48)
|
||||||
|
d[0] = 0x02 // report id
|
||||||
|
fillEffects(&d, at: 1, low: low, high: high)
|
||||||
|
return d
|
||||||
|
}
|
||||||
|
|
||||||
|
static func bluetoothReport(low: UInt8, high: UInt8) -> [UInt8] {
|
||||||
|
var d = [UInt8](repeating: 0, count: 78)
|
||||||
|
d[0] = 0x31 // report id
|
||||||
|
d[1] = 0x00 // seq/tag (static, as SDL)
|
||||||
|
d[2] = 0x10 // magic
|
||||||
|
fillEffects(&d, at: 3, low: low, high: high)
|
||||||
|
// Trailing CRC32 over a 0xA2 seed byte + the report minus its 4 CRC bytes, little-endian.
|
||||||
|
let crc = Self.crc32(seed: 0xA2, d[0..<(d.count - 4)])
|
||||||
|
d[74] = UInt8(crc & 0xFF)
|
||||||
|
d[75] = UInt8((crc >> 8) & 0xFF)
|
||||||
|
d[76] = UInt8((crc >> 16) & 0xFF)
|
||||||
|
d[77] = UInt8((crc >> 24) & 0xFF)
|
||||||
|
return d
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Standard reflected CRC32 (zlib poly 0xEDB88320, init 0xFFFFFFFF, final XOR) over `seed`
|
||||||
|
/// followed by `bytes` — the DualSense Bluetooth output-report checksum (seed 0xA2). Matches
|
||||||
|
/// SDL's `SDL_crc32`/the kernel's `crc32_le` framing.
|
||||||
|
static func crc32<S: Sequence>(seed: UInt8, _ bytes: S) -> UInt32
|
||||||
|
where S.Element == UInt8 {
|
||||||
|
var crc: UInt32 = 0xFFFF_FFFF
|
||||||
|
func step(_ b: UInt8) {
|
||||||
|
crc ^= UInt32(b)
|
||||||
|
for _ in 0..<8 {
|
||||||
|
crc = (crc & 1) != 0 ? (crc >> 1) ^ 0xEDB8_8320 : crc >> 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
step(seed)
|
||||||
|
for b in bytes { step(b) }
|
||||||
|
return ~crc
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -6,12 +6,14 @@
|
|||||||
// full GCExtendedGamepad state on every valueChanged and diff against the previous
|
// full GCExtendedGamepad state on every valueChanged and diff against the previous
|
||||||
// snapshot. Sticks are ±32767 with +y = up (GC already matches, no flip), triggers 0...255.
|
// snapshot. Sticks are ±32767 with +y = up (GC already matches, no flip), triggers 0...255.
|
||||||
//
|
//
|
||||||
// DualSense extras ride the rich-input plane (0xCC): touchpad contacts normalized
|
// PlayStation-pad extras ride the rich-input plane (0xCC): touchpad contacts normalized
|
||||||
// 0...65535 (origin top-left, +y down — GC's ±1/+y-up is converted here) and motion
|
// 0...65535 (origin top-left, +y down — GC's ±1/+y-up is converted here) and motion
|
||||||
// samples in raw DualSense sensor units (gyro 20 LSB per deg/s, accel 10000 LSB per g —
|
// samples in raw DualSense sensor units (gyro 20 LSB per deg/s, accel 10000 LSB per g —
|
||||||
// derived from the host's fixed calibration blob; the conversion lives in ONE place,
|
// derived from the host's fixed calibration blob; the conversion lives in ONE place,
|
||||||
// `Wire`, so a live sign/scale correction is a one-line change). The host ignores both
|
// `Wire`, so a live sign/scale correction is a one-line change). The host ignores both
|
||||||
// unless the session's virtual pad is a DualSense.
|
// unless the session's virtual pad is a DualSense or DualShock 4 — both carry a touchpad
|
||||||
|
// and motion, so the capture below covers either (`GCDualShockGamepad` exposes the same
|
||||||
|
// `touchpad*` surface as `GCDualSenseGamepad`).
|
||||||
//
|
//
|
||||||
// Unlike mouse/keyboard capture, gamepad forwarding is NOT gated on the mouse-capture
|
// Unlike mouse/keyboard capture, gamepad forwarding is NOT gated on the mouse-capture
|
||||||
// toggle — a controller can't click local UI, so it always drives the host while the app
|
// toggle — a controller can't click local UI, so it always drives the host while the app
|
||||||
@@ -154,8 +156,9 @@ public final class GamepadCapture {
|
|||||||
releaseAll()
|
releaseAll()
|
||||||
if let ext = bound?.extendedGamepad {
|
if let ext = bound?.extendedGamepad {
|
||||||
ext.valueChangedHandler = nil
|
ext.valueChangedHandler = nil
|
||||||
(ext as? GCDualSenseGamepad)?.touchpadPrimary.valueChangedHandler = nil
|
let tp = Self.touchpad(ext)
|
||||||
(ext as? GCDualSenseGamepad)?.touchpadSecondary.valueChangedHandler = nil
|
tp?.primary.valueChangedHandler = nil
|
||||||
|
tp?.secondary.valueChangedHandler = nil
|
||||||
}
|
}
|
||||||
if let motion = bound?.motion {
|
if let motion = bound?.motion {
|
||||||
motion.valueChangedHandler = nil
|
motion.valueChangedHandler = nil
|
||||||
@@ -186,11 +189,11 @@ public final class GamepadCapture {
|
|||||||
connection.send(.gamepadAxis(GamepadWire.axisLSX, value: 0, pad: 0))
|
connection.send(.gamepadAxis(GamepadWire.axisLSX, value: 0, pad: 0))
|
||||||
sync(ext)
|
sync(ext)
|
||||||
|
|
||||||
if let ds = ext as? GCDualSenseGamepad {
|
if let tp = Self.touchpad(ext) {
|
||||||
ds.touchpadPrimary.valueChangedHandler = { [weak self] _, x, y in
|
tp.primary.valueChangedHandler = { [weak self] _, x, y in
|
||||||
MainActor.assumeIsolated { self?.touch(finger: 0, x: x, y: y) }
|
MainActor.assumeIsolated { self?.touch(finger: 0, x: x, y: y) }
|
||||||
}
|
}
|
||||||
ds.touchpadSecondary.valueChangedHandler = { [weak self] _, x, y in
|
tp.secondary.valueChangedHandler = { [weak self] _, x, y in
|
||||||
MainActor.assumeIsolated { self?.touch(finger: 1, x: x, y: y) }
|
MainActor.assumeIsolated { self?.touch(finger: 1, x: x, y: y) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -257,12 +260,29 @@ public final class GamepadCapture {
|
|||||||
if g.buttonB.isPressed { b |= GamepadWire.b }
|
if g.buttonB.isPressed { b |= GamepadWire.b }
|
||||||
if g.buttonX.isPressed { b |= GamepadWire.x }
|
if g.buttonX.isPressed { b |= GamepadWire.x }
|
||||||
if g.buttonY.isPressed { b |= GamepadWire.y }
|
if g.buttonY.isPressed { b |= GamepadWire.y }
|
||||||
if (g as? GCDualSenseGamepad)?.touchpadButton.isPressed == true {
|
if Self.touchpad(g)?.button.isPressed == true {
|
||||||
b |= GamepadWire.touchpadClick
|
b |= GamepadWire.touchpadClick
|
||||||
}
|
}
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The touchpad surface of a PlayStation pad — present on both `GCDualSenseGamepad` and
|
||||||
|
/// `GCDualShockGamepad` (DualShock 4), which don't share a common touchpad type, so we
|
||||||
|
/// downcast either and project the identical `touchpad*` properties. `nil` for any other
|
||||||
|
/// controller (Xbox, MFi).
|
||||||
|
private static func touchpad(
|
||||||
|
_ g: GCExtendedGamepad
|
||||||
|
) -> (primary: GCControllerDirectionPad, secondary: GCControllerDirectionPad,
|
||||||
|
button: GCControllerButtonInput)? {
|
||||||
|
if let ds = g as? GCDualSenseGamepad {
|
||||||
|
return (ds.touchpadPrimary, ds.touchpadSecondary, ds.touchpadButton)
|
||||||
|
}
|
||||||
|
if let ds4 = g as? GCDualShockGamepad {
|
||||||
|
return (ds4.touchpadPrimary, ds4.touchpadSecondary, ds4.touchpadButton)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
/// One touchpad finger moved. GC reports ±1 positions and snaps to exactly (0, 0) on
|
/// One touchpad finger moved. GC reports ±1 positions and snaps to exactly (0, 0) on
|
||||||
/// lift — treated as the lift signal (a real finger landing on the precise center
|
/// lift — treated as the lift signal (a real finger landing on the precise center
|
||||||
/// momentarily reads as a lift; harmless for a 1-in-65k coincidence).
|
/// momentarily reads as a lift; harmless for a 1-in-65k coincidence).
|
||||||
|
|||||||
@@ -8,8 +8,9 @@
|
|||||||
// trigger FX → DualSenseTriggerEffect.parse → GCDualSenseAdaptiveTrigger.
|
// trigger FX → DualSenseTriggerEffect.parse → GCDualSenseAdaptiveTrigger.
|
||||||
//
|
//
|
||||||
// Only pad 0 is rendered (exactly one controller is forwarded). HID-output traffic exists
|
// Only pad 0 is rendered (exactly one controller is forwarded). HID-output traffic exists
|
||||||
// only on DualSense sessions — the drain always polls both planes with short timeouts and
|
// only on PlayStation-pad sessions (a DualSense, or a DualShock 4 = lightbar only) — the
|
||||||
// never spins, so an Xbox session just renders rumble. GameController profile mutation
|
// drain always polls both planes with short timeouts and never spins, so an Xbox session
|
||||||
|
// just renders rumble. GameController profile mutation
|
||||||
// happens on main; CHHapticEngine work on its own serial queue; the drain thread itself
|
// happens on main; CHHapticEngine work on its own serial queue; the drain thread itself
|
||||||
// touches neither. When GamepadManager switches the active controller mid-session, the
|
// touches neither. When GamepadManager switches the active controller mid-session, the
|
||||||
// old pad is reset (triggers off, player index unset) and the last known feedback state
|
// old pad is reset (triggers off, player index unset) and the last known feedback state
|
||||||
@@ -49,10 +50,12 @@ private final class FeedbackStopFlag: @unchecked Sendable {
|
|||||||
private final class RumbleRenderer: @unchecked Sendable {
|
private final class RumbleRenderer: @unchecked Sendable {
|
||||||
private let queue = DispatchQueue(label: "io.unom.punktfunk.haptics", qos: .userInteractive)
|
private let queue = DispatchQueue(label: "io.unom.punktfunk.haptics", qos: .userInteractive)
|
||||||
|
|
||||||
|
/// One actuator's started engine plus the player currently driving it (nil = idle). The
|
||||||
|
/// player is rebuilt per level change — `drive` bakes the target intensity into a fresh
|
||||||
|
/// continuous event rather than scaling a long-lived one with a dynamic parameter.
|
||||||
private struct Motor {
|
private struct Motor {
|
||||||
let engine: CHHapticEngine
|
let engine: CHHapticEngine
|
||||||
let player: CHHapticAdvancedPatternPlayer
|
var player: CHHapticAdvancedPatternPlayer?
|
||||||
var playing = false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private var controller: GCController?
|
private var controller: GCController?
|
||||||
@@ -66,11 +69,30 @@ private final class RumbleRenderer: @unchecked Sendable {
|
|||||||
/// Last logged active/silent state — for a one-line transition log, not per-event spam.
|
/// Last logged active/silent state — for a one-line transition log, not per-event spam.
|
||||||
private var wasActive = false
|
private var wasActive = false
|
||||||
|
|
||||||
func retarget(_ c: GCController?) {
|
/// CHHapticEvent sharpness = actuator frequency. A DualSense's voice-coil motors need a
|
||||||
|
/// defined frequency to move at all — an intensity-only event (no sharpness) left them
|
||||||
|
/// silent, while a classic Xbox rotor (which ignores sharpness) rumbled fine. 0.5 is the mid
|
||||||
|
/// value the known-working macOS DualSense rumble implementations use. (Used only on the
|
||||||
|
/// CoreHaptics path — a DualSense on macOS is driven over raw HID instead, see below.)
|
||||||
|
private static let sharpness: Float = 0.5
|
||||||
|
|
||||||
|
#if os(macOS)
|
||||||
|
/// Set when the active pad is a DualSense: its motors are driven over raw HID (CoreHaptics
|
||||||
|
/// does not reach them on macOS — adaptive triggers/lightbar work, rumble is silent). nil for
|
||||||
|
/// every other controller, which keeps the CoreHaptics path.
|
||||||
|
private var dualSenseHID: DualSenseHID?
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/// `onBackend`, if given, is invoked (on the internal queue) with a human-readable name of the
|
||||||
|
/// rumble backend now in use — for the debug controller-test panel.
|
||||||
|
func retarget(_ c: GCController?, onBackend: ((String) -> Void)? = nil) {
|
||||||
queue.async {
|
queue.async {
|
||||||
self.teardown()
|
self.teardown()
|
||||||
|
self.closeHID()
|
||||||
self.controller = c
|
self.controller = c
|
||||||
self.broken = false
|
self.broken = false
|
||||||
|
_ = self.openHIDIfDualSense(c)
|
||||||
|
onBackend?(self.backendNote(for: c))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,22 +104,36 @@ private final class RumbleRenderer: @unchecked Sendable {
|
|||||||
log.debug(
|
log.debug(
|
||||||
"rumble: \(active ? "active" : "stop", privacy: .public) low=\(lowAmp, privacy: .public) high=\(highAmp, privacy: .public)")
|
"rumble: \(active ? "active" : "stop", privacy: .public) low=\(lowAmp, privacy: .public) high=\(highAmp, privacy: .public)")
|
||||||
}
|
}
|
||||||
|
// A DualSense on macOS is driven over raw HID; CoreHaptics is the path for every
|
||||||
|
// other pad (and for a DualSense whose HID device could not be opened).
|
||||||
|
if self.hidRumble(low: lowAmp, high: highAmp) { return }
|
||||||
guard !self.broken else { return }
|
guard !self.broken else { return }
|
||||||
if active, self.low == nil, self.high == nil {
|
if active, self.low == nil, self.high == nil {
|
||||||
self.setup()
|
self.setup()
|
||||||
}
|
}
|
||||||
|
let ok: Bool
|
||||||
if self.high != nil {
|
if self.high != nil {
|
||||||
self.drive(&self.low, Float(lowAmp) / 65535)
|
// Per-handle: low = left/heavy motor, high = right/light — the XInput convention
|
||||||
self.drive(&self.high, Float(highAmp) / 65535)
|
// the wire carries.
|
||||||
|
let okLow = self.drive(&self.low, Float(lowAmp) / 65535)
|
||||||
|
let okHigh = self.drive(&self.high, Float(highAmp) / 65535)
|
||||||
|
ok = okLow && okHigh
|
||||||
} else {
|
} else {
|
||||||
// Combined engine: whichever motor is stronger wins.
|
// Combined engine: whichever motor is stronger wins.
|
||||||
self.drive(&self.low, Float(max(lowAmp, highAmp)) / 65535)
|
ok = self.drive(&self.low, Float(max(lowAmp, highAmp)) / 65535)
|
||||||
}
|
}
|
||||||
|
// Rebuild on the next nonzero amplitude if an engine errored — and tear down OUTSIDE
|
||||||
|
// the `inout` accesses above, so teardown() never mutates a motor that a `drive` call
|
||||||
|
// still holds an exclusive reference to.
|
||||||
|
if !ok { self.teardown() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func stop() {
|
func stop() {
|
||||||
queue.sync { self.teardown() }
|
queue.sync {
|
||||||
|
self.teardown()
|
||||||
|
self.closeHID()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Engines per handle when the pad distinguishes them (low = left/heavy motor,
|
/// Engines per handle when the pad distinguishes them (low = left/heavy motor,
|
||||||
@@ -143,44 +179,51 @@ private final class RumbleRenderer: @unchecked Sendable {
|
|||||||
self?.queue.async { self?.teardown() }
|
self?.queue.async { self?.teardown() }
|
||||||
}
|
}
|
||||||
do {
|
do {
|
||||||
|
// Start the engine now; the player that actually moves the motor is built per level
|
||||||
|
// change in `drive` (a fresh event baked at the target intensity).
|
||||||
try engine.start()
|
try engine.start()
|
||||||
let event = CHHapticEvent(
|
return Motor(engine: engine, player: nil)
|
||||||
eventType: .hapticContinuous,
|
|
||||||
parameters: [CHHapticEventParameter(parameterID: .hapticIntensity, value: 1)],
|
|
||||||
relativeTime: 0,
|
|
||||||
duration: TimeInterval(GCHapticDurationInfinite))
|
|
||||||
let player = try engine.makeAdvancedPlayer(with: CHHapticPattern(events: [event], parameters: []))
|
|
||||||
return Motor(engine: engine, player: player)
|
|
||||||
} catch {
|
} catch {
|
||||||
log.warning("haptic engine setup failed (\(locality.rawValue, privacy: .public)): \(error, privacy: .public)")
|
log.warning("haptic engine setup failed (\(locality.rawValue, privacy: .public)): \(error, privacy: .public)")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func drive(_ motor: inout Motor?, _ amplitude: Float) {
|
/// Drive one motor at `amplitude` (0...1) by (re)building a continuous player whose intensity
|
||||||
guard var m = motor else { return }
|
/// is BAKED into the event. On a DualSense this is what actually moves the actuators: a
|
||||||
|
/// fixed-intensity event scaled by a dynamic `.hapticIntensityControl` parameter (the old
|
||||||
|
/// path) drives the iPhone Taptic Engine but is silent on a controller's haptic engine. The
|
||||||
|
/// event carries an explicit sharpness (frequency) so the voice coils respond, and an infinite
|
||||||
|
/// duration so a single host update — the host sends rumble only when the level changes —
|
||||||
|
/// sustains until the next one. Returns false if the engine errored; the caller tears down for
|
||||||
|
/// a rebuild (done outside this `inout` access to avoid an exclusivity violation).
|
||||||
|
private func drive(_ motor: inout Motor?, _ amplitude: Float) -> Bool {
|
||||||
|
guard var m = motor else { return true }
|
||||||
|
// Replace any running player: stop the old, and for a zero level leave the motor idle.
|
||||||
|
try? m.player?.stop(atTime: CHHapticTimeImmediate)
|
||||||
|
m.player = nil
|
||||||
|
guard amplitude > 0 else { motor = m; return true }
|
||||||
do {
|
do {
|
||||||
if amplitude > 0 {
|
let event = CHHapticEvent(
|
||||||
if !m.playing {
|
eventType: .hapticContinuous,
|
||||||
try m.player.start(atTime: CHHapticTimeImmediate)
|
parameters: [
|
||||||
m.playing = true
|
CHHapticEventParameter(parameterID: .hapticIntensity, value: amplitude),
|
||||||
}
|
CHHapticEventParameter(parameterID: .hapticSharpness, value: Self.sharpness),
|
||||||
try m.player.sendParameters(
|
],
|
||||||
[CHHapticDynamicParameter(
|
relativeTime: 0,
|
||||||
parameterID: .hapticIntensityControl,
|
duration: TimeInterval(GCHapticDurationInfinite))
|
||||||
value: amplitude, relativeTime: 0)],
|
let player = try m.engine.makeAdvancedPlayer(
|
||||||
atTime: CHHapticTimeImmediate)
|
with: CHHapticPattern(events: [event], parameters: []))
|
||||||
} else if m.playing {
|
try player.start(atTime: CHHapticTimeImmediate)
|
||||||
try m.player.stop(atTime: CHHapticTimeImmediate)
|
m.player = player
|
||||||
m.playing = false
|
|
||||||
}
|
|
||||||
motor = m
|
motor = m
|
||||||
|
return true
|
||||||
} catch {
|
} catch {
|
||||||
// A transient failure (the engine stopped/reset between its handler firing and now).
|
// A transient failure (the engine stopped/reset between its handler firing and now).
|
||||||
// Tear down so the next nonzero amplitude rebuilds — do NOT latch rumble off for the
|
// Signal a rebuild — do NOT latch rumble off for the session (the old "spotty" bug).
|
||||||
// session (that was the old "spotty" behaviour).
|
|
||||||
log.warning("rumble: haptic update failed — rebuilding: \(error, privacy: .public)")
|
log.warning("rumble: haptic update failed — rebuilding: \(error, privacy: .public)")
|
||||||
teardown()
|
motor = m
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,12 +233,56 @@ private final class RumbleRenderer: @unchecked Sendable {
|
|||||||
// (Both properties are non-optional closures on this SDK, so assign no-ops, not nil.)
|
// (Both properties are non-optional closures on this SDK, so assign no-ops, not nil.)
|
||||||
m.engine.stoppedHandler = { _ in }
|
m.engine.stoppedHandler = { _ in }
|
||||||
m.engine.resetHandler = {}
|
m.engine.resetHandler = {}
|
||||||
try? m.player.stop(atTime: CHHapticTimeImmediate)
|
try? m.player?.stop(atTime: CHHapticTimeImmediate)
|
||||||
m.engine.stop()
|
m.engine.stop()
|
||||||
}
|
}
|
||||||
low = nil
|
low = nil
|
||||||
high = nil
|
high = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - DualSense raw-HID rumble (macOS)
|
||||||
|
//
|
||||||
|
// On macOS the DualSense's motors aren't reachable through CHHapticEngine, so for a DualSense
|
||||||
|
// we drive them over raw HID (see `DualSenseHID`); every other pad keeps the CoreHaptics path.
|
||||||
|
// All three run on the serial `queue`, like the rest of the renderer state.
|
||||||
|
|
||||||
|
private func openHIDIfDualSense(_ c: GCController?) -> Bool {
|
||||||
|
#if os(macOS)
|
||||||
|
guard let c, c.extendedGamepad is GCDualSenseGamepad else { return false }
|
||||||
|
let hid = DualSenseHID()
|
||||||
|
guard hid.open() else { return false }
|
||||||
|
dualSenseHID = hid
|
||||||
|
return true
|
||||||
|
#else
|
||||||
|
return false
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Drive the DualSense's motors over HID if that's the active backend; false → not a HID pad,
|
||||||
|
/// so the caller uses CoreHaptics. The wire's 0...0xFFFF amplitudes scale to the pad's 0...255.
|
||||||
|
private func hidRumble(low: UInt16, high: UInt16) -> Bool {
|
||||||
|
#if os(macOS)
|
||||||
|
guard let hid = dualSenseHID else { return false }
|
||||||
|
hid.rumble(low: UInt8(low >> 8), high: UInt8(high >> 8))
|
||||||
|
return true
|
||||||
|
#else
|
||||||
|
return false
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
private func closeHID() {
|
||||||
|
#if os(macOS)
|
||||||
|
dualSenseHID?.close()
|
||||||
|
dualSenseHID = nil
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
private func backendNote(for c: GCController?) -> String {
|
||||||
|
#if os(macOS)
|
||||||
|
if let hid = dualSenseHID { return "DualSense HID · \(hid.transport)" }
|
||||||
|
#endif
|
||||||
|
return c == nil ? "—" : "CoreHaptics"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final class GamepadFeedback {
|
public final class GamepadFeedback {
|
||||||
@@ -248,9 +335,12 @@ public final class GamepadFeedback {
|
|||||||
public func start() {
|
public func start() {
|
||||||
guard !drainStarted else { return }
|
guard !drainStarted else { return }
|
||||||
drainStarted = true
|
drainStarted = true
|
||||||
// No hidout traffic can exist on a non-DualSense session — poll that plane
|
// Hidout traffic (lightbar / player LEDs / triggers) only exists on a PlayStation-pad
|
||||||
// nonblocking there and let rumble own the wait.
|
// session — a DualSense or a DualShock 4 (lightbar only). Block briefly on it there and
|
||||||
let hidTimeout: UInt32 = connection.resolvedGamepad == .dualSense ? 10 : 0
|
// let rumble own the wait elsewhere; on an Xbox session it stays nonblocking.
|
||||||
|
let hasHidout = connection.resolvedGamepad == .dualSense
|
||||||
|
|| connection.resolvedGamepad == .dualShock4
|
||||||
|
let hidTimeout: UInt32 = hasHidout ? 10 : 0
|
||||||
let thread = Thread { [connection, flag, drainDone, weak self] in
|
let thread = Thread { [connection, flag, drainDone, weak self] in
|
||||||
while !flag.isStopped {
|
while !flag.isStopped {
|
||||||
do {
|
do {
|
||||||
@@ -365,3 +455,74 @@ public final class GamepadFeedback {
|
|||||||
return which == 0 ? ds.leftTrigger : ds.rightTrigger
|
return which == 0 ? ds.leftTrigger : ds.rightTrigger
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
/// Local feedback driver for the Settings → Controllers "Test Controller" panel (DEBUG builds
|
||||||
|
/// only). It drives the SAME CoreHaptics rumble renderer and `DualSenseTriggerEffect` path a
|
||||||
|
/// live session uses — just aimed at the physically-connected controller instead of the
|
||||||
|
/// host→client feedback planes — so rumble, the adaptive triggers, the lightbar and the player
|
||||||
|
/// LEDs can be confirmed on-device without a host. Reusing the real renderers is the point:
|
||||||
|
/// a passing test exercises the exact code a session runs.
|
||||||
|
@MainActor
|
||||||
|
public final class ControllerTester: ObservableObject {
|
||||||
|
private let renderer = RumbleRenderer()
|
||||||
|
private weak var controller: GCController?
|
||||||
|
|
||||||
|
/// The rumble backend now in use — "DualSense HID · USB/Bluetooth", "CoreHaptics", or "—" —
|
||||||
|
/// for the test panel to display so it's obvious which path a given pad takes.
|
||||||
|
@Published public private(set) var rumbleBackend = "—"
|
||||||
|
|
||||||
|
public init() {}
|
||||||
|
|
||||||
|
/// Aim the feedback at a controller (nil releases it). Idempotent — safe to call on every
|
||||||
|
/// active-controller change.
|
||||||
|
public func target(_ c: GCController?) {
|
||||||
|
guard c !== controller else { return }
|
||||||
|
controller = c
|
||||||
|
renderer.retarget(c) { [weak self] note in
|
||||||
|
Task { @MainActor in self?.rumbleBackend = note }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Drive both motors at 0...1 amplitudes — low = left/heavy, high = right/light — mapped to
|
||||||
|
/// the 0...0xFFFF wire range the session carries, through the real `RumbleRenderer`.
|
||||||
|
public func rumble(low: Float, high: Float) {
|
||||||
|
func u16(_ v: Float) -> UInt16 { UInt16((min(max(v, 0), 1) * 65535).rounded()) }
|
||||||
|
renderer.apply(low: u16(low), high: u16(high))
|
||||||
|
}
|
||||||
|
|
||||||
|
public func stopRumble() { renderer.apply(low: 0, high: 0) }
|
||||||
|
|
||||||
|
/// Replay an adaptive-trigger effect on a DualSense via the real `DualSenseTriggerEffect`
|
||||||
|
/// renderer. `right == false` → L2, `true` → R2. No-op on a non-DualSense pad.
|
||||||
|
public func applyTrigger(_ effect: DualSenseTriggerEffect, right: Bool) {
|
||||||
|
guard let ds = controller?.extendedGamepad as? GCDualSenseGamepad else { return }
|
||||||
|
effect.apply(to: right ? ds.rightTrigger : ds.leftTrigger)
|
||||||
|
}
|
||||||
|
|
||||||
|
public func resetTriggers() {
|
||||||
|
guard let ds = controller?.extendedGamepad as? GCDualSenseGamepad else { return }
|
||||||
|
ds.leftTrigger.setModeOff()
|
||||||
|
ds.rightTrigger.setModeOff()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Lightbar colour (DualSense / DualShock 4); nil turns it off. No-op without a light.
|
||||||
|
public func setLight(_ color: GCColor?) {
|
||||||
|
controller?.light?.color = color ?? GCColor(red: 0, green: 0, blue: 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Player-indicator LEDs (`.index1`...`.index4`, or `.indexUnset` to clear).
|
||||||
|
public func setPlayerIndex(_ index: GCControllerPlayerIndex) {
|
||||||
|
controller?.playerIndex = index
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Silence every channel and release the controller — call on the panel's disappear.
|
||||||
|
public func stop() {
|
||||||
|
resetTriggers()
|
||||||
|
setPlayerIndex(.indexUnset)
|
||||||
|
setLight(nil)
|
||||||
|
renderer.retarget(nil) // async teardown: stops the motors + drops the controller ref
|
||||||
|
controller = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -30,11 +30,22 @@ public final class GamepadManager: ObservableObject {
|
|||||||
public let productCategory: String
|
public let productCategory: String
|
||||||
/// The full extended profile exists — only these are forwardable.
|
/// The full extended profile exists — only these are forwardable.
|
||||||
public let isExtended: Bool
|
public let isExtended: Bool
|
||||||
public let isDualSense: Bool
|
/// The virtual-pad type a physical match resolves to under `.auto`: DualSense →
|
||||||
|
/// `.dualSense`, DualShock 4 → `.dualShock4`, an Xbox pad → `.xboxOne`, anything
|
||||||
|
/// else → `.xbox360`. (`.auto` is never stored here.)
|
||||||
|
public let kind: PunktfunkConnection.GamepadType
|
||||||
public let hasLight: Bool
|
public let hasLight: Bool
|
||||||
public let hasHaptics: Bool
|
public let hasHaptics: Bool
|
||||||
public let hasMotion: Bool
|
public let hasMotion: Bool
|
||||||
public let hasAdaptiveTriggers: Bool
|
public let hasAdaptiveTriggers: Bool
|
||||||
|
/// Specifically a DualSense — gates the DualSense-only feedback (adaptive triggers,
|
||||||
|
/// player LEDs) and the PlayStation glyph in Settings.
|
||||||
|
public var isDualSense: Bool { kind == .dualSense }
|
||||||
|
/// A PlayStation pad with a touchpad + motion (DualSense OR DualShock 4) — gates
|
||||||
|
/// rich-input CAPTURE (touchpad contacts + gyro/accel on plane 0xCC).
|
||||||
|
public var hasTouchpadAndMotion: Bool {
|
||||||
|
kind == .dualSense || kind == .dualShock4
|
||||||
|
}
|
||||||
/// 0...1, nil when the controller doesn't report a battery (e.g. wired).
|
/// 0...1, nil when the controller doesn't report a battery (e.g. wired).
|
||||||
public let batteryLevel: Float?
|
public let batteryLevel: Float?
|
||||||
public let isCharging: Bool
|
public let isCharging: Bool
|
||||||
@@ -102,7 +113,8 @@ public final class GamepadManager: ObservableObject {
|
|||||||
|
|
||||||
/// Connect-time resolution of the user's controller-type setting: an explicit choice
|
/// Connect-time resolution of the user's controller-type setting: an explicit choice
|
||||||
/// wins; `.auto` matches the virtual pad to the active physical controller (DualSense →
|
/// wins; `.auto` matches the virtual pad to the active physical controller (DualSense →
|
||||||
/// DualSense, anything else → Xbox 360); no controller at all defers to the host.
|
/// DualSense, DualShock 4 → DualShock 4, an Xbox pad → Xbox One, anything else → Xbox
|
||||||
|
/// 360); no controller at all defers to the host.
|
||||||
public func resolveType(
|
public func resolveType(
|
||||||
setting: PunktfunkConnection.GamepadType
|
setting: PunktfunkConnection.GamepadType
|
||||||
) -> PunktfunkConnection.GamepadType {
|
) -> PunktfunkConnection.GamepadType {
|
||||||
@@ -113,7 +125,7 @@ public final class GamepadManager: ObservableObject {
|
|||||||
// pad. `rebuild()` re-reads `GCController.controllers()` synchronously, closing that race.
|
// pad. `rebuild()` re-reads `GCController.controllers()` synchronously, closing that race.
|
||||||
rebuild()
|
rebuild()
|
||||||
guard let active else { return .auto }
|
guard let active else { return .auto }
|
||||||
return active.isDualSense ? .dualSense : .xbox360
|
return active.kind
|
||||||
}
|
}
|
||||||
|
|
||||||
private func noteConnected(_ c: GCController) {
|
private func noteConnected(_ c: GCController) {
|
||||||
@@ -152,20 +164,38 @@ public final class GamepadManager: ObservableObject {
|
|||||||
|
|
||||||
private static func describe(_ c: GCController, id: String) -> DiscoveredController {
|
private static func describe(_ c: GCController, id: String) -> DiscoveredController {
|
||||||
let extended = c.extendedGamepad
|
let extended = c.extendedGamepad
|
||||||
let ds = extended as? GCDualSenseGamepad
|
let kind = padKind(extended)
|
||||||
return DiscoveredController(
|
return DiscoveredController(
|
||||||
id: id,
|
id: id,
|
||||||
name: c.vendorName ?? c.productCategory,
|
name: c.vendorName ?? c.productCategory,
|
||||||
productCategory: c.productCategory,
|
productCategory: c.productCategory,
|
||||||
isExtended: extended != nil,
|
isExtended: extended != nil,
|
||||||
isDualSense: ds != nil,
|
kind: kind,
|
||||||
hasLight: c.light != nil,
|
hasLight: c.light != nil,
|
||||||
hasHaptics: c.haptics != nil,
|
hasHaptics: c.haptics != nil,
|
||||||
hasMotion: c.motion != nil,
|
hasMotion: c.motion != nil,
|
||||||
// GCDualSenseGamepad's triggers are GCDualSenseAdaptiveTrigger by declaration.
|
// GCDualSenseGamepad's triggers are GCDualSenseAdaptiveTrigger by declaration; the
|
||||||
hasAdaptiveTriggers: ds != nil,
|
// DualShock 4 has none.
|
||||||
|
hasAdaptiveTriggers: kind == .dualSense,
|
||||||
batteryLevel: c.battery.flatMap { $0.batteryLevel >= 0 ? $0.batteryLevel : nil },
|
batteryLevel: c.battery.flatMap { $0.batteryLevel >= 0 ? $0.batteryLevel : nil },
|
||||||
isCharging: c.battery?.batteryState == .charging,
|
isCharging: c.battery?.batteryState == .charging,
|
||||||
controller: c)
|
controller: c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Resolve a physical controller's matching virtual-pad type from its GameController
|
||||||
|
/// subclass. Detection order (all are `: GCExtendedGamepad`): DualSense first, then
|
||||||
|
/// DualShock 4, then any Xbox pad, else fall back to Xbox 360. A non-extended / absent
|
||||||
|
/// profile also falls back to `.xbox360` (it's never forwarded anyway).
|
||||||
|
private static func padKind(
|
||||||
|
_ extended: GCExtendedGamepad?
|
||||||
|
) -> PunktfunkConnection.GamepadType {
|
||||||
|
guard let extended else { return .xbox360 }
|
||||||
|
// Deployment floor (macOS 14 / iOS 17 / tvOS 17) clears every introduction version
|
||||||
|
// here, so no `@available` guard is needed — matching the unguarded
|
||||||
|
// `GCDualSenseGamepad` use elsewhere in the package.
|
||||||
|
if extended is GCDualSenseGamepad { return .dualSense }
|
||||||
|
if extended is GCDualShockGamepad { return .dualShock4 }
|
||||||
|
if extended is GCXboxGamepad { return .xboxOne }
|
||||||
|
return .xbox360
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
import Foundation
|
||||||
|
|
||||||
|
/// Open-source license / attribution text bundled with PunktfunkKit (see `Resources/`).
|
||||||
|
///
|
||||||
|
/// Exposed from the kit so the app shell can show an Acknowledgements screen. The text files are
|
||||||
|
/// bundled as SwiftPM resources and read via `Bundle.module`, which works both for `swift build`
|
||||||
|
/// and for the Xcode app (it links the PunktfunkKit product, so the resource bundle rides along).
|
||||||
|
public enum Licenses {
|
||||||
|
private static func resource(_ name: String) -> String {
|
||||||
|
guard let url = Bundle.module.url(forResource: name, withExtension: "txt"),
|
||||||
|
let text = try? String(contentsOf: url, encoding: .utf8)
|
||||||
|
else { return "" }
|
||||||
|
return text
|
||||||
|
}
|
||||||
|
|
||||||
|
/// punktfunk's own license — MIT OR Apache-2.0, at your option.
|
||||||
|
public static var appLicense: String {
|
||||||
|
let mit = resource("LICENSE-MIT")
|
||||||
|
let apache = resource("LICENSE-APACHE")
|
||||||
|
if mit.isEmpty && apache.isEmpty {
|
||||||
|
return "punktfunk is licensed under MIT OR Apache-2.0, at your option."
|
||||||
|
}
|
||||||
|
return "punktfunk is licensed under MIT OR Apache-2.0, at your option.\n\n"
|
||||||
|
+ "================================ MIT ================================\n\n"
|
||||||
|
+ mit
|
||||||
|
+ "\n\n============================== Apache-2.0 ==============================\n\n"
|
||||||
|
+ apache
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Third-party software notices for the linked Rust crates (generated by
|
||||||
|
/// `scripts/gen-third-party-notices.sh`).
|
||||||
|
public static var thirdPartyNotices: String {
|
||||||
|
let text = resource("THIRD-PARTY-NOTICES")
|
||||||
|
return text.isEmpty ? "Third-party notices unavailable." : text
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -170,13 +170,18 @@ public final class PunktfunkConnection {
|
|||||||
|
|
||||||
/// Which virtual gamepad the host creates for this session's pads (the
|
/// Which virtual gamepad the host creates for this session's pads (the
|
||||||
/// `PUNKTFUNK_GAMEPAD_*` ABI values). `.auto` lets the host decide (its env var, else
|
/// `PUNKTFUNK_GAMEPAD_*` ABI values). `.auto` lets the host decide (its env var, else
|
||||||
/// X-Box 360); `.dualSense` is honored only on hosts with UHID (Linux) — games then see
|
/// X-Box 360); `.dualSense` / `.dualShock4` are honored only on hosts with UHID (Linux) —
|
||||||
/// a real DualSense and their lightbar / adaptive-trigger writes come back on the
|
/// games then see a real PlayStation pad and its lightbar (and, on a DualSense,
|
||||||
/// HID-output plane (`nextHidOutput`). The host's actual choice is `resolvedGamepad`.
|
/// adaptive-trigger / player-LED) writes come back on the HID-output plane
|
||||||
|
/// (`nextHidOutput`). `.xboxOne` is an X-Box-Series-glyph variant of `.xbox360` (same
|
||||||
|
/// buttons/sticks/triggers + rumble, no touchpad/motion/lightbar). The host's actual
|
||||||
|
/// choice is `resolvedGamepad`.
|
||||||
public enum GamepadType: UInt32, CaseIterable, Sendable {
|
public enum GamepadType: UInt32, CaseIterable, Sendable {
|
||||||
case auto = 0
|
case auto = 0
|
||||||
case xbox360 = 1
|
case xbox360 = 1
|
||||||
case dualSense = 2
|
case dualSense = 2
|
||||||
|
case xboxOne = 3
|
||||||
|
case dualShock4 = 4
|
||||||
|
|
||||||
/// Loose name parsing for env/dev hooks, mirroring the host's
|
/// Loose name parsing for env/dev hooks, mirroring the host's
|
||||||
/// `GamepadPref::from_name`.
|
/// `GamepadPref::from_name`.
|
||||||
@@ -184,7 +189,9 @@ public final class PunktfunkConnection {
|
|||||||
switch name.lowercased() {
|
switch name.lowercased() {
|
||||||
case "auto", "default": self = .auto
|
case "auto", "default": self = .auto
|
||||||
case "xbox", "xbox360", "x360", "uinput": self = .xbox360
|
case "xbox", "xbox360", "x360", "uinput": self = .xbox360
|
||||||
case "dualsense", "ds", "ps5": self = .dualSense
|
case "dualsense", "ds", "ds5", "ps5": self = .dualSense
|
||||||
|
case "xboxone", "xbox-one", "xboxseries", "series": self = .xboxOne
|
||||||
|
case "dualshock4", "dualshock", "ds4", "ps4": self = .dualShock4
|
||||||
default: return nil
|
default: return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -228,6 +235,12 @@ public final class PunktfunkConnection {
|
|||||||
/// drain `nextHdrMeta`.
|
/// drain `nextHdrMeta`.
|
||||||
public var isHDR: Bool { colorTransfer == 16 || colorTransfer == 18 }
|
public var isHDR: Bool { colorTransfer == 16 || colorTransfer == 18 }
|
||||||
|
|
||||||
|
/// The audio channel count the host resolved for this session (the Welcome's echo of the
|
||||||
|
/// requested `audioChannels`, clamped to what the host can capture): `2` (stereo), `6` (5.1)
|
||||||
|
/// or `8` (7.1). Build the playback layout from THIS, never the request. `2` for an older host.
|
||||||
|
/// PCM from `nextAudioPcm` is interleaved in the canonical wire order FL FR FC LFE RL RR SL SR.
|
||||||
|
public private(set) var resolvedAudioChannels: UInt8 = 2
|
||||||
|
|
||||||
/// Connect and start a session at the requested mode (the host creates a native virtual
|
/// Connect and start a session at the requested mode (the host creates a native virtual
|
||||||
/// output at exactly this size/refresh). Blocks up to `timeoutMs`.
|
/// output at exactly this size/refresh). Blocks up to `timeoutMs`.
|
||||||
///
|
///
|
||||||
@@ -257,6 +270,7 @@ public final class PunktfunkConnection {
|
|||||||
gamepad: GamepadType = .auto,
|
gamepad: GamepadType = .auto,
|
||||||
bitrateKbps: UInt32 = 0,
|
bitrateKbps: UInt32 = 0,
|
||||||
videoCaps: UInt8 = 0,
|
videoCaps: UInt8 = 0,
|
||||||
|
audioChannels: UInt8 = 2,
|
||||||
launchID: String? = nil,
|
launchID: String? = nil,
|
||||||
timeoutMs: UInt32 = 10_000
|
timeoutMs: UInt32 = 10_000
|
||||||
) throws {
|
) throws {
|
||||||
@@ -272,16 +286,16 @@ public final class PunktfunkConnection {
|
|||||||
withOptionalCString(launchID) { launch in
|
withOptionalCString(launchID) { launch in
|
||||||
if let pin = pinSHA256 {
|
if let pin = pinSHA256 {
|
||||||
return pin.withUnsafeBytes { p in
|
return pin.withUnsafeBytes { p in
|
||||||
punktfunk_connect_ex5(
|
punktfunk_connect_ex6(
|
||||||
cs, port, width, height, refreshHz, compositor.rawValue,
|
cs, port, width, height, refreshHz, compositor.rawValue,
|
||||||
gamepad.rawValue, bitrateKbps, videoCaps, launch,
|
gamepad.rawValue, bitrateKbps, videoCaps, audioChannels, launch,
|
||||||
p.bindMemory(to: UInt8.self).baseAddress, &observed,
|
p.bindMemory(to: UInt8.self).baseAddress, &observed,
|
||||||
cert, key, timeoutMs)
|
cert, key, timeoutMs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return punktfunk_connect_ex5(
|
return punktfunk_connect_ex6(
|
||||||
cs, port, width, height, refreshHz, compositor.rawValue,
|
cs, port, width, height, refreshHz, compositor.rawValue,
|
||||||
gamepad.rawValue, bitrateKbps, videoCaps, launch,
|
gamepad.rawValue, bitrateKbps, videoCaps, audioChannels, launch,
|
||||||
nil, &observed, cert, key, timeoutMs)
|
nil, &observed, cert, key, timeoutMs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -313,6 +327,9 @@ public final class PunktfunkConnection {
|
|||||||
colorMatrix = mtx
|
colorMatrix = mtx
|
||||||
colorFullRange = fullRange != 0
|
colorFullRange = fullRange != 0
|
||||||
bitDepth = depth
|
bitDepth = depth
|
||||||
|
var ac: UInt8 = 2
|
||||||
|
_ = punktfunk_connection_audio_channels(handle, &ac)
|
||||||
|
resolvedAudioChannels = ac
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A bandwidth speed-test measurement (see `startSpeedTest`). Partial until `done`.
|
/// A bandwidth speed-test measurement (see `startSpeedTest`). Partial until `done`.
|
||||||
@@ -461,6 +478,50 @@ public final class PunktfunkConnection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// One decoded audio frame from `nextAudioPcm`: interleaved 32-bit float at 48 kHz, in the
|
||||||
|
/// canonical wire channel order FL FR FC LFE RL RR SL SR (the first `channels`).
|
||||||
|
public struct AudioPCM: Sendable {
|
||||||
|
/// Interleaved f32 samples (`frameCount * channels` long), wire channel order.
|
||||||
|
public let samples: [Float]
|
||||||
|
/// Samples per channel.
|
||||||
|
public let frameCount: Int
|
||||||
|
/// Channel count (2/6/8) — `resolvedAudioChannels`.
|
||||||
|
public let channels: Int
|
||||||
|
public let ptsNs: UInt64
|
||||||
|
public let seq: UInt32
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Pull the next audio frame, **decoded in-core** to interleaved f32 PCM — Apple's AudioToolbox
|
||||||
|
/// Opus path is stereo-only, so surround (and, for uniformity, stereo too) is decoded by the
|
||||||
|
/// Rust core (libopus multistream) and handed back as PCM. nil on timeout, throws `.closed` once
|
||||||
|
/// the session ended. Drain from a dedicated audio thread (do NOT also call `nextAudio` — they
|
||||||
|
/// share the underlying queue). The returned `samples` are copied out, so the buffer is owned.
|
||||||
|
public func nextAudioPcm(timeoutMs: UInt32 = 100) throws -> AudioPCM? {
|
||||||
|
audioLock.lock()
|
||||||
|
defer { audioLock.unlock() }
|
||||||
|
guard let h = liveHandle() else { throw PunktfunkClientError.closed }
|
||||||
|
|
||||||
|
var out = PunktfunkAudioPcm()
|
||||||
|
let rc = punktfunk_connection_next_audio_pcm(h, &out, timeoutMs)
|
||||||
|
switch rc {
|
||||||
|
case statusOK:
|
||||||
|
let channels = Int(out.channels)
|
||||||
|
let total = Int(out.frame_count) * channels
|
||||||
|
guard let base = out.samples, total > 0 else { return nil }
|
||||||
|
// Copy: the pointer borrows connection memory only until the next PCM call.
|
||||||
|
let samples = Array(UnsafeBufferPointer(start: base, count: total))
|
||||||
|
return AudioPCM(
|
||||||
|
samples: samples, frameCount: Int(out.frame_count),
|
||||||
|
channels: channels, ptsNs: out.pts_ns, seq: out.seq)
|
||||||
|
case statusNoFrame:
|
||||||
|
return nil
|
||||||
|
case statusClosed:
|
||||||
|
throw PunktfunkClientError.closed
|
||||||
|
default:
|
||||||
|
throw PunktfunkClientError.status(rc)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Pull the next force-feedback update for the GCController haptics engine:
|
/// Pull the next force-feedback update for the GCController haptics engine:
|
||||||
/// `(pad, lowFrequency, highFrequency)` with 0...0xFFFF amplitudes, (0, 0) = stop.
|
/// `(pad, lowFrequency, highFrequency)` with 0...0xFFFF amplitudes, (0, 0) = stop.
|
||||||
/// Drain from the (single) feedback thread, alongside `nextHidOutput`.
|
/// Drain from the (single) feedback thread, alongside `nextHidOutput`.
|
||||||
@@ -497,10 +558,11 @@ public final class PunktfunkConnection {
|
|||||||
case triggerEffect(pad: UInt8, which: UInt8, effect: [UInt8])
|
case triggerEffect(pad: UInt8, which: UInt8, effect: [UInt8])
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Pull the next DualSense feedback event (lightbar / player LEDs / adaptive triggers);
|
/// Pull the next PlayStation-pad feedback event (lightbar / player LEDs / adaptive
|
||||||
/// nil on timeout, throws `.closed` once the session ended. Drain from the (single)
|
/// triggers); nil on timeout, throws `.closed` once the session ended. Drain from the
|
||||||
/// feedback thread, alongside `nextRumble`. Nothing ever arrives unless
|
/// (single) feedback thread, alongside `nextRumble`. Nothing arrives unless the session's
|
||||||
/// `resolvedGamepad == .dualSense` — poll with a short timeout, never spin.
|
/// virtual pad is a DualSense (all three) or a DualShock 4 (lightbar only) — poll with a
|
||||||
|
/// short timeout, never spin.
|
||||||
public func nextHidOutput(timeoutMs: UInt32 = 0) throws -> HidOutputEvent? {
|
public func nextHidOutput(timeoutMs: UInt32 = 0) throws -> HidOutputEvent? {
|
||||||
feedbackLock.lock()
|
feedbackLock.lock()
|
||||||
defer { feedbackLock.unlock() }
|
defer { feedbackLock.unlock() }
|
||||||
|
|||||||
@@ -0,0 +1,201 @@
|
|||||||
|
Apache License
|
||||||
|
Version 2.0, January 2004
|
||||||
|
http://www.apache.org/licenses/
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
|
1. Definitions.
|
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction,
|
||||||
|
and distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by
|
||||||
|
the copyright owner that is granting the License.
|
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all
|
||||||
|
other entities that control, are controlled by, or are under common
|
||||||
|
control with that entity. For the purposes of this definition,
|
||||||
|
"control" means (i) the power, direct or indirect, to cause the
|
||||||
|
direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity
|
||||||
|
exercising permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
|
including but not limited to software source code, documentation
|
||||||
|
source, and configuration files.
|
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical
|
||||||
|
transformation or translation of a Source form, including but
|
||||||
|
not limited to compiled object code, generated documentation,
|
||||||
|
and conversions to other media types.
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or
|
||||||
|
Object form, made available under the License, as indicated by a
|
||||||
|
copyright notice that is included in or attached to the work
|
||||||
|
(an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object
|
||||||
|
form, that is based on (or derived from) the Work and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship. For the purposes
|
||||||
|
of this License, Derivative Works shall not include works that remain
|
||||||
|
separable from, or merely link (or bind by name) to the interfaces of,
|
||||||
|
the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including
|
||||||
|
the original version of the Work and any modifications or additions
|
||||||
|
to that Work or Derivative Works thereof, that is intentionally
|
||||||
|
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||||
|
or by an individual or Legal Entity authorized to submit on behalf of
|
||||||
|
the copyright owner. For the purposes of this definition, "submitted"
|
||||||
|
means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems,
|
||||||
|
and issue tracking systems that are managed by, or on behalf of, the
|
||||||
|
Licensor for the purpose of discussing and improving the Work, but
|
||||||
|
excluding communication that is conspicuously marked or otherwise
|
||||||
|
designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||||
|
on behalf of whom a Contribution has been received by Licensor and
|
||||||
|
subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the
|
||||||
|
Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
(except as stated in this section) patent license to make, have made,
|
||||||
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||||
|
where such license applies only to those patent claims licensable
|
||||||
|
by such Contributor that are necessarily infringed by their
|
||||||
|
Contribution(s) alone or by combination of their Contribution(s)
|
||||||
|
with the Work to which such Contribution(s) was submitted. If You
|
||||||
|
institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||||
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
|
or contributory patent infringement, then any patent licenses
|
||||||
|
granted to You under this License for that Work shall terminate
|
||||||
|
as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the
|
||||||
|
Work or Derivative Works thereof in any medium, with or without
|
||||||
|
modifications, and in Source or Object form, provided that You
|
||||||
|
meet the following conditions:
|
||||||
|
|
||||||
|
(a) You must give any other recipients of the Work or Derivative
|
||||||
|
Works a copy of this License; and
|
||||||
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices
|
||||||
|
stating that You changed the files; and
|
||||||
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works
|
||||||
|
that You distribute, all copyright, patent, trademark, and
|
||||||
|
attribution notices from the Source form of the Work,
|
||||||
|
excluding those notices that do not pertain to any part of
|
||||||
|
the Derivative Works; and
|
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its
|
||||||
|
distribution, then any Derivative Works that You distribute must
|
||||||
|
include a readable copy of the attribution notices contained
|
||||||
|
within such NOTICE file, excluding those notices that do not
|
||||||
|
pertain to any part of the Derivative Works, in at least one
|
||||||
|
of the following places: within a NOTICE text file distributed
|
||||||
|
as part of the Derivative Works; within the Source form or
|
||||||
|
documentation, if provided along with the Derivative Works; or,
|
||||||
|
within a display generated by the Derivative Works, if and
|
||||||
|
wherever such third-party notices normally appear. The contents
|
||||||
|
of the NOTICE file are for informational purposes only and
|
||||||
|
do not modify the License. You may add Your own attribution
|
||||||
|
notices within Derivative Works that You distribute, alongside
|
||||||
|
or as an addendum to the NOTICE text from the Work, provided
|
||||||
|
that such additional attribution notices cannot be construed
|
||||||
|
as modifying the License.
|
||||||
|
|
||||||
|
You may add Your own copyright statement to Your modifications and
|
||||||
|
may provide additional or different license terms and conditions
|
||||||
|
for use, reproduction, or distribution of Your modifications, or
|
||||||
|
for any such Derivative Works as a whole, provided Your use,
|
||||||
|
reproduction, and distribution of the Work otherwise complies with
|
||||||
|
the conditions stated in this License.
|
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||||
|
any Contribution intentionally submitted for inclusion in the Work
|
||||||
|
by You to the Licensor shall be under the terms and conditions of
|
||||||
|
this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify
|
||||||
|
the terms of any separate license agreement you may have executed
|
||||||
|
with Licensor regarding such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade
|
||||||
|
names, trademarks, service marks, or product names of the Licensor,
|
||||||
|
except as required for reasonable and customary use in describing the
|
||||||
|
origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||||
|
agreed to in writing, Licensor provides the Work (and each
|
||||||
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
implied, including, without limitation, any warranties or conditions
|
||||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||||
|
appropriateness of using or redistributing the Work and assume any
|
||||||
|
risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory,
|
||||||
|
whether in tort (including negligence), contract, or otherwise,
|
||||||
|
unless required by applicable law (such as deliberate and grossly
|
||||||
|
negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
|
liable to You for damages, including any direct, indirect, special,
|
||||||
|
incidental, or consequential damages of any character arising as a
|
||||||
|
result of this License or out of the use or inability to use the
|
||||||
|
Work (including but not limited to damages for loss of goodwill,
|
||||||
|
work stoppage, computer failure or malfunction, or any and all
|
||||||
|
other commercial damages or losses), even if such Contributor
|
||||||
|
has been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing
|
||||||
|
the Work or Derivative Works thereof, You may choose to offer,
|
||||||
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||||
|
or other liability obligations and/or rights consistent with this
|
||||||
|
License. However, in accepting such obligations, You may act only
|
||||||
|
on Your own behalf and on Your sole responsibility, not on behalf
|
||||||
|
of any other Contributor, and only if You agree to indemnify,
|
||||||
|
defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason
|
||||||
|
of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
APPENDIX: How to apply the Apache License to your work.
|
||||||
|
|
||||||
|
To apply the Apache License to your work, attach the following
|
||||||
|
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||||
|
replaced with your own identifying information. (Don't include
|
||||||
|
the brackets!) The text should be enclosed in the appropriate
|
||||||
|
comment syntax for the file format. We also recommend that a
|
||||||
|
file or class name and description of purpose be included on the
|
||||||
|
same "printed page" as the copyright notice for easier
|
||||||
|
identification within third-party archives.
|
||||||
|
|
||||||
|
Copyright 2026 unom
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
http://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.
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2026 unom
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -19,13 +19,13 @@ import os
|
|||||||
|
|
||||||
private let log = Logger(subsystem: "io.unom.punktfunk", category: "audio")
|
private let log = Logger(subsystem: "io.unom.punktfunk", category: "audio")
|
||||||
|
|
||||||
/// SPSC-ish jitter ring (interleaved stereo float), drain thread → render callback.
|
/// SPSC-ish jitter ring (interleaved float, `channels` per frame), drain thread → render
|
||||||
/// The unfair lock is held for microseconds; fine at render-callback rates. Priming:
|
/// callback. The unfair lock is held for microseconds; fine at render-callback rates. Priming:
|
||||||
/// reads return silence until enough is buffered (at least `prefill`, and at least one
|
/// reads return silence until enough is buffered (at least `prefill`, and at least one
|
||||||
/// packet more than the device's render quantum — large-buffer devices would otherwise
|
/// packet more than the device's render quantum — large-buffer devices would otherwise
|
||||||
/// chronically out-demand the prefill and oscillate prime → dropout → re-prime), and an
|
/// chronically out-demand the prefill and oscillate prime → dropout → re-prime), and an
|
||||||
/// underrun re-primes, concealing jitter as one short dip instead of sustained crackle.
|
/// underrun re-primes, concealing jitter as one short dip instead of sustained crackle.
|
||||||
/// All counts stay even (whole stereo frames), so L/R interleave can never flip.
|
/// All counts stay whole frames (multiples of `channels`), so the interleave can never slip.
|
||||||
final class AudioRing: @unchecked Sendable {
|
final class AudioRing: @unchecked Sendable {
|
||||||
private var buf: [Float]
|
private var buf: [Float]
|
||||||
private var readIdx = 0
|
private var readIdx = 0
|
||||||
@@ -34,12 +34,14 @@ final class AudioRing: @unchecked Sendable {
|
|||||||
private var renderQuantum = 0
|
private var renderQuantum = 0
|
||||||
private let prefill: Int
|
private let prefill: Int
|
||||||
private let highWater: Int
|
private let highWater: Int
|
||||||
|
private let channels: Int
|
||||||
private let lock = OSAllocatedUnfairLock()
|
private let lock = OSAllocatedUnfairLock()
|
||||||
|
|
||||||
/// `capacity`/`prefill` in samples (interleaved — 2 per frame, both must be even).
|
/// `capacity`/`prefill` in samples (interleaved — `channels` per frame, both whole frames).
|
||||||
init(capacity: Int, prefill: Int) {
|
init(capacity: Int, prefill: Int, channels: Int) {
|
||||||
buf = [Float](repeating: 0, count: capacity)
|
buf = [Float](repeating: 0, count: capacity)
|
||||||
self.prefill = prefill
|
self.prefill = prefill
|
||||||
|
self.channels = channels
|
||||||
highWater = prefill * 4
|
highWater = prefill * 4
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,8 +76,8 @@ final class AudioRing: @unchecked Sendable {
|
|||||||
renderQuantum = max(renderQuantum, count)
|
renderQuantum = max(renderQuantum, count)
|
||||||
let available = writeIdx - readIdx
|
let available = writeIdx - readIdx
|
||||||
if !primed {
|
if !primed {
|
||||||
// 480 samples = one 5 ms host packet of slack beyond the device's demand.
|
// One 5 ms host packet (240 frames × channels) of slack beyond the device's demand.
|
||||||
if available >= max(prefill, renderQuantum + 480) {
|
if available >= max(prefill, renderQuantum + 240 * channels) {
|
||||||
primed = true
|
primed = true
|
||||||
} else {
|
} else {
|
||||||
for i in 0..<count { out[i] = 0 }
|
for i in 0..<count { out[i] = 0 }
|
||||||
@@ -113,10 +115,55 @@ private final class StopFlag: @unchecked Sendable {
|
|||||||
/// Render-block-owned scratch storage: freed exactly when the closure (and thus the
|
/// Render-block-owned scratch storage: freed exactly when the closure (and thus the
|
||||||
/// last possible render call) is released — never racing CoreAudio.
|
/// last possible render call) is released — never racing CoreAudio.
|
||||||
private final class ScratchBuffer {
|
private final class ScratchBuffer {
|
||||||
let ptr = UnsafeMutablePointer<Float>.allocate(capacity: 8192 * 2)
|
// 8192 frames × up to 8 channels (7.1) — the render block caps `frames` at 8192.
|
||||||
|
let ptr = UnsafeMutablePointer<Float>.allocate(capacity: 8192 * 8)
|
||||||
deinit { ptr.deallocate() }
|
deinit { ptr.deallocate() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// CoreAudio channel layout for the canonical wire order FL FR FC LFE RL RR [SL SR]. nil for
|
||||||
|
/// stereo (the standard layout is correct). For 5.1/7.1 we list explicit channel labels via
|
||||||
|
/// `kAudioChannelLayoutTag_UseChannelDescriptions` — preset tags (DTS_5_1 etc.) don't reliably
|
||||||
|
/// match Moonlight's order. NB the 7.1 mapping (verified against the WASAPI 0x63F + SPA orderings):
|
||||||
|
/// wire idx 4-5 = RL/RR = the WAVE *back* pair → LeftSurround/RightSurround; idx 6-7 = SL/SR = the
|
||||||
|
/// WAVE *side* pair → LeftSurroundDirect/RightSurroundDirect. (Using RearSurround* for 6-7 would
|
||||||
|
/// swap side/back vs the Windows/Linux clients.)
|
||||||
|
private func wireChannelLayout(channels: Int) -> AVAudioChannelLayout? {
|
||||||
|
let labels: [AudioChannelLabel]
|
||||||
|
switch channels {
|
||||||
|
case 6:
|
||||||
|
labels = [
|
||||||
|
kAudioChannelLabel_Left, kAudioChannelLabel_Right, kAudioChannelLabel_Center,
|
||||||
|
kAudioChannelLabel_LFEScreen, kAudioChannelLabel_LeftSurround,
|
||||||
|
kAudioChannelLabel_RightSurround,
|
||||||
|
]
|
||||||
|
case 8:
|
||||||
|
labels = [
|
||||||
|
kAudioChannelLabel_Left, kAudioChannelLabel_Right, kAudioChannelLabel_Center,
|
||||||
|
kAudioChannelLabel_LFEScreen,
|
||||||
|
kAudioChannelLabel_LeftSurround, kAudioChannelLabel_RightSurround, // wire RL/RR (back)
|
||||||
|
kAudioChannelLabel_LeftSurroundDirect, kAudioChannelLabel_RightSurroundDirect, // wire SL/SR (side)
|
||||||
|
]
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
let size = MemoryLayout<AudioChannelLayout>.size
|
||||||
|
+ (labels.count - 1) * MemoryLayout<AudioChannelDescription>.stride
|
||||||
|
let raw = UnsafeMutableRawPointer.allocate(byteCount: size, alignment: 16)
|
||||||
|
defer { raw.deallocate() }
|
||||||
|
let layout = raw.bindMemory(to: AudioChannelLayout.self, capacity: 1)
|
||||||
|
layout.pointee.mChannelLayoutTag = kAudioChannelLayoutTag_UseChannelDescriptions
|
||||||
|
layout.pointee.mChannelBitmap = AudioChannelBitmap(rawValue: 0)
|
||||||
|
layout.pointee.mNumberChannelDescriptions = UInt32(labels.count)
|
||||||
|
let descs = UnsafeMutableBufferPointer(
|
||||||
|
start: &layout.pointee.mChannelDescriptions, count: labels.count)
|
||||||
|
for (i, lbl) in labels.enumerated() {
|
||||||
|
descs[i] = AudioChannelDescription(
|
||||||
|
mChannelLabel: lbl, mChannelFlags: AudioChannelFlags(rawValue: 0),
|
||||||
|
mCoordinates: (0, 0, 0))
|
||||||
|
}
|
||||||
|
return AVAudioChannelLayout(layout: layout)
|
||||||
|
}
|
||||||
|
|
||||||
public final class SessionAudio {
|
public final class SessionAudio {
|
||||||
private let connection: PunktfunkConnection
|
private let connection: PunktfunkConnection
|
||||||
private let flag = StopFlag()
|
private let flag = StopFlag()
|
||||||
@@ -229,9 +276,13 @@ public final class SessionAudio {
|
|||||||
// MARK: - Playback (host → speaker)
|
// MARK: - Playback (host → speaker)
|
||||||
|
|
||||||
private func startPlayback(speakerUID: String) {
|
private func startPlayback(speakerUID: String) {
|
||||||
// 1 s of interleaved stereo capacity, ~20 ms prefill: four 5 ms host packets of
|
// Build the playback layout from the host-RESOLVED channel count (never the request):
|
||||||
// jitter absorption before the first sample plays.
|
// 2 = stereo / 6 = 5.1 / 8 = 7.1, canonical wire order FL FR FC LFE RL RR SL SR.
|
||||||
let ring = AudioRing(capacity: 96_000, prefill: 1920)
|
let channels = Int(connection.resolvedAudioChannels)
|
||||||
|
// 1 s interleaved capacity, ~20 ms prefill (four 5 ms host packets of jitter absorption
|
||||||
|
// before the first sample plays), both scaled by the channel count.
|
||||||
|
let ring = AudioRing(
|
||||||
|
capacity: 48_000 * channels, prefill: 960 * channels, channels: channels)
|
||||||
|
|
||||||
let engine = AVAudioEngine()
|
let engine = AVAudioEngine()
|
||||||
#if os(macOS)
|
#if os(macOS)
|
||||||
@@ -247,21 +298,32 @@ public final class SessionAudio {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Engine-native deinterleaved float; the render block deinterleaves from the ring.
|
// Engine-native deinterleaved float; the render block deinterleaves from the ring. Surround
|
||||||
guard let format = AVAudioFormat(standardFormatWithSampleRate: 48_000, channels: 2)
|
// uses an explicit wire-order channel layout; the mixer downmixes to the output device when
|
||||||
else { return }
|
// it has fewer speakers (e.g. an iPhone's stereo built-ins). (Explicit if/else rather than
|
||||||
|
// map/flatMap so it's correct whether the channelLayout initializer is failable or not.)
|
||||||
|
var format: AVAudioFormat?
|
||||||
|
if channels == 2 {
|
||||||
|
format = AVAudioFormat(standardFormatWithSampleRate: 48_000, channels: 2)
|
||||||
|
} else if let layout = wireChannelLayout(channels: channels) {
|
||||||
|
format = AVAudioFormat(standardFormatWithSampleRate: 48_000, channelLayout: layout)
|
||||||
|
}
|
||||||
|
guard let format else {
|
||||||
|
log.error("could not build \(channels)-channel audio format — audio disabled")
|
||||||
|
return
|
||||||
|
}
|
||||||
let scratch = ScratchBuffer() // block-owned; freed with the closure
|
let scratch = ScratchBuffer() // block-owned; freed with the closure
|
||||||
let source = AVAudioSourceNode(format: format) { _, _, frameCount, abl -> OSStatus in
|
let source = AVAudioSourceNode(format: format) { _, _, frameCount, abl -> OSStatus in
|
||||||
let frames = Int(frameCount)
|
let frames = Int(frameCount)
|
||||||
guard frames <= 8192 else { return kAudioUnitErr_TooManyFramesToProcess }
|
guard frames <= 8192 else { return kAudioUnitErr_TooManyFramesToProcess }
|
||||||
ring.read(into: scratch.ptr, count: frames * 2)
|
ring.read(into: scratch.ptr, count: frames * channels)
|
||||||
let buffers = UnsafeMutableAudioBufferListPointer(abl)
|
let buffers = UnsafeMutableAudioBufferListPointer(abl)
|
||||||
if buffers.count >= 2,
|
// Deinterleave the wire-order interleaved ring into the engine's per-channel buses.
|
||||||
let left = buffers[0].mData?.assumingMemoryBound(to: Float.self),
|
if buffers.count >= channels {
|
||||||
let right = buffers[1].mData?.assumingMemoryBound(to: Float.self) {
|
for ch in 0..<channels {
|
||||||
for f in 0..<frames {
|
if let dst = buffers[ch].mData?.assumingMemoryBound(to: Float.self) {
|
||||||
left[f] = scratch.ptr[f * 2]
|
for f in 0..<frames { dst[f] = scratch.ptr[f * channels + ch] }
|
||||||
right[f] = scratch.ptr[f * 2 + 1]
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return noErr
|
return noErr
|
||||||
@@ -292,29 +354,20 @@ public final class SessionAudio {
|
|||||||
stateLock.unlock()
|
stateLock.unlock()
|
||||||
let thread = Thread { [connection, flag, drainDone] in
|
let thread = Thread { [connection, flag, drainDone] in
|
||||||
defer { drainDone.signal() }
|
defer { drainDone.signal() }
|
||||||
guard let decoder = try? OpusDecoder(framesPerPacket: 240),
|
// Decode happens IN-CORE (libopus multistream) — AudioToolbox's Opus path is
|
||||||
let pcm = AVAudioPCMBuffer(
|
// stereo-only — and is handed back as interleaved f32 PCM in wire channel order.
|
||||||
pcmFormat: decoder.pcmFormat, frameCapacity: 5760)
|
|
||||||
else {
|
|
||||||
log.error("Opus decoder unavailable — audio playback disabled")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
while !flag.isStopped {
|
while !flag.isStopped {
|
||||||
let packet: AudioPacket?
|
let pcm: PunktfunkConnection.AudioPCM?
|
||||||
do {
|
do {
|
||||||
packet = try connection.nextAudio(timeoutMs: 100)
|
pcm = try connection.nextAudioPcm(timeoutMs: 100)
|
||||||
} catch {
|
} catch {
|
||||||
break // session closed
|
break // session closed
|
||||||
}
|
}
|
||||||
guard let packet else { continue }
|
guard let pcm, pcm.frameCount > 0 else { continue }
|
||||||
do {
|
pcm.samples.withUnsafeBufferPointer { p in
|
||||||
let frames = try decoder.decode(packet.data, into: pcm)
|
if let base = p.baseAddress {
|
||||||
if frames > 0, let p = pcm.floatChannelData?[0] {
|
ring.write(base, count: pcm.frameCount * pcm.channels)
|
||||||
ring.write(p, count: Int(frames) * 2)
|
|
||||||
}
|
}
|
||||||
} catch {
|
|
||||||
// One corrupt packet ≠ a dead stream; skip it.
|
|
||||||
log.warning("audio decode failed: \(error.localizedDescription)")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
// Locks the DualSense raw-HID rumble report layout to the SDL / Linux hid-playstation spec.
|
||||||
|
// The motors can only be confirmed on a physical pad, but these guard against a silent byte
|
||||||
|
// error in the offsets, enable flags, lengths, and the Bluetooth CRC32 — the parts most likely
|
||||||
|
// to regress unnoticed. macOS-only (DualSenseHID isn't compiled elsewhere).
|
||||||
|
|
||||||
|
#if os(macOS)
|
||||||
|
import XCTest
|
||||||
|
|
||||||
|
@testable import PunktfunkKit
|
||||||
|
|
||||||
|
final class DualSenseHIDTests: XCTestCase {
|
||||||
|
func testUSBReportLayout() {
|
||||||
|
let r = DualSenseHID.usbReport(low: 0xAA, high: 0xBB)
|
||||||
|
XCTAssertEqual(r.count, 48)
|
||||||
|
XCTAssertEqual(r[0], 0x02) // report id
|
||||||
|
XCTAssertEqual(r[1], 0x03) // flag0: COMPATIBLE_VIBRATION | HAPTICS_SELECT
|
||||||
|
XCTAssertEqual(r[2], 0x00) // flag1 (untouched — leaves lightbar/LEDs alone)
|
||||||
|
XCTAssertEqual(r[3], 0xBB) // motor_right = high
|
||||||
|
XCTAssertEqual(r[4], 0xAA) // motor_left = low
|
||||||
|
XCTAssertEqual(r[39], 0x04) // flag2: COMPATIBLE_VIBRATION2 (payload offset 38 + report id)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testBluetoothReportLayoutAndCRC() {
|
||||||
|
let r = DualSenseHID.bluetoothReport(low: 0xAA, high: 0xBB)
|
||||||
|
XCTAssertEqual(r.count, 78)
|
||||||
|
XCTAssertEqual(r[0], 0x31) // report id
|
||||||
|
XCTAssertEqual(r[1], 0x00) // seq/tag
|
||||||
|
XCTAssertEqual(r[2], 0x10) // magic
|
||||||
|
XCTAssertEqual(r[3], 0x03) // flag0
|
||||||
|
XCTAssertEqual(r[5], 0xBB) // motor_right = high (payload offset 2 + 3-byte BT header)
|
||||||
|
XCTAssertEqual(r[6], 0xAA) // motor_left = low
|
||||||
|
XCTAssertEqual(r[41], 0x04) // flag2 (payload offset 38 + 3)
|
||||||
|
|
||||||
|
// Trailing CRC32 = standard CRC32 over (0xA2 seed + report[0..<74]), little-endian.
|
||||||
|
let expected = DualSenseHID.crc32(seed: 0xA2, r[0..<74])
|
||||||
|
let stored = UInt32(r[74]) | (UInt32(r[75]) << 8) | (UInt32(r[76]) << 16) | (UInt32(r[77]) << 24)
|
||||||
|
XCTAssertEqual(stored, expected)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testCRC32MatchesStandardCheckVector() {
|
||||||
|
// The canonical CRC32 check value: CRC32("123456789") == 0xCBF43926. Our helper folds a
|
||||||
|
// seed byte in first, so feed seed='1' and the rest — proving poly/reflection/init/final.
|
||||||
|
let crc = DualSenseHID.crc32(seed: UInt8(ascii: "1"), Array("23456789".utf8))
|
||||||
|
XCTAssertEqual(crc, 0xCBF4_3926)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
Executable
+168
@@ -0,0 +1,168 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# App Store screenshot driver for the Punktfunk Apple client.
|
||||||
|
#
|
||||||
|
# Launches the app in "shot mode" (PUNKTFUNK_SHOT_SCENE=<name> → one mock-populated screen,
|
||||||
|
# full-bleed; see Sources/PunktfunkClient/Screenshots/) once per scene per device, and lets the OS
|
||||||
|
# capture the REAL rendered UI:
|
||||||
|
# • macOS → `screencapture` of the app's borderless window.
|
||||||
|
# • iOS/iPadOS/tvOS → a booted Simulator + `xcrun simctl io booted screenshot` (native pixels =
|
||||||
|
# the exact App Store size for that device).
|
||||||
|
#
|
||||||
|
# The captured pixels are exactly App Store Connect's required sizes:
|
||||||
|
# mac 2880×1800 (a 1× display yields 1440×900 — also accepted)
|
||||||
|
# iphone-6.9 1320×2868 (portrait) / 2868×1320 (the landscape hero)
|
||||||
|
# ipad-13 2064×2752 (portrait) / 2752×2064 (the landscape hero)
|
||||||
|
# appletv 1920×1080
|
||||||
|
#
|
||||||
|
# Requirements:
|
||||||
|
# • macOS target: just the Swift toolchain (`swift build`) + a one-time Screen Recording grant
|
||||||
|
# for your terminal (System Settings → Privacy & Security → Screen Recording).
|
||||||
|
# • iOS/iPadOS/tvOS targets: full Xcode (xcodebuild + Simulators), not just Command Line Tools.
|
||||||
|
#
|
||||||
|
# Usage:
|
||||||
|
# tools/screenshots.sh all # every platform this machine can build
|
||||||
|
# tools/screenshots.sh macos # just macOS
|
||||||
|
# tools/screenshots.sh ios ipad tvos # specific platforms
|
||||||
|
# OUT=~/Desktop/shots tools/screenshots.sh all
|
||||||
|
# PUNKTFUNK_SHOT_HERO=~/frame.png tools/screenshots.sh ios # real captured frame for the hero
|
||||||
|
#
|
||||||
|
# Keep SCENES in sync with ShotScenes.all.
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
APPLE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||||
|
cd "$APPLE_DIR"
|
||||||
|
|
||||||
|
OUT="${OUT:-$APPLE_DIR/screenshots}"
|
||||||
|
BUNDLE_ID="io.unom.punktfunk"
|
||||||
|
SCENES=(01-stream 02-hosts 03-pair 04-trust 05-settings)
|
||||||
|
SETTLE="${SETTLE:-4}" # seconds to let a scene lay out before capturing
|
||||||
|
|
||||||
|
mkdir -p "$OUT"
|
||||||
|
|
||||||
|
log() { printf '\033[1;36m[shots]\033[0m %s\n' "$*"; }
|
||||||
|
warn() { printf '\033[1;33m[shots]\033[0m %s\n' "$*" >&2; }
|
||||||
|
die() { printf '\033[1;31m[shots]\033[0m %s\n' "$*" >&2; exit 1; }
|
||||||
|
|
||||||
|
require_xcode() {
|
||||||
|
xcrun --find simctl >/dev/null 2>&1 \
|
||||||
|
|| die "Full Xcode required for simulator capture (have Command Line Tools only).
|
||||||
|
Install Xcode, then: sudo xcode-select -s /Applications/Xcode.app"
|
||||||
|
}
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------- macOS
|
||||||
|
|
||||||
|
shoot_macos() {
|
||||||
|
log "macOS — building (swift build -c release)…"
|
||||||
|
swift build -c release >/dev/null
|
||||||
|
local bin=".build/release/PunktfunkClient"
|
||||||
|
[ -x "$bin" ] || die "build produced no $bin"
|
||||||
|
|
||||||
|
for scene in "${SCENES[@]}"; do
|
||||||
|
local logf; logf="$(mktemp)"
|
||||||
|
PUNKTFUNK_SHOT_SCENE="$scene" "$bin" >"$logf" 2>&1 &
|
||||||
|
local pid=$!
|
||||||
|
# Wait for the window to exist and the scene to settle.
|
||||||
|
local win=""
|
||||||
|
for _ in $(seq 1 50); do
|
||||||
|
win="$(grep -o 'PF_SHOT_WINDOW=[0-9]*' "$logf" | head -1 | cut -d= -f2 || true)"
|
||||||
|
[ -n "$win" ] && grep -q PF_SHOT_READY "$logf" && break
|
||||||
|
sleep 0.2
|
||||||
|
done
|
||||||
|
if [ -z "$win" ]; then
|
||||||
|
kill -9 "$pid" 2>/dev/null || true
|
||||||
|
warn "macOS/$scene: app never reported a window — skipping"; cat "$logf" >&2; continue
|
||||||
|
fi
|
||||||
|
local dest="$OUT/mac-$scene.png"
|
||||||
|
if screencapture -x -o -l"$win" "$dest" 2>/dev/null && [ -s "$dest" ]; then
|
||||||
|
log "macOS/$scene → $dest ($(pixels "$dest"))"
|
||||||
|
else
|
||||||
|
warn "macOS/$scene: screencapture failed — grant your terminal Screen Recording permission
|
||||||
|
(System Settings → Privacy & Security → Screen Recording), then re-run."
|
||||||
|
fi
|
||||||
|
kill -9 "$pid" 2>/dev/null || true
|
||||||
|
rm -f "$logf"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------ iOS / iPadOS / tvOS
|
||||||
|
|
||||||
|
# $1 device-type regex (matches both existing device names and the device-type catalog)
|
||||||
|
# $2 scheme $3 sdk $4 file prefix $5 runtime platform (iOS|tvOS — for the create fallback)
|
||||||
|
shoot_sim() {
|
||||||
|
require_xcode
|
||||||
|
local match="$1" scheme="$2" sdk="$3" prefix="$4" platform="$5"
|
||||||
|
|
||||||
|
# Reuse an existing device of this type; else create a throwaway one against the newest
|
||||||
|
# available runtime for the platform. CI runners commonly ship a runtime but not every device
|
||||||
|
# (the iPhone 16 Pro Max is absent on ours), so create-on-demand is what makes it reproducible.
|
||||||
|
local udid
|
||||||
|
udid="$(xcrun simctl list devices available | grep -E "$match" | grep -oE '[0-9A-F-]{36}' | head -1 || true)"
|
||||||
|
if [ -z "$udid" ]; then
|
||||||
|
local devtype rt
|
||||||
|
devtype="$(xcrun simctl list devicetypes | grep -E "$match" \
|
||||||
|
| grep -oE 'com\.apple\.CoreSimulator\.SimDeviceType\.[A-Za-z0-9.-]+' | head -1 || true)"
|
||||||
|
rt="$(xcrun simctl list runtimes available | grep -E "^$platform " \
|
||||||
|
| grep -oE 'com\.apple\.CoreSimulator\.SimRuntime\.[A-Za-z0-9.-]+' | tail -1 || true)"
|
||||||
|
if [ -n "$devtype" ] && [ -n "$rt" ]; then
|
||||||
|
udid="$(xcrun simctl create "pf-shot-$prefix" "$devtype" "$rt" 2>/dev/null || true)"
|
||||||
|
[ -n "$udid" ] && log "$prefix — created Simulator $udid ($devtype)"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
[ -n "$udid" ] || die "$prefix: no Simulator matching /$match/, and none could be created
|
||||||
|
(needs a $platform runtime + a matching device type — check 'xcrun simctl list')."
|
||||||
|
log "$prefix — Simulator $udid"
|
||||||
|
xcrun simctl boot "$udid" 2>/dev/null || true
|
||||||
|
xcrun simctl bootstatus "$udid" -b >/dev/null 2>&1 || true
|
||||||
|
|
||||||
|
log "$prefix — building ($scheme)…"
|
||||||
|
local dd; dd="$(mktemp -d)"
|
||||||
|
xcodebuild -project Punktfunk.xcodeproj -scheme "$scheme" -configuration Debug \
|
||||||
|
-sdk "$sdk" -destination "id=$udid" -derivedDataPath "$dd" \
|
||||||
|
CODE_SIGNING_ALLOWED=NO build >/dev/null \
|
||||||
|
|| die "$prefix: xcodebuild failed"
|
||||||
|
local app; app="$(find "$dd/Build/Products" -maxdepth 2 -name '*.app' -type d | head -1)"
|
||||||
|
[ -n "$app" ] || die "$prefix: no .app built"
|
||||||
|
xcrun simctl install "$udid" "$app"
|
||||||
|
|
||||||
|
for scene in "${SCENES[@]}"; do
|
||||||
|
xcrun simctl terminate "$udid" "$BUNDLE_ID" 2>/dev/null || true
|
||||||
|
SIMCTL_CHILD_PUNKTFUNK_SHOT_SCENE="$scene" \
|
||||||
|
${PUNKTFUNK_SHOT_HERO:+SIMCTL_CHILD_PUNKTFUNK_SHOT_HERO="$PUNKTFUNK_SHOT_HERO"} \
|
||||||
|
xcrun simctl launch "$udid" "$BUNDLE_ID" >/dev/null
|
||||||
|
sleep "$SETTLE"
|
||||||
|
local dest="$OUT/$prefix-$scene.png"
|
||||||
|
xcrun simctl io "$udid" screenshot "$dest" >/dev/null
|
||||||
|
log "$prefix/$scene → $dest ($(pixels "$dest"))"
|
||||||
|
done
|
||||||
|
xcrun simctl terminate "$udid" "$BUNDLE_ID" 2>/dev/null || true
|
||||||
|
rm -rf "$dd"
|
||||||
|
}
|
||||||
|
|
||||||
|
pixels() { sips -g pixelWidth -g pixelHeight "$1" 2>/dev/null | awk '/pixel/{print $2}' | paste -sd× -; }
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------- dispatch
|
||||||
|
|
||||||
|
[ $# -gt 0 ] || set -- all
|
||||||
|
for target in "$@"; do
|
||||||
|
case "$target" in
|
||||||
|
macos) shoot_macos ;;
|
||||||
|
ios) shoot_sim 'iPhone 16 Pro Max' Punktfunk-iOS iphonesimulator iphone-6.9 iOS ;;
|
||||||
|
ipad) shoot_sim 'iPad Pro 13|iPad Pro .*M4|iPad Pro \(13' Punktfunk-iOS iphonesimulator ipad-13 iOS ;;
|
||||||
|
tvos) shoot_sim 'Apple TV' Punktfunk-tvOS appletvsimulator appletv tvOS ;;
|
||||||
|
all)
|
||||||
|
shoot_macos
|
||||||
|
if xcrun --find simctl >/dev/null 2>&1; then
|
||||||
|
shoot_sim 'iPhone 16 Pro Max' Punktfunk-iOS iphonesimulator iphone-6.9 iOS
|
||||||
|
shoot_sim 'iPad Pro 13|iPad Pro .*M4|iPad Pro \(13' Punktfunk-iOS iphonesimulator ipad-13 iOS
|
||||||
|
shoot_sim 'Apple TV' Punktfunk-tvOS appletvsimulator appletv tvOS
|
||||||
|
else
|
||||||
|
warn "Skipping iOS/iPadOS/tvOS — full Xcode not found (Command Line Tools only)."
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
*) die "unknown target '$target' (use: all macos ios ipad tvos)" ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
log "Done. Screenshots in $OUT"
|
||||||
|
ls -1 "$OUT" 2>/dev/null || true
|
||||||
+36
-1
@@ -45,8 +45,9 @@ Gaming Mode automatically.
|
|||||||
| `src/steam.ts` | Steam-shortcut launch (`AddShortcut` / `SetAppLaunchOptions` / `RunGame`) — the focus-correct stream start. |
|
| `src/steam.ts` | Steam-shortcut launch (`AddShortcut` / `SetAppLaunchOptions` / `RunGame`) — the focus-correct stream start. |
|
||||||
| `src/backend.ts` | Typed `callable` bridges to `main.py`. |
|
| `src/backend.ts` | Typed `callable` bridges to `main.py`. |
|
||||||
| `bin/punktfunkrun.sh` | The launch wrapper the Steam shortcut targets (so the window is focusable). |
|
| `bin/punktfunkrun.sh` | The launch wrapper the Steam shortcut targets (so the window is focusable). |
|
||||||
| `main.py` | Backend: `discover` / `pair` / `runner_info` / `get_settings` / `set_settings` / `kill_stream`. |
|
| `main.py` | Backend: `discover` / `pair` / `runner_info` / `get_settings` / `set_settings` / `kill_stream` / `check_update`. |
|
||||||
| `plugin.json` | Decky plugin manifest. |
|
| `plugin.json` | Decky plugin manifest. |
|
||||||
|
| `update.json` | CI-baked `{channel, manifest}` — where `check_update()` polls (absent on dev builds). |
|
||||||
| `decky.pyi` | Type stub for the injected `decky` module (vendored from the template). |
|
| `decky.pyi` | Type stub for the injected `decky` module (vendored from the template). |
|
||||||
|
|
||||||
### Discovery (`discover()`)
|
### Discovery (`discover()`)
|
||||||
@@ -140,6 +141,40 @@ shows up in the Quick Access Menu.
|
|||||||
> [`../../packaging/flatpak/README.md`](../../packaging/flatpak/README.md)) — install that on
|
> [`../../packaging/flatpak/README.md`](../../packaging/flatpak/README.md)) — install that on
|
||||||
> the Deck too, or the panel's Connect surfaces a `client-not-found` error.
|
> the Deck too, or the panel's Connect surfaces a `client-not-found` error.
|
||||||
|
|
||||||
|
## Updating (self-update, no store)
|
||||||
|
|
||||||
|
The plugin updates itself without the official Decky store. CI (`decky.yml`) publishes a tiny
|
||||||
|
per-channel `manifest.json` next to the zip in the Gitea registry:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{"version":"0.3.123","artifact":".../punktfunk-decky/0.3.123/punktfunk.zip","sha256":"…"}
|
||||||
|
```
|
||||||
|
|
||||||
|
and bakes an `update.json` (`{channel, manifest}`) into the plugin so it knows which channel it was
|
||||||
|
installed from. The backend `check_update()` reads the **installed** version from `package.json` —
|
||||||
|
the value Decky itself reports (it does **not** read `plugin.json`) — fetches the channel manifest,
|
||||||
|
and compares. When a newer build exists the frontend shows an **Update to vX** button that drives
|
||||||
|
Decky Loader's own install RPC:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
window.DeckyBackend.callable("utilities/install_plugin")(artifact, "punktfunk", version, hash, /*UPDATE=*/2)
|
||||||
|
```
|
||||||
|
|
||||||
|
The loader (root) downloads the immutable per-version zip, **SHA-256-verifies** it against `hash`,
|
||||||
|
replaces `~/homebrew/plugins/punktfunk`, and hot-reloads — the unprivileged backend never writes the
|
||||||
|
root-owned plugins dir itself. `window.DeckyBackend` / `utilities/install_plugin` are loader
|
||||||
|
internals (not `@decky/api`), so every access is guarded; missing them, the button falls back to a
|
||||||
|
toast pointing at **Install Plugin from URL**.
|
||||||
|
|
||||||
|
> CI stamps a **plain numeric** semver per channel (`0.3.<run>` canary, `X.Y.Z` stable) into
|
||||||
|
> `package.json`. Decky's `compare-versions` orders pre-release identifiers lexically (so `ci10 < ci9`)
|
||||||
|
> — a `-ciN` suffix would mis-detect updates.
|
||||||
|
|
||||||
|
**Optional — native Updates tab:** Decky's store is single-source (a custom store URL *replaces* the
|
||||||
|
official catalog), so punktfunk doesn't ship one by default. A user who wants the native update badge
|
||||||
|
can point Decky → Settings → **Custom store** at a punktfunk-only store JSON — not recommended if you
|
||||||
|
use other plugins, since it hides the official catalog.
|
||||||
|
|
||||||
## Limitations / next steps
|
## Limitations / next steps
|
||||||
|
|
||||||
- **Needs on-Deck validation in Gaming Mode**: the Steam-shortcut launch (`AddShortcut` /
|
- **Needs on-Deck validation in Gaming Mode**: the Steam-shortcut launch (`AddShortcut` /
|
||||||
|
|||||||
@@ -31,4 +31,6 @@ fi
|
|||||||
echo "punktfunkrun: streaming $APPID --connect $PF_HOST" >&2
|
echo "punktfunkrun: streaming $APPID --connect $PF_HOST" >&2
|
||||||
# exec so the flatpak client IS the game process — when it exits, Steam ends the "game" and
|
# exec so the flatpak client IS the game process — when it exits, Steam ends the "game" and
|
||||||
# Gaming Mode reclaims focus automatically (no manual refocus needed).
|
# Gaming Mode reclaims focus automatically (no manual refocus needed).
|
||||||
exec "$FLATPAK" run --arch=x86_64 "$APPID" --connect "$PF_HOST"
|
# --fullscreen: present the stream chrome-less and fullscreen (the client also auto-detects the
|
||||||
|
# Deck/gamescope env, and ignores the flag harmlessly on older builds that predate it).
|
||||||
|
exec "$FLATPAK" run --arch=x86_64 "$APPID" --connect "$PF_HOST" --fullscreen
|
||||||
|
|||||||
+141
-4
@@ -17,6 +17,8 @@ The backend's jobs are the things Steam can't do:
|
|||||||
* **get_settings() / set_settings()** — read/write the flatpak client's stream settings JSON
|
* **get_settings() / set_settings()** — read/write the flatpak client's stream settings JSON
|
||||||
(resolution / bitrate / gamepad), so the Deck UI configures the stream the client reads.
|
(resolution / bitrate / gamepad), so the Deck UI configures the stream the client reads.
|
||||||
* **kill_stream()** — force-stop a wedged stream (``flatpak kill``).
|
* **kill_stream()** — force-stop a wedged stream (``flatpak kill``).
|
||||||
|
* **check_update()** — poll the registry's per-channel ``manifest.json`` and report whether a
|
||||||
|
newer build is available (the frontend then drives Decky's own install RPC to apply it).
|
||||||
|
|
||||||
The TXT-record keys parsed (``proto`` / ``fp`` / ``pair`` / ``id``) are defined by the host
|
The TXT-record keys parsed (``proto`` / ``fp`` / ``pair`` / ``id``) are defined by the host
|
||||||
advert in ``crates/punktfunk-host/src/discovery.rs``.
|
advert in ``crates/punktfunk-host/src/discovery.rs``.
|
||||||
@@ -26,7 +28,10 @@ import asyncio
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
|
import ssl
|
||||||
import stat
|
import stat
|
||||||
|
import time
|
||||||
|
import urllib.request
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import decky
|
import decky
|
||||||
@@ -37,22 +42,99 @@ APP_ID = "io.unom.Punktfunk"
|
|||||||
# Service type advertised by punktfunk/1 hosts (matches NATIVE_SERVICE in the Rust host).
|
# Service type advertised by punktfunk/1 hosts (matches NATIVE_SERVICE in the Rust host).
|
||||||
SERVICE_TYPE = "_punktfunk._udp"
|
SERVICE_TYPE = "_punktfunk._udp"
|
||||||
|
|
||||||
# The flatpak client persists identity / known-hosts / settings under HOME/.config/punktfunk;
|
# The flatpak client persists identity / known-hosts / settings under HOME/.config/punktfunk.
|
||||||
# inside the flatpak sandbox HOME is ~/.var/app/<APP_ID>, so the real on-disk location is this.
|
# The sandbox HOME resolves to the REAL user home (== DECKY_USER_HOME), NOT the per-app
|
||||||
# The backend writes settings here so the (sandboxed) client reads them.
|
# ~/.var/app/<APP_ID> dir — verified on-device (`flatpak run … sh -c 'echo $HOME'` prints
|
||||||
|
# /home/deck, and the manifest's `--filesystem=~/.config/punktfunk` grants exactly that path;
|
||||||
|
# we also pass HOME=DECKY_USER_HOME into `flatpak run`, see _flatpak_env). Pointing here is what
|
||||||
|
# lets plugin settings actually reach the client AND lets us read the client's known-hosts to
|
||||||
|
# tell whether THIS device is already paired with a given host.
|
||||||
def _client_config_dir() -> Path:
|
def _client_config_dir() -> Path:
|
||||||
return Path(decky.DECKY_USER_HOME) / ".var" / "app" / APP_ID / ".config" / "punktfunk"
|
return Path(decky.DECKY_USER_HOME) / ".config" / "punktfunk"
|
||||||
|
|
||||||
|
|
||||||
def _settings_path() -> Path:
|
def _settings_path() -> Path:
|
||||||
return _client_config_dir() / "client-gtk-settings.json"
|
return _client_config_dir() / "client-gtk-settings.json"
|
||||||
|
|
||||||
|
|
||||||
|
def _paired_fingerprints() -> set[str]:
|
||||||
|
"""Host cert fingerprints (lowercase hex) this client has PIN-paired, from the client's
|
||||||
|
known-hosts store. Keyed by fingerprint so it survives a host changing IP address."""
|
||||||
|
try:
|
||||||
|
data = json.loads((_client_config_dir() / "client-known-hosts.json").read_text())
|
||||||
|
except (OSError, json.JSONDecodeError):
|
||||||
|
return set()
|
||||||
|
hosts = data.get("hosts", []) if isinstance(data, dict) else []
|
||||||
|
return {
|
||||||
|
h["fp_hex"].lower()
|
||||||
|
for h in hosts
|
||||||
|
if isinstance(h, dict) and h.get("paired") and isinstance(h.get("fp_hex"), str)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def _runner_path() -> str:
|
def _runner_path() -> str:
|
||||||
"""Absolute path to the launch wrapper shipped with the plugin (bin/punktfunkrun.sh)."""
|
"""Absolute path to the launch wrapper shipped with the plugin (bin/punktfunkrun.sh)."""
|
||||||
return str(Path(decky.DECKY_PLUGIN_DIR) / "bin" / "punktfunkrun.sh")
|
return str(Path(decky.DECKY_PLUGIN_DIR) / "bin" / "punktfunkrun.sh")
|
||||||
|
|
||||||
|
|
||||||
|
# ----------------------------------------------------------------------------------------
|
||||||
|
# Self-update check (no Decky store). The plugin is distributed via "Install Plugin from
|
||||||
|
# URL" pointing at our Gitea generic registry, so the official store never sees it and
|
||||||
|
# can't offer updates. Instead the backend polls a tiny per-channel ``manifest.json`` the
|
||||||
|
# CI publishes next to the zip, compares it to the installed version, and the frontend
|
||||||
|
# offers a one-tap update that drives Decky's own (root, privileged) install RPC. The
|
||||||
|
# channel + manifest URL are baked into ``update.json`` by CI (.gitea/workflows/decky.yml);
|
||||||
|
# a dev/sideload build has no ``update.json`` and update checks are simply disabled.
|
||||||
|
_UPDATE_TTL_S = 1800.0 # cache a successful check for 30 min (the QAM remounts often)
|
||||||
|
_update_cache: dict = {"at": 0.0, "data": None}
|
||||||
|
|
||||||
|
|
||||||
|
def _update_config() -> dict:
|
||||||
|
"""The CI-baked ``{channel, manifest}`` next to the plugin (absent on dev builds)."""
|
||||||
|
try:
|
||||||
|
return json.loads((Path(decky.DECKY_PLUGIN_DIR) / "update.json").read_text())
|
||||||
|
except (OSError, json.JSONDecodeError):
|
||||||
|
return {}
|
||||||
|
|
||||||
|
|
||||||
|
def _installed_version() -> str:
|
||||||
|
"""The version Decky itself reports for this plugin — it reads ``package.json`` (NOT
|
||||||
|
plugin.json), so the CI stamps the build version there."""
|
||||||
|
try:
|
||||||
|
pkg = json.loads((Path(decky.DECKY_PLUGIN_DIR) / "package.json").read_text())
|
||||||
|
return str(pkg.get("version", "0.0.0"))
|
||||||
|
except (OSError, json.JSONDecodeError):
|
||||||
|
return "0.0.0"
|
||||||
|
|
||||||
|
|
||||||
|
def _semver_tuple(v: str) -> tuple[int, int, int]:
|
||||||
|
"""A tolerant (major, minor, patch) tuple for ``>`` comparison. We control the version
|
||||||
|
format (plain numeric ``X.Y.Z`` on both channels), so leading-int-per-component is
|
||||||
|
enough; any pre-release suffix is dropped before comparing."""
|
||||||
|
parts: list[int] = []
|
||||||
|
for comp in str(v).split("-", 1)[0].split(".")[:3]:
|
||||||
|
digits = ""
|
||||||
|
for ch in comp:
|
||||||
|
if ch.isdigit():
|
||||||
|
digits += ch
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
parts.append(int(digits) if digits else 0)
|
||||||
|
while len(parts) < 3:
|
||||||
|
parts.append(0)
|
||||||
|
return (parts[0], parts[1], parts[2])
|
||||||
|
|
||||||
|
|
||||||
|
def _fetch_json(url: str, timeout: float = 8.0) -> dict:
|
||||||
|
"""Blocking HTTPS GET of a small JSON document (run in an executor)."""
|
||||||
|
req = urllib.request.Request(
|
||||||
|
url, headers={"Accept": "application/json", "User-Agent": "punktfunk-decky"}
|
||||||
|
)
|
||||||
|
ctx = ssl.create_default_context()
|
||||||
|
with urllib.request.urlopen(req, timeout=timeout, context=ctx) as resp:
|
||||||
|
return json.loads(resp.read().decode("utf-8", errors="replace"))
|
||||||
|
|
||||||
|
|
||||||
def _flatpak() -> str | None:
|
def _flatpak() -> str | None:
|
||||||
return shutil.which("flatpak") or (
|
return shutil.which("flatpak") or (
|
||||||
"/usr/bin/flatpak" if Path("/usr/bin/flatpak").exists() else None
|
"/usr/bin/flatpak" if Path("/usr/bin/flatpak").exists() else None
|
||||||
@@ -179,6 +261,13 @@ class Plugin:
|
|||||||
if stderr:
|
if stderr:
|
||||||
decky.logger.debug("avahi-browse stderr: %s", stderr.decode(errors="replace"))
|
decky.logger.debug("avahi-browse stderr: %s", stderr.decode(errors="replace"))
|
||||||
hosts = _parse_avahi_browse(stdout.decode(errors="replace"))
|
hosts = _parse_avahi_browse(stdout.decode(errors="replace"))
|
||||||
|
# Mark which hosts THIS device has already paired (by cert fingerprint), so the UI can
|
||||||
|
# show "Stream" instead of "Pair" — the mDNS `pair` field is the host's policy, not our
|
||||||
|
# per-device pairing state.
|
||||||
|
paired = _paired_fingerprints()
|
||||||
|
for h in hosts:
|
||||||
|
fp = h.get("fp") or ""
|
||||||
|
h["paired"] = bool(fp) and fp.lower() in paired
|
||||||
decky.logger.info("discovered %d punktfunk host(s)", len(hosts))
|
decky.logger.info("discovered %d punktfunk host(s)", len(hosts))
|
||||||
return hosts
|
return hosts
|
||||||
|
|
||||||
@@ -279,6 +368,54 @@ class Plugin:
|
|||||||
return {"ok": False}
|
return {"ok": False}
|
||||||
return {"ok": True}
|
return {"ok": True}
|
||||||
|
|
||||||
|
async def check_update(self, force: bool = False) -> dict:
|
||||||
|
"""Is a newer build available in our registry? Compares the installed version
|
||||||
|
(``package.json``) against the per-channel ``manifest.json`` the CI publishes, and
|
||||||
|
returns everything the frontend needs to drive Decky's install RPC. Non-fatal: any
|
||||||
|
failure (no channel baked in, network down) returns ``update_available: False``.
|
||||||
|
"""
|
||||||
|
current = _installed_version()
|
||||||
|
cfg = _update_config()
|
||||||
|
result = {
|
||||||
|
"current": current,
|
||||||
|
"latest": current,
|
||||||
|
"artifact": "",
|
||||||
|
"hash": "",
|
||||||
|
"channel": str(cfg.get("channel", "")),
|
||||||
|
"update_available": False,
|
||||||
|
}
|
||||||
|
|
||||||
|
manifest_url = cfg.get("manifest")
|
||||||
|
if not manifest_url:
|
||||||
|
result["error"] = "update-channel-unknown" # dev / sideloaded build
|
||||||
|
return result
|
||||||
|
|
||||||
|
now = time.monotonic()
|
||||||
|
cached = _update_cache["data"]
|
||||||
|
if not force and cached and (now - _update_cache["at"]) < _UPDATE_TTL_S:
|
||||||
|
return cached
|
||||||
|
|
||||||
|
try:
|
||||||
|
loop = asyncio.get_running_loop()
|
||||||
|
manifest = await loop.run_in_executor(None, _fetch_json, manifest_url)
|
||||||
|
except Exception as exc: # noqa: BLE001
|
||||||
|
decky.logger.warning("update check failed: %s", exc)
|
||||||
|
result["error"] = "fetch-failed"
|
||||||
|
return result # transient — don't cache, retry next open
|
||||||
|
|
||||||
|
latest = str(manifest.get("version", current))
|
||||||
|
result["latest"] = latest
|
||||||
|
result["artifact"] = str(manifest.get("artifact", ""))
|
||||||
|
result["hash"] = str(manifest.get("sha256", ""))
|
||||||
|
result["update_available"] = bool(result["artifact"]) and (
|
||||||
|
_semver_tuple(latest) > _semver_tuple(current)
|
||||||
|
)
|
||||||
|
if result["update_available"]:
|
||||||
|
decky.logger.info("update available: %s -> %s (%s)", current, latest, result["channel"])
|
||||||
|
_update_cache["at"] = now
|
||||||
|
_update_cache["data"] = result
|
||||||
|
return result
|
||||||
|
|
||||||
# ---- Decky lifecycle ----
|
# ---- Decky lifecycle ----
|
||||||
|
|
||||||
async def _main(self):
|
async def _main(self):
|
||||||
|
|||||||
@@ -5,8 +5,9 @@ export interface Host {
|
|||||||
name: string;
|
name: string;
|
||||||
host: string;
|
host: string;
|
||||||
port: number;
|
port: number;
|
||||||
pair: string; // "required" | "optional"
|
pair: string; // "required" | "optional" — the HOST's policy
|
||||||
fp: string;
|
fp: string;
|
||||||
|
paired: boolean; // whether THIS device has already PIN-paired this host (by fingerprint)
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PairResult {
|
export interface PairResult {
|
||||||
@@ -32,6 +33,16 @@ export interface StreamSettings {
|
|||||||
mic_enabled: boolean;
|
mic_enabled: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface UpdateInfo {
|
||||||
|
current: string; // installed version (package.json)
|
||||||
|
latest: string; // newest version in our registry for this channel
|
||||||
|
artifact: string; // immutable zip URL Decky should install
|
||||||
|
hash: string; // sha256 of that zip (Decky verifies it)
|
||||||
|
channel: string; // "latest" (stable) | "canary"
|
||||||
|
update_available: boolean;
|
||||||
|
error?: string; // "update-channel-unknown" (dev build) | "fetch-failed"
|
||||||
|
}
|
||||||
|
|
||||||
export const discover = callable<[], Host[]>("discover");
|
export const discover = callable<[], Host[]>("discover");
|
||||||
export const pair = callable<
|
export const pair = callable<
|
||||||
[host: string, port: number, pin: string, name: string],
|
[host: string, port: number, pin: string, name: string],
|
||||||
@@ -43,3 +54,4 @@ export const setSettings = callable<[settings: StreamSettings], { ok: boolean }>
|
|||||||
"set_settings",
|
"set_settings",
|
||||||
);
|
);
|
||||||
export const killStream = callable<[], { ok: boolean }>("kill_stream");
|
export const killStream = callable<[], { ok: boolean }>("kill_stream");
|
||||||
|
export const checkUpdate = callable<[force: boolean], UpdateInfo>("check_update");
|
||||||
|
|||||||
+269
-38
@@ -10,12 +10,22 @@ import {
|
|||||||
PanelSectionRow,
|
PanelSectionRow,
|
||||||
SliderField,
|
SliderField,
|
||||||
Spinner,
|
Spinner,
|
||||||
|
Tabs,
|
||||||
ToggleField,
|
ToggleField,
|
||||||
showModal,
|
showModal,
|
||||||
staticClasses,
|
staticClasses,
|
||||||
} from "@decky/ui";
|
} from "@decky/ui";
|
||||||
import { definePlugin, routerHook, toaster } from "@decky/api";
|
import { definePlugin, routerHook, toaster } from "@decky/api";
|
||||||
import { FC, useCallback, useEffect, useState } from "react";
|
import {
|
||||||
|
Component,
|
||||||
|
CSSProperties,
|
||||||
|
ErrorInfo,
|
||||||
|
FC,
|
||||||
|
ReactNode,
|
||||||
|
useCallback,
|
||||||
|
useEffect,
|
||||||
|
useState,
|
||||||
|
} from "react";
|
||||||
import {
|
import {
|
||||||
FaTv,
|
FaTv,
|
||||||
FaSyncAlt,
|
FaSyncAlt,
|
||||||
@@ -23,19 +33,130 @@ import {
|
|||||||
FaLockOpen,
|
FaLockOpen,
|
||||||
FaPlay,
|
FaPlay,
|
||||||
FaArrowLeft,
|
FaArrowLeft,
|
||||||
|
FaDownload,
|
||||||
} from "react-icons/fa";
|
} from "react-icons/fa";
|
||||||
import {
|
import {
|
||||||
discover,
|
discover,
|
||||||
getSettings,
|
getSettings,
|
||||||
pair,
|
pair,
|
||||||
setSettings,
|
setSettings,
|
||||||
|
checkUpdate,
|
||||||
Host,
|
Host,
|
||||||
StreamSettings,
|
StreamSettings,
|
||||||
|
UpdateInfo,
|
||||||
} from "./backend";
|
} from "./backend";
|
||||||
import { launchStream } from "./steam";
|
import { launchStream } from "./steam";
|
||||||
|
|
||||||
const ROUTE = "/punktfunk";
|
const ROUTE = "/punktfunk";
|
||||||
|
|
||||||
|
// Decky Loader exposes its already-authenticated WSRouter as a global. This is NOT part of
|
||||||
|
// @decky/api (it's a loader internal), so we treat it as optional and guard every use — on a
|
||||||
|
// loader without it we fall back to manual "Install Plugin from URL". We use it to drive
|
||||||
|
// Decky's own privileged install path (the root loader does the download + SHA-256 verify +
|
||||||
|
// extract + hot-reload), which is the only way a plugin can update itself: ~/homebrew/plugins
|
||||||
|
// is root-owned, so our unprivileged backend can't swap its own files.
|
||||||
|
declare global {
|
||||||
|
interface Window {
|
||||||
|
DeckyBackend?: {
|
||||||
|
callable: (route: string) => (...args: unknown[]) => Promise<unknown>;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// PluginInstallType.UPDATE in decky-loader's browser.py (INSTALL=0/REINSTALL=1/UPDATE=2/…).
|
||||||
|
const INSTALL_TYPE_UPDATE = 2;
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------------------
|
||||||
|
// Error boundary — contains ANY render failure in our UI so a single bad render can never take
|
||||||
|
// down the whole Quick Access "Decky" section (Decky's tab-level boundary shows the generic
|
||||||
|
// "Something went wrong while displaying this content" for the entire tab when one plugin
|
||||||
|
// throws). The realistic trigger is a future Steam client update that makes a @decky/ui
|
||||||
|
// component resolve to `undefined` (React then throws "Element type is invalid"). The fallback
|
||||||
|
// is built from ONLY plain DOM elements + inline styles, so it cannot itself depend on a
|
||||||
|
// (possibly broken) Steam-internal component — it is guaranteed to render.
|
||||||
|
// ----------------------------------------------------------------------------------------
|
||||||
|
class PluginErrorBoundary extends Component<
|
||||||
|
{ children: ReactNode },
|
||||||
|
{ error: Error | null }
|
||||||
|
> {
|
||||||
|
state: { error: Error | null } = { error: null };
|
||||||
|
|
||||||
|
static getDerivedStateFromError(error: Error) {
|
||||||
|
return { error };
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidCatch(error: Error, info: ErrorInfo) {
|
||||||
|
// Surface it for diagnosis, but never rethrow — containment is the whole point.
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.error("[punktfunk] contained UI render error:", error, info?.componentStack);
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const { error } = this.state;
|
||||||
|
if (!error) return this.props.children;
|
||||||
|
return (
|
||||||
|
<div style={{ padding: "1em", lineHeight: 1.45 }}>
|
||||||
|
<div style={{ fontWeight: "bold", marginBottom: "0.4em" }}>
|
||||||
|
punktfunk couldn’t draw this view
|
||||||
|
</div>
|
||||||
|
<div style={{ opacity: 0.8, marginBottom: "0.6em" }}>
|
||||||
|
The plugin hit a display error — your Steam Deck is fine. Reload punktfunk from
|
||||||
|
Decky's plugin list, or update the plugin.
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
opacity: 0.55,
|
||||||
|
fontFamily: "monospace",
|
||||||
|
fontSize: "0.8em",
|
||||||
|
wordBreak: "break-word",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{String(error?.message ?? error)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Checks our registry for a newer build on mount (the backend caches + is non-fatal offline).
|
||||||
|
function useUpdate() {
|
||||||
|
const [info, setInfo] = useState<UpdateInfo | null>(null);
|
||||||
|
useEffect(() => {
|
||||||
|
void checkUpdate(false)
|
||||||
|
.then(setInfo)
|
||||||
|
.catch(() => {});
|
||||||
|
}, []);
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function applyUpdate(info: UpdateInfo) {
|
||||||
|
try {
|
||||||
|
const backend = window.DeckyBackend;
|
||||||
|
if (backend?.callable) {
|
||||||
|
// Fire-and-forget: the loader reinstalls + reloads THIS plugin, tearing the panel down
|
||||||
|
// before any result could arrive — so never await it. Decky shows its own confirm prompt.
|
||||||
|
void backend.callable("utilities/install_plugin")(
|
||||||
|
info.artifact,
|
||||||
|
"punktfunk",
|
||||||
|
info.latest,
|
||||||
|
info.hash,
|
||||||
|
INSTALL_TYPE_UPDATE,
|
||||||
|
);
|
||||||
|
toaster.toast({
|
||||||
|
title: "punktfunk",
|
||||||
|
body: `Updating to v${info.latest}… confirm the Decky prompt.`,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// fall through to the manual path
|
||||||
|
}
|
||||||
|
toaster.toast({
|
||||||
|
title: "punktfunk",
|
||||||
|
body: "Update from Decky → Developer → Install Plugin from URL.",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------------------
|
||||||
// Discovery hook — shared by the QAM panel and the full page.
|
// Discovery hook — shared by the QAM panel and the full page.
|
||||||
// ----------------------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------------------
|
||||||
@@ -255,20 +376,24 @@ const SettingsSection: FC = () => {
|
|||||||
// One host row on the full page.
|
// One host row on the full page.
|
||||||
// ----------------------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------------------
|
||||||
const HostRow: FC<{ host: Host }> = ({ host }) => {
|
const HostRow: FC<{ host: Host }> = ({ host }) => {
|
||||||
const pairRequired = host.pair === "required";
|
// The host's policy is `pair=required`, but if THIS device is already paired we don't need to
|
||||||
|
// pair again — show it as trusted and go straight to Stream.
|
||||||
|
const needsPair = host.pair === "required" && !host.paired;
|
||||||
return (
|
return (
|
||||||
<Field
|
<Field
|
||||||
label={
|
label={
|
||||||
<span style={{ display: "inline-flex", alignItems: "center", gap: "0.4em" }}>
|
<span style={{ display: "inline-flex", alignItems: "center", gap: "0.4em" }}>
|
||||||
{pairRequired ? <FaLock /> : <FaLockOpen />}
|
{needsPair ? <FaLock /> : <FaLockOpen />}
|
||||||
{host.name}
|
{host.name}
|
||||||
</span>
|
</span>
|
||||||
}
|
}
|
||||||
description={`${host.host}:${host.port}${pairRequired ? " · pairing required" : ""}`}
|
description={`${host.host}:${host.port}${
|
||||||
|
needsPair ? " · pairing required" : host.paired ? " · paired" : ""
|
||||||
|
}`}
|
||||||
childrenContainerWidth="max"
|
childrenContainerWidth="max"
|
||||||
>
|
>
|
||||||
<Focusable style={{ display: "flex", gap: "0.5em" }}>
|
<Focusable style={{ display: "flex", gap: "0.5em" }}>
|
||||||
{pairRequired && (
|
{needsPair && (
|
||||||
<DialogButton
|
<DialogButton
|
||||||
style={{ minWidth: "5em" }}
|
style={{ minWidth: "5em" }}
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
@@ -288,52 +413,129 @@ const HostRow: FC<{ host: Host }> = ({ host }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------------------
|
||||||
// The fullscreen page (registered as the /punktfunk route).
|
// The fullscreen page (registered as the /punktfunk route) — a tabbed Hosts / Settings view.
|
||||||
// ----------------------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Bottom inset so the last control clears Gaming Mode's footer hint bar. Routed pages render
|
||||||
|
// *under* that bar otherwise — that's why the last Stream-settings row was getting hidden. The
|
||||||
|
// value is generous on purpose (and harmless where the tab area already insets); tune to taste.
|
||||||
|
const SAFE_BOTTOM = "80px";
|
||||||
|
|
||||||
|
// Each tab is its own scroll area so long content is always reachable above the footer.
|
||||||
|
const tabScroll: CSSProperties = {
|
||||||
|
height: "100%",
|
||||||
|
overflowY: "auto",
|
||||||
|
padding: "0.5em 2.5em",
|
||||||
|
paddingBottom: SAFE_BOTTOM,
|
||||||
|
boxSizing: "border-box",
|
||||||
|
};
|
||||||
|
|
||||||
|
const HostsTab: FC<{
|
||||||
|
hosts: Host[];
|
||||||
|
scanning: boolean;
|
||||||
|
refresh: () => void;
|
||||||
|
}> = ({ hosts, scanning, refresh }) => (
|
||||||
|
<div style={tabScroll}>
|
||||||
|
<Field
|
||||||
|
label="Discover"
|
||||||
|
description={
|
||||||
|
scanning
|
||||||
|
? "Scanning the LAN…"
|
||||||
|
: `${hosts.length} host${hosts.length === 1 ? "" : "s"} on your network`
|
||||||
|
}
|
||||||
|
childrenContainerWidth="max"
|
||||||
|
bottomSeparator={hosts.length ? "standard" : "none"}
|
||||||
|
>
|
||||||
|
<DialogButton style={{ minWidth: "8em" }} disabled={scanning} onClick={refresh}>
|
||||||
|
{scanning ? (
|
||||||
|
<Spinner style={{ height: "1em", marginRight: "0.5em" }} />
|
||||||
|
) : (
|
||||||
|
<FaSyncAlt style={{ marginRight: "0.5em" }} />
|
||||||
|
)}
|
||||||
|
{scanning ? "Scanning…" : "Refresh"}
|
||||||
|
</DialogButton>
|
||||||
|
</Field>
|
||||||
|
|
||||||
|
{hosts.length === 0 && !scanning && (
|
||||||
|
<Field
|
||||||
|
focusable={false}
|
||||||
|
description="No punktfunk hosts found. Make sure a host is running on the same network."
|
||||||
|
>
|
||||||
|
No hosts found
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
{hosts.map((h) => (
|
||||||
|
<HostRow key={h.fp || `${h.host}:${h.port}`} host={h} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
const SettingsTab: FC = () => (
|
||||||
|
<div style={tabScroll}>
|
||||||
|
<SettingsSection />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
const PunktfunkPage: FC = () => {
|
const PunktfunkPage: FC = () => {
|
||||||
const { hosts, scanning, refresh } = useHosts();
|
const { hosts, scanning, refresh } = useHosts();
|
||||||
|
const update = useUpdate();
|
||||||
|
const [tab, setTab] = useState("hosts");
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
marginTop: "40px",
|
marginTop: "40px",
|
||||||
height: "calc(100% - 40px)",
|
height: "calc(100% - 40px)",
|
||||||
overflowY: "auto",
|
display: "flex",
|
||||||
padding: "0 2.5em 2.5em",
|
flexDirection: "column",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Focusable style={{ display: "flex", alignItems: "center", gap: "1em", marginBottom: "1em" }}>
|
<Focusable
|
||||||
|
style={{
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
gap: "1em",
|
||||||
|
padding: "0 2.5em",
|
||||||
|
marginBottom: "0.4em",
|
||||||
|
flexShrink: 0,
|
||||||
|
}}
|
||||||
|
>
|
||||||
<DialogButton
|
<DialogButton
|
||||||
style={{ width: "3em", minWidth: "3em" }}
|
style={{ width: "3em", minWidth: "3em", padding: 0 }}
|
||||||
onClick={() => Navigation.NavigateBack()}
|
onClick={() => Navigation.NavigateBack()}
|
||||||
>
|
>
|
||||||
<FaArrowLeft />
|
<FaArrowLeft />
|
||||||
</DialogButton>
|
</DialogButton>
|
||||||
<div className={staticClasses.Title} style={{ flex: 1 }}>
|
<div className={staticClasses?.Title} style={{ flex: 1, margin: 0 }}>
|
||||||
punktfunk
|
punktfunk
|
||||||
</div>
|
</div>
|
||||||
<DialogButton style={{ width: "10em" }} disabled={scanning} onClick={refresh}>
|
{update?.update_available && (
|
||||||
{scanning ? (
|
<DialogButton style={{ minWidth: "9em" }} onClick={() => applyUpdate(update)}>
|
||||||
<Spinner style={{ height: "1em", marginRight: "0.5em" }} />
|
<FaDownload style={{ marginRight: "0.4em" }} />
|
||||||
) : (
|
Update v{update.latest}
|
||||||
<FaSyncAlt style={{ marginRight: "0.5em" }} />
|
</DialogButton>
|
||||||
)}
|
)}
|
||||||
{scanning ? "Scanning…" : "Refresh"}
|
|
||||||
</DialogButton>
|
|
||||||
</Focusable>
|
</Focusable>
|
||||||
|
|
||||||
<div style={{ fontSize: "1.1em", fontWeight: "bold", margin: "0.5em 0" }}>Hosts</div>
|
<div style={{ flex: 1, minHeight: 0 }}>
|
||||||
{hosts.length === 0 && !scanning && (
|
<Tabs
|
||||||
<Field focusable={false}>No hosts discovered on the LAN.</Field>
|
activeTab={tab}
|
||||||
)}
|
onShowTab={(id: string) => setTab(id)}
|
||||||
{hosts.map((h) => (
|
autoFocusContents
|
||||||
<HostRow key={h.fp || `${h.host}:${h.port}`} host={h} />
|
tabs={[
|
||||||
))}
|
{
|
||||||
|
id: "hosts",
|
||||||
<div style={{ fontSize: "1.1em", fontWeight: "bold", margin: "1.5em 0 0.5em" }}>
|
title: "Hosts",
|
||||||
Stream settings
|
content: <HostsTab hosts={hosts} scanning={scanning} refresh={refresh} />,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "settings",
|
||||||
|
title: "Settings",
|
||||||
|
content: <SettingsTab />,
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<SettingsSection />
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -343,9 +545,25 @@ const PunktfunkPage: FC = () => {
|
|||||||
// ----------------------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------------------
|
||||||
const QamPanel: FC = () => {
|
const QamPanel: FC = () => {
|
||||||
const { hosts, scanning, refresh } = useHosts();
|
const { hosts, scanning, refresh } = useHosts();
|
||||||
|
const update = useUpdate();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
{update?.update_available && (
|
||||||
|
<PanelSection title="Update">
|
||||||
|
<PanelSectionRow>
|
||||||
|
<ButtonItem
|
||||||
|
layout="below"
|
||||||
|
onClick={() => applyUpdate(update)}
|
||||||
|
label={`v${update.current} → v${update.latest}`}
|
||||||
|
>
|
||||||
|
<FaDownload style={{ marginRight: "0.5em" }} />
|
||||||
|
Update punktfunk
|
||||||
|
</ButtonItem>
|
||||||
|
</PanelSectionRow>
|
||||||
|
</PanelSection>
|
||||||
|
)}
|
||||||
|
|
||||||
<PanelSection title="punktfunk">
|
<PanelSection title="punktfunk">
|
||||||
<PanelSectionRow>
|
<PanelSectionRow>
|
||||||
<ButtonItem
|
<ButtonItem
|
||||||
@@ -378,25 +596,25 @@ const QamPanel: FC = () => {
|
|||||||
</PanelSectionRow>
|
</PanelSectionRow>
|
||||||
)}
|
)}
|
||||||
{hosts.map((h) => {
|
{hosts.map((h) => {
|
||||||
const pairRequired = h.pair === "required";
|
const needsPair = h.pair === "required" && !h.paired;
|
||||||
return (
|
return (
|
||||||
<PanelSectionRow key={h.fp || `${h.host}:${h.port}`}>
|
<PanelSectionRow key={h.fp || `${h.host}:${h.port}`}>
|
||||||
<ButtonItem
|
<ButtonItem
|
||||||
layout="below"
|
layout="below"
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
pairRequired
|
needsPair
|
||||||
? showModal(<PairModal host={h} onPaired={() => startStream(h)} />)
|
? showModal(<PairModal host={h} onPaired={() => startStream(h)} />)
|
||||||
: startStream(h)
|
: startStream(h)
|
||||||
}
|
}
|
||||||
label={
|
label={
|
||||||
<span style={{ display: "inline-flex", alignItems: "center", gap: "0.4em" }}>
|
<span style={{ display: "inline-flex", alignItems: "center", gap: "0.4em" }}>
|
||||||
{pairRequired ? <FaLock /> : <FaLockOpen />}
|
{needsPair ? <FaLock /> : <FaLockOpen />}
|
||||||
{h.name}
|
{h.name}
|
||||||
</span>
|
</span>
|
||||||
}
|
}
|
||||||
description={`${h.host}:${h.port}`}
|
description={`${h.host}:${h.port}${h.paired ? " · paired" : ""}`}
|
||||||
>
|
>
|
||||||
{pairRequired ? "Pair & Stream" : "Stream"}
|
{needsPair ? "Pair & Stream" : "Stream"}
|
||||||
</ButtonItem>
|
</ButtonItem>
|
||||||
</PanelSectionRow>
|
</PanelSectionRow>
|
||||||
);
|
);
|
||||||
@@ -406,12 +624,25 @@ const QamPanel: FC = () => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Full page behind the boundary — registered as the /punktfunk route.
|
||||||
|
const PunktfunkRoute: FC = () => (
|
||||||
|
<PluginErrorBoundary>
|
||||||
|
<PunktfunkPage />
|
||||||
|
</PluginErrorBoundary>
|
||||||
|
);
|
||||||
|
|
||||||
export default definePlugin(() => {
|
export default definePlugin(() => {
|
||||||
routerHook.addRoute(ROUTE, PunktfunkPage, { exact: true });
|
routerHook.addRoute(ROUTE, PunktfunkRoute, { exact: true });
|
||||||
return {
|
return {
|
||||||
name: "punktfunk",
|
name: "punktfunk",
|
||||||
titleView: <div className={staticClasses.Title}>punktfunk</div>,
|
// `staticClasses?.Title` is guarded so a future client that drops the export can't throw
|
||||||
content: <QamPanel />,
|
// at plugin-load time (an error boundary only catches render-time, not load-time, errors).
|
||||||
|
titleView: <div className={staticClasses?.Title}>punktfunk</div>,
|
||||||
|
content: (
|
||||||
|
<PluginErrorBoundary>
|
||||||
|
<QamPanel />
|
||||||
|
</PluginErrorBoundary>
|
||||||
|
),
|
||||||
icon: <FaTv />,
|
icon: <FaTv />,
|
||||||
onDismount() {
|
onDismount() {
|
||||||
routerHook.removeRoute(ROUTE);
|
routerHook.removeRoute(ROUTE);
|
||||||
|
|||||||
@@ -24,12 +24,31 @@ declare const SteamClient: {
|
|||||||
SetShortcutExe(appId: number, exe: string): void;
|
SetShortcutExe(appId: number, exe: string): void;
|
||||||
SetShortcutStartDir(appId: number, dir: string): void;
|
SetShortcutStartDir(appId: number, dir: string): void;
|
||||||
SetAppLaunchOptions(appId: number, options: string): void;
|
SetAppLaunchOptions(appId: number, options: string): void;
|
||||||
SetAppHidden(appId: number, hidden: boolean): void;
|
|
||||||
RunGame(gameId: string, _unused: string, _i: number, _j: number): void;
|
RunGame(gameId: string, _unused: string, _i: number, _j: number): void;
|
||||||
TerminateApp(gameId: string, _b: boolean): void;
|
TerminateApp(gameId: string, _b: boolean): void;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Steam removed `SteamClient.Apps.SetAppHidden`. Hiding a non-Steam shortcut now goes through
|
||||||
|
// `collectionStore.SetAppsAsHidden([appId], true)` — but that looks the app up in appStore, which
|
||||||
|
// only registers a freshly-created shortcut a moment later (calling it immediately throws on a
|
||||||
|
// null overview). So hiding is BEST-EFFORT + DEFERRED and must NEVER block the launch.
|
||||||
|
declare const collectionStore:
|
||||||
|
| { SetAppsAsHidden?: (appIds: number[], hidden: boolean) => void }
|
||||||
|
| undefined;
|
||||||
|
|
||||||
|
function hideShortcut(appId: number): void {
|
||||||
|
const attempt = () => {
|
||||||
|
try {
|
||||||
|
collectionStore?.SetAppsAsHidden?.([appId], true);
|
||||||
|
} catch {
|
||||||
|
/* overview not registered yet, or the API changed — cosmetic, ignore */
|
||||||
|
}
|
||||||
|
};
|
||||||
|
attempt(); // succeeds immediately for an already-registered (reused) shortcut
|
||||||
|
setTimeout(attempt, 2500); // fresh shortcut: retry once its app overview lands
|
||||||
|
}
|
||||||
|
|
||||||
const SHORTCUT_NAME = "punktfunk";
|
const SHORTCUT_NAME = "punktfunk";
|
||||||
|
|
||||||
// The 64-bit "gameid" RunGame wants, derived from a 32-bit non-Steam shortcut appId: the
|
// The 64-bit "gameid" RunGame wants, derived from a 32-bit non-Steam shortcut appId: the
|
||||||
@@ -88,7 +107,8 @@ async function ensureShortcut(): Promise<number> {
|
|||||||
);
|
);
|
||||||
SteamClient.Apps.SetShortcutName(appId, SHORTCUT_NAME);
|
SteamClient.Apps.SetShortcutName(appId, SHORTCUT_NAME);
|
||||||
// Hide it from the library — it's an implementation detail, launched programmatically.
|
// Hide it from the library — it's an implementation detail, launched programmatically.
|
||||||
SteamClient.Apps.SetAppHidden(appId, true);
|
// Best-effort + deferred (see hideShortcut); never let it block the launch.
|
||||||
|
hideShortcut(appId);
|
||||||
rememberAppId(appId);
|
rememberAppId(appId);
|
||||||
return appId;
|
return appId;
|
||||||
}
|
}
|
||||||
|
|||||||
+252
-8
@@ -22,6 +22,8 @@ struct App {
|
|||||||
gamepad: crate::gamepad::GamepadService,
|
gamepad: crate::gamepad::GamepadService,
|
||||||
/// One session at a time — ignore connects while one is starting/running.
|
/// One session at a time — ignore connects while one is starting/running.
|
||||||
busy: std::cell::Cell<bool>,
|
busy: std::cell::Cell<bool>,
|
||||||
|
/// Steam Deck / Gaming-Mode launch: fullscreen the window (chrome-less) when a stream starts.
|
||||||
|
fullscreen: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl App {
|
impl App {
|
||||||
@@ -41,7 +43,13 @@ pub fn run() -> glib::ExitCode {
|
|||||||
if let Some(pin) = arg_value("--pair") {
|
if let Some(pin) = arg_value("--pair") {
|
||||||
return headless_pair(&pin);
|
return headless_pair(&pin);
|
||||||
}
|
}
|
||||||
let app = adw::Application::builder().application_id(APP_ID).build();
|
let mut builder = adw::Application::builder().application_id(APP_ID);
|
||||||
|
// Screenshot mode launches the app once per scene back-to-back; NON_UNIQUE keeps each
|
||||||
|
// launch its own primary instance instead of forwarding to a still-registered name.
|
||||||
|
if shot_scene().is_some() {
|
||||||
|
builder = builder.flags(gtk::gio::ApplicationFlags::NON_UNIQUE);
|
||||||
|
}
|
||||||
|
let app = builder.build();
|
||||||
app.connect_activate(build_ui);
|
app.connect_activate(build_ui);
|
||||||
// GTK doesn't see our argv (`--connect` is handled in `build_ui`); an empty argv also
|
// GTK doesn't see our argv (`--connect` is handled in `build_ui`); an empty argv also
|
||||||
// keeps GApplication from rejecting unknown options.
|
// keeps GApplication from rejecting unknown options.
|
||||||
@@ -56,6 +64,20 @@ fn arg_value(flag: &str) -> Option<String> {
|
|||||||
.filter(|v| !v.starts_with("--"))
|
.filter(|v| !v.starts_with("--"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// True if argv contains `flag` (a valueless switch).
|
||||||
|
fn arg_flag(flag: &str) -> bool {
|
||||||
|
std::env::args().any(|a| a == flag)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Run the stream fullscreen with no window chrome — the Steam Deck / Gaming-Mode launch path.
|
||||||
|
/// The Decky wrapper passes `--fullscreen`; we also honor the Deck/gamescope env as a fallback
|
||||||
|
/// so a manual launch under Gaming Mode does the right thing too.
|
||||||
|
fn fullscreen_mode() -> bool {
|
||||||
|
arg_flag("--fullscreen")
|
||||||
|
|| std::env::var_os("SteamDeck").is_some()
|
||||||
|
|| std::env::var_os("GAMESCOPE_WAYLAND_DISPLAY").is_some()
|
||||||
|
}
|
||||||
|
|
||||||
/// Run the SPAKE2 PIN ceremony without a GTK window and persist the verified host to the
|
/// Run the SPAKE2 PIN ceremony without a GTK window and persist the verified host to the
|
||||||
/// known-hosts store as paired, so a later `--connect` connects silently. Same identity
|
/// known-hosts store as paired, so a later `--connect` connects silently. Same identity
|
||||||
/// store the streaming path uses (same binary), so pairing here makes the stream work.
|
/// store the streaming path uses (same binary), so pairing here makes the stream work.
|
||||||
@@ -161,6 +183,7 @@ fn build_ui(gtk_app: &adw::Application) {
|
|||||||
identity,
|
identity,
|
||||||
gamepad: crate::gamepad::GamepadService::start(),
|
gamepad: crate::gamepad::GamepadService::start(),
|
||||||
busy: std::cell::Cell::new(false),
|
busy: std::cell::Cell::new(false),
|
||||||
|
fullscreen: fullscreen_mode(),
|
||||||
});
|
});
|
||||||
|
|
||||||
let hosts_page = crate::ui_hosts::new(
|
let hosts_page = crate::ui_hosts::new(
|
||||||
@@ -182,11 +205,65 @@ fn build_ui(gtk_app: &adw::Application) {
|
|||||||
nav.add(&hosts_page);
|
nav.add(&hosts_page);
|
||||||
window.present();
|
window.present();
|
||||||
|
|
||||||
|
// CI screenshot mode: render one scripted, host-free scene and signal readiness
|
||||||
|
// (clients/linux/tools/screenshots.sh). Mutually exclusive with a real connect.
|
||||||
|
if let Some(scene) = shot_scene() {
|
||||||
|
run_shot(app, &scene);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(req) = cli_connect_request() {
|
if let Some(req) = cli_connect_request() {
|
||||||
initiate_connect(app, req);
|
initiate_connect(app, req);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// `PUNKTFUNK_SHOT_SCENE`, when set, selects a scripted host-free scene for CI screenshots.
|
||||||
|
fn shot_scene() -> Option<String> {
|
||||||
|
std::env::var("PUNKTFUNK_SHOT_SCENE")
|
||||||
|
.ok()
|
||||||
|
.filter(|s| !s.is_empty())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Render one mock-populated, host-free scene over the already-presented window, then print
|
||||||
|
/// `PF_SHOT_READY` once it has had a moment to map + settle so the driver knows when to capture.
|
||||||
|
/// No `NativeClient` or session is created. The stream scene is deliberately absent — its page
|
||||||
|
/// requires a live connector (`ui_stream::new` takes an `Arc<NativeClient>`).
|
||||||
|
fn run_shot(app: Rc<App>, scene: &str) {
|
||||||
|
// A plausible host for the trust/pair dialogs (fp_hex is 64 hex chars, like a real SHA-256).
|
||||||
|
let mock_req = || ConnectRequest {
|
||||||
|
name: "Living Room PC".to_string(),
|
||||||
|
addr: "192.168.1.42".to_string(),
|
||||||
|
port: 9777,
|
||||||
|
fp_hex: Some(
|
||||||
|
"9f8e7d6c5b4a39281706f5e4d3c2b1a0998877665544332211ffeeddccbbaa00".to_string(),
|
||||||
|
),
|
||||||
|
pair_optional: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
match scene {
|
||||||
|
// The saved-hosts grid reads ~/.config/punktfunk/client-known-hosts.json, which the
|
||||||
|
// driver seeds — so the already-shown hosts page is the scene; nothing to do here.
|
||||||
|
"hosts" | "02-hosts" => {}
|
||||||
|
"settings" | "03-settings" => {
|
||||||
|
crate::ui_settings::show(&app.window, app.settings.clone(), &app.gamepad);
|
||||||
|
}
|
||||||
|
"trust" | "04-trust" => tofu_dialog(app.clone(), mock_req()),
|
||||||
|
"pair" | "05-pair" => pin_dialog(app.clone(), mock_req()),
|
||||||
|
other => tracing::warn!("unknown PUNKTFUNK_SHOT_SCENE={other:?}; showing hosts only"),
|
||||||
|
}
|
||||||
|
|
||||||
|
let settle_ms = std::env::var("PUNKTFUNK_SHOT_SETTLE_MS")
|
||||||
|
.ok()
|
||||||
|
.and_then(|v| v.parse().ok())
|
||||||
|
.unwrap_or(900);
|
||||||
|
let scene = scene.to_string();
|
||||||
|
glib::timeout_add_local_once(std::time::Duration::from_millis(settle_ms), move || {
|
||||||
|
use std::io::Write as _;
|
||||||
|
println!("PF_SHOT_READY scene={scene}");
|
||||||
|
let _ = std::io::stdout().flush();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/// The trust gate in front of every connect. The host is the policy authority (it
|
/// The trust gate in front of every connect. The host is the policy authority (it
|
||||||
/// advertises `pair=optional` only when it accepts unpaired clients); the client renders
|
/// advertises `pair=optional` only when it accepts unpaired clients); the client renders
|
||||||
/// its trust UI from that:
|
/// its trust UI from that:
|
||||||
@@ -218,19 +295,21 @@ fn initiate_connect(app: Rc<App>, req: ConnectRequest) {
|
|||||||
// Rule 3a: the host opted into reduced-security TOFU; offer it alongside PIN.
|
// Rule 3a: the host opted into reduced-security TOFU; offer it alongside PIN.
|
||||||
tofu_dialog(app, req);
|
tofu_dialog(app, req);
|
||||||
} else {
|
} else {
|
||||||
// Rule 3b: pair=required or unknown policy — PIN pairing is mandatory.
|
// Rule 3b: pair=required or unknown policy — offer no-PIN delegated approval
|
||||||
pin_dialog(app, req);
|
// (request access → approve in the console) or the PIN ceremony.
|
||||||
|
approval_dialog(app, req);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
// Manual entry (no advertised fingerprint). A known address connects silently
|
// Manual entry (no advertised fingerprint). A known address connects silently
|
||||||
// on its stored pin (rule 1); an unknown one must pair — never silent TOFU.
|
// on its stored pin (rule 1); an unknown one must pair — request access (approve in
|
||||||
|
// the console) or use a PIN; never silent TOFU.
|
||||||
match known
|
match known
|
||||||
.find_by_addr(&req.addr, req.port)
|
.find_by_addr(&req.addr, req.port)
|
||||||
.and_then(|k| crate::trust::parse_hex32(&k.fp_hex))
|
.and_then(|k| crate::trust::parse_hex32(&k.fp_hex))
|
||||||
{
|
{
|
||||||
Some(pin) => start_session(app, req, Some(pin)),
|
Some(pin) => start_session(app, req, Some(pin)),
|
||||||
None => pin_dialog(app, req), // rule 3b
|
None => approval_dialog(app, req), // rule 3b
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -341,6 +420,83 @@ fn pin_dialog(app: Rc<App>, req: ConnectRequest) {
|
|||||||
dialog.present(Some(&parent));
|
dialog.present(Some(&parent));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A fresh host that requires pairing: offer the two ways in. "Request access" is the no-PIN
|
||||||
|
/// path — connect and wait for the operator to click Approve in the host's console/web UI
|
||||||
|
/// (delegated approval); "Use a PIN instead…" runs the SPAKE2 ceremony.
|
||||||
|
fn approval_dialog(app: Rc<App>, req: ConnectRequest) {
|
||||||
|
let dialog = adw::AlertDialog::new(
|
||||||
|
Some("Pairing Required"),
|
||||||
|
Some(&format!(
|
||||||
|
"{} requires pairing.\n\nRequest access and approve this device in the host's console \
|
||||||
|
(or web UI) — no PIN needed. Or pair with the 4-digit PIN it can display.",
|
||||||
|
req.name
|
||||||
|
)),
|
||||||
|
);
|
||||||
|
dialog.add_responses(&[
|
||||||
|
("cancel", "Cancel"),
|
||||||
|
("pin", "Use a PIN instead…"),
|
||||||
|
("request", "Request Access"),
|
||||||
|
]);
|
||||||
|
dialog.set_response_appearance("request", adw::ResponseAppearance::Suggested);
|
||||||
|
dialog.set_default_response(Some("request"));
|
||||||
|
dialog.set_close_response("cancel");
|
||||||
|
let parent = app.window.clone();
|
||||||
|
dialog.connect_response(None, move |_, response| match response {
|
||||||
|
"request" => request_access(app.clone(), req.clone()),
|
||||||
|
"pin" => pin_dialog(app.clone(), req.clone()),
|
||||||
|
_ => {}
|
||||||
|
});
|
||||||
|
dialog.present(Some(&parent));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The no-PIN "request access" flow: open an identified connect that the host PARKS until the
|
||||||
|
/// operator approves it in the console, showing a cancelable "waiting" dialog meanwhile. On
|
||||||
|
/// approval the same connection is admitted (no reconnect) and the host is saved as paired.
|
||||||
|
fn request_access(app: Rc<App>, req: ConnectRequest) {
|
||||||
|
// Pin the advertised certificate for a discovered host (defence against a host impostor while
|
||||||
|
// we wait); a manually-typed host has no advertised fingerprint, so trust-on-first-use.
|
||||||
|
let pin = req.fp_hex.as_deref().and_then(crate::trust::parse_hex32);
|
||||||
|
let cancel = Rc::new(std::cell::Cell::new(false));
|
||||||
|
|
||||||
|
let waiting = adw::AlertDialog::new(
|
||||||
|
Some("Waiting for Approval"),
|
||||||
|
Some(&format!(
|
||||||
|
"Approve “{}” in {}’s console or web UI.\n\nThis device is waiting to be let in — it \
|
||||||
|
connects automatically once you approve it.",
|
||||||
|
glib::host_name(),
|
||||||
|
req.name
|
||||||
|
)),
|
||||||
|
);
|
||||||
|
waiting.add_responses(&[("cancel", "Cancel")]);
|
||||||
|
waiting.set_close_response("cancel");
|
||||||
|
{
|
||||||
|
let app = app.clone();
|
||||||
|
let cancel = cancel.clone();
|
||||||
|
waiting.connect_response(Some("cancel"), move |_, _| {
|
||||||
|
// Return the UI immediately; the in-flight connect is left to time out and is torn
|
||||||
|
// down silently by the event loop (see StartOpts::cancel).
|
||||||
|
cancel.set(true);
|
||||||
|
app.busy.set(false);
|
||||||
|
app.toast("Cancelled — the request may still be pending on the host.");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
waiting.present(Some(&app.window));
|
||||||
|
|
||||||
|
start_session_with(
|
||||||
|
app,
|
||||||
|
req,
|
||||||
|
pin,
|
||||||
|
StartOpts {
|
||||||
|
// Must exceed the host's approval window (PENDING_APPROVAL_WAIT) so a slow operator
|
||||||
|
// approval still lands on this connection rather than timing the client out first.
|
||||||
|
connect_timeout: std::time::Duration::from_secs(185),
|
||||||
|
persist_paired: true,
|
||||||
|
waiting: Some(waiting),
|
||||||
|
cancel: Some(cancel),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/// Measure the path to a host over the real data plane (Swift's "Test Network Speed…"):
|
/// Measure the path to a host over the real data plane (Swift's "Test Network Speed…"):
|
||||||
/// connect, have the host burst probe filler for 2 s up to its 3 Gbps ceiling, report
|
/// connect, have the host burst probe filler for 2 s up to its 3 Gbps ceiling, report
|
||||||
/// goodput · loss · a recommended bitrate (≈70 % of measured), and apply it in one tap.
|
/// goodput · loss · a recommended bitrate (≈70 % of measured), and apply it in one tap.
|
||||||
@@ -375,6 +531,7 @@ fn speed_test(app: Rc<App>, req: ConnectRequest) {
|
|||||||
GamepadPref::Auto,
|
GamepadPref::Auto,
|
||||||
0, // bitrate_kbps (host default)
|
0, // bitrate_kbps (host default)
|
||||||
0, // video_caps: the Linux client has no 10-bit/HDR present path yet
|
0, // video_caps: the Linux client has no 10-bit/HDR present path yet
|
||||||
|
2, // audio_channels: speed-test probe, stereo
|
||||||
None, // launch: speed-test probe connect, no game
|
None, // launch: speed-test probe connect, no game
|
||||||
pin,
|
pin,
|
||||||
Some(identity),
|
Some(identity),
|
||||||
@@ -443,11 +600,19 @@ fn resolve_mode(app: &App) -> punktfunk_core::config::Mode {
|
|||||||
refresh_hz: s.refresh_hz,
|
refresh_hz: s.refresh_hz,
|
||||||
};
|
};
|
||||||
if mode.width == 0 || mode.refresh_hz == 0 {
|
if mode.width == 0 || mode.refresh_hz == 0 {
|
||||||
|
// Prefer the monitor the window is on; fall back to the display's first monitor. On a
|
||||||
|
// `--connect` launch the window may not be mapped yet when this runs, and without the
|
||||||
|
// fallback we'd drop to the 1920×1080 floor below — wrong on the Deck (1280×800).
|
||||||
let monitor = app
|
let monitor = app
|
||||||
.window
|
.window
|
||||||
.surface()
|
.surface()
|
||||||
.zip(gdk::Display::default())
|
.zip(gdk::Display::default())
|
||||||
.and_then(|(surf, d)| d.monitor_at_surface(&surf));
|
.and_then(|(surf, d)| d.monitor_at_surface(&surf))
|
||||||
|
.or_else(|| {
|
||||||
|
gdk::Display::default()
|
||||||
|
.and_then(|d| d.monitors().item(0))
|
||||||
|
.and_then(|o| o.downcast::<gdk::Monitor>().ok())
|
||||||
|
});
|
||||||
if let Some(m) = monitor {
|
if let Some(m) = monitor {
|
||||||
let geo = m.geometry();
|
let geo = m.geometry();
|
||||||
let scale = m.scale_factor().max(1);
|
let scale = m.scale_factor().max(1);
|
||||||
@@ -470,7 +635,42 @@ fn resolve_mode(app: &App) -> punktfunk_core::config::Mode {
|
|||||||
mode
|
mode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Tunables for a session start that differ between the normal connect and the "request access"
|
||||||
|
/// (delegated-approval) flow. `Default` is the normal connect.
|
||||||
|
struct StartOpts {
|
||||||
|
/// Handshake budget. The request-access flow uses a long one because the host PARKS the
|
||||||
|
/// connection until the operator clicks Approve (see the host's `PENDING_APPROVAL_WAIT`).
|
||||||
|
connect_timeout: std::time::Duration,
|
||||||
|
/// Persist the host as *paired* on a successful connect. Set for request-access, where the
|
||||||
|
/// operator's approval IS the pairing, so future connects are silent (rule 1). Normal TOFU
|
||||||
|
/// persists the host *unpaired* (pinned, but not PIN/approval-verified).
|
||||||
|
persist_paired: bool,
|
||||||
|
/// A "waiting for approval" dialog to dismiss on the first session event (request-access only).
|
||||||
|
waiting: Option<adw::AlertDialog>,
|
||||||
|
/// Set by the waiting dialog's Cancel button. `NativeClient::connect` is a blocking call with
|
||||||
|
/// no abort, so Cancel returns the UI immediately (clears busy, closes the dialog) and leaves
|
||||||
|
/// the in-flight connect to time out; when it finally resolves, the event loop sees this flag
|
||||||
|
/// and tears down silently (drops the connector → closes the connection) without touching the
|
||||||
|
/// UI a new session may already own.
|
||||||
|
cancel: Option<Rc<std::cell::Cell<bool>>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for StartOpts {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
connect_timeout: std::time::Duration::from_secs(15),
|
||||||
|
persist_paired: false,
|
||||||
|
waiting: None,
|
||||||
|
cancel: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn start_session(app: Rc<App>, req: ConnectRequest, pin: Option<[u8; 32]>) {
|
fn start_session(app: Rc<App>, req: ConnectRequest, pin: Option<[u8; 32]>) {
|
||||||
|
start_session_with(app, req, pin, StartOpts::default());
|
||||||
|
}
|
||||||
|
|
||||||
|
fn start_session_with(app: Rc<App>, req: ConnectRequest, pin: Option<[u8; 32]>, opts: StartOpts) {
|
||||||
if app.busy.replace(true) {
|
if app.busy.replace(true) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -488,12 +688,17 @@ fn start_session(app: Rc<App>, req: ConnectRequest, pin: Option<[u8; 32]>) {
|
|||||||
},
|
},
|
||||||
bitrate_kbps: s.bitrate_kbps,
|
bitrate_kbps: s.bitrate_kbps,
|
||||||
mic_enabled: s.mic_enabled,
|
mic_enabled: s.mic_enabled,
|
||||||
|
audio_channels: s.audio_channels,
|
||||||
pin,
|
pin,
|
||||||
identity: app.identity.clone(),
|
identity: app.identity.clone(),
|
||||||
|
connect_timeout: opts.connect_timeout,
|
||||||
};
|
};
|
||||||
let inhibit = s.inhibit_shortcuts;
|
let inhibit = s.inhibit_shortcuts;
|
||||||
drop(s);
|
drop(s);
|
||||||
let tofu = pin.is_none();
|
let tofu = pin.is_none();
|
||||||
|
let persist_paired = opts.persist_paired;
|
||||||
|
let mut waiting = opts.waiting;
|
||||||
|
let cancel = opts.cancel;
|
||||||
|
|
||||||
let mut handle = crate::session::start(params);
|
let mut handle = crate::session::start(params);
|
||||||
let frames = std::mem::replace(&mut handle.frames, async_channel::bounded(1).1);
|
let frames = std::mem::replace(&mut handle.frames, async_channel::bounded(1).1);
|
||||||
@@ -501,14 +706,41 @@ fn start_session(app: Rc<App>, req: ConnectRequest, pin: Option<[u8; 32]>) {
|
|||||||
let mut frames = Some(frames);
|
let mut frames = Some(frames);
|
||||||
let mut page: Option<crate::ui_stream::StreamPage> = None;
|
let mut page: Option<crate::ui_stream::StreamPage> = None;
|
||||||
while let Ok(event) = handle.events.recv().await {
|
while let Ok(event) = handle.events.recv().await {
|
||||||
|
// A cancelled request-access connect resolved late: tear down silently. Don't touch
|
||||||
|
// app.busy — Cancel already cleared it, and a fresh session may now own it.
|
||||||
|
if cancel.as_ref().is_some_and(|c| c.get()) {
|
||||||
|
if let Some(w) = waiting.take() {
|
||||||
|
w.close();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
match event {
|
match event {
|
||||||
SessionEvent::Connected {
|
SessionEvent::Connected {
|
||||||
connector,
|
connector,
|
||||||
mode,
|
mode,
|
||||||
fingerprint,
|
fingerprint,
|
||||||
} => {
|
} => {
|
||||||
// A TOFU connect just observed the real fingerprint — pin it from now on.
|
// Dismiss the "waiting for approval" dialog (request-access flow), if any.
|
||||||
if tofu {
|
if let Some(w) = waiting.take() {
|
||||||
|
w.close();
|
||||||
|
}
|
||||||
|
if persist_paired {
|
||||||
|
// Request-access: the operator approved this device, so record the host as
|
||||||
|
// a trusted PAIRED host (pinning the fingerprint we observed) — future
|
||||||
|
// connects are then silent (rule 1), exactly like after a PIN ceremony.
|
||||||
|
let fp_hex = crate::trust::hex(&fingerprint);
|
||||||
|
let mut known = KnownHosts::load();
|
||||||
|
known.upsert(KnownHost {
|
||||||
|
name: req.name.clone(),
|
||||||
|
addr: req.addr.clone(),
|
||||||
|
port: req.port,
|
||||||
|
fp_hex,
|
||||||
|
paired: true,
|
||||||
|
});
|
||||||
|
let _ = known.save();
|
||||||
|
app.toast("Approved — connecting…");
|
||||||
|
} else if tofu {
|
||||||
|
// A TOFU connect just observed the real fingerprint — pin it from now on.
|
||||||
let fp_hex = crate::trust::hex(&fingerprint);
|
let fp_hex = crate::trust::hex(&fingerprint);
|
||||||
let mut known = KnownHosts::load();
|
let mut known = KnownHosts::load();
|
||||||
known.upsert(KnownHost {
|
known.upsert(KnownHost {
|
||||||
@@ -540,6 +772,12 @@ fn start_session(app: Rc<App>, req: ConnectRequest, pin: Option<[u8; 32]>) {
|
|||||||
&title,
|
&title,
|
||||||
);
|
);
|
||||||
app.nav.push(&p.page);
|
app.nav.push(&p.page);
|
||||||
|
// Steam Deck / Gaming Mode: gamescope fullscreens the window but GTK doesn't
|
||||||
|
// know it, so its header bar stays drawn. Enter GTK fullscreen explicitly —
|
||||||
|
// the stream page's `connect_fullscreened_notify` then hides all chrome.
|
||||||
|
if app.fullscreen {
|
||||||
|
app.window.fullscreen();
|
||||||
|
}
|
||||||
page = Some(p);
|
page = Some(p);
|
||||||
}
|
}
|
||||||
SessionEvent::Stats(s) => {
|
SessionEvent::Stats(s) => {
|
||||||
@@ -551,6 +789,9 @@ fn start_session(app: Rc<App>, req: ConnectRequest, pin: Option<[u8; 32]>) {
|
|||||||
msg,
|
msg,
|
||||||
trust_rejected,
|
trust_rejected,
|
||||||
} => {
|
} => {
|
||||||
|
if let Some(w) = waiting.take() {
|
||||||
|
w.close();
|
||||||
|
}
|
||||||
tracing::warn!(%msg, trust_rejected, "connect failed");
|
tracing::warn!(%msg, trust_rejected, "connect failed");
|
||||||
app.busy.set(false);
|
app.busy.set(false);
|
||||||
// A pinned connect rejected on trust grounds means the host's cert no
|
// A pinned connect rejected on trust grounds means the host's cert no
|
||||||
@@ -565,6 +806,9 @@ fn start_session(app: Rc<App>, req: ConnectRequest, pin: Option<[u8; 32]>) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
SessionEvent::Ended(err) => {
|
SessionEvent::Ended(err) => {
|
||||||
|
if let Some(w) = waiting.take() {
|
||||||
|
w.close();
|
||||||
|
}
|
||||||
app.gamepad.detach();
|
app.gamepad.detach();
|
||||||
app.nav.pop_to_tag("hosts");
|
app.nav.pop_to_tag("hosts");
|
||||||
if let Some(e) = err {
|
if let Some(e) = err {
|
||||||
|
|||||||
+21
-10
@@ -27,16 +27,17 @@ pub struct AudioPlayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl AudioPlayer {
|
impl AudioPlayer {
|
||||||
/// Spawn the PipeWire playback thread. Failure (no PipeWire in the session) is
|
/// Spawn the PipeWire playback thread for `channels` (2/6/8, canonical wire order
|
||||||
/// survivable — the caller streams video-only.
|
/// FL FR FC LFE RL RR SL SR). Failure (no PipeWire in the session) is survivable — the
|
||||||
pub fn spawn() -> Result<AudioPlayer> {
|
/// caller streams video-only.
|
||||||
|
pub fn spawn(channels: u32) -> Result<AudioPlayer> {
|
||||||
// 64 × 5 ms = 320 ms of slack between the pump and the PipeWire loop.
|
// 64 × 5 ms = 320 ms of slack between the pump and the PipeWire loop.
|
||||||
let (pcm_tx, pcm_rx) = std::sync::mpsc::sync_channel::<Vec<f32>>(64);
|
let (pcm_tx, pcm_rx) = std::sync::mpsc::sync_channel::<Vec<f32>>(64);
|
||||||
let (quit_tx, quit_rx) = pipewire::channel::channel::<Terminate>();
|
let (quit_tx, quit_rx) = pipewire::channel::channel::<Terminate>();
|
||||||
let thread = std::thread::Builder::new()
|
let thread = std::thread::Builder::new()
|
||||||
.name("punktfunk-audio".into())
|
.name("punktfunk-audio".into())
|
||||||
.spawn(move || {
|
.spawn(move || {
|
||||||
if let Err(e) = pw_thread(pcm_rx, quit_rx) {
|
if let Err(e) = pw_thread(pcm_rx, quit_rx, channels as usize) {
|
||||||
tracing::warn!(error = %e, "audio playback thread ended");
|
tracing::warn!(error = %e, "audio playback thread ended");
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -48,8 +49,8 @@ impl AudioPlayer {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Queue one interleaved-stereo f32 chunk. Drops the chunk if the PipeWire side is
|
/// Queue one interleaved f32 chunk (in the session's channel layout). Drops the chunk if the
|
||||||
/// wedged (the renderer conceals the gap; never block the session pump).
|
/// PipeWire side is wedged (the renderer conceals the gap; never block the session pump).
|
||||||
pub fn push(&self, pcm: Vec<f32>) {
|
pub fn push(&self, pcm: Vec<f32>) {
|
||||||
if let Err(TrySendError::Disconnected(_)) = self.pcm_tx.try_send(pcm) {
|
if let Err(TrySendError::Disconnected(_)) = self.pcm_tx.try_send(pcm) {
|
||||||
// Thread already dead — Drop will reap it; nothing to do per-chunk.
|
// Thread already dead — Drop will reap it; nothing to do per-chunk.
|
||||||
@@ -71,11 +72,14 @@ struct PlayerData {
|
|||||||
rx: Receiver<Vec<f32>>,
|
rx: Receiver<Vec<f32>>,
|
||||||
ring: VecDeque<f32>,
|
ring: VecDeque<f32>,
|
||||||
primed: bool,
|
primed: bool,
|
||||||
|
/// Interleaved channel count this stream was opened with (2/6/8).
|
||||||
|
channels: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pw_thread(
|
fn pw_thread(
|
||||||
pcm_rx: Receiver<Vec<f32>>,
|
pcm_rx: Receiver<Vec<f32>>,
|
||||||
quit_rx: pipewire::channel::Receiver<Terminate>,
|
quit_rx: pipewire::channel::Receiver<Terminate>,
|
||||||
|
channels: usize,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
use pipewire as pw;
|
use pipewire as pw;
|
||||||
use pw::{properties::properties, spa};
|
use pw::{properties::properties, spa};
|
||||||
@@ -115,6 +119,7 @@ fn pw_thread(
|
|||||||
rx: pcm_rx,
|
rx: pcm_rx,
|
||||||
ring: VecDeque::new(),
|
ring: VecDeque::new(),
|
||||||
primed: false,
|
primed: false,
|
||||||
|
channels,
|
||||||
};
|
};
|
||||||
|
|
||||||
let _listener = stream
|
let _listener = stream
|
||||||
@@ -130,19 +135,19 @@ fn pw_thread(
|
|||||||
while let Ok(chunk) = ud.rx.try_recv() {
|
while let Ok(chunk) = ud.rx.try_recv() {
|
||||||
ud.ring.extend(chunk);
|
ud.ring.extend(chunk);
|
||||||
}
|
}
|
||||||
let stride = 4 * CHANNELS; // F32LE interleaved
|
let stride = 4 * ud.channels; // F32LE interleaved
|
||||||
let datas = buffer.datas_mut();
|
let datas = buffer.datas_mut();
|
||||||
if datas.is_empty() {
|
if datas.is_empty() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let data = &mut datas[0];
|
let data = &mut datas[0];
|
||||||
let want_frames = data.data().map(|s| s.len() / stride).unwrap_or(0);
|
let want_frames = data.data().map(|s| s.len() / stride).unwrap_or(0);
|
||||||
let want = want_frames * CHANNELS;
|
let want = want_frames * ud.channels;
|
||||||
|
|
||||||
// Adaptive jitter buffer (same shape as the host's virtual mic): prime to
|
// Adaptive jitter buffer (same shape as the host's virtual mic): prime to
|
||||||
// ~3 quanta, cap at ~1 quantum of slack beyond that, re-prime after a
|
// ~3 quanta, cap at ~1 quantum of slack beyond that, re-prime after a
|
||||||
// genuine drain.
|
// genuine drain.
|
||||||
let target = (3 * want).clamp(720 * CHANNELS, 9600 * CHANNELS);
|
let target = (3 * want).clamp(720 * ud.channels, 9600 * ud.channels);
|
||||||
while ud.ring.len() > target.max(want) + want {
|
while ud.ring.len() > target.max(want) + want {
|
||||||
ud.ring.pop_front();
|
ud.ring.pop_front();
|
||||||
}
|
}
|
||||||
@@ -182,7 +187,13 @@ fn pw_thread(
|
|||||||
let mut info = AudioInfoRaw::new();
|
let mut info = AudioInfoRaw::new();
|
||||||
info.set_format(AudioFormat::F32LE);
|
info.set_format(AudioFormat::F32LE);
|
||||||
info.set_rate(SAMPLE_RATE);
|
info.set_rate(SAMPLE_RATE);
|
||||||
info.set_channels(CHANNELS as u32);
|
info.set_channels(channels as u32);
|
||||||
|
// Channel positions in canonical wire order (FL FR FC LFE RL RR SL SR) so PipeWire routes each
|
||||||
|
// slot to the matching speaker (and downmixes when the sink has fewer). Identity, no permute.
|
||||||
|
let order = punktfunk_core::audio::spa_positions(channels as u8);
|
||||||
|
let mut positions = [0u32; 64];
|
||||||
|
positions[..order.len()].copy_from_slice(order);
|
||||||
|
info.set_position(positions);
|
||||||
let obj = pw::spa::pod::Object {
|
let obj = pw::spa::pod::Object {
|
||||||
type_: pw::spa::utils::SpaTypes::ObjectParamFormat.as_raw(),
|
type_: pw::spa::utils::SpaTypes::ObjectParamFormat.as_raw(),
|
||||||
id: pw::spa::param::ParamType::EnumFormat.as_raw(),
|
id: pw::spa::param::ParamType::EnumFormat.as_raw(),
|
||||||
|
|||||||
@@ -39,7 +39,39 @@ const ESCAPE_CHORD: [u32; 4] = [wire::BTN_LB, wire::BTN_RB, wire::BTN_START, wir
|
|||||||
pub struct PadInfo {
|
pub struct PadInfo {
|
||||||
pub id: u32,
|
pub id: u32,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub is_dualsense: bool,
|
/// The virtual pad "Automatic" resolves to for this physical controller (so the host creates a
|
||||||
|
/// matching pad: DualSense → DualSense, DS4 → DualShock 4, Xbox One/Series → Xbox One, anything
|
||||||
|
/// else → Xbox 360). Drives [`GamepadService::auto_pref`] and the rich-feedback render path.
|
||||||
|
pub pref: GamepadPref,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PadInfo {
|
||||||
|
/// True for a real DualSense — the only pad whose lightbar / player-LED / adaptive-trigger
|
||||||
|
/// feedback we replay as raw DS5 HID effect packets (a DS4 uses SDL's generic `set_led`).
|
||||||
|
fn is_dualsense(&self) -> bool {
|
||||||
|
self.pref == GamepadPref::DualSense
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A short controller-kind label for the Settings list (`""` for a plain Xbox/standard pad).
|
||||||
|
pub fn kind_label(&self) -> &'static str {
|
||||||
|
match self.pref {
|
||||||
|
GamepadPref::DualSense => "DualSense",
|
||||||
|
GamepadPref::DualShock4 => "DualShock 4",
|
||||||
|
GamepadPref::XboxOne => "Xbox One",
|
||||||
|
_ => "",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Map the SDL-reported controller type to the virtual pad we'd ask the host to create.
|
||||||
|
fn pref_for_type(t: sdl3::gamepad::GamepadType) -> GamepadPref {
|
||||||
|
use sdl3::gamepad::GamepadType as T;
|
||||||
|
match t {
|
||||||
|
T::PS5 => GamepadPref::DualSense,
|
||||||
|
T::PS4 => GamepadPref::DualShock4,
|
||||||
|
T::XboxOne => GamepadPref::XboxOne,
|
||||||
|
_ => GamepadPref::Xbox360,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Ctl {
|
enum Ctl {
|
||||||
@@ -120,8 +152,7 @@ impl GamepadService {
|
|||||||
/// (Swift parity); no pad connected leaves the host's own default.
|
/// (Swift parity); no pad connected leaves the host's own default.
|
||||||
pub fn auto_pref(&self) -> GamepadPref {
|
pub fn auto_pref(&self) -> GamepadPref {
|
||||||
match self.active() {
|
match self.active() {
|
||||||
Some(p) if p.is_dualsense => GamepadPref::DualSense,
|
Some(p) => p.pref,
|
||||||
Some(_) => GamepadPref::Xbox360,
|
|
||||||
None => GamepadPref::Auto,
|
None => GamepadPref::Auto,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -247,10 +278,9 @@ impl Worker {
|
|||||||
Some(PadInfo {
|
Some(PadInfo {
|
||||||
id,
|
id,
|
||||||
name: pad.name().unwrap_or_else(|| "Controller".into()),
|
name: pad.name().unwrap_or_else(|| "Controller".into()),
|
||||||
is_dualsense: matches!(
|
pref: pref_for_type(
|
||||||
self.subsystem
|
self.subsystem
|
||||||
.type_for_id(sdl3::sys::joystick::SDL_JoystickID(id)),
|
.type_for_id(sdl3::sys::joystick::SDL_JoystickID(id)),
|
||||||
sdl3::gamepad::GamepadType::PS5
|
|
||||||
),
|
),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -552,7 +582,7 @@ fn run(
|
|||||||
}
|
}
|
||||||
while let Ok(hid) = connector.next_hidout(Duration::ZERO) {
|
while let Ok(hid) = connector.next_hidout(Duration::ZERO) {
|
||||||
let Some(id) = w.active_id() else { continue };
|
let Some(id) = w.active_id() else { continue };
|
||||||
let is_ds = w.pad_info(id).is_some_and(|p| p.is_dualsense);
|
let is_ds = w.pad_info(id).is_some_and(|p| p.is_dualsense());
|
||||||
let Some(pad) = w.opened.get_mut(&id) else {
|
let Some(pad) = w.opened.get_mut(&id) else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -20,11 +20,18 @@ pub struct SessionParams {
|
|||||||
pub compositor: CompositorPref,
|
pub compositor: CompositorPref,
|
||||||
pub gamepad: GamepadPref,
|
pub gamepad: GamepadPref,
|
||||||
pub bitrate_kbps: u32,
|
pub bitrate_kbps: u32,
|
||||||
|
/// Requested audio channel count (2/6/8); the host echoes the resolved value.
|
||||||
|
pub audio_channels: u8,
|
||||||
/// Stream the default microphone to the host's virtual mic source.
|
/// Stream the default microphone to the host's virtual mic source.
|
||||||
pub mic_enabled: bool,
|
pub mic_enabled: bool,
|
||||||
/// Pinned host fingerprint; `None` = trust on first use (caller persists the observed one).
|
/// Pinned host fingerprint; `None` = trust on first use (caller persists the observed one).
|
||||||
pub pin: Option<[u8; 32]>,
|
pub pin: Option<[u8; 32]>,
|
||||||
pub identity: (String, String),
|
pub identity: (String, String),
|
||||||
|
/// How long to wait for the handshake. The normal path uses a short budget; the
|
||||||
|
/// "request access" (delegated-approval) path uses a long one, because the host PARKS the
|
||||||
|
/// connection until the operator clicks Approve in its console (so this must exceed the
|
||||||
|
/// host's approval window — see `PENDING_APPROVAL_WAIT`).
|
||||||
|
pub connect_timeout: Duration,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Default)]
|
#[derive(Clone, Copy, Default)]
|
||||||
@@ -83,6 +90,42 @@ fn now_ns() -> u64 {
|
|||||||
.unwrap_or(0)
|
.unwrap_or(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Opus decoder for the audio plane: a plain stereo decoder (the validated path) or a multistream
|
||||||
|
/// decoder for 5.1/7.1, both behind one `decode_float`. Built from the host-RESOLVED channel count
|
||||||
|
/// via the shared layout table.
|
||||||
|
enum AudioDec {
|
||||||
|
Stereo(opus::Decoder),
|
||||||
|
Surround(opus::MSDecoder),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AudioDec {
|
||||||
|
fn new(channels: u8) -> Result<AudioDec, opus::Error> {
|
||||||
|
if channels == 2 {
|
||||||
|
Ok(AudioDec::Stereo(opus::Decoder::new(
|
||||||
|
48_000,
|
||||||
|
opus::Channels::Stereo,
|
||||||
|
)?))
|
||||||
|
} else {
|
||||||
|
let l = punktfunk_core::audio::layout_for(channels, false);
|
||||||
|
Ok(AudioDec::Surround(opus::MSDecoder::new(
|
||||||
|
48_000, l.streams, l.coupled, l.mapping,
|
||||||
|
)?))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn decode_float(
|
||||||
|
&mut self,
|
||||||
|
input: &[u8],
|
||||||
|
out: &mut [f32],
|
||||||
|
fec: bool,
|
||||||
|
) -> Result<usize, opus::Error> {
|
||||||
|
match self {
|
||||||
|
AudioDec::Stereo(d) => d.decode_float(input, out, fec),
|
||||||
|
AudioDec::Surround(d) => d.decode_float(input, out, fec),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn pump(
|
fn pump(
|
||||||
params: SessionParams,
|
params: SessionParams,
|
||||||
ev_tx: async_channel::Sender<SessionEvent>,
|
ev_tx: async_channel::Sender<SessionEvent>,
|
||||||
@@ -96,11 +139,12 @@ fn pump(
|
|||||||
params.compositor,
|
params.compositor,
|
||||||
params.gamepad,
|
params.gamepad,
|
||||||
params.bitrate_kbps,
|
params.bitrate_kbps,
|
||||||
0, // video_caps: the Linux client has no 10-bit/HDR present path yet
|
0, // video_caps: the Linux client has no 10-bit/HDR present path yet
|
||||||
|
params.audio_channels,
|
||||||
None, // launch: the Linux client has no library picker yet
|
None, // launch: the Linux client has no library picker yet
|
||||||
params.pin,
|
params.pin,
|
||||||
Some(params.identity),
|
Some(params.identity),
|
||||||
Duration::from_secs(15),
|
params.connect_timeout,
|
||||||
) {
|
) {
|
||||||
Ok(c) => Arc::new(c),
|
Ok(c) => Arc::new(c),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
@@ -134,11 +178,14 @@ fn pump(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
// Audio is best-effort: a session without it still streams. Gamepads are the
|
// Audio is best-effort: a session without it still streams. Gamepads are the
|
||||||
// app-lifetime service's job (the UI attaches it on Connected).
|
// app-lifetime service's job (the UI attaches it on Connected). Build the decoder + playback
|
||||||
let player = audio::AudioPlayer::spawn()
|
// from the host-RESOLVED channel count (never the request), so an older/clamping host that
|
||||||
|
// resolves stereo is decoded as stereo.
|
||||||
|
let channels = connector.audio_channels;
|
||||||
|
let player = audio::AudioPlayer::spawn(channels as u32)
|
||||||
.map_err(|e| tracing::warn!(error = %e, "audio disabled"))
|
.map_err(|e| tracing::warn!(error = %e, "audio disabled"))
|
||||||
.ok();
|
.ok();
|
||||||
let mut opus_dec = opus::Decoder::new(48_000, opus::Channels::Stereo)
|
let mut opus_dec = AudioDec::new(channels)
|
||||||
.map_err(|e| tracing::warn!(error = %e, "opus decoder failed — audio disabled"))
|
.map_err(|e| tracing::warn!(error = %e, "opus decoder failed — audio disabled"))
|
||||||
.ok();
|
.ok();
|
||||||
let _mic = params
|
let _mic = params
|
||||||
@@ -157,8 +204,8 @@ fn pump(
|
|||||||
let mut bytes_n = 0u64;
|
let mut bytes_n = 0u64;
|
||||||
let mut decode_us_sum = 0u64;
|
let mut decode_us_sum = 0u64;
|
||||||
let mut lat_us: Vec<u64> = Vec::with_capacity(256);
|
let mut lat_us: Vec<u64> = Vec::with_capacity(256);
|
||||||
let mut pcm = vec![0f32; 5760 * 2]; // decode scratch: max Opus frame (120 ms stereo)
|
let mut pcm = vec![0f32; 5760 * channels as usize]; // scratch: max Opus frame (120 ms) × channels
|
||||||
// Loss recovery: watch the host→client unrecoverable-drop count and ask for an IDR when it climbs.
|
// Loss recovery: watch the host→client unrecoverable-drop count and ask for an IDR when it climbs.
|
||||||
let mut last_dropped = connector.frames_dropped();
|
let mut last_dropped = connector.frames_dropped();
|
||||||
let mut last_kf_req: Option<Instant> = None;
|
let mut last_kf_req: Option<Instant> = None;
|
||||||
|
|
||||||
@@ -221,7 +268,8 @@ fn pump(
|
|||||||
while let Ok(pkt) = connector.next_audio(Duration::ZERO) {
|
while let Ok(pkt) = connector.next_audio(Duration::ZERO) {
|
||||||
if let (Some(player), Some(dec)) = (&player, opus_dec.as_mut()) {
|
if let (Some(player), Some(dec)) = (&player, opus_dec.as_mut()) {
|
||||||
match dec.decode_float(&pkt.data, &mut pcm, false) {
|
match dec.decode_float(&pkt.data, &mut pcm, false) {
|
||||||
Ok(samples) => player.push(pcm[..samples * 2].to_vec()),
|
// `samples` is per-channel; the interleaved frame is `samples * channels`.
|
||||||
|
Ok(samples) => player.push(pcm[..samples * channels as usize].to_vec()),
|
||||||
Err(e) => tracing::debug!(error = %e, "opus decode"),
|
Err(e) => tracing::debug!(error = %e, "opus decode"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,6 +90,14 @@ impl KnownHosts {
|
|||||||
self.hosts.iter().find(|h| h.addr == addr && h.port == port)
|
self.hosts.iter().find(|h| h.addr == addr && h.port == port)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Forget the entry with this fingerprint. Returns true if one was removed (the user
|
||||||
|
/// will have to pair/trust again to reconnect).
|
||||||
|
pub fn remove_by_fp(&mut self, fp_hex: &str) -> bool {
|
||||||
|
let before = self.hosts.len();
|
||||||
|
self.hosts.retain(|h| h.fp_hex != fp_hex);
|
||||||
|
self.hosts.len() != before
|
||||||
|
}
|
||||||
|
|
||||||
/// Insert or refresh an entry, keyed by fingerprint. `paired` only ever upgrades
|
/// Insert or refresh an entry, keyed by fingerprint. `paired` only ever upgrades
|
||||||
/// (a later TOFU connect must not demote a PIN-paired host).
|
/// (a later TOFU connect must not demote a PIN-paired host).
|
||||||
pub fn upsert(&mut self, entry: KnownHost) {
|
pub fn upsert(&mut self, entry: KnownHost) {
|
||||||
@@ -124,6 +132,9 @@ pub struct Settings {
|
|||||||
pub inhibit_shortcuts: bool,
|
pub inhibit_shortcuts: bool,
|
||||||
/// Stream the default microphone to the host's virtual mic source.
|
/// Stream the default microphone to the host's virtual mic source.
|
||||||
pub mic_enabled: bool,
|
pub mic_enabled: bool,
|
||||||
|
/// Requested audio channel count: 2 (stereo), 6 (5.1) or 8 (7.1). The host clamps to what it
|
||||||
|
/// can capture; the resolved count drives the decoder + playback layout.
|
||||||
|
pub audio_channels: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Settings {
|
impl Default for Settings {
|
||||||
@@ -137,6 +148,7 @@ impl Default for Settings {
|
|||||||
compositor: "auto".into(),
|
compositor: "auto".into(),
|
||||||
inhibit_shortcuts: true,
|
inhibit_shortcuts: true,
|
||||||
mic_enabled: false,
|
mic_enabled: false,
|
||||||
|
audio_channels: 2,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -181,6 +181,52 @@ pub fn new(
|
|||||||
// pinned connect; TOFU eligibility is irrelevant.
|
// pinned connect; TOFU eligibility is irrelevant.
|
||||||
pair_optional: false,
|
pair_optional: false,
|
||||||
};
|
};
|
||||||
|
// Forget this host (drops the pinned fingerprint — a later connect re-pairs).
|
||||||
|
// Confirmed first, since it's destructive and a misclick on the Deck is easy.
|
||||||
|
let remove_btn = gtk::Button::from_icon_name("user-trash-symbolic");
|
||||||
|
remove_btn.set_tooltip_text(Some("Remove saved host"));
|
||||||
|
remove_btn.set_valign(gtk::Align::Center);
|
||||||
|
remove_btn.add_css_class("flat");
|
||||||
|
{
|
||||||
|
let fp = k.fp_hex.clone();
|
||||||
|
let name = k.name.clone();
|
||||||
|
let saved_list = saved_list.clone();
|
||||||
|
let saved_label = saved_label.clone();
|
||||||
|
let row = row.clone();
|
||||||
|
remove_btn.connect_clicked(move |_| {
|
||||||
|
let dialog = adw::AlertDialog::new(
|
||||||
|
Some("Remove saved host?"),
|
||||||
|
Some(&format!(
|
||||||
|
"Forget “{name}”? You'll need to pair (or trust) it again to reconnect."
|
||||||
|
)),
|
||||||
|
);
|
||||||
|
dialog.add_responses(&[("cancel", "Cancel"), ("remove", "Remove")]);
|
||||||
|
dialog.set_response_appearance(
|
||||||
|
"remove",
|
||||||
|
adw::ResponseAppearance::Destructive,
|
||||||
|
);
|
||||||
|
dialog.set_default_response(Some("cancel"));
|
||||||
|
dialog.set_close_response("cancel");
|
||||||
|
{
|
||||||
|
// Scoped clones for the response handler so `row` survives for present().
|
||||||
|
let fp = fp.clone();
|
||||||
|
let saved_list = saved_list.clone();
|
||||||
|
let saved_label = saved_label.clone();
|
||||||
|
let row = row.clone();
|
||||||
|
dialog.connect_response(Some("remove"), move |_, _| {
|
||||||
|
let mut known = KnownHosts::load();
|
||||||
|
known.remove_by_fp(&fp);
|
||||||
|
let _ = known.save();
|
||||||
|
saved_list.remove(&row);
|
||||||
|
let empty = known.hosts.is_empty();
|
||||||
|
saved_list.set_visible(!empty);
|
||||||
|
saved_label.set_visible(!empty);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
dialog.present(Some(&row));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
row.add_suffix(&remove_btn);
|
||||||
let speed_btn = gtk::Button::from_icon_name("network-transmit-receive-symbolic");
|
let speed_btn = gtk::Button::from_icon_name("network-transmit-receive-symbolic");
|
||||||
speed_btn.set_tooltip_text(Some("Test network speed"));
|
speed_btn.set_tooltip_text(Some("Test network speed"));
|
||||||
speed_btn.set_valign(gtk::Align::Center);
|
speed_btn.set_valign(gtk::Align::Center);
|
||||||
|
|||||||
@@ -16,9 +16,52 @@ const RESOLUTIONS: &[(u32, u32)] = &[
|
|||||||
];
|
];
|
||||||
/// `0` = the monitor's native refresh, resolved at connect.
|
/// `0` = the monitor's native refresh, resolved at connect.
|
||||||
const REFRESH: &[u32] = &[0, 30, 60, 90, 120, 144, 165, 240];
|
const REFRESH: &[u32] = &[0, 30, 60, 90, 120, 144, 165, 240];
|
||||||
const GAMEPADS: &[&str] = &["auto", "xbox360", "dualsense"];
|
const GAMEPADS: &[&str] = &["auto", "xbox360", "dualsense", "xboxone", "dualshock4"];
|
||||||
const COMPOSITORS: &[&str] = &["auto", "kwin", "wlroots", "mutter", "gamescope"];
|
const COMPOSITORS: &[&str] = &["auto", "kwin", "wlroots", "mutter", "gamescope"];
|
||||||
|
|
||||||
|
/// punktfunk's own license (MIT OR Apache-2.0), shown on the About dialog's Legal page.
|
||||||
|
const APP_LICENSE: &str = concat!(
|
||||||
|
"punktfunk is licensed under MIT OR Apache-2.0, at your option.\n\n",
|
||||||
|
"================================ MIT ================================\n\n",
|
||||||
|
include_str!("../../../LICENSE-MIT"),
|
||||||
|
"\n\n=============================== Apache-2.0 ===============================\n\n",
|
||||||
|
include_str!("../../../LICENSE-APACHE"),
|
||||||
|
);
|
||||||
|
/// Third-party software notices for the linked Rust crates (generated by
|
||||||
|
/// scripts/gen-third-party-notices.sh; shown as a Legal section in the About dialog).
|
||||||
|
const THIRD_PARTY_NOTICES: &str = include_str!("../../../THIRD-PARTY-NOTICES.txt");
|
||||||
|
|
||||||
|
/// Show the About dialog (app license + the third-party-software Legal section).
|
||||||
|
fn show_about(parent: &impl IsA<gtk::Widget>) {
|
||||||
|
let about = adw::AboutDialog::builder()
|
||||||
|
.application_name("punktfunk")
|
||||||
|
.developer_name("unom")
|
||||||
|
.version(env!("CARGO_PKG_VERSION"))
|
||||||
|
.website("https://git.unom.io/unom/punktfunk")
|
||||||
|
.license_type(gtk::License::Custom)
|
||||||
|
.license(APP_LICENSE)
|
||||||
|
.build();
|
||||||
|
// The native (FFmpeg/GTK/PipeWire/SDL3) components are dynamically linked under their own
|
||||||
|
// (LGPL/Zlib/MIT) licenses; the Rust crate notices are the substantive attribution set.
|
||||||
|
about.add_legal_section(
|
||||||
|
"Third-party software (Rust crates)",
|
||||||
|
None,
|
||||||
|
gtk::License::Custom,
|
||||||
|
Some(THIRD_PARTY_NOTICES),
|
||||||
|
);
|
||||||
|
about.add_legal_section(
|
||||||
|
"Third-party software (system libraries)",
|
||||||
|
None,
|
||||||
|
gtk::License::Custom,
|
||||||
|
Some(
|
||||||
|
"This application dynamically links system libraries under their own licenses, \
|
||||||
|
including FFmpeg (LGPL v2.1+), GTK 4 and libadwaita (LGPL v2.1+), PipeWire (MIT), \
|
||||||
|
and SDL 3 (Zlib). Their full license texts are available from each project.",
|
||||||
|
),
|
||||||
|
);
|
||||||
|
about.present(Some(parent));
|
||||||
|
}
|
||||||
|
|
||||||
pub fn show(
|
pub fn show(
|
||||||
parent: &impl IsA<gtk::Widget>,
|
parent: &impl IsA<gtk::Widget>,
|
||||||
settings: Rc<RefCell<Settings>>,
|
settings: Rc<RefCell<Settings>>,
|
||||||
@@ -85,10 +128,11 @@ pub fn show(
|
|||||||
let pads = gamepads.pads();
|
let pads = gamepads.pads();
|
||||||
let mut pad_names = vec!["Automatic (most recent)".to_string()];
|
let mut pad_names = vec!["Automatic (most recent)".to_string()];
|
||||||
pad_names.extend(pads.iter().map(|p| {
|
pad_names.extend(pads.iter().map(|p| {
|
||||||
if p.is_dualsense {
|
let kind = p.kind_label();
|
||||||
format!("{} · DualSense", p.name)
|
if kind.is_empty() {
|
||||||
} else {
|
|
||||||
p.name.clone()
|
p.name.clone()
|
||||||
|
} else {
|
||||||
|
format!("{} · {kind}", p.name)
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
let forward_row = adw::ComboRow::builder()
|
let forward_row = adw::ComboRow::builder()
|
||||||
@@ -126,6 +170,8 @@ pub fn show(
|
|||||||
"Automatic",
|
"Automatic",
|
||||||
"Xbox 360",
|
"Xbox 360",
|
||||||
"DualSense",
|
"DualSense",
|
||||||
|
"Xbox One",
|
||||||
|
"DualShock 4",
|
||||||
]))
|
]))
|
||||||
.build();
|
.build();
|
||||||
let inhibit_row = adw::SwitchRow::builder()
|
let inhibit_row = adw::SwitchRow::builder()
|
||||||
@@ -137,15 +183,39 @@ pub fn show(
|
|||||||
input.add(&inhibit_row);
|
input.add(&inhibit_row);
|
||||||
|
|
||||||
let audio = adw::PreferencesGroup::builder().title("Audio").build();
|
let audio = adw::PreferencesGroup::builder().title("Audio").build();
|
||||||
|
let surround_row = adw::ComboRow::builder()
|
||||||
|
.title("Audio channels")
|
||||||
|
.subtitle("Request stereo or surround (the host downmixes if its output has fewer)")
|
||||||
|
.model(>k::StringList::new(&[
|
||||||
|
"Stereo",
|
||||||
|
"5.1 Surround",
|
||||||
|
"7.1 Surround",
|
||||||
|
]))
|
||||||
|
.build();
|
||||||
|
audio.add(&surround_row);
|
||||||
let mic_row = adw::SwitchRow::builder()
|
let mic_row = adw::SwitchRow::builder()
|
||||||
.title("Stream microphone")
|
.title("Stream microphone")
|
||||||
.subtitle("Send the default input device to the host's virtual microphone")
|
.subtitle("Send the default input device to the host's virtual microphone")
|
||||||
.build();
|
.build();
|
||||||
audio.add(&mic_row);
|
audio.add(&mic_row);
|
||||||
|
|
||||||
|
let about = adw::PreferencesGroup::builder().title("About").build();
|
||||||
|
let licenses_row = adw::ActionRow::builder()
|
||||||
|
.title("Third-party licenses")
|
||||||
|
.subtitle("Open-source software used by punktfunk")
|
||||||
|
.activatable(true)
|
||||||
|
.build();
|
||||||
|
licenses_row.add_suffix(>k::Image::from_icon_name("go-next-symbolic"));
|
||||||
|
{
|
||||||
|
let about_parent: gtk::Widget = parent.clone().upcast();
|
||||||
|
licenses_row.connect_activated(move |_| show_about(&about_parent));
|
||||||
|
}
|
||||||
|
about.add(&licenses_row);
|
||||||
|
|
||||||
page.add(&stream);
|
page.add(&stream);
|
||||||
page.add(&input);
|
page.add(&input);
|
||||||
page.add(&audio);
|
page.add(&audio);
|
||||||
|
page.add(&about);
|
||||||
|
|
||||||
// Seed from the current settings.
|
// Seed from the current settings.
|
||||||
{
|
{
|
||||||
@@ -167,6 +237,11 @@ pub fn show(
|
|||||||
compositor_row.set_selected(comp_i as u32);
|
compositor_row.set_selected(comp_i as u32);
|
||||||
inhibit_row.set_active(s.inhibit_shortcuts);
|
inhibit_row.set_active(s.inhibit_shortcuts);
|
||||||
mic_row.set_active(s.mic_enabled);
|
mic_row.set_active(s.mic_enabled);
|
||||||
|
surround_row.set_selected(match s.audio_channels {
|
||||||
|
6 => 1,
|
||||||
|
8 => 2,
|
||||||
|
_ => 0,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let dialog = adw::PreferencesDialog::new();
|
let dialog = adw::PreferencesDialog::new();
|
||||||
@@ -183,6 +258,11 @@ pub fn show(
|
|||||||
.to_string();
|
.to_string();
|
||||||
s.inhibit_shortcuts = inhibit_row.is_active();
|
s.inhibit_shortcuts = inhibit_row.is_active();
|
||||||
s.mic_enabled = mic_row.is_active();
|
s.mic_enabled = mic_row.is_active();
|
||||||
|
s.audio_channels = match surround_row.selected() {
|
||||||
|
1 => 6,
|
||||||
|
2 => 8,
|
||||||
|
_ => 2,
|
||||||
|
};
|
||||||
s.save();
|
s.save();
|
||||||
});
|
});
|
||||||
dialog.present(Some(parent));
|
dialog.present(Some(parent));
|
||||||
|
|||||||
Executable
+123
@@ -0,0 +1,123 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Capture host-free UI screenshots of the native Linux client under a virtual X
|
||||||
|
# display. Mirrors the iOS harness (clients/apple/tools/screenshots.sh): one app
|
||||||
|
# launch per scene (PUNKTFUNK_SHOT_SCENE), the app renders a mock-populated REAL
|
||||||
|
# view and prints `PF_SHOT_READY`, then we grab the X root window. No host, GPU, or
|
||||||
|
# live stream — only the chrome scenes (the stream page needs a live connector).
|
||||||
|
#
|
||||||
|
# cargo build --release -p punktfunk-client-linux
|
||||||
|
# bash clients/linux/tools/screenshots.sh # → clients/linux/screenshots/<scene>.png
|
||||||
|
# bash clients/linux/tools/screenshots.sh hosts pair # a subset
|
||||||
|
#
|
||||||
|
# Env knobs: BIN (client binary), OUT (output dir), GEOMETRY (Xvfb WxHxDepth),
|
||||||
|
# SETTLE (extra seconds after PF_SHOT_READY), SHOT_DISPLAY (X display), GSK_RENDERER
|
||||||
|
# (gl|ngl|cairo — gl/llvmpipe by default for full libadwaita fidelity).
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
here="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" # clients/linux
|
||||||
|
BIN="${BIN:-$here/../../target/release/punktfunk-client}"
|
||||||
|
OUT="${OUT:-$here/screenshots}"
|
||||||
|
# The client window maps at its 1100x720 default; with no WM under Xvfb it lands at the
|
||||||
|
# top-left, so keep the root just larger so the full window (incl. its CSD shadow) is
|
||||||
|
# captured by a root grab with only a thin margin to crop.
|
||||||
|
GEOMETRY="${GEOMETRY:-1280x800x24}"
|
||||||
|
SETTLE="${SETTLE:-1.2}"
|
||||||
|
SHOT_DISPLAY="${SHOT_DISPLAY:-:99}"
|
||||||
|
|
||||||
|
if [ "$#" -gt 0 ]; then SCENES=("$@"); else SCENES=(hosts settings trust pair); fi
|
||||||
|
|
||||||
|
[ -x "$BIN" ] || {
|
||||||
|
echo "client binary not found: $BIN (build it first: cargo build --release -p punktfunk-client-linux)" >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Isolated scratch HOME: the client generates its identity here on first run, and the
|
||||||
|
# saved-hosts grid is read from client-known-hosts.json, so seed mock hosts for the
|
||||||
|
# `hosts` scene (the dialogs/settings build their own mock state in-app).
|
||||||
|
WORK="$(mktemp -d)"
|
||||||
|
export HOME="$WORK"
|
||||||
|
mkdir -p "$HOME/.config/punktfunk"
|
||||||
|
cat >"$HOME/.config/punktfunk/client-known-hosts.json" <<'JSON'
|
||||||
|
{
|
||||||
|
"hosts": [
|
||||||
|
{ "name": "Living Room PC", "addr": "192.168.1.42", "port": 9777,
|
||||||
|
"fp_hex": "9f8e7d6c5b4a39281706f5e4d3c2b1a0998877665544332211ffeeddccbbaa00",
|
||||||
|
"paired": true },
|
||||||
|
{ "name": "Office", "addr": "192.168.1.50", "port": 9777,
|
||||||
|
"fp_hex": "a1b2c3d4e5f60718293a4b5c6d7e8f90112233445566778899aabbccddeeff00",
|
||||||
|
"paired": false }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
JSON
|
||||||
|
|
||||||
|
# Software-rendered X session — no GPU/Wayland. GL/llvmpipe runs the real NGL renderer
|
||||||
|
# (cairo is documented-incomplete for 3D-transformed content / libadwaita transitions).
|
||||||
|
unset WAYLAND_DISPLAY
|
||||||
|
export DISPLAY="$SHOT_DISPLAY"
|
||||||
|
export GDK_BACKEND=x11
|
||||||
|
export LIBGL_ALWAYS_SOFTWARE=1
|
||||||
|
export GALLIUM_DRIVER="${GALLIUM_DRIVER:-llvmpipe}"
|
||||||
|
export GSK_RENDERER="${GSK_RENDERER:-gl}"
|
||||||
|
|
||||||
|
Xvfb "$SHOT_DISPLAY" -screen 0 "$GEOMETRY" -nolisten tcp >"$WORK/xvfb.log" 2>&1 &
|
||||||
|
XVFB_PID=$!
|
||||||
|
cleanup() {
|
||||||
|
kill "$XVFB_PID" 2>/dev/null || true
|
||||||
|
rm -rf "$WORK"
|
||||||
|
}
|
||||||
|
trap cleanup EXIT
|
||||||
|
|
||||||
|
# Wait for the display to accept connections.
|
||||||
|
for _ in $(seq 1 50); do
|
||||||
|
if command -v xdpyinfo >/dev/null 2>&1; then
|
||||||
|
xdpyinfo -display "$SHOT_DISPLAY" >/dev/null 2>&1 && break
|
||||||
|
else
|
||||||
|
[ -e "/tmp/.X11-unix/X${SHOT_DISPLAY#:}" ] && break
|
||||||
|
fi
|
||||||
|
sleep 0.1
|
||||||
|
done
|
||||||
|
|
||||||
|
capture() {
|
||||||
|
local out="$1"
|
||||||
|
if command -v import >/dev/null 2>&1; then
|
||||||
|
import -silent -window root "$out"
|
||||||
|
elif command -v scrot >/dev/null 2>&1; then
|
||||||
|
scrot -o "$out"
|
||||||
|
else
|
||||||
|
echo "no screenshot tool — install imagemagick or scrot" >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
mkdir -p "$OUT"
|
||||||
|
rc=0
|
||||||
|
for scene in "${SCENES[@]}"; do
|
||||||
|
: >"$WORK/log"
|
||||||
|
PUNKTFUNK_SHOT_SCENE="$scene" "$BIN" >"$WORK/log" 2>&1 &
|
||||||
|
pid=$!
|
||||||
|
ready=0
|
||||||
|
for _ in $(seq 1 200); do # up to ~20s
|
||||||
|
if grep -q "PF_SHOT_READY" "$WORK/log"; then
|
||||||
|
ready=1
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
if ! kill -0 "$pid" 2>/dev/null; then break; fi
|
||||||
|
sleep 0.1
|
||||||
|
done
|
||||||
|
if [ "$ready" = 1 ]; then
|
||||||
|
sleep "$SETTLE"
|
||||||
|
if capture "$OUT/$scene.png"; then
|
||||||
|
echo "✓ $scene → $OUT/$scene.png"
|
||||||
|
else
|
||||||
|
rc=1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "✗ $scene: client never signalled PF_SHOT_READY" >&2
|
||||||
|
sed 's/^/ /' "$WORK/log" >&2 || true
|
||||||
|
rc=1
|
||||||
|
fi
|
||||||
|
kill "$pid" 2>/dev/null || true
|
||||||
|
wait "$pid" 2>/dev/null || true
|
||||||
|
done
|
||||||
|
|
||||||
|
exit "$rc"
|
||||||
@@ -18,8 +18,7 @@ tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
|||||||
# LAN host discovery (`--discover`): browse the native `_punktfunk._udp` mDNS service the host
|
# LAN host discovery (`--discover`): browse the native `_punktfunk._udp` mDNS service the host
|
||||||
# advertises (same crate/version the host advertises with).
|
# advertises (same crate/version the host advertises with).
|
||||||
mdns-sd = "0.20"
|
mdns-sd = "0.20"
|
||||||
|
# Opus: multistream DECODE of the host's audio plane (the surround validator) + `--mic-test`'s
|
||||||
# Linux-only: --mic-test's Opus encoder (libopus). The mic UPLINK itself is portable —
|
# encoder. libopus is already in the graph via `punktfunk-core`'s quic feature; this exposes the
|
||||||
# only this synthetic-tone test rig needs the encoder.
|
# name directly. Cross-platform (cmake-vendored), so the probe builds + validates everywhere.
|
||||||
[target.'cfg(target_os = "linux")'.dependencies]
|
|
||||||
opus = "0.3"
|
opus = "0.3"
|
||||||
|
|||||||
+58
-10
@@ -27,9 +27,10 @@
|
|||||||
//! `gamescope`); the host honors it if available, else auto-detects and reports the resolved
|
//! `gamescope`); the host honors it if available, else auto-detects and reports the resolved
|
||||||
//! choice in its Welcome (logged as `session offer … compositor=…`).
|
//! choice in its Welcome (logged as `session offer … compositor=…`).
|
||||||
//!
|
//!
|
||||||
//! `--gamepad NAME` requests a host virtual-pad backend (`auto`|`xbox360`|`dualsense`); the
|
//! `--gamepad NAME` requests a host virtual-pad backend
|
||||||
//! host honors it where available (DualSense needs Linux UHID), else falls back to X-Box 360,
|
//! (`auto`|`xbox360`|`dualsense`|`xboxone`|`dualshock4`); the host honors it where available (the
|
||||||
//! and reports the resolved choice in its Welcome (logged as `session offer … gamepad=…`).
|
//! UHID pads — DualSense, DualShock 4 — need Linux), else falls back to X-Box 360, and reports the
|
||||||
|
//! resolved choice in its Welcome (logged as `session offer … gamepad=…`).
|
||||||
//!
|
//!
|
||||||
//! `--discover [SECS]` browses the LAN for native (`_punktfunk._udp`) hosts the host advertises
|
//! `--discover [SECS]` browses the LAN for native (`_punktfunk._udp`) hosts the host advertises
|
||||||
//! over mDNS, prints each (name, addr:port, pairing requirement, cert fingerprint to pin), and
|
//! over mDNS, prints each (name, addr:port, pairing requirement, cert fingerprint to pin), and
|
||||||
@@ -77,6 +78,10 @@ struct Args {
|
|||||||
gamepad: GamepadPref,
|
gamepad: GamepadPref,
|
||||||
/// `--bitrate KBPS` — request this encoder bitrate (kilobits/s); 0 = host default.
|
/// `--bitrate KBPS` — request this encoder bitrate (kilobits/s); 0 = host default.
|
||||||
bitrate_kbps: u32,
|
bitrate_kbps: u32,
|
||||||
|
/// `--audio-channels N` — request stereo (2), 5.1 (6) or 7.1 (8) audio; default 2. The probe
|
||||||
|
/// multistream-decodes the host's frames and asserts the per-channel sample count, so it's the
|
||||||
|
/// headless validator for the surround encode path.
|
||||||
|
audio_channels: u8,
|
||||||
/// `--launch ID` — ask the host to launch a library title in this session (a store-qualified
|
/// `--launch ID` — ask the host to launch a library title in this session (a store-qualified
|
||||||
/// id from the host's `GET /api/v1/library`, e.g. `steam:570`). Host resolves it; `None` = none.
|
/// id from the host's `GET /api/v1/library`, e.g. `steam:570`). Host resolves it; `None` = none.
|
||||||
launch: Option<String>,
|
launch: Option<String>,
|
||||||
@@ -178,7 +183,9 @@ fn parse_args() -> Args {
|
|||||||
Some(s) => match GamepadPref::from_name(s) {
|
Some(s) => match GamepadPref::from_name(s) {
|
||||||
Some(g) => g,
|
Some(g) => g,
|
||||||
None => {
|
None => {
|
||||||
eprintln!("--gamepad must be one of: auto, xbox360, dualsense");
|
eprintln!(
|
||||||
|
"--gamepad must be one of: auto, xbox360, dualsense, xboxone, dualshock4"
|
||||||
|
);
|
||||||
std::process::exit(2);
|
std::process::exit(2);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -198,6 +205,11 @@ fn parse_args() -> Args {
|
|||||||
compositor,
|
compositor,
|
||||||
gamepad,
|
gamepad,
|
||||||
bitrate_kbps: get("--bitrate").and_then(|s| s.parse().ok()).unwrap_or(0),
|
bitrate_kbps: get("--bitrate").and_then(|s| s.parse().ok()).unwrap_or(0),
|
||||||
|
audio_channels: punktfunk_core::audio::normalize_channels(
|
||||||
|
get("--audio-channels")
|
||||||
|
.and_then(|s| s.parse().ok())
|
||||||
|
.unwrap_or(2),
|
||||||
|
),
|
||||||
launch: get("--launch").map(str::to_string),
|
launch: get("--launch").map(str::to_string),
|
||||||
speed_test: get("--speed-test").and_then(|s| {
|
speed_test: get("--speed-test").and_then(|s| {
|
||||||
let (kbps, ms) = s.split_once(':')?;
|
let (kbps, ms) = s.split_once(':')?;
|
||||||
@@ -382,13 +394,23 @@ async fn session(args: Args) -> Result<()> {
|
|||||||
// `--launch ID` — host resolves it against its own library and runs it this session.
|
// `--launch ID` — host resolves it against its own library and runs it this session.
|
||||||
launch: args.launch.clone(),
|
launch: args.launch.clone(),
|
||||||
// This headless tool just dumps the bitstream (no decode), so it can always claim
|
// This headless tool just dumps the bitstream (no decode), so it can always claim
|
||||||
// 10-bit support. Gated by env so latency runs stay on the 8-bit baseline:
|
// 10-bit / 4:4:4 support. Gated by env so latency runs stay on the 8-bit 4:2:0 baseline:
|
||||||
// PUNKTFUNK_CLIENT_10BIT=1 advertises VIDEO_CAP_10BIT to exercise the host Main10 path.
|
// PUNKTFUNK_CLIENT_10BIT=1 advertises VIDEO_CAP_10BIT (host Main10 path);
|
||||||
video_caps: if std::env::var_os("PUNKTFUNK_CLIENT_10BIT").is_some() {
|
// PUNKTFUNK_CLIENT_444=1 advertises VIDEO_CAP_444 (host HEVC 4:4:4 path) — verify the
|
||||||
punktfunk_core::quic::VIDEO_CAP_10BIT
|
// resulting chroma with `ffprobe` on the `--out` .h265.
|
||||||
} else {
|
video_caps: {
|
||||||
0
|
let mut caps = 0u8;
|
||||||
|
if std::env::var_os("PUNKTFUNK_CLIENT_10BIT").is_some() {
|
||||||
|
caps |= punktfunk_core::quic::VIDEO_CAP_10BIT;
|
||||||
|
}
|
||||||
|
if std::env::var_os("PUNKTFUNK_CLIENT_444").is_some() {
|
||||||
|
caps |= punktfunk_core::quic::VIDEO_CAP_444;
|
||||||
|
}
|
||||||
|
caps
|
||||||
},
|
},
|
||||||
|
// `--audio-channels` (default stereo); the probe multistream-decodes + validates the
|
||||||
|
// host's frames to exercise the surround encode path headlessly.
|
||||||
|
audio_channels: args.audio_channels,
|
||||||
}
|
}
|
||||||
.encode(),
|
.encode(),
|
||||||
)
|
)
|
||||||
@@ -405,6 +427,8 @@ async fn session(args: Args) -> Result<()> {
|
|||||||
bit_depth = welcome.bit_depth,
|
bit_depth = welcome.bit_depth,
|
||||||
color = ?welcome.color,
|
color = ?welcome.color,
|
||||||
hdr = welcome.color.is_hdr(),
|
hdr = welcome.color.is_hdr(),
|
||||||
|
chroma_444 = welcome.chroma_format == punktfunk_core::quic::CHROMA_IDC_444,
|
||||||
|
chroma_format_idc = welcome.chroma_format,
|
||||||
"session offer"
|
"session offer"
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -827,13 +851,37 @@ async fn session(args: Args) -> Result<()> {
|
|||||||
hidout_pkts.clone(),
|
hidout_pkts.clone(),
|
||||||
);
|
);
|
||||||
let conn2 = conn.clone();
|
let conn2 = conn.clone();
|
||||||
|
// Build a multistream decoder for the host-RESOLVED layout so the probe actually decodes
|
||||||
|
// the surround stream (not just counts bytes) — the headless validator for the encode path.
|
||||||
|
let audio_channels = welcome.audio_channels;
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
use std::sync::atomic::Ordering::Relaxed;
|
use std::sync::atomic::Ordering::Relaxed;
|
||||||
let mut hdr_logged = false;
|
let mut hdr_logged = false;
|
||||||
|
let layout = punktfunk_core::audio::layout_for(audio_channels, false);
|
||||||
|
let mut audio_dec =
|
||||||
|
opus::MSDecoder::new(48_000, layout.streams, layout.coupled, layout.mapping).ok();
|
||||||
|
let mut pcm = vec![0f32; 5760 * audio_channels as usize];
|
||||||
|
let mut audio_decoded_logged = false;
|
||||||
while let Ok(d) = conn2.read_datagram().await {
|
while let Ok(d) = conn2.read_datagram().await {
|
||||||
if let Some((_, _, opus)) = punktfunk_core::quic::decode_audio_datagram(&d) {
|
if let Some((_, _, opus)) = punktfunk_core::quic::decode_audio_datagram(&d) {
|
||||||
a.fetch_add(1, Relaxed);
|
a.fetch_add(1, Relaxed);
|
||||||
ab.fetch_add(opus.len() as u64, Relaxed);
|
ab.fetch_add(opus.len() as u64, Relaxed);
|
||||||
|
// Decode + validate: the per-channel sample count must be a legal Opus frame
|
||||||
|
// size; log the first success so a loopback test can assert surround decoded.
|
||||||
|
if let Some(dec) = audio_dec.as_mut() {
|
||||||
|
match dec.decode_float(opus, &mut pcm, false) {
|
||||||
|
Ok(samples) if !audio_decoded_logged => {
|
||||||
|
audio_decoded_logged = true;
|
||||||
|
tracing::info!(
|
||||||
|
channels = audio_channels,
|
||||||
|
samples_per_channel = samples,
|
||||||
|
"audio decoded (Opus multistream)"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Ok(_) => {}
|
||||||
|
Err(e) => tracing::debug!(error = %e, "probe audio decode"),
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if punktfunk_core::quic::decode_rumble_datagram(&d).is_some() {
|
} else if punktfunk_core::quic::decode_rumble_datagram(&d).is_some() {
|
||||||
r.fetch_add(1, Relaxed);
|
r.fetch_add(1, Relaxed);
|
||||||
} else if let Some(meta) = punktfunk_core::quic::decode_hdr_meta_datagram(&d) {
|
} else if let Some(meta) = punktfunk_core::quic::decode_hdr_meta_datagram(&d) {
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ The Windows client ships as **signed MSIX** packages so Windows boxes get a real
|
|||||||
tile, clean install/uninstall) instead of a loose exe. CI builds + publishes them from
|
tile, clean install/uninstall) instead of a loose exe. CI builds + publishes them from
|
||||||
[`.gitea/workflows/windows-msix.yml`](../../../.gitea/workflows/windows-msix.yml) to Gitea's
|
[`.gitea/workflows/windows-msix.yml`](../../../.gitea/workflows/windows-msix.yml) to Gitea's
|
||||||
**generic** package registry (`https://git.unom.io/unom/-/packages`), on every `main` push that
|
**generic** package registry (`https://git.unom.io/unom/-/packages`), on every `main` push that
|
||||||
touches the client and on `win-v*` release tags.
|
touches the client (canary) and on `vX.Y.Z` release tags (stable) — see
|
||||||
|
[Release Channels](https://punktfunk.unom.io/docs/channels).
|
||||||
|
|
||||||
**Two architectures, one x64 runner.** Both `x64` and `arm64` packages are produced off the single
|
**Two architectures, one x64 runner.** Both `x64` and `arm64` packages are produced off the single
|
||||||
x64 Windows runner — `x86_64-pc-windows-msvc` builds natively, `aarch64-pc-windows-msvc` is
|
x64 Windows runner — `x86_64-pc-windows-msvc` builds natively, `aarch64-pc-windows-msvc` is
|
||||||
@@ -39,9 +40,9 @@ because it owns raw D3D11, Win32 low-level input hooks, WASAPI and SDL3.
|
|||||||
## Versioning
|
## Versioning
|
||||||
|
|
||||||
MSIX requires a strictly 4-part numeric version. The workflow computes:
|
MSIX requires a strictly 4-part numeric version. The workflow computes:
|
||||||
- `win-vX.Y.Z` tag → `X.Y.Z.0` (a real client release; `win-v*` is its own tag namespace, kept off
|
- `vX.Y.Z` tag → `X.Y.Z.0` (THE release; any `-rc`/`+meta` suffix is dropped for MSIX). Published to
|
||||||
the host's `host-v*` and Apple's `v*` to avoid the version-shadow bug).
|
the stable `latest/` alias and attached to the unified Gitea Release.
|
||||||
- `main` push / `workflow_dispatch` → `0.2.<run_number>.0` (rolling, climbs by run number).
|
- `main` push / `workflow_dispatch` → `0.3.<run_number>.0` (canary, climbs by run number; `canary/` alias).
|
||||||
|
|
||||||
## Signing & install
|
## Signing & install
|
||||||
|
|
||||||
|
|||||||
@@ -76,11 +76,29 @@ foreach ($f in $required) {
|
|||||||
Copy-Item $src (Join-Path $layout $f) -Force
|
Copy-Item $src (Join-Path $layout $f) -Force
|
||||||
}
|
}
|
||||||
|
|
||||||
# FFmpeg runtime DLLs (the exe link-imports the decode set; copy them all — small and correct)
|
# FFmpeg runtime DLLs (the exe link-imports the decode set; copy them all — small and correct).
|
||||||
|
# These are unmodified BtbN *lgpl-shared* builds, linked dynamically (replaceable DLLs) — FFmpeg is
|
||||||
|
# used under the LGPL v2.1+; the license text + notice ship in licenses\ below.
|
||||||
$ff = Get-ChildItem -Path $FfmpegBin -Filter *.dll -ErrorAction SilentlyContinue
|
$ff = Get-ChildItem -Path $FfmpegBin -Filter *.dll -ErrorAction SilentlyContinue
|
||||||
if (-not $ff) { throw "no FFmpeg DLLs in $FfmpegBin" }
|
if (-not $ff) { throw "no FFmpeg DLLs in $FfmpegBin" }
|
||||||
$ff | ForEach-Object { Copy-Item $_.FullName (Join-Path $layout $_.Name) -Force }
|
$ff | ForEach-Object { Copy-Item $_.FullName (Join-Path $layout $_.Name) -Force }
|
||||||
|
|
||||||
|
# license/attribution payload (MSIX has no installer EULA page, so ship them as files): FFmpeg's LGPL
|
||||||
|
# notice + license text, the project's own MIT/Apache texts, and the generated third-party notices.
|
||||||
|
$licDir = Join-Path $layout 'licenses'
|
||||||
|
New-Item -ItemType Directory -Force -Path $licDir | Out-Null
|
||||||
|
$repoRoot = (Resolve-Path (Join-Path $PSScriptRoot '..\..\..')).Path
|
||||||
|
Copy-Item (Join-Path $repoRoot 'packaging\windows\licenses\FFmpeg-LGPL-NOTICE.txt') $licDir -Force -ErrorAction SilentlyContinue
|
||||||
|
foreach ($n in @('THIRD-PARTY-NOTICES.txt', 'LICENSE-MIT', 'LICENSE-APACHE')) {
|
||||||
|
$p = Join-Path $repoRoot $n
|
||||||
|
if (Test-Path $p) { Copy-Item $p $licDir -Force }
|
||||||
|
}
|
||||||
|
$ffRoot = Split-Path $FfmpegBin -Parent
|
||||||
|
foreach ($lic in @('LICENSE.txt', 'LICENSE', 'COPYING.LGPLv2.1', 'COPYING.LGPLv3', 'COPYING.txt')) {
|
||||||
|
$p = Join-Path $ffRoot $lic
|
||||||
|
if (Test-Path $p) { Copy-Item $p $licDir -Force }
|
||||||
|
}
|
||||||
|
|
||||||
# tile/store assets
|
# tile/store assets
|
||||||
Copy-Item (Join-Path $assets '*') (Join-Path $layout 'Assets') -Force
|
Copy-Item (Join-Path $assets '*') (Join-Path $layout 'Assets') -Force
|
||||||
|
|
||||||
|
|||||||
+333
-17
@@ -20,7 +20,9 @@ use crate::video::{DecodedFrame, DecoderPref};
|
|||||||
use punktfunk_core::client::NativeClient;
|
use punktfunk_core::client::NativeClient;
|
||||||
use punktfunk_core::config::{CompositorPref, GamepadPref, Mode};
|
use punktfunk_core::config::{CompositorPref, GamepadPref, Mode};
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
use std::time::Duration;
|
||||||
use windows_reactor::*;
|
use windows_reactor::*;
|
||||||
|
|
||||||
const RESOLUTIONS: &[(u32, u32)] = &[
|
const RESOLUTIONS: &[(u32, u32)] = &[
|
||||||
@@ -39,13 +41,31 @@ const DECODERS: &[(&str, &str)] = &[
|
|||||||
];
|
];
|
||||||
/// Bitrate presets in Mb/s; `0` = host default.
|
/// Bitrate presets in Mb/s; `0` = host default.
|
||||||
const BITRATES_MBPS: &[u32] = &[0, 10, 20, 30, 50, 80, 150];
|
const BITRATES_MBPS: &[u32] = &[0, 10, 20, 30, 50, 80, 150];
|
||||||
|
/// Audio channel presets: `(channel count, display label)`. The host clamps to what it can
|
||||||
|
/// capture; the resolved count drives the decoder + WASAPI render layout.
|
||||||
|
const AUDIO_CHANNELS: &[(u8, &str)] = &[(2, "Stereo"), (6, "5.1 Surround"), (8, "7.1 Surround")];
|
||||||
|
|
||||||
|
/// punktfunk's own license (MIT OR Apache-2.0), shown on the Licenses screen.
|
||||||
|
const APP_LICENSE: &str = concat!(
|
||||||
|
include_str!("../../../LICENSE-MIT"),
|
||||||
|
"\n\n================================ Apache-2.0 ================================\n\n",
|
||||||
|
include_str!("../../../LICENSE-APACHE"),
|
||||||
|
);
|
||||||
|
/// Third-party software notices for the linked Rust crates (generated by
|
||||||
|
/// scripts/gen-third-party-notices.sh; the MSIX also ships this under licenses/).
|
||||||
|
const THIRD_PARTY_NOTICES: &str = include_str!("../../../THIRD-PARTY-NOTICES.txt");
|
||||||
|
|
||||||
#[derive(Clone, PartialEq)]
|
#[derive(Clone, PartialEq)]
|
||||||
enum Screen {
|
enum Screen {
|
||||||
Hosts,
|
Hosts,
|
||||||
Connecting,
|
Connecting,
|
||||||
|
/// The no-PIN "request access" wait: an identified connect is in flight, parked by the host
|
||||||
|
/// until the operator approves this device in its console. Cancelable.
|
||||||
|
RequestAccess,
|
||||||
Stream,
|
Stream,
|
||||||
Settings,
|
Settings,
|
||||||
|
/// Open-source / third-party license notices (reached from Settings).
|
||||||
|
Licenses,
|
||||||
Pair,
|
Pair,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,6 +149,11 @@ struct Shared {
|
|||||||
/// Latest stream stats, written by the session's event loop and mirrored into reactor state
|
/// Latest stream stats, written by the session's event loop and mirrored into reactor state
|
||||||
/// by the stream page's HUD poll thread to drive the overlay.
|
/// by the stream page's HUD poll thread to drive the overlay.
|
||||||
stats: Mutex<Stats>,
|
stats: Mutex<Stats>,
|
||||||
|
/// Cancel flag for the in-flight "request access" connect. A FRESH flag is installed per
|
||||||
|
/// request: the waiting screen's Cancel button reads it back from here and sets it, and that
|
||||||
|
/// request's event loop (which captured the same `Arc` at spawn) then tears down silently when
|
||||||
|
/// the parked connect finally resolves. `None` outside a request-access flow.
|
||||||
|
cancel: Mutex<Option<Arc<AtomicBool>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct AppCtx {
|
pub struct AppCtx {
|
||||||
@@ -373,8 +398,13 @@ fn root(cx: &mut RenderCx, ctx: &Arc<AppCtx>) -> Element {
|
|||||||
.vertical_alignment(VerticalAlignment::Center)
|
.vertical_alignment(VerticalAlignment::Center)
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
// request_access_page (like settings_page/Connecting) uses no hooks, so calling it inline
|
||||||
|
// is sound — it only wires a Cancel button to the shared cancel flag + navigation.
|
||||||
|
Screen::RequestAccess => request_access_page(ctx, &set_screen),
|
||||||
// settings_page uses no hooks (it never touches `cx`), so calling it inline is sound.
|
// settings_page uses no hooks (it never touches `cx`), so calling it inline is sound.
|
||||||
Screen::Settings => settings_page(ctx, &set_screen),
|
Screen::Settings => settings_page(ctx, &set_screen),
|
||||||
|
// licenses_page is a static text screen (no hooks), so inline is sound.
|
||||||
|
Screen::Licenses => licenses_page(&set_screen),
|
||||||
Screen::Pair => component(pair_page, svc),
|
Screen::Pair => component(pair_page, svc),
|
||||||
Screen::Stream => component(stream_page, StreamProps { svc, stats }),
|
Screen::Stream => component(stream_page, StreamProps { svc, stats }),
|
||||||
}
|
}
|
||||||
@@ -566,12 +596,61 @@ fn initiate(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Tunables that differ between the normal connect and the no-PIN "request access" flow.
|
||||||
|
/// `Default` is the normal connect: short handshake budget, persist *unpaired* on TOFU, and the
|
||||||
|
/// plain "Connecting" screen.
|
||||||
|
struct ConnectOpts {
|
||||||
|
/// Handshake budget. Request-access uses a long one because the host PARKS the connection
|
||||||
|
/// until the operator clicks Approve in its console (see the host's `PENDING_APPROVAL_WAIT`).
|
||||||
|
connect_timeout: Duration,
|
||||||
|
/// Persist the host as *paired* on a successful connect. Set for request-access, where the
|
||||||
|
/// operator's approval IS the pairing, so future connects are silent (rule 1). Normal TOFU
|
||||||
|
/// persists the host *unpaired* (pinned, but not PIN/approval-verified).
|
||||||
|
persist_paired: bool,
|
||||||
|
/// Show the cancelable "waiting for approval" screen instead of "Connecting" (request-access).
|
||||||
|
awaiting_approval: bool,
|
||||||
|
/// Set by the waiting screen's Cancel button. `NativeClient::connect` is blocking with no
|
||||||
|
/// abort, so Cancel returns the UI immediately and leaves the parked connect to resolve/time
|
||||||
|
/// out; this request's event loop then sees the flag and tears down silently (drops the
|
||||||
|
/// connector → closes the connection) without touching a screen a new session may already own.
|
||||||
|
cancel: Option<Arc<AtomicBool>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for ConnectOpts {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
connect_timeout: Duration::from_secs(15),
|
||||||
|
persist_paired: false,
|
||||||
|
awaiting_approval: false,
|
||||||
|
cancel: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn connect(
|
fn connect(
|
||||||
ctx: &Arc<AppCtx>,
|
ctx: &Arc<AppCtx>,
|
||||||
target: &Target,
|
target: &Target,
|
||||||
pin: Option<[u8; 32]>,
|
pin: Option<[u8; 32]>,
|
||||||
set_screen: &AsyncSetState<Screen>,
|
set_screen: &AsyncSetState<Screen>,
|
||||||
set_status: &AsyncSetState<String>,
|
set_status: &AsyncSetState<String>,
|
||||||
|
) {
|
||||||
|
connect_with(
|
||||||
|
ctx,
|
||||||
|
target,
|
||||||
|
pin,
|
||||||
|
set_screen,
|
||||||
|
set_status,
|
||||||
|
ConnectOpts::default(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn connect_with(
|
||||||
|
ctx: &Arc<AppCtx>,
|
||||||
|
target: &Target,
|
||||||
|
pin: Option<[u8; 32]>,
|
||||||
|
set_screen: &AsyncSetState<Screen>,
|
||||||
|
set_status: &AsyncSetState<String>,
|
||||||
|
opts: ConnectOpts,
|
||||||
) {
|
) {
|
||||||
let s = ctx.settings.lock().unwrap().clone();
|
let s = ctx.settings.lock().unwrap().clone();
|
||||||
let mode = if s.width != 0 && s.refresh_hz != 0 {
|
let mode = if s.width != 0 && s.refresh_hz != 0 {
|
||||||
@@ -598,34 +677,60 @@ fn connect(
|
|||||||
compositor: CompositorPref::Auto,
|
compositor: CompositorPref::Auto,
|
||||||
gamepad: gamepad_pref,
|
gamepad: gamepad_pref,
|
||||||
bitrate_kbps: s.bitrate_kbps,
|
bitrate_kbps: s.bitrate_kbps,
|
||||||
|
audio_channels: s.audio_channels,
|
||||||
mic_enabled: s.mic_enabled,
|
mic_enabled: s.mic_enabled,
|
||||||
hdr_enabled: s.hdr_enabled,
|
hdr_enabled: s.hdr_enabled,
|
||||||
decoder: DecoderPref::from_name(&s.decoder),
|
decoder: DecoderPref::from_name(&s.decoder),
|
||||||
pin,
|
pin,
|
||||||
identity: ctx.identity.clone(),
|
identity: ctx.identity.clone(),
|
||||||
|
connect_timeout: opts.connect_timeout,
|
||||||
});
|
});
|
||||||
set_status.call(String::new());
|
set_status.call(String::new());
|
||||||
set_screen.call(Screen::Connecting);
|
set_screen.call(if opts.awaiting_approval {
|
||||||
|
Screen::RequestAccess
|
||||||
|
} else {
|
||||||
|
Screen::Connecting
|
||||||
|
});
|
||||||
|
|
||||||
let tofu = pin.is_none();
|
let tofu = pin.is_none();
|
||||||
|
let persist_paired = opts.persist_paired;
|
||||||
|
let cancel = opts.cancel;
|
||||||
let (shared, gamepad) = (ctx.shared.clone(), ctx.gamepad.clone());
|
let (shared, gamepad) = (ctx.shared.clone(), ctx.gamepad.clone());
|
||||||
let (ss, st) = (set_screen.clone(), set_status.clone());
|
let (ss, st) = (set_screen.clone(), set_status.clone());
|
||||||
let target = target.clone();
|
let target = target.clone();
|
||||||
std::thread::spawn(move || loop {
|
std::thread::spawn(move || loop {
|
||||||
match handle.events.recv_blocking() {
|
let event = match handle.events.recv_blocking() {
|
||||||
Ok(SessionEvent::Connected {
|
Ok(e) => e,
|
||||||
|
Err(_) => {
|
||||||
|
gamepad.detach();
|
||||||
|
ss.call(Screen::Hosts);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// A cancelled request-access connect that resolved late (the host approved or the park
|
||||||
|
// timed out after the user walked away): tear down silently. Cancel already returned the
|
||||||
|
// UI to the host list; dropping `event` (and with it any connector) closes the connection
|
||||||
|
// without popping a stream or a stray error over the screen a new session may own.
|
||||||
|
if cancel.as_ref().is_some_and(|c| c.load(Ordering::SeqCst)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
match event {
|
||||||
|
SessionEvent::Connected {
|
||||||
connector,
|
connector,
|
||||||
fingerprint,
|
fingerprint,
|
||||||
..
|
..
|
||||||
}) => {
|
} => {
|
||||||
if tofu {
|
if persist_paired || tofu {
|
||||||
|
// Request-access: the operator approved this device, so record the host as a
|
||||||
|
// trusted PAIRED host — future connects are then silent (rule 1), exactly like
|
||||||
|
// after a PIN ceremony. A plain TOFU connect persists it *unpaired* (pinned).
|
||||||
let mut k = KnownHosts::load();
|
let mut k = KnownHosts::load();
|
||||||
k.upsert(KnownHost {
|
k.upsert(KnownHost {
|
||||||
name: target.name.clone(),
|
name: target.name.clone(),
|
||||||
addr: target.addr.clone(),
|
addr: target.addr.clone(),
|
||||||
port: target.port,
|
port: target.port,
|
||||||
fp_hex: trust::hex(&fingerprint),
|
fp_hex: trust::hex(&fingerprint),
|
||||||
paired: false,
|
paired: persist_paired,
|
||||||
});
|
});
|
||||||
let _ = k.save();
|
let _ = k.save();
|
||||||
}
|
}
|
||||||
@@ -634,10 +739,10 @@ fn connect(
|
|||||||
*shared.handoff.lock().unwrap() = Some((connector, handle.frames.clone()));
|
*shared.handoff.lock().unwrap() = Some((connector, handle.frames.clone()));
|
||||||
ss.call(Screen::Stream);
|
ss.call(Screen::Stream);
|
||||||
}
|
}
|
||||||
Ok(SessionEvent::Failed {
|
SessionEvent::Failed {
|
||||||
msg,
|
msg,
|
||||||
trust_rejected,
|
trust_rejected,
|
||||||
}) => {
|
} => {
|
||||||
st.call(msg);
|
st.call(msg);
|
||||||
gamepad.detach();
|
gamepad.detach();
|
||||||
if trust_rejected {
|
if trust_rejected {
|
||||||
@@ -649,22 +754,100 @@ fn connect(
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Ok(SessionEvent::Ended(err)) => {
|
SessionEvent::Ended(err) => {
|
||||||
st.call(err.unwrap_or_else(|| "Session ended".into()));
|
st.call(err.unwrap_or_else(|| "Session ended".into()));
|
||||||
gamepad.detach();
|
gamepad.detach();
|
||||||
ss.call(Screen::Hosts);
|
ss.call(Screen::Hosts);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Ok(SessionEvent::Stats(s)) => *shared.stats.lock().unwrap() = s,
|
SessionEvent::Stats(s) => *shared.stats.lock().unwrap() = s,
|
||||||
Err(_) => {
|
|
||||||
gamepad.detach();
|
|
||||||
ss.call(Screen::Hosts);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The no-PIN "request access" flow: open an identified connect that the host PARKS until the
|
||||||
|
/// operator approves this device in its console (or web UI), showing a cancelable "waiting"
|
||||||
|
/// screen meanwhile. On approval the SAME connection is admitted (no reconnect) and the host is
|
||||||
|
/// saved as paired, so later connects are silent.
|
||||||
|
fn request_access(
|
||||||
|
ctx: &Arc<AppCtx>,
|
||||||
|
target: &Target,
|
||||||
|
set_screen: &AsyncSetState<Screen>,
|
||||||
|
set_status: &AsyncSetState<String>,
|
||||||
|
) {
|
||||||
|
// Pin the advertised certificate for a discovered host (defence against a host impostor while
|
||||||
|
// we wait); a manually-typed host has no advertised fingerprint, so trust-on-first-use.
|
||||||
|
let pin = target.fp_hex.as_deref().and_then(trust::parse_hex32);
|
||||||
|
// A fresh cancel flag per request, installed where the waiting screen's Cancel button can read
|
||||||
|
// it back; this request's event loop captures the same `Arc` (via ConnectOpts) below.
|
||||||
|
let cancel = Arc::new(AtomicBool::new(false));
|
||||||
|
*ctx.shared.cancel.lock().unwrap() = Some(cancel.clone());
|
||||||
|
connect_with(
|
||||||
|
ctx,
|
||||||
|
target,
|
||||||
|
pin,
|
||||||
|
set_screen,
|
||||||
|
set_status,
|
||||||
|
ConnectOpts {
|
||||||
|
// Must exceed the host's approval window (PENDING_APPROVAL_WAIT) so a slow operator
|
||||||
|
// approval still lands on this connection rather than timing the client out first.
|
||||||
|
connect_timeout: Duration::from_secs(185),
|
||||||
|
persist_paired: true,
|
||||||
|
awaiting_approval: true,
|
||||||
|
cancel: Some(cancel),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The cancelable "waiting for approval" screen (request-access flow): a spinner + guidance while
|
||||||
|
/// the identified connect sits parked on the host, plus a Cancel that returns to the host list and
|
||||||
|
/// trips the shared cancel flag so the parked connect tears down silently if it resolves after the
|
||||||
|
/// user has walked away. Mirrors the inline `Connecting` screen; uses no hooks.
|
||||||
|
fn request_access_page(ctx: &Arc<AppCtx>, set_screen: &AsyncSetState<Screen>) -> Element {
|
||||||
|
let target_name = ctx.shared.target.lock().unwrap().name.clone();
|
||||||
|
let headline = if target_name.is_empty() {
|
||||||
|
"Waiting for approval\u{2026}".to_string()
|
||||||
|
} else {
|
||||||
|
format!("Waiting for {target_name} to approve\u{2026}")
|
||||||
|
};
|
||||||
|
let cancel_btn = {
|
||||||
|
let (ctx, ss) = (ctx.clone(), set_screen.clone());
|
||||||
|
button("Cancel")
|
||||||
|
.icon(SymbolGlyph::Cancel)
|
||||||
|
.on_click(move || {
|
||||||
|
// Return the UI immediately; the parked connect is blocking with no abort, so trip
|
||||||
|
// the flag this request's event loop captured — it then tears down silently when
|
||||||
|
// the connect finally resolves (see ConnectOpts::cancel).
|
||||||
|
if let Some(c) = ctx.shared.cancel.lock().unwrap().as_ref() {
|
||||||
|
c.store(true, Ordering::SeqCst);
|
||||||
|
}
|
||||||
|
ss.call(Screen::Hosts);
|
||||||
|
})
|
||||||
|
.horizontal_alignment(HorizontalAlignment::Center)
|
||||||
|
};
|
||||||
|
vstack((
|
||||||
|
ProgressRing::indeterminate()
|
||||||
|
.width(48.0)
|
||||||
|
.height(48.0)
|
||||||
|
.horizontal_alignment(HorizontalAlignment::Center),
|
||||||
|
text_block(headline)
|
||||||
|
.font_size(18.0)
|
||||||
|
.semibold()
|
||||||
|
.horizontal_alignment(HorizontalAlignment::Center),
|
||||||
|
text_block(
|
||||||
|
"Approve this device in the host's console or web UI \u{2014} it connects automatically \
|
||||||
|
once you approve it. No PIN needed.",
|
||||||
|
)
|
||||||
|
.foreground(ThemeRef::SecondaryText)
|
||||||
|
.horizontal_alignment(HorizontalAlignment::Center),
|
||||||
|
cancel_btn,
|
||||||
|
))
|
||||||
|
.spacing(16.0)
|
||||||
|
.horizontal_alignment(HorizontalAlignment::Center)
|
||||||
|
.vertical_alignment(VerticalAlignment::Center)
|
||||||
|
.into()
|
||||||
|
}
|
||||||
|
|
||||||
fn pair_page(props: &Svc, cx: &mut RenderCx) -> Element {
|
fn pair_page(props: &Svc, cx: &mut RenderCx) -> Element {
|
||||||
let ctx = &props.ctx;
|
let ctx = &props.ctx;
|
||||||
let set_screen = &props.set_screen;
|
let set_screen = &props.set_screen;
|
||||||
@@ -724,6 +907,20 @@ fn pair_page(props: &Svc, cx: &mut RenderCx) -> Element {
|
|||||||
.icon(SymbolGlyph::Cancel)
|
.icon(SymbolGlyph::Cancel)
|
||||||
.on_click(move || ss.call(Screen::Hosts))
|
.on_click(move || ss.call(Screen::Hosts))
|
||||||
};
|
};
|
||||||
|
// The no-PIN alternative offered alongside the PIN ceremony: open an identified connect that
|
||||||
|
// the host parks until the operator approves this device in its console (delegated approval).
|
||||||
|
let request_btn = {
|
||||||
|
let (ctx2, ss, st, target2) = (
|
||||||
|
ctx.clone(),
|
||||||
|
set_screen.clone(),
|
||||||
|
set_status.clone(),
|
||||||
|
target.clone(),
|
||||||
|
);
|
||||||
|
button("Request access without a PIN")
|
||||||
|
.icon(SymbolGlyph::Send)
|
||||||
|
.on_click(move || request_access(&ctx2, &target2, &ss, &st))
|
||||||
|
.horizontal_alignment(HorizontalAlignment::Stretch)
|
||||||
|
};
|
||||||
|
|
||||||
let content = card(vstack((
|
let content = card(vstack((
|
||||||
grid((
|
grid((
|
||||||
@@ -756,6 +953,13 @@ fn pair_page(props: &Svc, cx: &mut RenderCx) -> Element {
|
|||||||
.font_size(28.0)
|
.font_size(28.0)
|
||||||
.on_changed(move |s| set_code.call(s)),
|
.on_changed(move |s| set_code.call(s)),
|
||||||
hstack((pair_btn, cancel_btn)).spacing(8.0),
|
hstack((pair_btn, cancel_btn)).spacing(8.0),
|
||||||
|
text_block(
|
||||||
|
"Don\u{2019}t have a PIN? Request access instead and approve this device on the host \
|
||||||
|
(its console or web UI) \u{2014} no PIN needed.",
|
||||||
|
)
|
||||||
|
.font_size(12.0)
|
||||||
|
.foreground(ThemeRef::SecondaryText),
|
||||||
|
request_btn,
|
||||||
))
|
))
|
||||||
.spacing(16.0))
|
.spacing(16.0))
|
||||||
.max_width(480.0)
|
.max_width(480.0)
|
||||||
@@ -886,6 +1090,23 @@ fn settings_page(ctx: &Arc<AppCtx>, set_screen: &AsyncSetState<Screen>) -> Eleme
|
|||||||
s.save();
|
s.save();
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
let ac_i = AUDIO_CHANNELS
|
||||||
|
.iter()
|
||||||
|
.position(|&(v, _)| v == s.audio_channels)
|
||||||
|
.unwrap_or(0) as i32;
|
||||||
|
let ac_names: Vec<String> = AUDIO_CHANNELS.iter().map(|&(_, l)| l.to_string()).collect();
|
||||||
|
let channels_combo = {
|
||||||
|
let ctx = ctx.clone();
|
||||||
|
ComboBox::new(ac_names)
|
||||||
|
.header("Audio channels")
|
||||||
|
.selected_index(ac_i)
|
||||||
|
.on_selection_changed(move |i: i32| {
|
||||||
|
let (v, _) = AUDIO_CHANNELS[(i.max(0) as usize).min(AUDIO_CHANNELS.len() - 1)];
|
||||||
|
let mut s = ctx.settings.lock().unwrap();
|
||||||
|
s.audio_channels = v;
|
||||||
|
s.save();
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
let header = grid((
|
let header = grid((
|
||||||
text_block("Settings")
|
text_block("Settings")
|
||||||
@@ -934,8 +1155,32 @@ fn settings_page(ctx: &Arc<AppCtx>, set_screen: &AsyncSetState<Screen>) -> Eleme
|
|||||||
.spacing(10.0),
|
.spacing(10.0),
|
||||||
);
|
);
|
||||||
|
|
||||||
let audio_card =
|
let audio_card = card(
|
||||||
card(vstack((text_block("Audio").font_size(15.0).semibold(), mic_toggle)).spacing(10.0));
|
vstack((
|
||||||
|
text_block("Audio").font_size(15.0).semibold(),
|
||||||
|
text_block("Request stereo or surround — the host downmixes if its output has fewer.")
|
||||||
|
.font_size(12.0)
|
||||||
|
.foreground(ThemeRef::SecondaryText),
|
||||||
|
channels_combo,
|
||||||
|
mic_toggle,
|
||||||
|
))
|
||||||
|
.spacing(10.0),
|
||||||
|
);
|
||||||
|
|
||||||
|
let licenses_button = {
|
||||||
|
let ss = set_screen.clone();
|
||||||
|
button("Third-party licenses").on_click(move || ss.call(Screen::Licenses))
|
||||||
|
};
|
||||||
|
let about_card = card(
|
||||||
|
vstack((
|
||||||
|
text_block("About").font_size(15.0).semibold(),
|
||||||
|
text_block("punktfunk is licensed under MIT OR Apache-2.0.")
|
||||||
|
.font_size(12.0)
|
||||||
|
.foreground(ThemeRef::SecondaryText),
|
||||||
|
licenses_button,
|
||||||
|
))
|
||||||
|
.spacing(10.0),
|
||||||
|
);
|
||||||
|
|
||||||
page(vec![
|
page(vec![
|
||||||
header.into(),
|
header.into(),
|
||||||
@@ -945,6 +1190,77 @@ fn settings_page(ctx: &Arc<AppCtx>, set_screen: &AsyncSetState<Screen>) -> Eleme
|
|||||||
video_card.into(),
|
video_card.into(),
|
||||||
section("AUDIO"),
|
section("AUDIO"),
|
||||||
audio_card.into(),
|
audio_card.into(),
|
||||||
|
section("ABOUT"),
|
||||||
|
about_card.into(),
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Static screen: the app's own license + the third-party software notices (reached from Settings).
|
||||||
|
fn licenses_page(set_screen: &AsyncSetState<Screen>) -> Element {
|
||||||
|
let header = grid((
|
||||||
|
text_block("Third-party licenses")
|
||||||
|
.font_size(30.0)
|
||||||
|
.bold()
|
||||||
|
.grid_column(0)
|
||||||
|
.vertical_alignment(VerticalAlignment::Center),
|
||||||
|
button("Back")
|
||||||
|
.accent()
|
||||||
|
.icon(SymbolGlyph::Back)
|
||||||
|
.on_click({
|
||||||
|
let ss = set_screen.clone();
|
||||||
|
move || ss.call(Screen::Settings)
|
||||||
|
})
|
||||||
|
.grid_column(1)
|
||||||
|
.vertical_alignment(VerticalAlignment::Center),
|
||||||
|
))
|
||||||
|
.columns([GridLength::Star(1.0), GridLength::Auto])
|
||||||
|
.margin(edges(0.0, 0.0, 0.0, 6.0));
|
||||||
|
|
||||||
|
let app_card = card(
|
||||||
|
vstack((
|
||||||
|
text_block("punktfunk").font_size(15.0).semibold(),
|
||||||
|
text_block("Licensed under MIT OR Apache-2.0, at your option.")
|
||||||
|
.font_size(12.0)
|
||||||
|
.foreground(ThemeRef::SecondaryText),
|
||||||
|
text_block(APP_LICENSE)
|
||||||
|
.font_size(11.0)
|
||||||
|
.foreground(ThemeRef::SecondaryText),
|
||||||
|
))
|
||||||
|
.spacing(8.0),
|
||||||
|
);
|
||||||
|
|
||||||
|
let natives_card = card(
|
||||||
|
vstack((
|
||||||
|
text_block("Bundled components").font_size(15.0).semibold(),
|
||||||
|
text_block(
|
||||||
|
"FFmpeg is bundled under the LGPL v2.1+ (dynamically linked, replaceable DLLs); its \
|
||||||
|
license and notice ship in the installed licenses\\ folder. SDL 3 (Zlib) and the \
|
||||||
|
Windows App SDK (Microsoft) are also linked.",
|
||||||
|
)
|
||||||
|
.font_size(12.0)
|
||||||
|
.foreground(ThemeRef::SecondaryText),
|
||||||
|
))
|
||||||
|
.spacing(8.0),
|
||||||
|
);
|
||||||
|
|
||||||
|
let notices_card = card(
|
||||||
|
vstack((
|
||||||
|
text_block("Rust crates").font_size(15.0).semibold(),
|
||||||
|
text_block(THIRD_PARTY_NOTICES)
|
||||||
|
.font_size(11.0)
|
||||||
|
.foreground(ThemeRef::SecondaryText),
|
||||||
|
))
|
||||||
|
.spacing(8.0),
|
||||||
|
);
|
||||||
|
|
||||||
|
page(vec![
|
||||||
|
header.into(),
|
||||||
|
section("PUNKTFUNK"),
|
||||||
|
app_card.into(),
|
||||||
|
section("BUNDLED"),
|
||||||
|
natives_card.into(),
|
||||||
|
section("OPEN SOURCE"),
|
||||||
|
notices_card.into(),
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,9 +21,9 @@ use std::time::Duration;
|
|||||||
use wasapi::{DeviceEnumerator, Direction, SampleType, StreamMode, WaveFormat};
|
use wasapi::{DeviceEnumerator, Direction, SampleType, StreamMode, WaveFormat};
|
||||||
|
|
||||||
const SAMPLE_RATE: usize = 48_000;
|
const SAMPLE_RATE: usize = 48_000;
|
||||||
|
/// The microphone uplink stays stereo (the host's virtual mic is stereo). The render path is
|
||||||
|
/// multichannel — its channel count + block align are runtime, driven by the host-resolved layout.
|
||||||
const CHANNELS: usize = 2;
|
const CHANNELS: usize = 2;
|
||||||
/// 48 kHz stereo f32: 2 channels * 4 bytes = 8 bytes per frame.
|
|
||||||
const BLOCK_ALIGN: usize = CHANNELS * 4;
|
|
||||||
/// Mic frames are 20 ms (960 samples/channel) — any size ≤ 120 ms is fine host-side.
|
/// Mic frames are 20 ms (960 samples/channel) — any size ≤ 120 ms is fine host-side.
|
||||||
const MIC_FRAME: usize = 960;
|
const MIC_FRAME: usize = 960;
|
||||||
|
|
||||||
@@ -34,9 +34,10 @@ pub struct AudioPlayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl AudioPlayer {
|
impl AudioPlayer {
|
||||||
/// Spawn the WASAPI render thread. Failure (no render endpoint on this box) is
|
/// Spawn the WASAPI render thread for `channels` (2/6/8, canonical wire order
|
||||||
/// survivable — the caller streams video-only.
|
/// FL FR FC LFE RL RR SL SR). Failure (no render endpoint on this box) is survivable — the
|
||||||
pub fn spawn() -> Result<AudioPlayer> {
|
/// caller streams video-only.
|
||||||
|
pub fn spawn(channels: u8) -> Result<AudioPlayer> {
|
||||||
// 64 × 5 ms = 320 ms of slack between the pump and the WASAPI loop.
|
// 64 × 5 ms = 320 ms of slack between the pump and the WASAPI loop.
|
||||||
let (pcm_tx, pcm_rx) = std::sync::mpsc::sync_channel::<Vec<f32>>(64);
|
let (pcm_tx, pcm_rx) = std::sync::mpsc::sync_channel::<Vec<f32>>(64);
|
||||||
let stop = Arc::new(AtomicBool::new(false));
|
let stop = Arc::new(AtomicBool::new(false));
|
||||||
@@ -45,14 +46,14 @@ impl AudioPlayer {
|
|||||||
let thread = std::thread::Builder::new()
|
let thread = std::thread::Builder::new()
|
||||||
.name("punktfunk-audio".into())
|
.name("punktfunk-audio".into())
|
||||||
.spawn(move || {
|
.spawn(move || {
|
||||||
if let Err(e) = render_thread(pcm_rx, stop_t, ready_tx) {
|
if let Err(e) = render_thread(pcm_rx, stop_t, ready_tx, channels) {
|
||||||
tracing::warn!(error = format!("{e:#}"), "audio playback thread ended");
|
tracing::warn!(error = format!("{e:#}"), "audio playback thread ended");
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.context("spawn audio thread")?;
|
.context("spawn audio thread")?;
|
||||||
match ready_rx.recv_timeout(Duration::from_secs(3)) {
|
match ready_rx.recv_timeout(Duration::from_secs(3)) {
|
||||||
Ok(Ok(())) => {
|
Ok(Ok(())) => {
|
||||||
tracing::info!("WASAPI render: 48 kHz stereo f32 (default endpoint)");
|
tracing::info!(channels, "WASAPI render: 48 kHz f32 (default endpoint)");
|
||||||
Ok(AudioPlayer {
|
Ok(AudioPlayer {
|
||||||
pcm_tx,
|
pcm_tx,
|
||||||
stop,
|
stop,
|
||||||
@@ -66,8 +67,8 @@ impl AudioPlayer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Queue one interleaved-stereo f32 chunk. Drops the chunk if the WASAPI side is wedged
|
/// Queue one interleaved f32 chunk (in the session's channel layout). Drops the chunk if the
|
||||||
/// (the renderer conceals the gap; never block the session pump).
|
/// WASAPI side is wedged (the renderer conceals the gap; never block the session pump).
|
||||||
pub fn push(&self, pcm: Vec<f32>) {
|
pub fn push(&self, pcm: Vec<f32>) {
|
||||||
if let Err(TrySendError::Disconnected(_)) = self.pcm_tx.try_send(pcm) {
|
if let Err(TrySendError::Disconnected(_)) = self.pcm_tx.try_send(pcm) {
|
||||||
// Thread already dead — Drop will reap it; nothing to do per-chunk.
|
// Thread already dead — Drop will reap it; nothing to do per-chunk.
|
||||||
@@ -88,6 +89,7 @@ fn render_thread(
|
|||||||
pcm_rx: Receiver<Vec<f32>>,
|
pcm_rx: Receiver<Vec<f32>>,
|
||||||
stop: Arc<AtomicBool>,
|
stop: Arc<AtomicBool>,
|
||||||
ready: SyncSender<Result<()>>,
|
ready: SyncSender<Result<()>>,
|
||||||
|
channels: u8,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
if let Err(e) = wasapi::initialize_mta()
|
if let Err(e) = wasapi::initialize_mta()
|
||||||
.ok()
|
.ok()
|
||||||
@@ -97,12 +99,26 @@ fn render_thread(
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
let res = (|| -> Result<()> {
|
let res = (|| -> Result<()> {
|
||||||
|
// F32LE interleaved: channels × 4 bytes/sample. Stereo (channels == 2) is byte-identical
|
||||||
|
// to the old fixed path (mask 0x3, block align 8).
|
||||||
|
let block_align = channels as usize * 4;
|
||||||
let device = DeviceEnumerator::new()
|
let device = DeviceEnumerator::new()
|
||||||
.context("DeviceEnumerator")?
|
.context("DeviceEnumerator")?
|
||||||
.get_default_device(&Direction::Render)
|
.get_default_device(&Direction::Render)
|
||||||
.context("default render endpoint")?;
|
.context("default render endpoint")?;
|
||||||
let mut audio_client = device.get_iaudioclient().context("IAudioClient")?;
|
let mut audio_client = device.get_iaudioclient().context("IAudioClient")?;
|
||||||
let desired = WaveFormat::new(32, 32, &SampleType::Float, SAMPLE_RATE, CHANNELS, None);
|
// The explicit dwChannelMask is the wire order (FL FR FC LFE RL RR SL SR); 5.1 = 0x3F,
|
||||||
|
// 7.1 = 0x63F. WASAPI delivers channels in ascending mask-bit order, which equals the wire
|
||||||
|
// order, so the render mapping is the identity — no permute. `autoconvert` (below) lets the
|
||||||
|
// audio engine downmix when the endpoint has fewer speakers.
|
||||||
|
let desired = WaveFormat::new(
|
||||||
|
32,
|
||||||
|
32,
|
||||||
|
&SampleType::Float,
|
||||||
|
SAMPLE_RATE,
|
||||||
|
channels as usize,
|
||||||
|
Some(punktfunk_core::audio::wasapi_channel_mask(channels)),
|
||||||
|
);
|
||||||
let (default_period, _min_period) =
|
let (default_period, _min_period) =
|
||||||
audio_client.get_device_period().context("device period")?;
|
audio_client.get_device_period().context("device period")?;
|
||||||
let mode = StreamMode::EventsShared {
|
let mode = StreamMode::EventsShared {
|
||||||
@@ -139,10 +155,10 @@ fn render_thread(
|
|||||||
if avail_frames == 0 {
|
if avail_frames == 0 {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let want_bytes = avail_frames * BLOCK_ALIGN;
|
let want_bytes = avail_frames * block_align;
|
||||||
|
|
||||||
// Prime to ~3 quanta; cap at ~1 quantum of slack beyond that; re-prime on drain.
|
// Prime to ~3 quanta; cap at ~1 quantum of slack beyond that; re-prime on drain.
|
||||||
let target = (3 * want_bytes).clamp(720 * BLOCK_ALIGN, 9600 * BLOCK_ALIGN);
|
let target = (3 * want_bytes).clamp(720 * block_align, 9600 * block_align);
|
||||||
while ring.len() > target.max(want_bytes) + want_bytes {
|
while ring.len() > target.max(want_bytes) + want_bytes {
|
||||||
ring.pop_front();
|
ring.pop_front();
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user