#!/usr/bin/env bash
set -x

FlagsForChromium="--ozone-platform=wayland --disk-cache-dir=/dev/null --enable-features=WaylandWindowDecorations --disable-features=ExtensionManifestV2Unsupported,ExtensionManifestV2Disabled $@"

if [[ -d "$HOME/.config/google-chrome-canary" && -d "$HOME/.cache/google-chrome-canary" ]]; then
	/usr/bin/google-chrome-canary $FlagsForChromium
elif [[ -d "$HOME/.config/google-chrome-unstable" && -d "$HOME/.cache/google-chrome-unstable" ]]; then
	/usr/bin/google-chrome-unstable $FlagsForChromium
elif [[ -d "$HOME/.config/google-chrome-beta" && -d "$HOME/.cache/google-chrome-beta" ]]; then
	/usr/bin/google-chrome-beta $FlagsForChromium
elif hash google-chrome-stable 2> /dev/null; then
	/usr/bin/google-chrome-stable $FlagsForChromium
elif hash google-chrome-beta 2> /dev/null; then
	/usr/bin/google-chrome-beta $FlagsForChromium
elif hash google-chrome-unstable 2> /dev/null; then
	/usr/bin/google-chrome-unstable $FlagsForChromium
elif hash google-chrome-canary 2> /dev/null; then
	/usr/bin/google-chrome-canary $FlagsForChromium
elif hash com.google.Chrome 2> /dev/null; then
	com.google.Chrome $FlagsForChromium
else
	chromiuma "$@"
fi
set +x
