When visiting a mesh site choose from a list of users

This commit is contained in:
Bob Mottram 2017-12-09 10:56:22 +00:00
parent 64d843d615
commit dec2f54a1b
1 changed files with 53 additions and 30 deletions

View File

@ -49,9 +49,13 @@ if [ ! -f $USERS_FILE ]; then
exit 0
fi
data=$(zenity --entry --title="Visit IPFS site" --text="Enter the username or Tox ID for the site you wish to visit")
sel=$?
case $sel in
USERS_FILE_LINES=$(wc -l $USERS_FILE | awk -F ' ' '{print $1}')
if [ $USERS_FILE_LINES -gt 200 ]; then
# If there are more than a Dunbar number of peers then ask for the peer name or ID
data=$(zenity --entry --title="Visit IPFS site" --text="Enter the username or Tox ID for the site you wish to visit")
sel=$?
case $sel in
0)
TOX_USERNAME_OR_ID="$data"
if [ ${#TOX_USERNAME_OR_ID} -gt 0 ]; then
@ -63,14 +67,10 @@ case $sel in
if [ ${#TOX_ID} -gt 5 ]; then
if ! grep -q "$TOX_ID" $IPFS_USERS_FILE; then
dialog --title $"Visit IPFS site" \
--backtitle $"Freedombone mesh" \
--msgbox $"An IPFS site was not found for the user '$TOX_USERNAME_OR_ID'" 8 60
zenity --info --title $"Visit a site" --text $"An IPFS site was not found for the user '$TOX_USERNAME_OR_ID'" --width 500
exit 3
fi
IPFS_FULL_URL=${IPFS_URL}/$(cat "$IPFS_USERS_FILE" | grep $TOX_ID | head -n 1 | awk -F ':' '{print $2}')
clear
echo $'Opening browser. Please wait...'
pkill $BROWSER
setsid sh -c "$BROWSER $BROWSER_OPTIONS $IPFS_FULL_URL$SUFFIX" > /dev/null 2>&1 < /dev/null &
@ -81,6 +81,29 @@ case $sel in
exit 1
fi
;;
esac
esac
else
# If there are a relatively small number of users then choose from a list
TOX_ID=$(
cat $USERS_FILE | \
awk -F ' ' '{
for(i=1;i<=NF;i++){
print $i;
}
}' | \
zenity --list \
--title='Visit the site of another user' \
--column='Username' --column='Tox ID' \
--print-column=2 --hide-column=2 --width=300 --height=400)
if [ ! $TOX_ID ]; then
exit 0
fi
IPFS_FULL_URL=${IPFS_URL}/$(cat "$IPFS_USERS_FILE" | grep $TOX_ID | head -n 1 | awk -F ':' '{print $2}')
pkill $BROWSER
setsid sh -c "$BROWSER $BROWSER_OPTIONS $IPFS_FULL_URL$SUFFIX" > /dev/null 2>&1 < /dev/null &
# Need to wait a while for the browser to begin opening
sleep 3
fi
exit 0