# Maintainer: PalaceChat 5 dev team <alexandra@elitepalaces.com>
pkgname=palacechat
pkgver=5.0.273.2
pkgrel=1
pkgdesc="Graphical chat client for the Palace Chat protocol — avatars, IptScrae room scripts, embedded web content, voice chat, prop / paint tools."
arch=('x86_64')
url="https://pchat.org"
license=('custom')

# Runtime dependencies. Same set as the .deb but with Arch package names.
# webkit2gtk-4.1 is the modern API matching what the Linux build links
# against. gst-libav + gst-plugins-good/bad/ugly cover the codec stack
# needed for HTML5 video inside webembeds (YouTube, ktplayer). bind
# provides /usr/bin/dig for the TCPDNSSocket fallback. speech-dispatcher
# powers the Accessibility tab's TTS via spd-say.
depends=(
    'gtk3'
    'webkit2gtk-4.1'
    'gstreamer'
    'gst-libav'
    'gst-plugins-good'
    'gst-plugins-bad'
    'gst-plugins-ugly'
    'speech-dispatcher'
    'bind'
)

# Optional but improves the user experience.
optdepends=(
    'gstreamer-vaapi: hardware video decoding when supported'
    'mbrola-voices-en1: better-sounding TTS for English'
    'mbrola-voices-es1: better-sounding TTS for Spanish'
    'mbrola-voices-fr1: better-sounding TTS for French'
)

# Source: the staging tarball produced by build-arch.sh. Lives in the
# same folder as the PKGBUILD so makepkg picks it up locally without
# needing a hosted URL. Just drop the tarball + this PKGBUILD + the
# .install file into one folder and run `makepkg -si`.
source=("palacechat-${pkgver}.tar.gz")
sha256sums=('1d7bb23013b5ad052fb9a28b535c100953ff8ecb6627d4230fbfdb3ae6a22827')
install=palacechat.install

# Tell makepkg not to strip the binary or compress with hardened flags
# that conflict with Xojo's runtime layout. The binary already ships in
# its final form straight from the cross-compile.
options=(!strip !makeflags)

package() {
    cd "$srcdir"

    # /opt/palacechat/  — binary, libs, resources, palacechat.sh wrapper
    install -dm755 "$pkgdir/opt/palacechat"
    cp -a "palacechat-${pkgver}/." "$pkgdir/opt/palacechat/"
    chmod +x "$pkgdir/opt/palacechat/PalaceChat"
    chmod +x "$pkgdir/opt/palacechat/palacechat.sh"

    # /usr/bin/palacechat  — symlink to the wrapper
    install -dm755 "$pkgdir/usr/bin"
    ln -sf /opt/palacechat/palacechat.sh "$pkgdir/usr/bin/palacechat"

    # Application menu entry
    install -Dm644 "palacechat-${pkgver}/palacechat.desktop" \
        "$pkgdir/usr/share/applications/palacechat.desktop"

    # Icon — install at TWO paths for compatibility across icon themes.
    # Hicolor 256x256 is the modern XDG path; /usr/share/pixmaps is the
    # legacy fallback every DE still checks.
    if [ -f "palacechat-${pkgver}/icon.png" ]; then
        install -Dm644 "palacechat-${pkgver}/icon.png" \
            "$pkgdir/usr/share/icons/hicolor/256x256/apps/palacechat.png"
        install -Dm644 "palacechat-${pkgver}/icon.png" \
            "$pkgdir/usr/share/pixmaps/palacechat.png"
    fi

    # Proprietary freeware license (PalaceChat 5 dev team, 2026).
    install -dm755 "$pkgdir/usr/share/licenses/$pkgname"
    cat > "$pkgdir/usr/share/licenses/$pkgname/copyright" <<EOF
PalaceChat
Copyright (c) 2026 ElitePalaces.com / The PalaceChat 5 dev team
All Rights Reserved.

LICENSE TERMS

This software is provided free of charge for personal and commercial
use. No payment or registration is required.

YOU MAY:
  - Install and use PalaceChat on any number of computers.
  - Share the original, unmodified installer with others.

YOU MAY NOT:
  - Modify, decompile, disassemble, or reverse-engineer the software
    or any part of it.
  - Redistribute modified versions.
  - Sell, sublicense, rent, or lease the software.
  - Remove or alter any copyright, trademark, or attribution notices.

AGE RESTRICTION

You must be at least 16 years old to use this software. By
installing or using PalaceChat, you represent that you meet this
age requirement. If you are under 16, you may not install or use
PalaceChat. You are responsible for complying with the laws of
your jurisdiction.

PalaceChat is not directed at children and does not knowingly
collect personal information from users under the minimum age.

WARRANTY

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
CLAIM, DAMAGES, OR OTHER LIABILITY ARISING FROM THE USE OF THE
SOFTWARE.

Contact: alexandra@elitepalaces.com
EOF
}
