'$"Para adicionar um WebApp,
você precisa informar a URL e o Nome."'
você precisa informar a URL e o Nome."'
'$"Para detectar o Nome e o Ícone,
você precisa informar a URL."'
você precisa informar a URL."'
'$"A URL é inválida ou a conexão falhou.
Tente inserir o ícone pelo botão Alterar."'
Tente inserir o ícone pelo botão Alterar."'
'$"O WebApp foi adicionado com sucesso!"'
'$"Selecione o ícone preferido:"'
'
CUSTOMFILES=""
if compgen -G ~/.local/share/applications/*-webapp-biglinux-custom.desktop >/dev/null;then
IFS=$'\n' read -r -d '' -a CUSTOMFILES < <(find ~/.local/share/applications -iname "*-webapp-biglinux-custom.desktop")
fi
# Start of gawk script
gawk -v development=$"Desenvolvimento" \
-v office=$"Escritório" \
-v graphics=$"Gráficos" \
-v game=$"Jogos" \
-v audiovideo=$"Multimídia" \
-v internet=$"Internet" \
-v google=$"Google" \
-v webapp=$"WebApps" \
-v nenhum=$"Nenhum WebApp adicionado!" \
-v apply=$"Aplicar" \
-v cancel=$"Cancelar" \
-v certeza=$"Tem certeza que deseja remover este WebApp?" \
-v restaurar=$"Importar Backup" \
-v backup=$"Criar Backup" \
-v all_remove=$"Remover WebApps" \
-v add=$"Adicionar WebApps" \
-v adicionar=$"Adicionar" -- '
BEGIN {
# This OFS helps writing readable code on printing
OFS = "\n"
# Sorts array indexes as strings in ascending order
# PROCINFO["sorted_in"] = "@ind_str_asc"
# Keep count of how many proper desktop files have been read
filesread = 0
}
BEGINFILE {
# If there is no suitable .desktop file, skips to the END block
if ( FILENAME == "-" ) {
++noinput
exit
}
allset = app_category = name_category = icon = name = deskexec = url = browser = browser_name = name_file = ""
}
/^Categories=/ {
app_category = gensub(/^Categories=|;/,"","g")
# Deploys translations over the name_category variable
# The untranslated texts are assigned using the -v argument in the first line of this script
switch ( app_category ) {
case /Development/:
name_category = development
break
case /Office/:
name_category = office
break
case /Graphics/:
name_category = graphics
break
case /Network/:
name_category = internet
break
case /Game/:
name_category = game
break
case /AudioVideo/:
name_category = audiovideo
break
case /Webapps/:
name_category = webapp
break
case /Google/:
name_category = google
break
default:
# Undefined category found. Skips to next file.
nextfile
}
}
/^Icon=/ {
icon = gensub(/^Icon=/,"",1)
}
/^Name=/ {
name = gensub(/^Name=/,"",1)
}
/^Exec=/ {
deskexec = gensub(/^Exec=/,"",1)
if ( /local\/bin/ ) {
# Reads the whole amofiexec file as a string, and removes the unimportant parts to keep the url
# More info about this maneuver:https://www.gnu.org/software/gawk/manual/html_node/Readfile-Function.html
RS_BAK = RS
RS = "^$"
getline amofiexec < deskexec
close(deskexec)
RS = RS_BAK
url = gensub(/.*new-instance "|" .*$/,"","g",amofiexec)
browser_amofiexec = gensub(/.*T_SANDBOX=1 | --cl.*$/,"","g",amofiexec)
switch(browser_amofiexec){
case /firefox/:
case /.*org.mozilla.firefox/:
browser_name = "firefox"
break
case /librewolf/:
case /.*io.gitlab.librewolf-community/:
browser_name = "librewolf"
break
}
} else if (/.*org.gnome.Epiphany/) {
url = $4
browser_name = "epiphany"
} else if (/falkon/) {
url = $NF
browser_name = "falkon"
} else {
url = gensub(/.*app=/,"",1)
browser_name = gensub(/^Exec=/,"",1,$1)
}
}
{
switch( browser_name ) {
case /brave/:
case /.*com.brave.Browser/:
browser = "icons/brave.svg"
break
case /google-chrome-stable/:
case /.*com.google.Chrome/:
browser = "icons/chrome.svg"
break
case /chromium/:
case /.*org.chromium.Chromium/:
browser = "icons/chromium.svg"
break
case /.*com.github.Eloston.UngoogledChromium/:
browser = "icons/ungoogled.svg"
break
case /microsoft-edge-stable/:
case /.*com.microsoft.Edge/:
browser = "icons/edge.svg"
break
case /epiphany/:
browser = "icons/epiphany.svg"
break
case /firefox/:
browser = "icons/firefox.svg"
break
case /falkon/:
browser = "icons/falkon.svg"
break
case /librewolf/:
browser = "icons/librewolf.svg"
break
case /vivaldi-stable/:
browser = "icons/vivaldi.svg"
break
}
name_file = gensub(/.*\//, "", 1, FILENAME)
}
# If all variables are set, skip to ENDFILE block
app_category && name_category && icon && name && deskexec && url && browser {
++allset
nextfile
}
# Runs after each file is read, or when nextfile statement is called
ENDFILE {
# Only includes webapps if all variables are set (app_category, name_category, icon, name, etc.)
if ( allset ) {
app_array[app_category][FILENAME]["name_file"] = name_file
app_array[app_category]["name_category"] = name_category
app_array[app_category][FILENAME]["name_category"] = name_category
app_array[app_category][FILENAME]["icon"] = icon
app_array[app_category][FILENAME]["name"] = name
app_array[app_category][FILENAME]["url"] = url
app_array[app_category][FILENAME]["browser"] = browser
++filesread
}
}
# Runs after all desktop files are read, or if there is no desktop file at all
END {
if ( ( noinput > 0) || ( filesread == 0 ) ) {
print(\
" ",
"
") } } ' "${CUSTOMFILES[@]}" # End of gawk script echo -n '
",
"
",
" ")
# Because there is no desktop file, we shall exit the script now
exit
}
{
print(\
" ")
}
n=0
for ( app_category in app_array ) {
# Prints header of the category
print(\
" ",
"
",
" " nenhum "
",
" - ",
"
- ", " ", " ", " ", "
",
"
",
" ",
app_array[app_category]["name_category"], "()",
"
",
" - ")
for ( filename in app_array[app_category] ) {
# Skips "name_category" index from the app_array[app_category] array
if ( filename == "name_category" ) {
continue
}
# Prints info about each webapp installed by the user
print(\
"
- ",
" ", " ", "", "" app_array[app_category][filename]["name"] "", "
", " ", " ", " ", " ", "
", "", "" certeza "", " ", " ")
n++
}
print("
") } } ' "${CUSTOMFILES[@]}" # End of gawk script echo -n '
'$"Editar WebApp"'
'$"O backup dos WebApps foi salvo em: "'
'$"Os WebApps foram restaurados com sucesso!"'
'$"Você deseja remover todos os WebApps?"'
'
BROWSER=$(<~/.bigwebapps/BROWSER)
case "$BROWSER" in
brave)
ICON='brave'
if [ ! -e /usr/lib/brave-browser/brave ] && [ ! -e /opt/brave-bin/brave ];then
ICON='none'
title='title="'$"O navegador não está instalado!"'"'
else
title='title="'$"BRAVE"'"'
fi
;;
google-chrome-stable)
ICON='chrome'
if [ ! -e /opt/google/chrome/google-chrome ];then
ICON='none'
title='title="'$"O navegador não está instalado!"'"'
else
title='title="'$"CHROME"'"'
fi
;;
chromium)
ICON='chromium'
if [ ! -e /usr/lib/chromium/chromium ];then
ICON='none'
title='title="'$"O navegador não está instalado!"'"'
else
title='title="'$"CHROMIUM"'"'
fi
;;
microsoft-edge-stable)
ICON='edge'
if [ ! -e /opt/microsoft/msedge/microsoft-edge ];then
ICON='none'
title='title="'$"O navegador não está instalado!"'"'
else
title='title="'$"EDGE"'"'
fi
;;
firefox)
ICON='firefox'
if [ ! -e /usr/lib/firefox/firefox ];then
ICON='none'
title='title="'$"O navegador não está instalado!"'"'
else
title='title="'$"FIREFOX"'"'
fi
;;
falkon)
ICON='falkon'
if [ ! -e /usr/bin/falkon ];then
ICON='none'
title='title="'$"O navegador não está instalado!"'"'
else
title='title="'$"FALKON"'"'
fi
;;
librewolf)
ICON='librewolf'
if [ ! -e /usr/lib/librewolf/librewolf ];then
ICON='none'
title='title="'$"O navegador não está instalado!"'"'
else
title='title="'$"LIBREWOLF"'"'
fi
;;
vivaldi-stable)
ICON='vivaldi'
if [ ! -e /opt/vivaldi/vivaldi ];then
ICON='none'
title='title="'$"O navegador não está instalado!"'"'
else
title='title="'$"VIVALDI"'"'
fi
;;
com.brave.Browser)
ICON='brave'
if [ ! -e /var/lib/flatpak/exports/bin/com.brave.Browser ];then
ICON='none'
title='title="'$"O navegador não está instalado!"'"'
else
title='title="'$"BRAVE (FLATPAK)"'"'
fi
;;
com.google.Chrome)
ICON='chrome'
if [ ! -e /var/lib/flatpak/exports/bin/com.google.Chrome ];then
ICON='none'
title='title="'$"O navegador não está instalado!"'"'
else
title='title="'$"CHROME (FLATPAK)"'"'
fi
;;
org.chromium.Chromium)
ICON='chromium'
if [ ! -e /var/lib/flatpak/exports/bin/org.chromium.Chromium ];then
ICON='none'
title='title="'$"O navegador não está instalado!"'"'
else
title='title="'$"CHROMIUM (FLATPAK)"'"'
fi
;;
com.github.Eloston.UngoogledChromium)
ICON='chromium'
if [ ! -e /var/lib/flatpak/exports/bin/com.github.Eloston.UngoogledChromium ];then
ICON='none'
title='title="'$"O navegador não está instalado!"'"'
else
title='title="'$"UNGOOGLED (FLATPAK)"'"'
fi
;;
com.microsoft.Edge)
ICON='edge'
if [ ! -e /var/lib/flatpak/exports/bin/com.microsoft.Edge ];then
ICON='none'
title='title="'$"O navegador não está instalado!"'"'
else
title='title="'$"EDGE (FLATPAK)"'"'
fi
;;
org.mozilla.firefox)
ICON='firefox'
if [ ! -e /var/lib/flatpak/exports/bin/org.mozilla.firefox ];then
ICON='none'
title='title="'$"O navegador não está instalado!"'"'
else
title='title="'$"FIREFOX (FLATPAK)"'"'
fi
;;
io.gitlab.librewolf-community)
ICON='librewolf'
if [ ! -e /var/lib/flatpak/exports/bin/io.gitlab.librewolf-community ];then
ICON='none'
title='title="'$"O navegador não está instalado!"'"'
else
title='title="'$"LIBREWOLF (FLATPAK)"'"'
fi
;;
*):;;
esac
if [ $COUNT_BROWSER -eq 0 ];then
ICON='none'
title='title="'$"Não existem navegadores compatíveis instalados no sistema!"'"'
fi
echo -n '
'
if [ $COUNT_BROWSER -eq 0 ];then
echo -n '
'$"Navegador padrão
dos WebApps:"'
dos WebApps:"'
'$"Não existem navegadores compatíveis instalados no sistema!"'
'$"Selecione o navegador preferido:"'
'
if [ "$NATIVE" = "true" ];then
echo -n ''$"Nativo"'
'
fi
if [ "$FLATPAK" = "true" ];then
echo -n ''$"Flatpak"'
'
fi
echo -n ''$"WebApps Nativos"'
- '
IFS=$'\n' read -r -d '' -a files < <(find ./webapps -iname "*-webapp-biglinux.desktop")
gawk -v browser="${ICON}" '
BEGIN {
# This OFS helps write readable code on printing
OFS = "\n"
# Grabs localization language, e.g., en_US.UTF-8 --> en
lang = gensub(/[._].*/,"",1,ENVIRON["LANG"])
}
# BEGINFILE block runs before each file is read
BEGINFILE {
# Resets current webapp variables
name = namelang = icon = urldesk = url = ""
webapp = gensub(/.+\//,"","g",FILENAME)
# n counts the webapps
++n
}
# Ternary condition checks if name has already been localized
# This may happen depending on position of Name= and Name[XX]= on file
/^Name=/ {
name = ( name ) ? ( name ) :gensub(/^Name=/,"",1)
}
# Localizing name
$0 ~ "^Name\\["lang {
name = gensub(/^Name\[.+\]=/,"",1)
namelang = "localized"
}
# Grabs icon
/^Icon=/ {
icon = gensub(/^Icon=/,"",1)
}
# Grabs url for the browser and for bbv
/^Exec=/ {
urldesk = gensub(/^Exec=|"/,"","g")
url = gensub(/.*--app=/,"","g")
}
# Skips to next file if all the variables are already set
name && namelang && icon && urldesk && url {
nextfile
}
# ENDFILE block runs after each file is read
ENDFILE {
# Checks if webapp is installed
if ( system("[ ! -e ~/.local/share/applications/"webapp" ]") ) {
color = "green"
checked = "checked"
disabled = ""
} else {
color = "gray"
checked = ""
disabled = "disabled"
}
### Printing the HTML ###
# The comma between strings returns the OFS variable, which was set in the BEGIN block as \n to create a line break at the html code
#
# Caution:
# some double quotes (") are being escaped, and others are real double quotes which opens and closes strings to concatenate gawk variables
print(\
"
- ",
" ",
" ", "", " ", " ", "
", name, "
", " ", " ", url, " ", "", " ", "", "
")
}' "${files[@]}"
# End of gawk script
echo -n '