#!/bin/sh
# Backfill for the gnome-session helper systemd-xdg-autostart-generator(8) PATH-searches
# to evaluate AutostartCondition=. Debian does not ship it, so without this drop-in every
# such condition is silently dropped and the unit fires unconditionally.

[ "$1" = "--condition" ] || exit 1
shift

# shellcheck disable=SC2086
set -- $1
kind=$1
shift

case "$kind" in
	if-exists)
		[ -e "$1" ]
		;;
	unless-exists)
		[ ! -e "$1" ]
		;;
	GSettings)
		val=$(gsettings get "$1" "$2" 2>/dev/null)
		[ "$val" = "true" ]
		;;
	GNOME|GNOME3)
		case ":$XDG_CURRENT_DESKTOP:" in *:GNOME:*) exit 0 ;; esac
		exit 1
		;;
	IfSession)
		case ":$XDG_CURRENT_DESKTOP:" in *:"$1":*) exit 0 ;; esac
		exit 1
		;;
	UnlessSession)
		case ":$XDG_CURRENT_DESKTOP:" in *:"$1":*) exit 1 ;; esac
		exit 0
		;;
	*)
		exit 0
		;;
esac
