# Local offline verification of org.meshtastic.MeshtasticDesktop.
# Differences from vid's upstream manifest (vidplace7/org.meshtastic.MeshtasticDesktop):
#   1. Meshtastic-Android source: `type: dir` pointing at our local checkout instead of `type: git`.
#   2. flatpak-sources.json is INCLUDED (uncommented) so Gradle resolves from the offline-repository.
#   3. Build uses `--offline` for Gradle — true Flathub-style offline compilation.
#      (finish-args still grants runtime network since the app needs it; only the build is offline.)
# Generated by scripts/verify-flatpak/verify.sh; do not edit upstream from here.

id: org.meshtastic.MeshtasticDesktop
runtime: org.freedesktop.Platform
runtime-version: '25.08'
sdk: org.freedesktop.Sdk
sdk-extensions:
  - org.freedesktop.Sdk.Extension.openjdk21
command: meshtastic-wrapper.sh

finish-args:
  - --share=ipc
  - --socket=x11
  - --device=dri
  - --device=all
  - --share=network
  - --talk-name=org.kde.StatusNotifierWatcher
  - --talk-name=org.freedesktop.Notifications
  - --allow=bluetooth
  - --system-talk-name=org.bluez.*
  - --env=PATH=/app/jre/bin:/app/bin:/usr/bin
  - --env=JAVA_HOME=/app/jre

modules:
  - name: jbr
    buildsystem: simple
    build-commands:
      - mkdir -p /app/jre
      - tar xzf jbr-*.tar.gz -C /app/jre --strip-components=1
    sources:
      - type: file
        url: https://cache-redirector.jetbrains.com/intellij-jbr/jbr-21.0.11-linux-x64-b1163.116.tar.gz
        sha256: 72bf2d1830587a3cd31b718d4af9fc7a88fc6c3740642d842b3b378d4acbe476
        only-arches:
          - x86_64
      - type: file
        url: https://cache-redirector.jetbrains.com/intellij-jbr/jbr-21.0.11-linux-aarch64-b1163.116.tar.gz
        sha256: 02124d01591c173f9a51ef84d99ce248900d4d1e1aa52a38c65f4708f66b6e98
        only-arches:
          - aarch64

  - name: meshtastic-wrapper
    buildsystem: simple
    build-commands:
      - install -Dm755 meshtastic-wrapper.sh /app/bin/meshtastic-wrapper.sh
    sources:
      - type: file
        path: meshtastic-wrapper.sh

  - name: meshtastic-desktop
    buildsystem: simple
    build-options:
      append-path: "/usr/lib/sdk/openjdk21/bin"
      env:
        JAVA_HOME: /usr/lib/sdk/openjdk21/jvm/openjdk-21
        # Point Gradle at the offline mirror produced by flatpak-sources.json
        GRADLE_USER_HOME: /run/build/meshtastic-desktop/.gradle
    build-commands:
      # Install desktop metadata from the in-repo packaging sources (mirrors vid's upstream manifest,
      # which stopped shipping standalone root-level copies as of 2026-05-30).
      - install -Dm644 desktopApp/packaging/icons/icon.svg /app/share/icons/hicolor/scalable/apps/org.meshtastic.MeshtasticDesktop.svg
      - install -Dm644 -t /app/share/applications desktopApp/packaging/linux/org.meshtastic.MeshtasticDesktop.desktop
      - desktop-file-edit --set-key="Exec" --set-value="meshtastic-wrapper.sh %U"
        /app/share/applications/org.meshtastic.MeshtasticDesktop.desktop
      - install -Dm644 -t /app/share/metainfo desktopApp/packaging/linux/org.meshtastic.MeshtasticDesktop.metainfo.xml
      # Redirect the Gradle wrapper to the bundled distribution (no network).
      - sed -i 's|distributionUrl=.*|distributionUrl=gradle-all.zip|' gradle/wrapper/gradle-wrapper.properties
      - echo "org.gradle.java.installations.auto-detect=false" >> gradle.properties
      - echo "org.gradle.java.installations.auto-download=false" >> gradle.properties
      - echo "org.gradle.java.installations.paths=/usr/lib/sdk/openjdk21/jvm/openjdk-21" >> gradle.properties
      - >
        sed -i
        's/^\(\s*\)vendor\.set(JvmVendorSpec\.JETBRAINS)/\1\/\/ vendor.set(JvmVendorSpec.JETBRAINS)/'
        desktopApp/build.gradle.kts
      # Force Gradle to resolve from the bundled offline-repository ONLY (true offline test).
      - ./gradlew --offline :desktopApp:packageUberJarForCurrentOS
      - >
        JAR_FILE=$(find desktopApp/build/compose/jars/ -name "*.jar" -type f | head -1)
        && install -Dm755 "$JAR_FILE" /app/lib/meshtastic-desktop.jar
    sources:
      # Desktop metadata (.desktop/.metainfo.xml/.svg) now lives inside the meshtastic-android
      # source tree (desktopApp/packaging/...) and is installed by build-commands above —
      # no longer sourced as standalone root-level files.
      - type: dir
        path: meshtastic-android
      - type: file
        # Must match the version in gradle/wrapper/gradle-wrapper.properties.
        # Bumping the wrapper? Update both the URL and sha256 here.
        url: https://services.gradle.org/distributions/gradle-9.6.0-all.zip
        sha256: 87a2216cc1f9122192d4e0fe905ffdf1b4c72cff797e9f733b174e157cadd396
        dest: "gradle/wrapper"
        dest-filename: "gradle-all.zip"
      - flatpak-sources.json
