app-id: io.github.tommyfang.DshDesktop
runtime: org.gnome.Platform
runtime-version: '50'
sdk: org.gnome.Sdk
sdk-extensions:
  - org.freedesktop.Sdk.Extension.node24
  - org.freedesktop.Sdk.Extension.rust-stable
command: dsh-desktop

finish-args:
  - --device=dri
  - --share=ipc
  - --socket=fallback-x11
  - --socket=wayland
  - --share=network
  - --filesystem=host
  - --filesystem=xdg-download
  - --talk-name=org.freedesktop.Notifications
  - --talk-name=org.freedesktop.portal.Desktop
  - --talk-name=org.a11y.Bus
  - --talk-name=org.freedesktop.Flatpak

cleanup:
  - /include
  - /lib/pkgconfig
  - /share/man
  - '*.a'
  - '*.la'

modules:
  - name: dsh-runtime
    buildsystem: simple
    build-commands:
      - mkdir -p ${FLATPAK_DEST}/bin
      - cp -a /usr/lib/sdk/node24 ${FLATPAK_DEST}/node24
      - ln -sf ../node24/bin/node ${FLATPAK_DEST}/bin/node
      - ln -sf ../node24/bin/npm ${FLATPAK_DEST}/bin/npm
      - ln -sf ../node24/bin/npx ${FLATPAK_DEST}/bin/npx
      - cp -a . ${FLATPAK_DEST}/
    sources:
      - type: dir
        path: ../vendor/dsh-prefix

  - name: dsh-desktop
    buildsystem: simple
    build-options:
      append-path: /usr/lib/sdk/rust-stable/bin
      env:
        CARGO_HOME: /run/build/dsh-desktop/cargo
      build-args:
        - --share=network
    build-commands:
      - mkdir -p vendor/modlens vendor/anchored-standard vendor/zero-anchored-standard
      - cargo build --release --locked --offline || cargo build --release
      - install -Dm755 target/release/dsh-desktop ${FLATPAK_DEST}/bin/dsh-desktop
      - mkdir -p ${FLATPAK_DEST}/share/dsh-desktop/vision
      - cp -a plugins/dsh-desktop-vision/. ${FLATPAK_DEST}/share/dsh-desktop/vision
      - install -Dm644 data/applications/io.github.tommyfang.DshDesktop.desktop ${FLATPAK_DEST}/share/applications/io.github.tommyfang.DshDesktop.desktop
      - install -Dm644 data/metainfo/io.github.tommyfang.DshDesktop.metainfo.xml ${FLATPAK_DEST}/share/metainfo/io.github.tommyfang.DshDesktop.metainfo.xml
      - for size in 16 24 32 48 64 128 256 512; do install -Dm644 data/icons/hicolor/${size}x${size}/apps/io.github.tommyfang.DshDesktop.png ${FLATPAK_DEST}/share/icons/hicolor/${size}x${size}/apps/io.github.tommyfang.DshDesktop.png; done
    sources:
      - type: dir
        path: ..
        skip:
          - .flatpak-build
          - .flatpak-builder
          - .flatpak-repo
          - dist
          - vendor
          - .git
          - target

  - name: modlens-plugin
    buildsystem: simple
    build-commands:
      - mkdir -p ${FLATPAK_DEST}/share/dsh-desktop/modlens
      - cp -a . ${FLATPAK_DEST}/share/dsh-desktop/modlens
    sources:
      - type: dir
        path: ../vendor/modlens

  - name: anchored-standard-preset
    buildsystem: simple
    build-commands:
      - mkdir -p ${FLATPAK_DEST}/share/dsh-desktop/anchored-standard
      - cp -a . ${FLATPAK_DEST}/share/dsh-desktop/anchored-standard
    sources:
      - type: dir
        path: ../vendor/anchored-standard

  - name: zero-anchored-standard-preset
    buildsystem: simple
    build-commands:
      - mkdir -p ${FLATPAK_DEST}/share/dsh-desktop/zero-anchored-standard
      - cp -a . ${FLATPAK_DEST}/share/dsh-desktop/zero-anchored-standard
    sources:
      - type: dir
        path: ../vendor/zero-anchored-standard
