diff --git a/fishy/__main__.py b/fishy/__main__.py index 68eb611..5035259 100644 --- a/fishy/__main__.py +++ b/fishy/__main__.py @@ -53,43 +53,46 @@ def initialize(window_to_hide): helper.install_required_addons() +def on_gui_load(gui, finish_splash, logger): + finish_splash() + update_dialog.check_update(gui) + logger.connect(gui) + + def main(): print("launching please wait...") - - config.init() - if not check_eula(): - return - - finish_splash = splash.start() - logger = GuiLogger() - config.start_backup_scheduler() - active.init() - hotkey.init() - - def on_gui_load(): - finish_splash() - update_dialog.check_update(gui) - logger.connect(gui) - - window_to_hide = win32gui.GetForegroundWindow() - bot = EngineEventHandler(lambda: gui) - gui = GUI(lambda: bot, on_gui_load) + gui = GUI(lambda: bot, lambda: on_gui_load(gui, finish_splash, logger)) + window_to_hide = win32gui.GetForegroundWindow() + logger = GuiLogger() + hotkey.init() + active.init() - hotkey.start() + try: + config.init() + if not check_eula(): + return - logging.info(f"Fishybot v{fishy.__version__}") - initialize(window_to_hide) + logging.info(f"Fishybot v{fishy.__version__}") - gui.start() - active.start() + finish_splash = splash.start() + config.start_backup_scheduler() - bot.start_event_handler() # main thread loop + initialize(window_to_hide) - hotkey.stop() - active.stop() - config.stop() - bot.stop() + hotkey.start() + gui.start() + active.start() + + bot.start_event_handler() # main thread loop + except KeyboardInterrupt as e: + ... + finally: + gui._destroyed = True + hotkey.stop() + active.stop() + config.stop() + bot.stop() if __name__ == "__main__": diff --git a/fishy/helper/active_poll.py b/fishy/helper/active_poll.py index 5406dc8..28b5144 100644 --- a/fishy/helper/active_poll.py +++ b/fishy/helper/active_poll.py @@ -14,12 +14,12 @@ class active: return active._scheduler = EventScheduler() - active._scheduler.start() logging.debug("active scheduler initialized") @staticmethod def start(): web.ping() + active._scheduler.start() active._scheduler.enter_recurring(60, 1, web.ping) logging.debug("active scheduler started")