Home > Software design >  Why is this if statement forcing zenity's --auto-close to close immediately?
Why is this if statement forcing zenity's --auto-close to close immediately?

Time:10-22

Got a Debian package set up for a little application I was working on, this isn't really relevant for the question but for some context, the application is a simple bash script that deploys some docker containers on the local machine. But I wanted to add a dependency check to make sure the system had docker before it attempted to do anything. If it doesn't, download it, if it does, ignore it. Figured it be nice to have a little zenity dialog alongside it to show what was going on.

In that process, I check for internet before starting for obvious reasons and for some reason, the way I check if there is internet if zenity has the --auto-close flag, will instantly close the entire progress block.

Here is a little dummy example, that if statement is a straight copy-paste from my code, everything else is filler. :

#!/bin/bash
condition=0
if [[ $condition ]]; then
(
    echo "0"
    # Check for internet
    if ping -c 3 -W 3 gcr.io; then
        echo "# Internet detected, starting updates..."; sleep 1
        echo "10"
    else            
        err_msg="# No internet detected. You may be missing some dependencies. 
        Services may not function as expected until they are installed."
        echo $err_msg
        zenity --error --text="$err_msg"
        echo "100"
        exit 1
    fi
    
    echo "15"

    echo "# Downloading a thing" ; sleep 1
    echo "50" 
    if zenity --question --text="Do you want to download a special thing?"; then
        echo "# Downloading special thing" ; sleep 1
    else
        echo "# Not downloading special thing" ; sleep 1
    fi
    echo "75" 
    echo "# downloading big thing" ; sleep 3
    echo "90"
    echo "# Downloading last thing" ; sleep 1
    echo "100" 
) | 
zenity --progress --title="Dependency Management" --text="downloading dependencies, please wait..." \
--percentage=0 --auto-close
fi

So im really just wondering why this is making zenity freak-out. If you comment out that if statement, everything works as you expect and zenity progress screen closes once it hits 100. If you keep the if statement but remove the auto-close flag, it will execute as expected. It's like its initializing at 100 and then going to 0 to progress normally. But if that was the case, --auto-close would never work but in the little example they give you in the help section, it works just fine. https://help.gnome.org/users/zenity/stable/progress.html.en

CodePudding user response:

Thank you for a fun puzzle! Spoiler is at the end, but I thought it might be helpful to look over my shoulder while I poked at the problem.

  • Related