#!/usr/bin/env bash

# omarchy:summary=Install a supported browser
# omarchy:args=<chrome|brave|edge|firefox|zen>
# omarchy:examples=omarchy install browser firefox | omarchy install browser brave

# Based: the browsers the AUR carried come from Flathub, and so does Firefox,
# which Based editions pin out of apt. A sandboxed browser reads none of the
# host's policy directories, so the theme policy the packaged browsers get
# stays behind. Chrome still takes Omarchy's flags from ~/.config, which the
# image's flatpak override lets it read.
announce_browser_installed() {
  echo ""
  echo "$1 installed from Flathub."
}

install_flatpak_browser() {
  echo "Installing $1..."
  omarchy-pkg-flatpak-add "$2" || exit 1
}

case $1 in
chrome)
  install_flatpak_browser Chrome com.google.Chrome
  mkdir -p ~/.config
  cp -f "$OMARCHY_PATH/config/chromium-flags.conf" ~/.config/chrome-flags.conf
  announce_browser_installed Chrome
  ;;
edge)
  install_flatpak_browser Edge com.microsoft.Edge
  announce_browser_installed Edge
  ;;
brave)
  install_flatpak_browser Brave com.brave.Browser
  announce_browser_installed Brave
  ;;
firefox)
  install_flatpak_browser Firefox org.mozilla.firefox
  announce_browser_installed Firefox
  ;;
zen)
  install_flatpak_browser Zen app.zen_browser.zen
  announce_browser_installed Zen
  ;;
*)
  echo "Usage: omarchy-install-browser <chrome|brave|edge|firefox|zen>"
  exit 1
  ;;
esac
