#!/bin/bash

## Copyright (C) 2012 - 2025 ENCRYPTED SUPPORT LLC <adrelanos@whonix.org>
## See the file COPYING for copying conditions.

## This file gets sourced by msgdispatcher and msgprogressbar.
## Therefore the error_handler function has been already load.

fallbacks() {
   trap "error_handler" ERR

   if [ "$DISPLAY" = "" ] && [ "$WAYLAND_DISPLAY" = "" ]; then
      no_gui="1"
   else
      no_gui="0"
   fi

   ## Check if 'yad' is installed.
   ## - This is not the case for cli users,
   ##   who removed yad or custom builds which never had 'yad' installed.
   if [ "$(command -v "yad")" = "" ] || [ "$no_gui" = "1" ]; then
      ## 'yad' is not installed or no Wayland / X server running.
      yad() {
         ## dummy
         true
      }
   fi

   if [ "$(command -v "kdialog")" = "" ] || [ "$no_gui" = "1" ]; then
      ## kdialog is not installed or no Wayland / X server running.
      kdialog() {
         ## dummy
         true
      }
   fi

   if [ "$(command -v "notify-send")" = "" ] || [ "$no_gui" = "1" ]; then
      ## notify-send is not installed or no Wayland / X server running.
      notify-send() {
         ## dummy
         true
      }
   fi
}
