# SPDX-FileCopyrightText: 2024 Scarlett Moore <sgmoore@kde.org>
#
# SPDX-License-Identifier: CC0-1.0
---
name: krfb
confinement: strict
grade: stable
base: core22
adopt-info: krfb
apps:
  krfb:
    extensions:
      - kde-neon-6
    common-id: org.kde.krfb.desktop
    desktop: usr/share/applications/org.kde.krfb.desktop
    command: usr/bin/krfb
    plugs:
      - audio-record
    environment:
      LD_LIBRARY_PATH: $SNAP/ffmpeg-platform/usr/lib/$CRAFT_ARCH_TRIPLET_BUILD_FOR:${LD_LIBRARY_PATH}
      PATH: $SNAP/ffmpeg-platform/usr/bin:${PATH}
      ALSA_CONFIG_PATH: "$SNAP/kf6/etc/asound.conf"
plugs:
  ffmpeg-2204:
    interface: content
    target: ffmpeg-platform # the folder where this content snap will be mounted
    default-provider: ffmpeg-2204
slots:
  session-dbus-interface:
    interface: dbus
    name: org.kde.krfb
    bus: session
package-repositories:
  - type: apt
    components:
      - main
    suites:
      - jammy
    key-id: 444DABCF3667D0283F894EDDE6D4736255751E5D
    url: http://origin.archive.neon.kde.org/user
    key-server: keyserver.ubuntu.com
parts:
  kpipewire:
    plugin: cmake
    source: https://invent.kde.org/plasma/kpipewire.git
    source-branch: master
    cmake-parameters:
      - -DCMAKE_INSTALL_PREFIX=/usr
      - -DCMAKE_BUILD_TYPE=Release
      - -DQT_MAJOR_VERSION=6
      - -DBUILD_WITH_QT6=ON
      - -DBUILD_TESTING=OFF
      - -DCMAKE_INSTALL_SYSCONFDIR=/etc
      - -DCMAKE_INSTALL_LOCALSTATEDIR=/var
      - -DCMAKE_EXPORT_NO_PACKAGE_REGISTRY=ON
      - -DCMAKE_FIND_USE_PACKAGE_REGISTRY=OFF
      - -DCMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY=ON
      - -DCMAKE_INSTALL_RUNSTATEDIR=/run
      - -DCMAKE_SKIP_INSTALL_ALL_DEPENDENCY=ON
      - -DCMAKE_VERBOSE_MAKEFILE=ON
      - -DCMAKE_INSTALL_LIBDIR=lib/$CRAFT_ARCH_TRIPLET_BUILD_FOR
      - --log-level=STATUS
      - -DCMAKE_LIBRARY_PATH=lib/$CRAFT_ARCH_TRIPLET_BUILD_FOR
  krfb:
    after:
      - kpipewire
    parse-info:
      - usr/share/metainfo/org.kde.krfb.appdata.xml
    plugin: cmake
    source: .
    source-type: local
    build-packages:
      - libxcb-render0-dev
      - libxcb-shape0-dev
      - libxcb-xfixes0-dev
      - libxcb-shm0-dev
      - libxcb-damage0-dev
      - libxcb-image0-dev
      - libvncserver-dev
      - libpipewire-0.3-dev
      - libepoxy-dev
      - libgbm-dev
      - libwayland-dev
      - libxdamage-dev
      - libxtst-dev
    build-snaps:
      - ffmpeg-2204-sdk
    stage-packages:
      - libxcb-render0
      - libxcb-shape0
      - libxcb-xfixes0
      - libxcb-shm0-dev
      - libxcb-damage0-dev
      - libxcb-image0-dev
      - libvncserver1
      - pipewire-bin
      - pipewire-audio-client-libraries
      - libepoxy0
      - libgbm1
      - libwayland-client0
      - libxdamage1
      - libxtst6
    cmake-parameters:
      - -DCMAKE_INSTALL_PREFIX=/usr
      - -DCMAKE_BUILD_TYPE=Release
      - -DQT_MAJOR_VERSION=6
      - -DBUILD_WITH_QT6=ON
      - -DBUILD_TESTING=OFF
      - -DCMAKE_INSTALL_SYSCONFDIR=/etc
      - -DCMAKE_INSTALL_LOCALSTATEDIR=/var
      - -DCMAKE_EXPORT_NO_PACKAGE_REGISTRY=ON
      - -DCMAKE_FIND_USE_PACKAGE_REGISTRY=OFF
      - -DCMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY=ON
      - -DCMAKE_INSTALL_RUNSTATEDIR=/run
      - -DCMAKE_SKIP_INSTALL_ALL_DEPENDENCY=ON
      - -DCMAKE_VERBOSE_MAKEFILE=ON
      - -DCMAKE_INSTALL_LIBDIR=lib/$CRAFT_ARCH_TRIPLET_BUILD_FOR
      - --log-level=STATUS
      - -DCMAKE_LIBRARY_PATH=lib/$CRAFT_ARCH_TRIPLET_BUILD_FOR
    build-environment:
      - CMAKE_FIND_ROOT_PATH: "${CMAKE_FIND_ROOT_PATH}:/snap/ffmpeg-2204-sdk/current"
      - PKG_CONFIG_PATH: "/snap/ffmpeg-2204-sdk/current/usr/lib/$CRAFT_ARCH_TRIPLET_BUILD_FOR/pkgconfig"
      - LD_LIBRARY_PATH: "${LD_LIBRARY_PATH}:/snap/ffmpeg-2204-sdk/current/usr/lib/$CRAFT_ARCH_TRIPLET_BUILD_FOR"
    prime:
      - -usr/lib/*/cmake/*
      - -usr/include/*
      - -usr/share/ECM/*
      - -usr/share/man/*
      - -usr/bin/X11
      - -usr/lib/gcc/$CRAFT_ARCH_TRIPLET_BUILD_FOR/6.0.0
      - -usr/lib/aspell/*
      - -usr/share/lintian
  cleanup:
    after:
      - krfb
    plugin: nil
    build-snaps:
      - core22
      - kf6-core22
    override-prime: |
      set -eux
      for snap in "core22" "kf6-core22"; do
          cd "/snap/$snap/current" && find . -type f,l -exec rm -rf "${CRAFT_PRIME}/{}" \;
      done
