pinephone-scripts

Scripts and small applications for the PinePhone
git clone https://src.jayvii.de/pub/pinephone-scripts.git
Log | Files | Refs | README | LICENSE

lock (1089B)


      1 #!/usr/bin/env sh
      2 
      3 function suspend_after_x() {
      4     
      5     # Initial timeout
      6     sleep $1
      7 
      8     # As long as media is running / sound is playing, do not suspend.
      9     while [ $(check_player_state) == "true" ]; do
     10         sleep $1
     11     done
     12     
     13     # If screen is locked, suspend immediately again.
     14     if [ ! -z $(pidof sxmo_screenlock) ]; then
     15         #pkill -9 sxmo_screenlock # probably not necessary...
     16         if [ -z $SXMO_RTCWAKEINTERVAL ]; then
     17             sxmo_screenlock --suspend
     18         else
     19             sxmo_screenlock --suspend --wake-interval $SXMO_RTCWAKEINTERVAL
     20         fi
     21     fi
     22 
     23     # Post wake: reset backlight again
     24     sxmo_setpinebacklight $2
     25 }
     26 
     27 function check_player_state {
     28     if [[ -z $(pacmd list-sink-inputs | grep "state: RUNNING$") ]]; then
     29         echo false
     30     else
     31         echo true
     32     fi
     33 }
     34 
     35 # Current backlight?
     36 CUR_BL=$(cat /sys/class/backlight/backlight/brightness)
     37 
     38 SXMO_LOCK_SUSPEND_AFTER_X=30 # that should be in .profile or .xinitrc
     39 
     40 if [! -z $SXMO_LOCK_SUSPEND_AFTER_X ]; then
     41     suspend_after_x $SXMO_LOCK_SUSPEND_AFTER_X $CUR_BL &
     42 fi
     43 
     44 # EOF lock