#!/bin/bash

DIRECTORY="$(dirname "$(dirname "$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )")")"

function error {
  echo -e "\\e[91m$1\\e[39m"
  exit 1
}

cd $HOME
mkdir -p ~/WhatsappWeb/userdata

echo "#!/bin/bash
chromium-browser %U --user-agent='Mozilla/5.0 (X11; CrOS armv7l 11895.95.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.125 Safari/537.36' --user-data-dir=$HOME/WhatsappWeb/userdata --app=https://web.whatsapp.com/  --window-size=1200,700" > ~/WhatsappWeb/whatsappweb.sh
sudo chmod +x ~/WhatsappWeb/whatsappweb.sh

echo "[Desktop Entry]
Name=Whatsapp Web
Comment=Whatsapp Web webapp.
Exec=$HOME/WhatsappWeb/whatsappweb.sh
Path=$HOME/WhatsappWeb
Icon=$(dirname "$0")/icon-64.png
Terminal=false
StartupNotify=true
Type=Application
Categories=Network;" > ~/.local/share/applications/whatsappweb.desktop || error "Failed to create menu button!"
