Commit 3b52355f authored by Roman Alifanov's avatar Roman Alifanov

service: big update

1. big fixes in the reaction mode for changing the config file. 2. current mode (light/dark) is now visible in thhelp,force-file-reactione config. 3. added flags: h,help,force-file-reaction 4. other code improvements
parent 01da45b5
......@@ -7,13 +7,38 @@ CONFIG_FILE="/etc/ximper-unified-theme-switcher/themes"
HOME_CONFIG_DIR="$HOME/.config/ximper-unified-theme-switcher"
HOME_CONFIG_FILE="$HOME_CONFIG_DIR/themes"
# Функция для создания конфига в домашнем каталоге (TODO: перенести в GUI)
FORCE_FILE_REACTION=false
# Функция для создания конфига в домашнем каталоге
create_home_config() {
mkdir -p "$HOME_CONFIG_DIR"
touch "$HOME_CONFIG_FILE"
create_default_config_values "$HOME_CONFIG_FILE"
echo "$HOME_CONFIG_FILE"
}
create_default_config_values() {
local CFG_PATH
CFG_PATH="$1"
if [ -w "$CFG_PATH" ]; then
if [ -z "$(shell_config_get "$CFG_PATH" KV_DARK_THEME)" ]; then
shell_config_set "$CFG_PATH" CURRENT_THEME "dark"
fi
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
fi
}
cfg_check() {
# Проверка наличия конфига в /etc
if [ -f "$CONFIG_FILE" ]; then
......@@ -71,75 +96,97 @@ update_gtk3_theme() {
# 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 NEW_THEME
NEW_THEME="$1"
local CFG_PATH
CFG_PATH=$(cfg_check)
create_default_config_values
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
shell_config_set "$CFG_PATH" CURRENT_THEME "$NEW_THEME"
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
case "$NEW_THEME" in
"default"|"light"|"prefer-light")
update_kv_theme "light" "$CFG_PATH"
update_gtk3_theme "light" "$CFG_PATH"
;;
"dark"|"prefer-dark")
update_kv_theme "dark" "$CFG_PATH"
update_gtk3_theme "dark" "$CFG_PATH"
;;
esac
}
if [ "$CURRENT_THEME" == "default" ]; then
update_kv_theme "light" "$CFG_PATH"
update_gtk3_theme "light" "$CFG_PATH"
else
update_kv_theme "dark" "$CFG_PATH"
update_gtk3_theme "dark" "$CFG_PATH"
fi
OPTS=$(getopt -o h --long help,force-file-reaction -- "$@") || {
echo "Ошибка обработки опций."
exit 1
}
# Initial check and update
check_and_update_themes
eval set -- "$OPTS"
while true; do
case "$1" in
-h|--help)
echo "Usage: $0 [options]"
echo "Options:"
echo " --help Show this help message"
echo " --force-file-reaction Force reaction to config file changes"
exit 0
;;
--force-file-reaction)
FORCE_FILE_REACTION=true
shift
;;
--)
shift
break
;;
*)
echo "Неизвестный аргумент: $1"
exit 1
;;
esac
done
main() {
if check_gsettings_schema; then
if [ "$FORCE_FILE_REACTION" = true ] || ! check_gsettings_schema; then
echo "reaction mode: after changes in config file"
create_home_config
local CONFIG_FILE
CONFIG_FILE=$(cfg_check)
while true; do
inotifywait -e attrib "$CONFIG_FILE" | \
while read -r directory events filename; do
NEW_THEME=$(shell_config_get "$CONFIG_FILE" CURRENT_THEME)
if [ -n "$NEW_THEME" ]; then
echo "Config file updated: $NEW_THEME"
check_and_update_themes "$NEW_THEME"
fi
done
done
else
echo "reaction mode: after dbus signal"
case "$XDG_SESSION_DESKTOP" in
gnome*)
echo "GNOME DETECTED"
local GNOME_DE=True
;;
Hyprland*)
echo "HYPRLAND DETECTED"
;;
*)
;;
esac
dbus-monitor "interface='org.freedesktop.portal.Settings',member=SettingChanged" | \
while IFS= read -r LINE; do
local THEME
local NEW_THEME
local CURRENT_TIME
local LAST_UPDATE
THEME=$(echo "$LINE" | grep -E -o 'string "(prefer-dark|default)"')
if [ -n "$THEME" ]; then
# Текущее время в миллисекундах
CURRENT_TIME=$(date +%s%3N)
if [ -z "$LAST_UPDATE" ] || [ $((CURRENT_TIME - LAST_UPDATE)) -ge 150 ]; then
LAST_UPDATE=$CURRENT_TIME
echo "$THEME"
check_and_update_themes
fi
NEW_THEME=$(gsettings get org.gnome.desktop.interface color-scheme | awk -F"'" '{print $2}')
CURRENT_TIME=$(date +%s%3N)
if [ -n "$THEME" ] && [ $((CURRENT_TIME - LAST_UPDATE)) -ge 150 ]; then
LAST_UPDATE=$CURRENT_TIME
echo "D-Bus signal detected: $THEME"
check_and_update_themes "$NEW_THEME"
fi
done
else
echo "reaction mode: after changes in config file"
local CONFIG_FILE=$(cfg_check)
inotifywait -m -e modify "$CONFIG_FILE" | \
while read -r directory events filename; do
check_and_update_themes
done
fi
}
......
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