#!/bin/bash
# ============================================================
# firefox.sh — Mozilla Firefox browser (Flatpak)
# ============================================================
# Installs Firefox via Flatpak rather than from the official
# Arch repos or AUR.  The Flatpak version is sandboxed, ships
# with its own bundled libraries (avoiding libpulse/libx11
# version conflicts), and auto-updates independently of the
# system package manager.
#
# Firefox is offered as an optional module because some users
# prefer a different browser (Chromium, LibreWolf, Zen) as
# their primary, or they use only a Wayland-native browser;
# installing multiple browsers is intentional for testing or
# compartmentalisation.
# ============================================================

set -euo pipefail
# Load shared logging helpers and Flatpak utility functions
source "$(dirname "${BASH_SOURCE[0]}")/../../lib/logging.sh"

log "Installing Firefox (Flatpak)..."

# ensure_flatpak: checks that Flatpak and the Flathub remote are configured;
# idempotent — safe to call multiple times.
ensure_flatpak

# Install from Flathub. -y skips interactive confirmation.
sudo flatpak install --system -y flathub org.mozilla.firefox

# apply_flatpak_theme: injects the cyberqueer GTK theme so Firefox's native
# file-open dialogs and context menus match the rest of the desktop.
apply_flatpak_theme "org.mozilla.firefox"

log "Firefox installed."
