#!/bin/sh

has_desktop() {
  [ -f "$HOME/.local/share/applications/$1" ] || [ -f "/usr/share/applications/$1" ]
}

set_default_if_available() {
  desktop_id="$1"
  mime_type="$2"

  if has_desktop "$desktop_id"; then
    xdg-mime default "$desktop_id" "$mime_type" >/dev/null 2>&1 || true
  fi
}

set_default_if_available org.kde.gwenview.desktop image/jpeg
set_default_if_available org.kde.gwenview.desktop image/png
set_default_if_available org.kde.gwenview.desktop image/webp
set_default_if_available org.kde.gwenview.desktop image/gif

set_default_if_available org.gnome.Papers.desktop application/pdf
set_default_if_available io.github.celluloid_player.Celluloid.desktop video/mp4
set_default_if_available io.github.celluloid_player.Celluloid.desktop video/webm
set_default_if_available io.github.celluloid_player.Celluloid.desktop video/mpeg
set_default_if_available celluloid.desktop video/x-matroska

set_default_if_available userapp-Thunderbird-MTXOJ3.desktop x-scheme-handler/mailto
set_default_if_available userapp-Thunderbird-MTXOJ3.desktop x-scheme-handler/mid
set_default_if_available lmstudio.desktop x-scheme-handler/lmstudio
