1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-01-29 07:52:50 -05:00

proper KColorScheme generation

This commit is contained in:
bbedward
2025-08-20 15:40:23 -04:00
parent ee8ab26d45
commit 835d46a7af
3 changed files with 176 additions and 63 deletions

View File

@@ -96,71 +96,34 @@ update_qt_config() {
update_qt_color_config() {
local config_file="$1"
local version="$2"
local color_scheme_path="$config_dir/qt${version}ct/colors/matugen.conf"
local color_scheme_path="$(dirname "$config_dir")/.local/share/color-schemes/DankMatugen.colors"
if [ -f "$config_file" ]; then
# Read the entire file and carefully update only what we need
python3 -c "
import sys
import re
config_file = '$config_file'
color_scheme_path = '$color_scheme_path'
try:
with open(config_file, 'r') as f:
content = f.read()
lines = content.split('\n')
result = []
in_appearance = False
custom_palette_found = False
color_scheme_found = False
for line in lines:
stripped = line.strip()
if stripped == '[Appearance]':
in_appearance = True
result.append(line)
elif stripped.startswith('[') and stripped != '[Appearance]':
# End of [Appearance] section, add missing settings if needed
if in_appearance:
if not custom_palette_found:
result.append('custom_palette=true')
if not color_scheme_found:
result.append('color_scheme_path=' + color_scheme_path)
in_appearance = False
result.append(line)
elif in_appearance and stripped.startswith('custom_palette='):
custom_palette_found = True
result.append('custom_palette=true')
elif in_appearance and stripped.startswith('color_scheme_path='):
color_scheme_found = True
result.append('color_scheme_path=' + color_scheme_path)
else:
result.append(line)
# Handle case where [Appearance] is the last section
if in_appearance:
if not custom_palette_found:
result.append('custom_palette=true')
if not color_scheme_found:
result.append('color_scheme_path=' + color_scheme_path)
# If no [Appearance] section exists, create one
if not any('[Appearance]' in line for line in lines):
result.extend(['', '[Appearance]', 'custom_palette=true', 'color_scheme_path=' + color_scheme_path])
with open(config_file, 'w') as f:
f.write('\n'.join(result))
except Exception as e:
print(f'Error updating {config_file}: {e}', file=sys.stderr)
sys.exit(1)
"
# Use a simple sed approach to only update specific lines
# First, check if the [Appearance] section exists
if grep -q '^\[Appearance\]' "$config_file"; then
# Update custom_palette if it exists, otherwise add it after [Appearance]
if grep -q '^custom_palette=' "$config_file"; then
sed -i 's/^custom_palette=.*/custom_palette=true/' "$config_file"
else
sed -i '/^\[Appearance\]/a custom_palette=true' "$config_file"
fi
# Update color_scheme_path if it exists, otherwise add it after [Appearance]
if grep -q '^color_scheme_path=' "$config_file"; then
sed -i "s|^color_scheme_path=.*|color_scheme_path=$color_scheme_path|" "$config_file"
else
sed -i "/^\[Appearance\]/a color_scheme_path=$color_scheme_path" "$config_file"
fi
else
# Add [Appearance] section at the end with our settings
echo "" >> "$config_file"
echo "[Appearance]" >> "$config_file"
echo "custom_palette=true" >> "$config_file"
echo "color_scheme_path=$color_scheme_path" >> "$config_file"
fi
else
# Create new config file
# Create new config file with minimal settings
printf '[Appearance]\ncustom_palette=true\ncolor_scheme_path=%s\n' "$color_scheme_path" > "$config_file"
fi
}