# Maintainer: David Heinemeier Hansson <david@hey.com>

# TMOG publishes no source and no AUR package, so this repackages the vendor's
# Linux tarball. That tarball is 8 MB against the system Qt, where the AppImage
# is 55 MB of bundled Qt -- the same binary, minus a second copy of what
# Omarchy already installs.
#
# The download URL carries no version: tmog.org serves every release from the
# same path. .omarchy/upstream.sh rewrites the pkgver and sha256 below when
# /version.txt moves, and checks the tarball's own directory name to be sure
# the mutable URL really served the version it announced.

pkgname=tmog-bin
pkgver=0.1.1
pkgrel=1
pkgdesc="Native system monitor and task manager"
arch=('x86_64')
url="https://tmog.org/"
license=('LicenseRef-proprietary')

depends=(
  'gcc-libs'
  'glibc'
  'hicolor-icon-theme'
  'qt6-base'
  'qt6-multimedia'
  'qt6-svg'
  # Omarchy is a Wayland desktop, so the Wayland platform plugin is what this
  # actually runs on; without it Qt falls back to xcb under XWayland.
  'qt6-wayland'
  'systemd-libs'
)

provides=('tmog')
conflicts=('tmog')

# Upstream ships a stripped release build and no debug symbols to split out.
options=('!debug' '!strip')

_srcdir="TaskManagerOG-${pkgver}-linux-x86_64"

# The query string is upstream's own cache key -- tmog.org appends it to the
# Linux links for the same reason, so a CDN holding an older object under this
# mutable path cannot answer for a new release.
source=("${pkgname}-${pkgver}.tar.gz::${url}downloads/TMOG-Task-Manager-Linux-x86_64.tar.gz?v=${pkgver}-free")
sha256sums=('4d319d3d27f513e83801daeec8eb64cb78ddec1f6483bbe90d57d11e607af39d')

package() {
  cd "${_srcdir}"

  install -Dm755 bin/tmog-task-manager "${pkgdir}/usr/bin/tmog-task-manager"

  install -Dm644 share/applications/com.tmog.taskmanager.desktop \
    "${pkgdir}/usr/share/applications/com.tmog.taskmanager.desktop"
  install -Dm644 share/metainfo/com.tmog.taskmanager.metainfo.xml \
    "${pkgdir}/usr/share/metainfo/com.tmog.taskmanager.metainfo.xml"
  install -Dm644 share/pixmaps/tmog-task-manager.png \
    "${pkgdir}/usr/share/pixmaps/tmog-task-manager.png"

  local icon
  for icon in share/icons/hicolor/*/apps/tmog-task-manager.png; do
    install -Dm644 "$icon" "${pkgdir}/usr/${icon}"
  done

  # Upstream files its licence texts under share/doc, which is Debian's layout.
  # On Arch they belong with the package's licences.
  local doc
  for doc in share/doc/tmog/* share/doc/taskmanagerog/copyright; do
    install -Dm644 "$doc" "${pkgdir}/usr/share/licenses/${pkgname}/${doc##*/}"
  done
}
