Skip to content

  • Projects
  • Groups
  • Snippets
  • Help
  • This project
    • Loading...
  • Sign in / Register
X
ximper-unified-theme-switcher
  • Project
    • Project
    • Details
    • Activity
    • Cycle Analytics
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Charts
  • Issues 0
    • Issues 0
    • List
    • Board
    • Labels
    • Milestones
  • Merge Requests 1
    • Merge Requests 1
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
    • Charts
  • Registry
    • Registry
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Ximper Linux
  • ximper-unified-theme-switcher
  • Merge Requests
  • !4

Closed
Opened Dec 05, 2024 by Алексей Николаевич Пахомкин@ArkaPan 1
  • Report abuse
Report abuse

Update ximper-unified-theme-switcher-service

режим цветовой схемы по умолчанию:

Check out, review, and merge locally

Step 1. Fetch and check out the branch for this merge request

git fetch https://gitlab.eterfund.ru/ArkaPan/ximper-unified-theme-switcher.git patch-1
git checkout -b ArkaPan/ximper-unified-theme-switcher-patch-1 FETCH_HEAD

Step 2. Review the changes locally

Step 3. Merge the branch and fix any conflicts that come up

git checkout master
git merge --no-ff ArkaPan/ximper-unified-theme-switcher-patch-1

Step 4. Push the result of the merge to GitLab

git push origin master

Note that pushing to GitLab requires write access to this repository.

Tip: You can also checkout merge requests locally by following these guidelines.

  • Discussion 1
  • Commits 1
  • Changes 1
{{ resolvedDiscussionCount }}/{{ discussionCount }} {{ resolvedCountText }} resolved
  • Алексей Николаевич Пахомкин @ArkaPan commented · Dec 05, 2024
    1

    #!/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"

    #Значение текущего режима цветовой схемы { "current_theme": "light" }

    Функция для создания конфига в домашнем каталоге (TODO: перенести в GUI)

    create_home_config() { mkdir -p "$HOME_CONFIG_DIR" touch "$HOME_CONFIG_FILE" echo "$HOME_CONFIG_FILE" }

    cfg_check() { # Проверка наличия конфига в /etc if [ -f "$CONFIG_FILE" ]; then if [ -f "$HOME_CONFIG_FILE" ]; then echo "$HOME_CONFIG_FILE" else echo "$CONFIG_FILE" fi elif [ -f "$HOME_CONFIG_FILE" ]; then echo "$HOME_CONFIG_FILE" else create_home_config fi }

    check_gsettings_schema() { local SCHEMA="org.gnome.desktop.interface" local KEY="color-scheme"

    if gsettings list-schemas | grep -q "$SCHEMA"; then
        if gsettings list-keys "$SCHEMA" | grep -q "$KEY"; then
            echo "Schema '$SCHEMA' and KEY '$KEY' exist."
            return 0
        else
            echo "Schema '$SCHEMA' exists, but KEY '$KEY' not found."
            return 1
        fi
    else
        echo "Schema '$SCHEMA' not found."
        return 1
    fi

    }

    update_kv_theme() { echo "Updating Kvantum theme to $1..." echo "Cfg path: $2..." if [ "$1" == "light" ]; then kvantummanager --set "$(shell_config_get "$2" KV_LIGHT_THEME)"

    elif [ "$1" == "dark" ]; then
        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 "$(shell_config_get "$2" GTK3_LIGHT_THEME)"
    elif [ "$1" == "dark" ]; then
        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" "$CFG_PATH"
        update_gtk3_theme "light" "$CFG_PATH"
    else
        update_kv_theme "dark" "$CFG_PATH"
        update_gtk3_theme "dark" "$CFG_PATH"
    fi

    }

    Initial check and update

    check_and_update_themes

    main() { if check_gsettings_schema; then echo "reaction mode: after dbus signal"

        case "$XDG_SESSION_DESKTOP" in
            gnome*)
                echo "GNOME DETECTED"
                local GNOME_DE=True
                ;;
            Hyprland*)
                echo "HYPRLAND DETECTED"
                ;;
            *)
                ;;
        esac
    
        if [ "$GNOME_DE" = True ] ; then
            local COUNT=0
        fi
    
        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
    
                if [ "$GNOME_DE" = True ] ; then
                    ((COUNT++))
                    if [ $(($COUNT % 2)) = 0 ]; then
                        echo "$THEME"
                        check_and_update_themes
                        COUNT=0
                    fi
                else
                    echo "$THEME"
                    check_and_update_themes
                    CURRENT_THEME=$(jq -r '.current_theme' config.json)
                    check_and_update_themes "$CURRENT_THEME"
                fi
            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

    }

    main

    #!/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" #Значение текущего режима цветовой схемы { "current_theme": "light" } # Функция для создания конфига в домашнем каталоге (TODO: перенести в GUI) create_home_config() { mkdir -p "$HOME_CONFIG_DIR" touch "$HOME_CONFIG_FILE" echo "$HOME_CONFIG_FILE" } cfg_check() { # Проверка наличия конфига в /etc if [ -f "$CONFIG_FILE" ]; then if [ -f "$HOME_CONFIG_FILE" ]; then echo "$HOME_CONFIG_FILE" else echo "$CONFIG_FILE" fi elif [ -f "$HOME_CONFIG_FILE" ]; then echo "$HOME_CONFIG_FILE" else create_home_config fi } check_gsettings_schema() { local SCHEMA="org.gnome.desktop.interface" local KEY="color-scheme" if gsettings list-schemas | grep -q "$SCHEMA"; then if gsettings list-keys "$SCHEMA" | grep -q "$KEY"; then echo "Schema '$SCHEMA' and KEY '$KEY' exist." return 0 else echo "Schema '$SCHEMA' exists, but KEY '$KEY' not found." return 1 fi else echo "Schema '$SCHEMA' not found." return 1 fi } update_kv_theme() { echo "Updating Kvantum theme to $1..." echo "Cfg path: $2..." if [ "$1" == "light" ]; then kvantummanager --set "$(shell_config_get "$2" KV_LIGHT_THEME)" elif [ "$1" == "dark" ]; then 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 "$(shell_config_get "$2" GTK3_LIGHT_THEME)" elif [ "$1" == "dark" ]; then 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" "$CFG_PATH" update_gtk3_theme "light" "$CFG_PATH" else update_kv_theme "dark" "$CFG_PATH" update_gtk3_theme "dark" "$CFG_PATH" fi } # Initial check and update check_and_update_themes main() { if check_gsettings_schema; then echo "reaction mode: after dbus signal" case "$XDG_SESSION_DESKTOP" in gnome*) echo "GNOME DETECTED" local GNOME_DE=True ;; Hyprland*) echo "HYPRLAND DETECTED" ;; *) ;; esac if [ "$GNOME_DE" = True ] ; then local COUNT=0 fi 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 if [ "$GNOME_DE" = True ] ; then ((COUNT++)) if [ $(($COUNT % 2)) = 0 ]; then echo "$THEME" check_and_update_themes COUNT=0 fi else echo "$THEME" check_and_update_themes CURRENT_THEME=$(jq -r '.current_theme' config.json) check_and_update_themes "$CURRENT_THEME" fi 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 } main
  • Алексей Николаевич Пахомкин @ArkaPan

    closed

    · Dec 05, 2024

    closed

    closed
    Toggle commit list
  • Write
  • Preview
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 sign in to comment
Assignee
No assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
0
Labels
None
Assign labels
  • View project labels
Reference: ximperlinux/ximper-unified-theme-switcher!4