fix: set Feishin theme to default on install.sh run and preserve user's Feishin theme choice during QuickShell theme switches

This commit is contained in:
Sho 2026-08-02 00:18:45 +09:00
parent 46e2b616c4
commit 6e8dd482e0
2 changed files with 37 additions and 36 deletions

View File

@ -388,33 +388,48 @@ EOF
success "Systemd user service configured at ${SERVICE_DIR}/quickshell.service!" success "Systemd user service configured at ${SERVICE_DIR}/quickshell.service!"
} }
# Helper to repair Flatpak Feishin sandbox config corruption # Helper to set Feishin theme to default and repair sandbox configurations
repair_feishin_flatpak() { repair_feishin_flatpak() {
info "Scanning and repairing Flatpak Feishin sandbox configurations..." info "Setting Feishin theme to default & repairing sandbox configurations..."
local VAR_APP="${HOME}/.var/app" python3 -c "
if [ -d "$VAR_APP" ]; then
for app_dir in "$VAR_APP"/*feishin* "$VAR_APP"/*Feishin*; do
if [ -d "$app_dir" ]; then
for sub in "config/feishin" "config/Feishin" "data/feishin" "data/Feishin" "config" "data"; do
local target="${app_dir}/${sub}"
if [ -d "$target" ]; then
python3 -c "
import os, json import os, json
for bad in ['config.json', 'settings.json']: home = os.path.expanduser('~')
p = os.path.join('$target', bad) target_dirs = [
if os.path.exists(p): os.path.join(home, '.config', 'feishin'),
os.path.join(home, '.local', 'share', 'feishin')
]
var_app = os.path.join(home, '.var', 'app')
if os.path.exists(var_app):
for d in os.listdir(var_app):
if 'feishin' in d.lower():
for sub in ['config/feishin', 'data/feishin', 'config', 'data']:
target_dirs.append(os.path.join(var_app, d, sub))
for td in target_dirs:
if os.path.exists(td):
# 1. Set preferences.json theme to defaultDark
pref_file = os.path.join(td, 'preferences.json')
try: try:
with open(p, 'r', encoding='utf-8') as f: d = json.load(f) pdata = {}
if isinstance(d, dict) and list(d.keys()) == ['theme']: if os.path.exists(pref_file):
os.remove(p) with open(pref_file, 'r', encoding='utf-8') as f:
print(f'[Repaired Flatpak Feishin] Removed bad {bad} at {p}') pdata = json.load(f)
pdata['theme'] = 'defaultDark'
with open(pref_file, 'w', encoding='utf-8') as f:
json.dump(pdata, f, indent=2)
except Exception: pass except Exception: pass
# 2. Clean up corrupted config.json / settings.json
for bad in ['config.json', 'settings.json']:
bp = os.path.join(td, bad)
if os.path.exists(bp):
try:
with open(bp, 'r', encoding='utf-8') as f: bd = json.load(f)
if isinstance(bd, dict) and list(bd.keys()) == ['theme']:
os.remove(bp)
except Exception: pass
" 2>/dev/null || true " 2>/dev/null || true
fi
done
fi
done
fi
} }
# 7. Run Theme Sync Engine # 7. Run Theme Sync Engine

View File

@ -915,20 +915,6 @@ def sync_feishin(bg, surface, current_line, fg, accent, sub_accent, is_dark, var
with open(os.path.join(themes_dir, "quickshell.json"), 'w', encoding='utf-8') as f: with open(os.path.join(themes_dir, "quickshell.json"), 'w', encoding='utf-8') as f:
json.dump(qs_json, f, indent=2) json.dump(qs_json, f, indent=2)
# Update ONLY preferences.json safely
pref_file = os.path.join(base_dir, 'preferences.json')
pref_data = {}
if os.path.exists(pref_file):
try:
with open(pref_file, 'r', encoding='utf-8') as f:
pref_data = json.load(f)
except Exception:
pref_data = {}
pref_data["theme"] = active_slug
with open(pref_file, 'w', encoding='utf-8') as f:
json.dump(pref_data, f, indent=2)
# Repair/remove any corrupted config.json or settings.json files created by previous bad writes # Repair/remove any corrupted config.json or settings.json files created by previous bad writes
for bad_file_name in ['config.json', 'settings.json']: for bad_file_name in ['config.json', 'settings.json']:
bad_path = os.path.join(base_dir, bad_file_name) bad_path = os.path.join(base_dir, bad_file_name)