From 2f452ca045e6295094997363eaf01e427406ddf7 Mon Sep 17 00:00:00 2001 From: DevilXD Date: Sun, 10 Apr 2022 16:02:59 +0200 Subject: [PATCH] Fix an issue with settings being saved too early --- main.py | 4 ++++ twitch.py | 5 ++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 6a05715..b10aee8 100644 --- a/main.py +++ b/main.py @@ -177,6 +177,10 @@ if not client.gui.close_requested: "\nApplication Terminated.\nClose the window to exit the application." ) loop.run_until_complete(client.gui.wait_until_closed()) +# save settings +# NOTE: we have to do it after wait_until_closed, +# because the user can alter settings between shutdown and closing the window +client.settings.save() client.gui.stop() client.gui.close_window() loop.run_until_complete(loop.shutdown_asyncgens()) diff --git a/twitch.py b/twitch.py index df17c5b..81a8009 100644 --- a/twitch.py +++ b/twitch.py @@ -102,9 +102,8 @@ class Twitch: session, self._session = self._session, None await session.close() await self.websocket.stop() - # save other important files - self.settings.save() # settings - self.gui.save() # image cache + # save image cache + self.gui.save() # wait at least half a second + whatever it takes to complete the closing # this allows aiohttp to safely close the session await asyncio.sleep(start_time + 0.5 - time())