#!/bin/bash

[ $# -eq 1 ] || exit 1
[ -x"$XDG_SESSION_TYPE" = -x"wayland" ] || exit 1
[ -e /etc/astra/machine_type ] || exit 1

machine_type=`cat /etc/astra/machine_type | head -1 | tr -s ' '`
machines_list=("KVADRAT.arm64.v1.rev1")

grep -q "$machine_type" <<<"$machines_list" || exit 1

util_name=`basename $0`
argv="$1"

case $argv in
    pre_hook )
        >&2 echo "$util_name: executing $argv for $machine_type"
        timeout 0.75s kscreen-doctor -d off
    ;;

    post_hook )
        >&2 echo "$util_name: executing $argv for $machine_type"
        timeout 0.75s kscreen-doctor -d on
    ;;

    trigger )
        >&2 echo "$util_name: executing $argv for $machine_type"
        timeout 0.75s kscreen-doctor -d off
        timeout 0.75s kscreen-doctor -d on
    ;;

    *) exit 1
esac
