fixed dangling threads after denying eula,

now only config is partially initialized just to check if eula is accepted
This commit is contained in:
Adam Saudagar 2022-02-03 01:40:18 +05:30
parent 17c014d690
commit 572604ff36
2 changed files with 15 additions and 8 deletions

View File

@ -68,8 +68,12 @@ def initialize(window_to_hide):
def main(): def main():
active.init()
config.init() config.init()
if not gui.check_eula():
return
config.start_backup_scheduler()
active.init()
finish_splash = splash.start() finish_splash = splash.start()
hotkey.init() hotkey.init()
@ -82,9 +86,6 @@ def main():
window_to_hide = win32gui.GetForegroundWindow() window_to_hide = win32gui.GetForegroundWindow()
if not gui.check_eula():
return
bot = EngineEventHandler(lambda: gui_window) bot = EngineEventHandler(lambda: gui_window)
gui_window = GUI(lambda: bot, finish_splash) gui_window = GUI(lambda: bot, finish_splash)
@ -98,9 +99,9 @@ def main():
bot.start_event_handler() # main thread loop bot.start_event_handler() # main thread loop
config.stop()
hotkey.stop() hotkey.stop()
active.stop() active.stop()
config.stop()
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -3,6 +3,7 @@ config.py
Saves configuration in file as json file Saves configuration in file as json file
""" """
import json import json
import logging
import os import os
# path to save the configuration file # path to save the configuration file
from typing import Optional from typing import Optional
@ -46,17 +47,18 @@ class Config:
self._config_dict = json.loads(open(filename()).read()) self._config_dict = json.loads(open(filename()).read())
except json.JSONDecodeError: except json.JSONDecodeError:
try: 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._config_dict = json.loads(open(temp_file).read())
self.save_config() self.save_config()
except (FileNotFoundError, json.JSONDecodeError): except (FileNotFoundError, json.JSONDecodeError):
print("couldn't restore, creating new") logging.warning("couldn't restore, creating new")
os.remove(filename()) os.remove(filename())
self._config_dict = dict() self._config_dict = dict()
else: else:
self._config_dict = dict() self._config_dict = dict()
def start_backup_scheduler(self):
self._create_backup() self._create_backup()
self._scheduler.start() self._scheduler.start()
self._scheduler.enter_recurring(5 * 60, 1, self._create_backup) self._scheduler.enter_recurring(5 * 60, 1, self._create_backup)
@ -67,7 +69,7 @@ class Config:
def _create_backup(self): def _create_backup(self):
with open(temp_file, 'w') as f: with open(temp_file, 'w') as f:
f.write(json.dumps(self._config_dict)) f.write(json.dumps(self._config_dict))
print("created backup") logging.debug("created backup")
def _sort_dict(self): def _sort_dict(self):
tmpdict = dict() tmpdict = dict()
@ -93,6 +95,10 @@ class config:
config._instance = Config() config._instance = Config()
config._instance.initialize() config._instance.initialize()
@staticmethod
def start_backup_scheduler():
config._instance.start_backup_scheduler()
@staticmethod @staticmethod
def stop(): def stop():
config._instance.stop() config._instance.stop()