Skip to content

Instantly share code, notes, and snippets.

@aarestu
Last active February 3, 2023 02:16
Show Gist options
  • Save aarestu/a8f8db3c50dc4ba5c9a64a5abc9a7623 to your computer and use it in GitHub Desktop.
Save aarestu/a8f8db3c50dc4ba5c9a64a5abc9a7623 to your computer and use it in GitHub Desktop.
one command to install Nativefier, create desktop app for any web site also make shortcut icon for you [tested on Pop!_OS]
#!/bin/bash
if ! command -v node &> /dev/null
then
echo "nodejs could not be found"
sudo apt install -y nodejs
fi
if ! command -v npm &> /dev/null
then
echo "npm could not be found"
sudo apt install -y npm
fi
if ! command -v nativefier &> /dev/null
then
echo "nativefier could not be found"
sudo npm install -g nativefier
fi
TARGET_PATH=~/.local/share/nativefier
mkdir -p $TARGET_PATH
SHORTCUT_TARGET_PATH=~/.local/share/applications
mkdir -p $SHORTCUT_TARGET_PATH
ARGS_NATIVEFIER=$@
while test $# -gt 0
do
case "$1" in
-*) PARAM="$1"
;;
*) if [ "$PARAM" = "-n" ] || [ "$PARAM" = "--name" ]
then
APP_NAME=$1
unset PARAM
else
APP_URL=$1
fi
;;
esac
shift
done
if [ -z "$APP_NAME" ]
then
>&2 echo "Please provide -n or --name argument for the application name."
exit 2
fi
regex='(https?://)[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]'
if [[ ! $APP_URL =~ $regex ]]
then
echo "Web Link not valid"
exit 0
fi
nativefier -p linux --tray -a x64 ${ARGS_NATIVEFIER} ${TARGET_PATH}
SHORTCUT_TARGET_PATH_FULL="${SHORTCUT_TARGET_PATH}/nativefier.web.${APP_NAME// /}.desktop"
echo "App built shortcut to ${SHORTCUT_TARGET_PATH_FULL}"
cat > "$SHORTCUT_TARGET_PATH_FULL" <<- EOM
[Desktop Entry]
Type=Application
Name=${APP_NAME}
Icon=${TARGET_PATH}/${APP_NAME}-linux-x64/resources/app/icon.png
Exec=${TARGET_PATH}/${APP_NAME}-linux-x64/${APP_NAME// /}
Categories=Network
EOM

Installation

sudo curl https://gist.githubusercontent.com/aarestu/a8f8db3c50dc4ba5c9a64a5abc9a7623/raw/web2app -o /usr/bin/web2app && sudo chmod +x /usr/bin/web2app

Usage

$ web2app -n Whatsapp https://web.whatsapp.com/ 
@MercMayhem
Copy link

Hey man, how do you uninstall the desktop app which is created?

@aarestu
Copy link
Author

aarestu commented Jul 31, 2020

Hey man, how do you uninstall the desktop app which is created?

@MercMayhem you can remove directory under
~/.local/share/nativefier
and remove icon in:
~/.local/share/applications

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment