#!/usr/bin/env bash

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

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

if [[ -n $matched ]]; then
    hyprctl dispatch exec -- polybar top
    hyprctl dispatch exec -- polybar bottom
    hyprctl dispatch exec -- dunst
    hyprctl dispatch exec -- emacs --daemon
else
    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-macchiato.png ~/.wallpaper.png
feh --bg-scale ~/.wallpaper.png
notify-send "Theme switch complete"
