name: rustdesk
version: git
summary: rustdesk
description: |
  rustdesk

base: core18
confinement: strict
grade: stable

plugs:
  gsettings:
  gtk-3-themes:
    interface: content
    target: $SNAP/data-dir/themes
    default-provider: gtk-common-themes
  icon-themes:
    interface: content
    target: $SNAP/data-dir/icons
    default-provider: gtk-common-themes
  sound-themes:
    interface: content
    target: $SNAP/data-dir/sounds
    default-provider: gtk-common-themes

parts:
  vcpkg-packages:
    plugin: nil
    build-packages:
      - git
      - curl
      - unzip
      - zip
      - tar
    build-environment:
      - PATH: ${SNAPCRAFT_PART_SRC}/vcpkg:$PATH
    override-pull: |
      git clone https://github.com/Microsoft/vcpkg.git --depth=1
      ./vcpkg/bootstrap-vcpkg.sh
      vcpkg install libyuv libvpx opus
  
  sciter-deps:
    plugin: nil
    build-packages:
      - curl
    override-pull: |
      curl "https://raw.githubusercontent.com/c-smile/sciter-sdk/master/bin.lnx/x64/libsciter-gtk.so" -o libsciter-gtk.so
    override-build: |
      mkdir -p ${SNAPCRAFT_PART_INSTALL}/usr/lib/rustdesk/
      cp ${SNAPCRAFT_PART_SRC}/libsciter-gtk.so ${SNAPCRAFT_PART_INSTALL}/usr/lib/rustdesk/

  rustdesk:
    plugin: rust
    source: .
    build-environment:
      - VCPKG_ROOT: ${SNAPCRAFT_PART_SRC}/../../vcpkg-packages/src/vcpkg
      - PATH: ${SNAPCRAFT_PART_SRC}/../../vcpkg-packages/src/vcpkg:$PATH
    override-pull: |
      snapcraftctl pull
      python3 inline-sciter.py
    rust-features:
      - inline
    build-packages:
      - g++ 
      - gcc 
      - git 
      - curl
      - wget 
      - nasm 
      - yasm 
      - libgtk-3-dev
      - clang 
      - libxcb-randr0-dev 
      - libxdo-dev 
      - libxfixes-dev 
      - libxcb-shape0-dev 
      - libxcb-xfixes0-dev 
      - libasound2-dev 
      - libpulse-dev 
      - cmake
      - python3
    stage-packages:
      - libssl1.1
      - libasound2
      - libpulse0
      - libatk-bridge2.0-0
      - libgtk-3-0
      - libxcb-randr0
      - libxdo3
      - libxfixes3
      - libxcb-shape0
      - libxcb-xfixes0
      - libxkbcommon0
      - adwaita-icon-theme
      - libcanberra-gtk-module
      - libgdk-pixbuf2.0-0
      - libglib2.0-bin
      - xdg-user-dirs
      - shared-mime-info
      - light-themes
      - dmz-cursor-theme
      - gnome-themes-standard
      - ttf-ubuntu-font-family
    after:
      - vcpkg-packages

  rustdesk-files:
    plugin: nil
    override-pull: |
      mkdir -p ${SNAPCRAFT_PART_INSTALL}/usr/share/rustdesk/files/systemd/
      cp ${SNAPCRAFT_PART_SRC}/../../rustdesk/src/rustdesk.service ${SNAPCRAFT_PART_INSTALL}/usr/share/rustdesk/files/systemd/
      
layout:
  /usr/share/rustdesk:
    bind: $SNAP/usr/share/rustdesk
  /usr/lib/rustdesk:
    bind: $SNAP/usr/lib/rustdesk

apps:
  rustdesk:
    command: bin/rustdesk
    plugs:
      - network
      - audio-playback
      - home
      - x11
      - opengl
      - wayland
      - desktop
      - desktop-legacy
      - pulseaudio
      - gsettings
      - unity7
      # must manually connect
      - login-session-observe
      # [option] manually connect
      - audio-record
  rustdesk-service:
    command: bin/rustdesk --service
    daemon: simple
    plugs:
      - network
      - audio-playback
      - home
      - x11
      - opengl
      - wayland
      - desktop
      - desktop-legacy
      - pulseaudio
      - gsettings
      - unity7
      # must manually connect
      - login-session-observe
      # [option] manually connect
      - audio-record

