Skip to content

Commit

Permalink
Handle corrupted configuration file, fix #37
Browse files Browse the repository at this point in the history
  • Loading branch information
interlark committed Sep 8, 2022
1 parent fba992f commit 13bf95a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
9 changes: 5 additions & 4 deletions gui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,14 @@ async def read_window() -> Any:

# Click "Start"
elif event == '-BTN_START-':
# Sync settings
if not sync_settings():
continue

# Save settings
save_settings(settings)

# Lock user inputs
lock_controls()

loop = asyncio.get_running_loop()
Expand All @@ -227,8 +232,4 @@ async def read_window() -> Any:
n, total = values['@PROGRESS_UPDATE']
window['-PROGRESSBAR-'].update(current_count=n, max=total)

# Save settings before exit
sync_settings(verbose=False)
save_settings(settings)

window.close()
6 changes: 5 additions & 1 deletion gui/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ def load_settings() -> dict[str, Any]:
settings = default_settings()
settings_path = config_path() / 'settings.cfg'
if settings_path.is_file():
user_settings = json.loads(settings_path.read_text(encoding='utf-8'))
try:
user_settings = json.loads(settings_path.read_text(encoding='utf-8'))
except json.JSONDecodeError:
user_settings = {}

settings = {**settings, **user_settings}
else:
save_settings(settings)
Expand Down

0 comments on commit 13bf95a

Please sign in to comment.