Skip to content

Instantly share code, notes, and snippets.

@tong
Last active April 7, 2022 20:45
Show Gist options
  • Save tong/6aa3c7268b18ec1eae1fb01a46233e1b to your computer and use it in GitHub Desktop.
Save tong/6aa3c7268b18ec1eae1fb01a46233e1b to your computer and use it in GitHub Desktop.
#!/bin/sh
## Armory3D html5 player launcher
if ! [[ $1 =~ https?://.* ]]; then
echo "invalid url"
exit
fi
#if [ -z "$1" ] || [ $1 != http?(s)://* ]; then
#echo "Usage: armory-browser <url>"
#exit 1
#fi
if [ -z "$ARMORY_BROWSER_OPTIONS" ]; then
echo "ARMORY_BROWSER_OPTIONS environment variable not set"
fi
if [ -z "$ARMORY_BROWSER" ]; then
BIN=`xdg-settings get default-web-browser`
else
BIN=$ARMORY_BROWSER
fi
URL=$1
WIDTH=1920
HEIGHT=1080
FULLSCREEN=1
VSYNC=0
DEVTOOLS=1
START_DELAY=0.2
#parse_options() {
#echo "PARSE"
#IFS=','
#read -ra opts <<< "$1"
##echo $opts
#IFS='='
#for opt in "${opts[@]}"; do
#read -ra kv <<< "$opt"
#k=${kv[0]}
#v=${kv[1]}
#echo "$k $v"
#done
#}
IFS=','
read -ra opts <<< "$ARMORY_BROWSER_OPTIONS"
IFS='='
for opt in "${opts[@]}"; do
read -ra kv <<< "$opt"
k=${kv[0]}
v=${kv[1]}
case $k in
"width") WIDTH=$v;;
"height") HEIGHT=$v;;
"fullscreen") FULLSCREEN=$v;;
"vsync") VSYNC=$v;;
"devtools") DEVTOOLS=$v;;
*) echo "Unknown option: ${k}";;
esac
done
case $BIN in
brave|chrome|chromium|opera)
ARGS=""
ARGS+=" --disable-metrics"
ARGS+=" --user-data-dir=/tmp"
if [ $FULLSCREEN -eq 0 ]; then
ARGS+=" --start-fullscreen"
else
ARGS+=" --new-window"
ARGS+=" --window-size=${WIDTH},${HEIGHT}"
fi
if [ $DEVTOOLS -eq 0 ]; then ARGS+=" --auto-open-devtools-for-tabs"; fi
if [ $VSYNC -eq 0 ]; then ARGS+=" --disable-gpu-vsync"; fi
ARGS+=" --app=${URL}"
echo $ARGS
;;
firefox)
ARGS="--new-window"
#ARGS+=" --safe-mode"
ARGS+=" --window-size $W $H"
ARGS+=" $URL"
;;
esac
if [ ! -z "$ARMORY_BROWSER_EXTRA_OPTIONS" ]; then
#parse_options $ARMORY_BROWSER_EXTRA_OPTIONS
ARGS+=" $ARMORY_BROWSER_EXTRA_OPTIONS"
fi
[ START_DELAY > 0 ] && sleep $START_DELAY
echo "Launching armory browser"
echo "$BIN $ARGS"
eval "$BIN $ARGS"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment