fix: repair Feishin crash by fixing preferences.json handling, removing bad config files, and eliminating aggressive restarts
This commit is contained in:
parent
eb4d019cd6
commit
a0c4b8d1c5
@ -890,18 +890,16 @@ def sync_feishin(bg, surface, current_line, fg, accent, sub_accent, is_dark, var
|
|||||||
themes_dir = os.path.join(base_dir, t_dir_name)
|
themes_dir = os.path.join(base_dir, t_dir_name)
|
||||||
os.makedirs(themes_dir, exist_ok=True)
|
os.makedirs(themes_dir, exist_ok=True)
|
||||||
|
|
||||||
# 1. Clean up any previous .backup files and restore as .json
|
# Clean up backup files or zero-byte corrupted files
|
||||||
for backup_file in glob.glob(os.path.join(themes_dir, '*.backup')):
|
for f_name in os.listdir(themes_dir):
|
||||||
|
f_path = os.path.join(themes_dir, f_name)
|
||||||
|
if f_name.endswith('.backup') or (os.path.isfile(f_path) and os.path.getsize(f_path) == 0):
|
||||||
try:
|
try:
|
||||||
clean_json = backup_file[:-7]
|
os.remove(f_path)
|
||||||
if not os.path.exists(clean_json):
|
|
||||||
os.rename(backup_file, clean_json)
|
|
||||||
else:
|
|
||||||
os.remove(backup_file)
|
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# 2. Pre-generate JSON files for all predefined variants so all themes are available
|
# Pre-generate JSON files for all predefined variants so all themes are available
|
||||||
for v in PREDEFINED_VARIANTS:
|
for v in PREDEFINED_VARIANTS:
|
||||||
v_slug = slugify(v["name"])
|
v_slug = slugify(v["name"])
|
||||||
v_json = make_feishin_json(v["bg"], v["surface"], v["currentLine"], v["fg"], v["accent"], v["isDark"], v["name"], v_slug)
|
v_json = make_feishin_json(v["bg"], v["surface"], v["currentLine"], v["fg"], v["accent"], v["isDark"], v["name"], v_slug)
|
||||||
@ -909,7 +907,7 @@ def sync_feishin(bg, surface, current_line, fg, accent, sub_accent, is_dark, var
|
|||||||
with open(v_path, 'w', encoding='utf-8') as f:
|
with open(v_path, 'w', encoding='utf-8') as f:
|
||||||
json.dump(v_json, f, indent=2)
|
json.dump(v_json, f, indent=2)
|
||||||
|
|
||||||
# 3. Write active variant JSON with runtime parameters + quickshell.json
|
# Write active variant JSON with runtime parameters + quickshell.json
|
||||||
active_path = os.path.join(themes_dir, f"{active_slug}.json")
|
active_path = os.path.join(themes_dir, f"{active_slug}.json")
|
||||||
with open(active_path, 'w', encoding='utf-8') as f:
|
with open(active_path, 'w', encoding='utf-8') as f:
|
||||||
json.dump(active_json, f, indent=2)
|
json.dump(active_json, f, indent=2)
|
||||||
@ -917,33 +915,33 @@ 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)
|
||||||
|
|
||||||
# 4. Auto-update preferences.json / config.json / settings.json in Feishin config directory
|
# Update ONLY preferences.json safely
|
||||||
for pref_name in ['preferences.json', 'config.json', 'settings.json']:
|
pref_file = os.path.join(base_dir, 'preferences.json')
|
||||||
pref_file = os.path.join(base_dir, pref_name)
|
|
||||||
try:
|
|
||||||
pref_data = {}
|
pref_data = {}
|
||||||
if os.path.exists(pref_file):
|
if os.path.exists(pref_file):
|
||||||
|
try:
|
||||||
with open(pref_file, 'r', encoding='utf-8') as f:
|
with open(pref_file, 'r', encoding='utf-8') as f:
|
||||||
pref_data = json.load(f)
|
pref_data = json.load(f)
|
||||||
|
except Exception:
|
||||||
|
pref_data = {}
|
||||||
|
|
||||||
pref_data["theme"] = active_slug
|
pref_data["theme"] = active_slug
|
||||||
with open(pref_file, 'w', encoding='utf-8') as f:
|
with open(pref_file, 'w', encoding='utf-8') as f:
|
||||||
json.dump(pref_data, f, indent=2)
|
json.dump(pref_data, f, indent=2)
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
restart_app_if_running(
|
# Repair/remove any corrupted config.json or settings.json files created by previous bad writes
|
||||||
"feishin",
|
for bad_file_name in ['config.json', 'settings.json']:
|
||||||
["feishin", "io.github.jeffvli.feishin", "org.jeffvli.feishin"],
|
bad_path = os.path.join(base_dir, bad_file_name)
|
||||||
[
|
if os.path.exists(bad_path):
|
||||||
"flatpak run io.github.jeffvli.feishin",
|
try:
|
||||||
"flatpak run org.jeffvli.feishin",
|
with open(bad_path, 'r', encoding='utf-8') as f:
|
||||||
"gtk-launch io.github.jeffvli.feishin",
|
bad_data = json.load(f)
|
||||||
"gtk-launch feishin",
|
if isinstance(bad_data, dict) and list(bad_data.keys()) == ['theme']:
|
||||||
"feishin"
|
os.remove(bad_path)
|
||||||
]
|
except Exception:
|
||||||
)
|
pass
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
def sync_starship(bg, surface, current_line, fg, accent, sub_accent, is_dark):
|
def sync_starship(bg, surface, current_line, fg, accent, sub_accent, is_dark):
|
||||||
starship_dir = os.path.expanduser('~/.config')
|
starship_dir = os.path.expanduser('~/.config')
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user