[TASK] Better handle when spectacle is active for a long time
This commit is contained in:
+23
-1
@@ -5,6 +5,10 @@ FORMAT="png"
|
|||||||
SIMILARITY_DELETE_TRESHOLD=100
|
SIMILARITY_DELETE_TRESHOLD=100
|
||||||
HTML_THUMB_WIDTH=200
|
HTML_THUMB_WIDTH=200
|
||||||
SCALE="50%"
|
SCALE="50%"
|
||||||
|
# Max time (in seconds) to wait before forcing a screenshot even if spectacle is running
|
||||||
|
SPECTACLE_BLOCKED_TIMEOUT=600 # 10 minutes
|
||||||
|
|
||||||
|
SPECTACLE_BLOCKED_FILE="$HOME/.cache/screenshot-spectacle-blocked"
|
||||||
|
|
||||||
DAY=`date +%Y-%m-%d`
|
DAY=`date +%Y-%m-%d`
|
||||||
TIME=`date +%H.%M.%S.%3N`
|
TIME=`date +%H.%M.%S.%3N`
|
||||||
@@ -16,9 +20,24 @@ SCR_LAST=`ls -t $DIR/$DAY/*.png | head -n1`
|
|||||||
if [ "$XDG_CURRENT_DESKTOP" = "KDE" ]
|
if [ "$XDG_CURRENT_DESKTOP" = "KDE" ]
|
||||||
then
|
then
|
||||||
if pgrep -x spectacle > /dev/null; then
|
if pgrep -x spectacle > /dev/null; then
|
||||||
echo "`date`: Spectacle is already running; skipping screenshot"
|
# Spectacle is running; check if we've been blocked for too long
|
||||||
|
if [ -f "$SPECTACLE_BLOCKED_FILE" ]; then
|
||||||
|
BLOCKED_SINCE=`cat "$SPECTACLE_BLOCKED_FILE"`
|
||||||
|
NOW=`date +%s`
|
||||||
|
BLOCKED_FOR=$(( NOW - BLOCKED_SINCE ))
|
||||||
|
if [ "$BLOCKED_FOR" -ge "$SPECTACLE_BLOCKED_TIMEOUT" ]; then
|
||||||
|
echo "`date`: Spectacle has been blocking screenshot for ${BLOCKED_FOR}s (>= ${SPECTACLE_BLOCKED_TIMEOUT}s); forcing screenshot"
|
||||||
|
else
|
||||||
|
echo "`date`: Spectacle is already running (blocked for ${BLOCKED_FOR}s); skipping screenshot"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
# First time we're being blocked; record the timestamp
|
||||||
|
date +%s > "$SPECTACLE_BLOCKED_FILE"
|
||||||
|
echo "`date`: Spectacle is already running; skipping screenshot (recording block time)"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
spectacle -bn -o $SCR_NEW
|
spectacle -bn -o $SCR_NEW
|
||||||
else
|
else
|
||||||
import -window root $SCR_NEW
|
import -window root $SCR_NEW
|
||||||
@@ -38,6 +57,9 @@ fi
|
|||||||
|
|
||||||
echo $DISTANCE between $SCR_LAST and $SCR_NEW
|
echo $DISTANCE between $SCR_LAST and $SCR_NEW
|
||||||
IS_SIMILAR=`echo "$DISTANCE < $SIMILARITY_DELETE_TRESHOLD" | bc`
|
IS_SIMILAR=`echo "$DISTANCE < $SIMILARITY_DELETE_TRESHOLD" | bc`
|
||||||
|
# Clean up the blocked-file now that a screenshot succeeded
|
||||||
|
rm -f "$SPECTACLE_BLOCKED_FILE"
|
||||||
|
|
||||||
if [ "$IS_SIMILAR" = "1" ]
|
if [ "$IS_SIMILAR" = "1" ]
|
||||||
then
|
then
|
||||||
rm $SCR_NEW
|
rm $SCR_NEW
|
||||||
|
|||||||
Reference in New Issue
Block a user