Jump to content

User:Kyotonixx

From postmarketOS Wiki

HAIYAAA IM KYOOO !!!!! I LOVE LINUX AND FOSS !!

i fell down the rabbit hole of linux phones not too long ago, and now I’m hooked.

Webapps

so originally, i thought to use chromium for webapps because firefox just doesn't have that functionality, and the script on the postmarketos firefox page is outdated and non-functioning. but chromium doesn't function very well in my experience.

so i wrote an updated version of that script.

#!/usr/bin/env bash

# Installation check
if command -v firefox &> /dev/null
then
  firefoxinst=firefox

elif command -v firefox-esr &> /dev/null
then
  firefoxinst=firefox-esr

else
  echo "No Firefox installation found."
  exit 1 
fi

# Create firefox profile
set -e
name=$1
url=$2
# Ugly, copy-pasted from SO
simple_name=$(echo "$name" | awk '{print tolower($0)}' | sed 's/ //g')
echo "Creating webapp $name, using $url."

# ugly, i hate shell scripts can you tell....
$firefoxinst --headless -CreateProfile $simple_name
$firefoxinst --headless -P $simple_name &
echo "Initializing profile."
sleep 3
pkill $firefoxinst

profile_dir=$(find ~/.mozilla/firefox/ -maxdepth 1 | grep $simple_name)
mkdir -p "$profile_dir/chrome"

echo -e "\e[1;31mNOTICE: If you get an ambiguous redirect error, it is due to having multiple Firefox profiles with the same name. Otherwise, continue.\e[0m"

cat << EOF >> $profile_dir/chrome/userChrome.css
#nav-bar {
  visibility: collapse;
}

#TabsToolbar {
  visibility: collapse;
}

#statuspanel {
  visibility: collapse;
}
EOF

# Create desktop entry
cat >~/.local/share/applications/$simple_name.desktop <<EOL
[Desktop Entry]
Exec=$firefoxinst -P $simple_name $url
Icon=/home/user/.local/share/applications/$simple_name.png
Type=Application
Terminal=false
Name=$name
StartupNotify=true
StartupWMClass=firefox
EOL

# Get high quality icon from googles api
wget https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.google.com%2Fs2%2Ffavicons%3Fdomain%3D$url%26sz%3D128 -O /tmp/$simple_name.png
mv /tmp/$simple_name.png ~/.local/share/applications

save as add-webapp.sh

usage: ./add-webapp.sh "Hacker News" "https://news.ycombinator.com"

to reload the page, or go back/forward, just press and hold your finger down on any blank space, and a firefox menu thingy should pop up.


for the most part, i thought utilizing userChrome.css was a pretty clever idea, and i still think so :p

and also, you don't have to put up with shitty quality icons, which is something that definitely irked me off about the favicon.ico files.

hopefully, anyone who was in the same situation as me finds this, as that's the only reason i've shared this here.

Owns devices

Device Notes
OnePlus 6 (oneplus-enchilada) phosh daily driver, calls not working :<