#!/usr/bin/env bash
#  ____      _                 _   ____  _        _            _
# |  _ \ ___| | ___   __ _  __| | / ___|| |_ __ _| |_ _   _ __| |__   __ _ _ __
# | |_) / _ \ |/ _ \ / _` |/ _` | \___ \| __/ _` | __| | | / _` | '_ \ / _` | '__|
# |  _ <  __/ | (_) | (_| | (_| |  ___) | || (_| | |_| |_| \__,_| |_) | (_| | |
# |_| \_\___|_|\___/ \__,_|\__,_| |____/ \__\__,_|\__|\__,_|\__,_|_.__/ \__,_|_|
#
# Reload the statusbar used by ML4W OS. Reads the configured statusbar from
# ~/.config/ml4w/settings/statusbar and reloads the matching bar.

settings_file="$HOME/.config/ml4w/settings/statusbar"

# Default to waybar if no setting file is present.
statusbar="waybar"
if [ -f "$settings_file" ]; then
    statusbar=$(tr -d '[:space:]' < "$settings_file")
fi

case "$statusbar" in
    quickshell)
        qs ipc call statusbar reload
        ;;
    waybar)
        "$HOME/.config/waybar/launch.sh"
        ;;
    *)
        echo "Unknown statusbar '$statusbar' in $settings_file" >&2
        exit 1
        ;;
esac
