name='claude-desktop'
version=1.24012.0
release=5
summary='Claude desktop application'
summary_ru='Десктопное приложение Claude'
group='Development/Tools'
desc='Claude is the Anthropic desktop application for Claude and Claude Code workflows with chat, project context, integrated terminal, editor and visual diff review.'
desc_ru='Claude — десктопное приложение Anthropic для Claude и сценариев Claude Code: чат, контекст проекта, встроенный терминал, редактор и визуальный просмотр diff.'
homepage='https://code.claude.com/docs/en/desktop-quickstart'
maintainer='Anthropic PBC <support@anthropic.com>'

architectures=('amd64' 'arm64')

license=('Custom')
nonfree=1
nonfree_msg='Claude Desktop является проприетарным приложением Anthropic. Использование Claude, Claude Code, учетной записи, подписки, сетевых функций и моделей регулируется условиями Anthropic.'
nonfree_url='https://www.anthropic.com/legal/consumer-terms'

provides=()
replaces=('claude-desktop')
conflicts=()

auto_reqprov_method="dirty"
auto_req=0
auto_prov=0

deps=()
deps_debian=('libgtk-3-0' 'libnotify4' 'libnss3' 'xdg-utils' 'libatspi2.0-0' 'libdrm2' 'libgbm1' 'libxcb-dri3-0' 'libsecret-1-0' 'libc6' 'libxtst6' 'libuuid1' 'xdg-desktop-portal' 'xdg-desktop-portal-gtk | xdg-desktop-portal-gnome | xdg-desktop-portal-kde')
deps_ubuntu=("${deps_debian[@]}")
deps_fedora=('gtk3' 'libnotify' 'nss' 'xdg-utils' 'at-spi2-core' 'libdrm' 'mesa-libgbm' 'libxcb' 'libsecret' 'glibc' 'libXtst' 'libuuid' 'xdg-desktop-portal' 'xdg-desktop-portal-gtk')
deps_arch=('gtk3' 'libnotify' 'nss' 'xdg-utils' 'at-spi2-core' 'libdrm' 'libgbm' 'libxcb' 'libsecret' 'glibc' 'libxtst' 'libutil-linux' 'xdg-desktop-portal' 'xdg-desktop-portal-gtk')
deps_opensuse=('gtk3' 'libnotify4' 'mozilla-nss' 'xdg-utils' 'at-spi2-core' 'libdrm2' 'libgbm1' 'libxcb-dri3-0' 'libsecret-1-0' 'glibc' 'libXtst6' 'libuuid1' 'xdg-desktop-portal' 'xdg-desktop-portal-gtk')
deps_altlinux=('libgtk+3' 'libnotify' 'libnss' 'xdg-utils' 'libat-spi2-core' 'libdrm' 'libgbm' 'libxcb' 'libsecret' 'glibc' 'libXtst' 'libuuid' 'xdg-desktop-portal' 'xdg-desktop-portal-gtk')

opt_deps=()
opt_deps_debian=('libasound2t64 | libasound2 | pulseaudio' 'libayatana-appindicator3-1 | libappindicator3-1' 'ca-certificates' 'gnome-keyring | kwalletd6 | kwalletd5' 'qemu-system-x86' 'ovmf' 'virtiofsd')
opt_deps_ubuntu=("${opt_deps_debian[@]}")
opt_deps_fedora=('alsa-lib' 'pulseaudio-libs' 'libappindicator-gtk3' 'ca-certificates' 'gnome-keyring' 'kwallet' 'qemu-system-x86' 'edk2-ovmf' 'virtiofsd')
opt_deps_arch=('alsa-lib' 'pulseaudio' 'libappindicator-gtk3' 'ca-certificates' 'gnome-keyring' 'kwallet' 'qemu-system-x86' 'edk2-ovmf' 'virtiofsd')
opt_deps_opensuse=('libasound2' 'libpulse0' 'libappindicator3-1' 'ca-certificates' 'gnome-keyring' 'kwallet6' 'qemu-x86' 'ovmf' 'virtiofsd')
opt_deps_altlinux=('libalsa' 'libappindicator-gtk3' 'ca-certificates' 'gnome-keyring' 'qemu-system-x86' 'virtiofsd')

build_deps=('binutils')
build_deps_debian=('binutils' 'python3')
build_deps_ubuntu=("${build_deps_debian[@]}")
build_deps_fedora=('binutils' 'python3')
build_deps_arch=('binutils' 'python')
build_deps_opensuse=('binutils' 'python3')
build_deps_altlinux=('binutils' 'python3')

sources=(
	"https://downloads.claude.ai/claude-desktop/apt/stable/pool/main/c/claude-desktop/claude-desktop_${version}_amd64.deb?~archive=false&~name=claude-desktop.deb"
	"local:///claude-tray-orange.png"
	'local:///LICENSE'
)

