diff --git a/install.sh b/install.sh index 8ae16a3..1cbea88 100755 --- a/install.sh +++ b/install.sh @@ -440,26 +440,18 @@ if os.path.exists(var_app): 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: - pdata = {} - if os.path.exists(pref_file): - with open(pref_file, 'r', encoding='utf-8') as f: - 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 - - # 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): + # Clean up / sanitize invalid Electron theme strings in config.json, preferences.json, settings.json + for fn in ['config.json', 'preferences.json', 'settings.json']: + fp = os.path.join(td, fn) + if os.path.exists(fp): 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) + with open(fp, 'r', encoding='utf-8') as f: data = json.load(f) + if isinstance(data, dict): + if list(data.keys()) == ['theme'] and data['theme'] not in ['dark', 'light', 'system', 'defaultDark', 'defaultLight']: + os.remove(fp) + elif 'theme' in data and data['theme'] not in ['dark', 'light', 'system', 'defaultDark', 'defaultLight']: + data['theme'] = 'dark' + with open(fp, 'w', encoding='utf-8') as f: json.dump(data, f, indent=2) except Exception: pass " 2>/dev/null || true } diff --git a/quickshell/services/python/theme_sync.py b/quickshell/services/python/theme_sync.py index 9dde055..02f0c23 100644 --- a/quickshell/services/python/theme_sync.py +++ b/quickshell/services/python/theme_sync.py @@ -1298,15 +1298,21 @@ 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: json.dump(qs_json, f, indent=2) - # Repair/remove any corrupted config.json or settings.json files created by previous bad writes - for bad_file_name in ['config.json', 'settings.json']: - bad_path = os.path.join(base_dir, bad_file_name) - if os.path.exists(bad_path): + # Ensure config.json, preferences.json, and settings.json maintain valid Electron themeSource ("dark" or "light") + valid_electron_theme = "dark" if is_dark else "light" + for conf_file_name in ['config.json', 'preferences.json', 'settings.json']: + conf_path = os.path.join(base_dir, conf_file_name) + if os.path.exists(conf_path): try: - with open(bad_path, 'r', encoding='utf-8') as f: - bad_data = json.load(f) - if isinstance(bad_data, dict) and list(bad_data.keys()) == ['theme']: - os.remove(bad_path) + with open(conf_path, 'r', encoding='utf-8') as f: + cdata = json.load(f) + if isinstance(cdata, dict): + if list(cdata.keys()) == ['theme'] and cdata['theme'] not in ['dark', 'light', 'system', 'defaultDark', 'defaultLight']: + os.remove(conf_path) + elif 'theme' in cdata and cdata['theme'] not in ['dark', 'light', 'system', 'defaultDark', 'defaultLight']: + cdata['theme'] = valid_electron_theme + with open(conf_path, 'w', encoding='utf-8') as f: + json.dump(cdata, f, indent=2) except Exception: pass except Exception: