# SPDX-FileCopyrightText: 2024-2026 Scarlett Moore <sgmoore@kde.org>
#
# SPDX-License-Identifier: CC0-1.0
---
name: falkon
confinement: strict
grade: stable
base: core24
adopt-info: falkon
apps:
  falkon:
    extensions:
      - kde-neon-6
    common-id: org.kde.falkon.desktop
    desktop: usr/share/applications/org.kde.falkon.desktop
    command: usr/bin/falkon
    plugs:
      - audio-record
      - browser-support
      - cups
    environment:
      QTWEBENGINE_DISABLE_SANDBOX: 1
      ALSA_CONFIG_PATH: "$SNAP/kf6/etc/asound.conf"
      DICPATH: "$SNAP/usr/share/hunspell"
      PYSIDE_DESIGNER_PLUGINS: /snap/kde-pyside6-core24-sdk/current/usr/lib/x86_64-linux-gnu/qt6/plugins/designer
      PYTHONPATH: /snap/kde-qt6-core24-sdk/current/usr/lib/python3.12:/snap/kde-qt6-core24-sdk/current/usr/lib/python3/dist-packages:/snap/kde-pyside6-core24-sdk/current/usr/lib/python3.12:/snap/kde-pyside6-core24-sdk/current/usr/lib/python3/dist-packages${PYTHONPATH:+:$PYTHONPATH}
plugs:
  hunspell-dictionaries:
    content: hunspell-dictionaries
    interface: content
    target: "$SNAP/usr/share/hunspell"
    default-provider: hunspell-dictionaries
slots:
  session-dbus-interface:
    interface: dbus
    name: org.kde.falkon
    bus: session
parts:
  falkon:
    parse-info:
      - usr/share/metainfo/org.kde.falkon.appdata.xml
    plugin: cmake
    source: .
    source-type: local
    build-snaps:
      - kde-qt6-core24-sdk/latest/stable
      - kde-pyside6-core24-sdk/latest/stable
      - kf6-core24-sdk/latest/stable
      - hunspell-dictionaries
    build-packages:
      - libxcb-util-dev
      - libssl-dev
      - gnome-keyring
      - libxkbcommon-dev
      - libcups2-dev
      - python3-dev
    stage-packages:
      - libxcb-util1
      - gnome-keyring
      - libxkbcommon0
      - libcups2t64
      - cups-client
    stage-snaps:
      - kget
    cmake-parameters:
      - -DCMAKE_INSTALL_PREFIX=/usr
      - -DCMAKE_BUILD_TYPE=Release
      - -DQT_MAJOR_VERSION=6
      - -DBUILD_WITH_QT6=ON
      - "-DCMAKE_FIND_ROOT_PATH=$CRAFT_STAGE\\;/snap/kde-qt6-core24-sdk/current\\/snap/kde-pyside6-core24-sdk/current\\;/usr"
      - "-DCMAKE_PREFIX_PATH=$CRAFT_STAGE\\:/snap/kde-qt6-core24-sdk/current\\/snap/kde-pyside6-core24-sdk/current\\:/usr"
    build-environment:
      - DICPATH: "$SNAP/usr/share/hunspell"
      - PYSIDE_DESIGNER_PLUGINS: /snap/kde-pyside6-core24-sdk/current/usr/lib/x86_64-linux-gnu/qt6/plugins/designer
      - PYTHONPATH: /snap/kde-qt6-core24-sdk/current/usr/lib/python3.12:/snap/kde-qt6-core24-sdk/current/usr/lib/python3/dist-packages:/snap/kde-pyside6-core24-sdk/current/usr/lib/python3.12:/snap/kde-pyside6-core24-sdk/current/usr/lib/python3/dist-packages${PYTHONPATH:+:$PYTHONPATH}
    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
  gpu-2404:
    after: [falkon]
    source: https://github.com/canonical/gpu-snap.git
    plugin: dump
    override-prime: |
      craftctl default
      ${CRAFT_PART_SRC}/bin/gpu-2404-cleanup mesa-2404
    prime:
      - bin/gpu-2404-wrapper
  cleanup:
    after:
      - falkon
    plugin: nil
    build-snaps:
      - core24
      - kf6-core24
    override-prime: |
      set -eux
      for snap in "core24" "kf6-core24"; do
        cd "/snap/$snap/current" && find . -type f,l -exec rm -rf "${CRAFT_PRIME}/{}" \;
      done
