#!/bin/bash
# This script will be called after i3 starts. It's purpose is to do things
# that only make sense for the first time the user starts Regolith.

UPDATE_FLAG_DIR="$HOME/.config/regolith3/flags"
UPDATE_FLAG_PATH="$UPDATE_FLAG_DIR/show-shortcuts"
TERM_PROFILE_PATH="$UPDATE_FLAG_DIR/term-profile"
TERM_PROFILE_ENABLED="$(xrescat gnome.terminal.update true)"

if [ ! -f "$UPDATE_FLAG_PATH" ]; then
    # Use the active look's stylesheet, as the help keybinding does
    # (ilia.stylesheet, read with trawlcat in the sway session).
    if [ "${XDG_SESSION_TYPE-}" == "wayland" ]; then
        STYLESHEET="$(trawlcat ilia.stylesheet "" 2> /dev/null)"
    else
        STYLESHEET="$(xrescat ilia.stylesheet "" 2> /dev/null)"
    fi
    if [ -z "$STYLESHEET" ] || [ ! -f "$STYLESHEET" ]; then
        STYLESHEET=/usr/share/regolith-look/default/ilia.css
    fi

    if [ -f "$STYLESHEET" ]; then
        ilia -p keybindings -a -t "$STYLESHEET" &
    else
        ilia -p keybindings -a &
    fi

    mkdir -p "$UPDATE_FLAG_DIR"
    touch "$UPDATE_FLAG_PATH"
fi

if [[ ! -z "$(command -v gnome-terminal 2> /dev/null)" && "$TERM_PROFILE_ENABLED" == "true" && ! -f "$TERM_PROFILE_PATH" ]]; then
    /usr/share/regolith-ftue/regolith-init-term-profile

    touch "$TERM_PROFILE_PATH"
fi
