From 572604ff36814de3ddacc2d66a3ef362d3d5b4e3 Mon Sep 17 00:00:00 2001 From: Adam Saudagar Date: Thu, 3 Feb 2022 01:40:18 +0530 Subject: [PATCH] fixed dangling threads after denying eula, now only config is partially initialized just to check if eula is accepted --- fishy/__main__.py | 11 ++++++----- fishy/helper/config.py | 12 +++++++++--- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/fishy/__main__.py b/fishy/__main__.py index 0a24602..7ab333e 100644 --- a/fishy/__main__.py +++ b/fishy/__main__.py @@ -68,8 +68,12 @@ def initialize(window_to_hide): def main(): - active.init() config.init() + if not gui.check_eula(): + return + + config.start_backup_scheduler() + active.init() finish_splash = splash.start() hotkey.init() @@ -82,9 +86,6 @@ def main(): window_to_hide = win32gui.GetForegroundWindow() - if not gui.check_eula(): - return - bot = EngineEventHandler(lambda: gui_window) gui_window = GUI(lambda: bot, finish_splash) @@ -98,9 +99,9 @@ def main(): bot.start_event_handler() # main thread loop - config.stop() hotkey.stop() active.stop() + config.stop() if __name__ == "__main__": diff --git a/fishy/helper/config.py b/fishy/helper/config.py index 773c32b..b7aaaf1 100644 --- a/fishy/helper/config.py +++ b/fishy/helper/config.py @@ -3,6 +3,7 @@ config.py Saves configuration in file as json file """ import json +import logging import os # path to save the configuration file from typing import Optional @@ -46,17 +47,18 @@ class Config: self._config_dict = json.loads(open(filename()).read()) except json.JSONDecodeError: try: - print("Config file got corrupted, trying to restore backup") + logging.warning("Config file got corrupted, trying to restore backup") self._config_dict = json.loads(open(temp_file).read()) self.save_config() except (FileNotFoundError, json.JSONDecodeError): - print("couldn't restore, creating new") + logging.warning("couldn't restore, creating new") os.remove(filename()) self._config_dict = dict() else: self._config_dict = dict() + def start_backup_scheduler(self): self._create_backup() self._scheduler.start() self._scheduler.enter_recurring(5 * 60, 1, self._create_backup) @@ -67,7 +69,7 @@ class Config: def _create_backup(self): with open(temp_file, 'w') as f: f.write(json.dumps(self._config_dict)) - print("created backup") + logging.debug("created backup") def _sort_dict(self): tmpdict = dict() @@ -93,6 +95,10 @@ class config: config._instance = Config() config._instance.initialize() + @staticmethod + def start_backup_scheduler(): + config._instance.start_backup_scheduler() + @staticmethod def stop(): config._instance.stop()