# Font-icon directories
FONT_DIRS="/usr/share/fonts/TTF /usr/share/fonts/OTF /usr/share/fonts/misc"
ICON_DIR="/usr/share/icons/hicolor"
GLIB_SCHEMA_DIR="usr/share/glib-2.0/schemas"

# Font-related commands
update_fonts() {
  mkfontscale "$FONT_DIRS" >/dev/null 2>&1
  mkfontdir "$FONT_DIRS" >/dev/null 2>&1
  fc-cache -s >/dev/null
}

# GTK related commands
update_gtk() {
  glib-compile-schemas $GLIB_SCHEMA_DIR
  gtk-update-icon-cache -ftq $ICON_DIR
  /bin/sh -c 'dconf update'
}

# Post installation
post_install() {
  update_fonts
  update_gtk
}

# Post upgrade
post_upgrade() {
  post_install
  if [[ $(vercmp 4.0.1-1 $2) -gt 0 ]] && [ -f /etc/sddm.conf.d/kde_settings.conf ] && grep -qe "^Current=Dr460nized-Sugar-Candy$" /etc/sddm.conf.d/kde_settings.conf; then
    rm -f /etc/sddm.conf.d/kde_settings.conf
  fi
}
