A little bit of smarter checks instead of blind sleeps

This commit is contained in:
Kuba Orlik 2022-05-25 21:35:55 +02:00
parent ae0f6fde8d
commit a0fea094f5

View File

@ -92,20 +92,22 @@ start_firefox(){
FIREFOX_PID=$! FIREFOX_PID=$!
while [ $(get_pixel_color 100 100) = "NONE" ] while [ $(get_pixel_color 100 100) = "NONE" ]
do do
echo "waiting for firefox to open the window"
sleep 0.1 sleep 0.1
done; done;
echo "firefox opened the window"
} }
prepare_firefox(){ prepare_firefox(){
xdotool key Return # in case there's a "firefox closed unexpectedly" button # xdotool key Return # in case there's a "firefox closed unexpectedly" button
sleep 1 # sleep 1
grab "after sleep 1" # grab "after sleep 1"
click 1886 13 #maximize button click 1886 13 #maximize button
grab "after maximize" grab "after maximize"
sleep 1 FIREFOX_WIDTH=$(wmctrl -lpG | grep Firefox | awk '{print $6}')
grab "after sleep 1" while [ "$FIREFOX_WIDTH" != "2880" ]
do
sleep 0.1
done
#grab "after sleep 1"
# no need to reopen the network tab, as it's almost certainly already open # no need to reopen the network tab, as it's almost certainly already open
# keycombo Control_L Shift_L e # keycombo Control_L Shift_L e
# grab "after ctrl+shift+e" # grab "after ctrl+shift+e"
@ -121,9 +123,15 @@ wait_for_pixel_color(){
y=$2; y=$2;
color=$3; color=$3;
timeout=$4; timeout=$4;
while [ $(get_pixel_color 143 122) = "#2e3436" ] start=$(timestamp)
while [ $(get_pixel_color 143 122) != "$color" ]
do do
sleep 0.1 sleep 0.1
ts=$(timestamp)
if [ $(( ts - start )) -gt $(( timeout * 1000 )) ]
then
return
fi
done done
} }
@ -155,7 +163,7 @@ load_website(){
open_network_inspector(){ open_network_inspector(){
keycombo Shift_L F5 #profiler keycombo Shift_L F5 #profiler
sleep 1 wait_for_pixel_color 1777 152 0a84ff 3
keycombo Control_L Shift_L e keycombo Control_L Shift_L e
} }