Commit 51034d36 authored by Roman Alifanov's avatar Roman Alifanov

added support for configuration files in /etc and home directories

parent 94cf1411
#!/bin/bash
# shellcheck source=/usr/bin/shell-config
source shell-config
CONFIG_FILE="/etc/ximper-unified-theme-switcher/themes"
HOME_CONFIG_DIR="$HOME/.config/ximper-unified-theme-switcher"
HOME_CONFIG_FILE="$HOME_CONFIG_DIR/themes"
# Функция для создания конфига в домашнем каталоге
create_home_config() {
mkdir -p "$HOME_CONFIG_DIR"
touch "$HOME_CONFIG_FILE"
echo "Config file created in $HOME_CONFIG_FILE"
}
cfg_check() {
# Проверка наличия конфига в /etc
if [ -f "$CONFIG_FILE" ]; then
echo "$CONFIG_FILE"
else
# Если нет конфига в /etc, ищем в домашнем каталоге
if [ -f "$HOME_CONFIG_FILE" ]; then
echo "$HOME_CONFIG_FILE"
else
create_home_config
fi
fi
}
update_kv_theme() {
echo "Updating Kvantum theme to $1..."
echo "Cfg path: $2..."
if [ "$1" == "light" ]; then
kvantummanager --set KvGnome
kvantummanager --set "$(shell_config_get "$2" KV_LIGHT_THEME)"
elif [ "$1" == "dark" ]; then
kvantummanager --set KvGnomeDark
kvantummanager --set "$(shell_config_get "$2" KV_DARK_THEME)"
fi
}
update_gtk3_theme() {
echo "Updating GTK3 theme to $1..."
echo "Cfg path: $2..."
if [ "$1" == "light" ]; then
gsettings set org.gnome.desktop.interface gtk-theme 'adw-gtk3'
gsettings set org.gnome.desktop.interface gtk-theme "\'$(shell_config_get "$2" GTK3_LIGHT_THEME)\'"
elif [ "$1" == "dark" ]; then
gsettings set org.gnome.desktop.interface gtk-theme 'adw-gtk3-dark'
gsettings set org.gnome.desktop.interface gtk-theme "\'$(shell_config_get "$2" GTK3_DARK_THEME)\'"
fi
}
# Function to check and update the theme
check_and_update_themes() {
local CURRENT_THEME
CURRENT_THEME=$(gsettings get org.gnome.desktop.interface color-scheme | awk -F"'" '{print $2}')
local CFG_PATH
CFG_PATH=$(cfg_check)
if [ -z "$(shell_config_get "$CFG_PATH" KV_DARK_THEME)" ]; then
shell_config_set "$CFG_PATH" KV_LIGHT_THEME "KvGnome"
shell_config_set "$CFG_PATH" KV_DARK_THEME "KvGnomeDark"
fi
if [ -z "$(shell_config_get "$CFG_PATH" GTK3_DARK_THEME)" ]; then
shell_config_set "$CFG_PATH" GTK3_LIGHT_THEME "adw-gtk3"
shell_config_set "$CFG_PATH" GTK3_DARK_THEME "adw-gtk3-dark"
fi
if [ "$CURRENT_THEME" == "default" ]; then
update_kv_theme "light"
update_gtk3_theme "light"
update_kv_theme "light" "$CFG_PATH"
update_gtk3_theme "light" "$CFG_PATH"
else
update_kv_theme "dark"
update_gtk3_theme "dark"
update_kv_theme "dark" "$CFG_PATH"
update_gtk3_theme "dark" "$CFG_PATH"
fi
}
......@@ -35,18 +80,21 @@ check_and_update_themes() {
check_and_update_themes
COUNT=0
dbus-monitor "interface='org.freedesktop.portal.Settings',member=SettingChanged" | \
while IFS= read -r LINE; do
THEME=$(echo "$LINE" | grep -E -o 'string "(prefer-dark|default)"')
if [ -n "$THEME" ]; then
((COUNT++))
if [ $(($COUNT % 2)) = 0 ]; then
echo "$THEME"
check_and_update_themes
COUNT=0
main() {
dbus-monitor "interface='org.freedesktop.portal.Settings',member=SettingChanged" | \
while IFS= read -r LINE; do
local THEME
THEME=$(echo "$LINE" | grep -E -o 'string "(prefer-dark|default)"')
if [ -n "$THEME" ]; then
((COUNT++))
if [ $(($COUNT % 2)) = 0 ]; then
echo "$THEME"
check_and_update_themes
COUNT=0
fi
fi
fi
done
done
}
main
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment