name: qv2ray
base: core18
adopt-info: qv2ray
icon: assets/icons/qv2ray.png

grade: devel
confinement: devmode

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

apps:
  qv2ray:
      command: bin/desktop-launch qv2ray
      environment:
        QT_QPA_PLATFORMTHEME: gtk3
      common-id: com.github.Qv2ray
      desktop: "usr/share/applications/qv2ray.desktop"

parts:
  qv2ray:
    plugin: qmake
    source-type: git
    source: .
    parse-info: [usr/share/metainfo/qv2ray.metainfo.xml]
    build-packages:
      - build-essential
      - qttools5-dev-tools
      - qt5-default
      - libgrpc++-dev
      - libprotobuf-dev
      - protobuf-compiler-grpc
    stage-packages:
      - libgcc1
      - libstdc++6
      - libssl1.1
      - libgrpc++1
      - libprotobuf17
      - libqt5core5a
      - libqt5gui5
      - libqt5network5
      - libqt5widgets5
      - fonts-noto-cjk
      - libglib2.0-bin
    options:
      - PREFIX=/usr
      - CONFIG+=with_metainfo
      - CONFIG+=use_grpc
    override-pull: |
      snapcraftctl pull
      build_number=$(cat makespec/BUILDVERSION)
      tag=$(git describe --abbrev=0 --tags)
      version=$tag.$build_number
      snapcraftctl set-version "$version"
      sed -i 's|^Icon=.*|Icon=/usr/share/icons/hicolor/256x256/apps/qv2ray.png|g' assets/qv2ray.desktop
    after:
      - mytools
      - desktop-qt5

  desktop-qt5:
    source: https://github.com/ubuntu/snapcraft-desktop-helpers.git
    source-subdir: qt
    plugin: make
    make-parameters: ["FLAVOR=qt5"]
    build-packages:
      - build-essential
      - qtbase5-dev
      - dpkg-dev
    stage-packages:
      - libxkbcommon0
      - ttf-ubuntu-font-family
      - dmz-cursor-theme
      - light-themes
      - adwaita-icon-theme
      - gnome-themes-standard
      - shared-mime-info
      - libqt5gui5
      - libgdk-pixbuf2.0-0
      - libqt5svg5 # for loading icon themes which are svg
      - try: [appmenu-qt5] # not available on core18
      - locales-all
      - xdg-user-dirs
      - fcitx-frontend-qt5
    after:
      - mytools
  
  qt5-gtk-platform:
    plugin: nil
    stage-packages:
      - qt5-gtk-platformtheme
    after:
      - mytools
  
  mytools:
    plugin: nil
    build-packages:
      - dirmngr
    override-pull: |
      echo 'deb http://archive.neon.kde.org/unstable bionic main' > /etc/apt/sources.list.d/neon.list
      echo 'deb http://ppa.launchpad.net/ymshenyu/grpc-1/ubuntu bionic main' >> /etc/apt/sources.list.d/tools.list
      sudo apt-key adv --keyserver keyserver.ubuntu.com --recv E6D4736255751E5D
      sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 281f24e574404629aa3bda1a4f10c386c55cdb04
      sudo apt-get update
      snapcraftctl pull
    override-build: |
      snapcraftctl build
      sudo apt upgrade -y
      sudo apt dist-upgrade -y