#!/bin/bash

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

donate() {
   ## Do not ask for donations if a bug occurred. More important things have to be sorted out.
   if [ "$BUG" = "1" ]; then
      return 0
   fi

   local MSG="<p>Please donate!
   See: <a href=${PROJECT_HOMEPAGE}/wiki/Donate>${PROJECT_HOMEPAGE}/wiki/Donate</a></p>"
   $output_cli ${output_opts[@]} --messagecli --typecli "info" --message "$MSG"

   ## Do not ask for donations if the user has something important to do.

   local TYPE output_status_exit_code

   output_status_exit_code="0"
   $output_general ${output_opts[@]} --identifier "$IDENTIFIER" --status --messagex || { output_status_exit_code="$?" ; true; };

   if [ "$output_status_exit_code" = "0" ]; then
      TYPE="$($output_general ${output_opts[@]} --identifier "$IDENTIFIER" --status --typexstatus)"
      if [ "$TYPE" = "info" ]; then
         local MSG="<p>Please <a href=${PROJECT_HOMEPAGE}/wiki/Donate>donate</a>!</p>"
         $output_x ${output_opts[@]} --messagex --typex "info" --message "$MSG"
      fi
   else
      true "No messages for --messagex in the queue. Not adding donation message."
      return 0
   fi

   return 0
}
