#!/usr/bin/bash

# Script Version
VER=2
LOCAL_UBLUE_DIR="${XDG_DATA_HOME:-${HOME}/.local/share}/ublue"
VER_FILE="${LOCAL_UBLUE_DIR}/flatpak_manager_version"
VER_RAN=$(cat "$VER_FILE")

mkdir -p "${LOCAL_UBLUE_DIR}" || exit 1

# Install flatpaks if the list has been updated
ujust install-system-flatpaks "${LOCAL_UBLUE_DIR}/flatpak_current_list"

# Run script if updated
if [[ -f $VER_FILE && $VER = "$VER_RAN" ]]; then
	echo "Flatpak manager v$VER has already ran. Exiting..."
	exit 0
fi

# Set up Firefox default configuration
mkdir -p /var/lib/flatpak/extension/org.mozilla.firefox.systemconfig/$(arch)/stable/defaults/pref
rm -f /var/lib/flatpak/extension/org.mozilla.firefox.systemconfig/$(arch)/stable/defaults/pref/*aurora*.js
/usr/bin/cp -rf /usr/share/ublue-os/firefox-config/* /var/lib/flatpak/extension/org.mozilla.firefox.systemconfig/$(arch)/stable/defaults/pref/

# Use until yafti rework is done
flatpak --system update -y

notify-send "Welcome to Aurora" "Your computer is ready!" --app-name="Flatpak Manager Service" -u NORMAL

echo $VER >"$VER_FILE"
