#!/usr/bin/env bash

sed -i 's/dark/light/g' ~/.config/chezmoi/chezmoi.toml
chezmoi apply
xfconf-query -c xsettings -p /Net/ThemeName -s "Catppuccin-Latte-Standard-Rosewater-Light"
xrdb -load ~/.Xresources
"$XDG_CONFIG_HOME/emacs/bin/doom" sync

matched=$(hyprctl instances | grep -oE "instance [a-zA-Z0-9]{40}_[a-zA-Z0-9]{10}:")

pkill dunst
pkill emacs
if [[ -n $matched ]]; then
    # Within Hyprland
    pkill waybar
    hyprctl dispatch exec -- waybar
    hyprctl dispatch exec -- dunst
    hyprctl dispatch exec -- emacs --daemon
else
    # Without Hyprland
    pkill polybar
    i3-msg exec "polybar top"
    i3-msg exec "polybar bottom"
    i3-msg exec "dunst"
    i3-msg exec "emacs --daemon"
fi

unlink ~/.wallpaper.png
ln -s ~/Pictures/walls/catppuccin-latte.png ~/.wallpaper.png
feh --bg-scale ~/.wallpaper.png
notify-send "Theme switch complete"