sources_arm64=(
	"https://downloads.claude.ai/claude-desktop/apt/stable/pool/main/c/claude-desktop/claude-desktop_${version}_arm64.deb?~archive=false&~name=claude-desktop.deb"
	"local:///claude-tray-orange.png"
	'local:///LICENSE'
)

checksums=(
	'sha256:1096a8063956f8430fdbe504bb1c5e02985f31d0f45d082e4966e5d30ea7e3ac'
	'sha256:be51081c0e0b2eec3489c25da38194dccf68fe7445928b32c30e1b8051eb557b'
	'sha256:40efe7a2755d02c9fe13f98cae18705e2d31e5bbb24816ebbd4951c5e3a56b3f'
)

checksums_arm64=(
	'sha256:37dd5dc1b0bfcb3192561acbd33cb59037806fe9b95221a3ddf38244203196f1'
	'sha256:be51081c0e0b2eec3489c25da38194dccf68fe7445928b32c30e1b8051eb557b'
	'sha256:40efe7a2755d02c9fe13f98cae18705e2d31e5bbb24816ebbd4951c5e3a56b3f'
)

scripts=(
	['postinstall']='postinstall.sh'
	['postremove']='postremove.sh'
)

package() {
	cd "${srcdir}"

	mkdir -p "${srcdir}/extracted"
	ar x claude-desktop.deb
	tar -xf data.tar.* -C "${srcdir}/extracted"

	install -dm755 "${pkgdir}/usr/lib"
	cp -a "${srcdir}/extracted/usr/lib/claude-desktop" "${pkgdir}/usr/lib/"
	chmod 0755 "${pkgdir}/usr/lib/claude-desktop/chrome-sandbox"
	chmod 755 \
		"${pkgdir}/usr/lib/claude-desktop/claude-desktop" \
		"${pkgdir}/usr/lib/claude-desktop/resources/chrome-native-host" \
		"${pkgdir}/usr/lib/claude-desktop/resources/cowork-linux-helper" \
		"${pkgdir}/usr/lib/claude-desktop/resources/virtiofsd"

	# Сохраняем штатный tray-глиф Claude, меняя только его цвет.
	for icon_name in TrayIconLinux.png TrayIconLinux-Dark.png; do
		install -Dm644 "${srcdir}/claude-tray-orange.png" \
			"${pkgdir}/usr/lib/claude-desktop/resources/${icon_name}"
	done

	install -dm755 "${pkgdir}/usr/share"
	cp -a "${srcdir}/extracted/usr/share/applications" "${pkgdir}/usr/share/"
	cp -a "${srcdir}/extracted/usr/share/icons" "${pkgdir}/usr/share/"

	desktop_file="$(find "${pkgdir}/usr/share/applications" -maxdepth 1 -type f -name "*.desktop" | head -1)"
	[[ -n "${desktop_file}" ]] || {
		echo "Claude desktop file not found" >&2
		return 1
	}
	sed -i \
		-e '0,/^Name=/{s/^Name=.*/Name=Claude\nName[ru]=Claude/}' \
		-e 's/^Categories=.*/Categories=Development;/' \
		"${desktop_file}"

	install -dm755 "${pkgdir}/usr/bin"
	ln -sfn /usr/lib/claude-desktop/claude-desktop "${pkgdir}/usr/bin/claude-desktop"

	install -dm755 "${pkgdir}/usr/share/licenses/claude-desktop"
	install-license "${srcdir}/LICENSE" "claude-desktop/LICENSE.nivora"
	install -Dm644 "${srcdir}/extracted/usr/share/doc/claude-desktop/copyright" \
		"${pkgdir}/usr/share/licenses/claude-desktop/copyright"
	install -Dm644 "${srcdir}/extracted/usr/lib/claude-desktop/LICENSES.chromium.html" \
		"${pkgdir}/usr/share/licenses/claude-desktop/LICENSES.chromium.html"
	install -Dm644 "${srcdir}/extracted/usr/lib/claude-desktop/resources/virtiofsd.LICENSE-APACHE" \
		"${pkgdir}/usr/share/licenses/claude-desktop/virtiofsd.LICENSE-APACHE"
	install -Dm644 "${srcdir}/extracted/usr/lib/claude-desktop/resources/virtiofsd.LICENSE-BSD-3-Clause" \
		"${pkgdir}/usr/share/licenses/claude-desktop/virtiofsd.LICENSE-BSD-3-Clause"
}

files() {
	files-find-binary
	files-find-desktop
	files-find-license
	files-find \
		"/usr/lib/claude-desktop/**/*" \
		"/usr/share/icons/hicolor/*/apps/claude-desktop.png"
}
