pkgname=dida
pkgver=8.0.10
pkgrel=1
pkgdesc='DIDA is a powerful to-do & task management app with seamless cloud synchronization across all your devices. Whether you need to schedule an agenda, make memos, share shopping lists, collaborate in a team, or even develop a new habit, DIDA is always here to help you get stuff done and keep life on track.'
arch=('x86_64')
url='https://www.dida365.com/about/download'
license=('custom')
depends=('alsa-lib' 'gtk3' 'nss')
provides=('dida365')
conflicts=('dida365')
source=("${pkgname}-${pkgver}.deb::https://cdn.dida365.cn/download/linux/linux_deb_x64/${pkgname}-${pkgver}-amd64.deb"
	"LICENSE::https://dida365.com/tos")
sha256sums=('cf3e25f360d55924f5f2aca7ebe6dc7866f645d596df011e47a01eabb5e3d183'
            'dc9eb0c8f4fcab5a37b1025d61b29d3da4cfbe04e22c53a26a67cd2822cf78dd')

package() {
  cd "${srcdir}"

  tar -xf data.tar.xz -C "${pkgdir}"
  gunzip "${pkgdir}/usr/share/doc/${pkgname}/changelog.gz"

  # Use symlink to run the program
  sed -i 's/^Exec=.*/Exec=dida %U/' "${pkgdir}/usr/share/applications/dida.desktop"

  mkdir -p "${pkgdir}/usr/lib" "${pkgdir}/usr/bin/"
  mv "${pkgdir}/opt/dida" "${pkgdir}/usr/lib/${pkgname}"
  rmdir "${pkgdir}/opt"
  ln -srf "${pkgdir}/usr/lib/${pkgname}/dida" "${pkgdir}/usr/bin/dida"

  # Install license from https://dida365.com/about/tos
  install -Dm644 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
  # Included licenses in .deb
  mv "${pkgdir}/usr/lib/${pkgname}/LICENSE.electron.txt" \
    "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE.electron.txt"
  mv "${pkgdir}/usr/lib/${pkgname}/LICENSES.chromium.html" \
    "${pkgdir}/usr/share/licenses/${pkgname}/LICENSES.chromium.html"
}
