fix: resolve Feishin white screen boot crash by sanitizing Electron nativeTheme configuration

This commit is contained in:
Sho 2026-08-02 14:58:03 +09:00
parent 2609dcd854
commit 5cb7679b59
2 changed files with 25 additions and 27 deletions

View File

@ -440,26 +440,18 @@ if os.path.exists(var_app):
for td in target_dirs: for td in target_dirs:
if os.path.exists(td): if os.path.exists(td):
# 1. Set preferences.json theme to defaultDark # Clean up / sanitize invalid Electron theme strings in config.json, preferences.json, settings.json
pref_file = os.path.join(td, 'preferences.json') for fn in ['config.json', 'preferences.json', 'settings.json']:
fp = os.path.join(td, fn)
if os.path.exists(fp):
try: try:
pdata = {} with open(fp, 'r', encoding='utf-8') as f: data = json.load(f)
if os.path.exists(pref_file): if isinstance(data, dict):
with open(pref_file, 'r', encoding='utf-8') as f: if list(data.keys()) == ['theme'] and data['theme'] not in ['dark', 'light', 'system', 'defaultDark', 'defaultLight']:
pdata = json.load(f) os.remove(fp)
pdata['theme'] = 'defaultDark' elif 'theme' in data and data['theme'] not in ['dark', 'light', 'system', 'defaultDark', 'defaultLight']:
with open(pref_file, 'w', encoding='utf-8') as f: data['theme'] = 'dark'
json.dump(pdata, f, indent=2) with open(fp, 'w', encoding='utf-8') as f: json.dump(data, 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):
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 except Exception: pass
" 2>/dev/null || true " 2>/dev/null || true
} }

View File

@ -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: 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)
# Repair/remove any corrupted config.json or settings.json files created by previous bad writes # Ensure config.json, preferences.json, and settings.json maintain valid Electron themeSource ("dark" or "light")
for bad_file_name in ['config.json', 'settings.json']: valid_electron_theme = "dark" if is_dark else "light"
bad_path = os.path.join(base_dir, bad_file_name) for conf_file_name in ['config.json', 'preferences.json', 'settings.json']:
if os.path.exists(bad_path): conf_path = os.path.join(base_dir, conf_file_name)
if os.path.exists(conf_path):
try: try:
with open(bad_path, 'r', encoding='utf-8') as f: with open(conf_path, 'r', encoding='utf-8') as f:
bad_data = json.load(f) cdata = json.load(f)
if isinstance(bad_data, dict) and list(bad_data.keys()) == ['theme']: if isinstance(cdata, dict):
os.remove(bad_path) 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: except Exception:
pass pass
except Exception: except Exception: