name: songrec # you probably want to 'snapcraft register <name>'
base: core20 # the base snap is the execution environment for this snap
version: '0.1.4' # just for humans, typically '1.2+git' or '1.3.2'
summary: An open-source, unofficial Shazam client for Linux, written in Rust # 79 char long summary
description: |
  Features:
  - Recognize audio from an arbitrary audio file.
  - Recognize audio from the microphone.
  - Usage from both GUI and command line (for the file recognition part).
  - Provide an history of the recognized songs on the GUI, exportable to CSV.
  - Continuous song detection from the microphone, with the ability to choose your input device.
  - Generate a lure from a song that, when played, will fool Shazam into thinking that it is the concerned song.

grade: stable # must be 'stable' to release into candidate/stable channels
confinement: strict # use 'strict' once you have the right plugs and slots

apps:
  songrec:
    command: bin/desktop-launch songrec
    desktop: usr/share/applications/com.github.marinm.songrec.desktop
    plugs: 
      - home
      - network
      - desktop
      - desktop-legacy
      - wayland
      - unity7
      - gsettings
      - alsa
      - audio-record
      - audio-playback
    slots: [dbus-svc]

slots:
  dbus-svc: # name that is used with 'snap connect' on slots side
    interface: dbus
    bus: session
    name: com.github.marinm.songrec

plugs:
  gnome-3-34-1804:
    interface: content
    target: $SNAP/gnome-platform
    default-provider: gnome-3-34-1804
  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:
  songrec:
    build-packages:
      - libasound2-dev
      - libgtk-3-dev
      - libssl-dev
      - libffi-dev
    
    stage-packages:
      - libasound2
      - libssl1.1
      - libgtk-3-0
      - libffi7
    
    plugin: rust
    source: ../..

    after: [desktop-gnome-platform, alsa-mixin]

  # This part installs the `desktop-launch` script which initialises desktop
  # features such as fonts, themes and the XDG environment.
  # 
  # It is copied straight from the snapcraft desktop helpers project. Please
  # periodically check the source for updates and copy the changes.
  #    https://github.com/ubuntu/snapcraft-desktop-helpers/blob/master/snapcraft.yaml
  
  desktop-gnome-platform:
    source: https://github.com/ubuntu/snapcraft-desktop-helpers.git
    source-subdir: gtk
    plugin: make
    make-parameters: ["FLAVOR=gtk3"]
    build-packages:
      - gcc
    override-build: |
      snapcraftctl build
      mkdir -pv $SNAPCRAFT_PART_INSTALL/gnome-platform

  alsa-mixin:
    plugin: dump
    source: https://github.com/diddlesnaps/snapcraft-alsa.git
    source-subdir: snapcraft-assets
    build-packages:
      - libasound2-dev
    
    stage-packages:
      - libasound2
      - libasound2-plugins
      - yad

  share:
    plugin: dump
    source: ../rootfs/

    override-pull: |
      snapcraftctl pull

      # Point icon to the correct location
      sed -i -e 's|Icon=com.github.marinm.songrec|Icon=/usr/share/icons/hicolor/scalable/apps/com.github.marinm.songrec.svg|g' usr/share/applications/com.github.marinm.songrec.desktop

layout:
  /usr/lib/$SNAPCRAFT_ARCH_TRIPLET/alsa-lib:
    bind: $SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/alsa-lib
  /usr/share/alsa:
    bind: $SNAP/usr/share/alsa
