#!/usr/bin/env fish

set theme (ron-theme-get)

# niri
if pgrep -x niri >/dev/null
    niri msg action load-config-file
end

# qt
mkdir -p ~/.config/qt5ct/colors
mkdir -p ~/.config/qt6ct/colors
ln -sfv ~/.cache/hellwal/qt.conf ~/.config/qt5ct/colors/colors.conf
ln -sfv ~/.cache/hellwal/qt.conf ~/.config/qt6ct/colors/colors.conf

# gtk
mkdir -p ~/.config/gtk-3.0
mkdir -p ~/.config/gtk-4.0
ln -sfv ~/.cache/hellwal/gtk.css ~/.config/gtk-3.0/colors.css
ln -sfv ~/.cache/hellwal/gtk.css ~/.config/gtk-4.0/colors.css
gsettings set org.gnome.desktop.interface gtk-theme ""
gsettings set org.gnome.desktop.interface gtk-theme adw-gtk3-$theme
gsettings set org.gnome.desktop.interface color-scheme "prefer-$theme"

# apps
pkill nautilus

# waybar
ln -sfv ~/.cache/hellwal/waybar.css ~/.config/waybar/style.css

# mako
mkdir -p ~/.config/mako
rm -f ~/.config/mako/config
cat ~/.cache/hellwal/colors-mako ~/.config/mako/base-config >~/.config/mako/config
if pgrep mako
    makoctl reload
end

# ghostty
mkdir -p ~/.cache/ghostty
ln -sfv ~/.config/ghostty/theme_$theme.ghostty ~/.cache/ghostty/current_theme.ghostty
pkill -SIGUSR2 ghostty

# kitty
ln -sfv ~/.config/kitty/theme_$theme.conf ~/.config/kitty/current_theme.conf
pkill -SIGUSR1 kitty

# tmux
tmux source-file ~/.config/tmux/tmux.conf

# qutebrowser
if pgrep qutebrowser
    qutebrowser :config-source
end

# firefox
if command -vq pywalfox
    ln -sfv ~/.cache/hellwal/colors.json ~/.cache/wal/colors.json
    if test -n "$theme"
        pywalfox $theme
    else
        pywalfox auto
    end
    pywalfox update
end

exit 0
