2020-04-19 11:52:42 +00:00
|
|
|
import logging
|
|
|
|
import sys
|
2021-05-09 07:05:51 +00:00
|
|
|
|
2020-04-19 11:52:42 +00:00
|
|
|
import fishy
|
2023-03-06 18:33:24 +00:00
|
|
|
from fishy.gui import GUI, update_dialog, check_eula
|
2022-02-02 23:45:00 +00:00
|
|
|
from fishy import helper, web
|
2020-10-17 10:52:04 +00:00
|
|
|
from fishy.engine.common.event_handler import EngineEventHandler
|
2022-02-02 23:45:00 +00:00
|
|
|
from fishy.gui.log_config import GuiLogger
|
2023-03-06 18:33:24 +00:00
|
|
|
from fishy.gui.splash import Splash
|
2022-02-02 23:45:00 +00:00
|
|
|
from fishy.helper import hotkey
|
2021-05-16 03:04:35 +00:00
|
|
|
from fishy.helper.active_poll import active
|
2020-10-17 19:06:07 +00:00
|
|
|
from fishy.helper.config import config
|
2021-05-15 22:40:48 +00:00
|
|
|
from fishy.helper.hotkey.hotkey_process import hotkey
|
2021-11-21 11:00:41 +00:00
|
|
|
from fishy.helper.migration import Migration
|
2023-02-21 17:31:31 +00:00
|
|
|
from fishy.osservices.os_services import os_services
|
2020-06-27 15:23:32 +00:00
|
|
|
|
|
|
|
|
2020-05-14 02:03:13 +00:00
|
|
|
# noinspection PyBroadException
|
2023-02-21 17:35:44 +00:00
|
|
|
def initialize():
|
2021-11-21 11:00:41 +00:00
|
|
|
Migration.migrate()
|
|
|
|
|
2023-02-21 17:35:44 +00:00
|
|
|
if not config.get("shortcut_created", False):
|
|
|
|
os_services.create_shortcut(False)
|
|
|
|
config.set("shortcut_created", True)
|
2020-04-19 11:52:42 +00:00
|
|
|
|
2020-10-17 19:06:07 +00:00
|
|
|
new_session = web.get_session()
|
2022-02-02 22:17:35 +00:00
|
|
|
|
2020-05-05 12:55:06 +00:00
|
|
|
if new_session is None:
|
|
|
|
logging.error("Couldn't create a session, some features might not work")
|
2022-02-02 22:39:39 +00:00
|
|
|
logging.debug(f"created session {new_session}")
|
2020-05-05 12:55:06 +00:00
|
|
|
|
2023-02-21 17:35:44 +00:00
|
|
|
if os_services.is_admin():
|
2020-05-05 15:11:00 +00:00
|
|
|
logging.info("Running with admin privileges")
|
|
|
|
|
2023-02-21 17:35:44 +00:00
|
|
|
if not config.get("debug", False):
|
|
|
|
os_services.hide_terminal()
|
2020-04-19 11:52:42 +00:00
|
|
|
helper.install_thread_excepthook()
|
|
|
|
sys.excepthook = helper.unhandled_exception_logging
|
|
|
|
|
2021-11-21 11:00:41 +00:00
|
|
|
helper.install_required_addons()
|
2020-06-25 01:22:39 +00:00
|
|
|
|
2020-04-20 19:46:12 +00:00
|
|
|
|
2023-03-06 18:33:24 +00:00
|
|
|
def on_gui_load(gui, splash, logger):
|
|
|
|
splash.finish()
|
2023-02-15 07:08:47 +00:00
|
|
|
update_dialog.check_update(gui)
|
|
|
|
logger.connect(gui)
|
2022-02-02 22:39:39 +00:00
|
|
|
|
2022-02-02 20:10:18 +00:00
|
|
|
|
2023-02-15 07:08:47 +00:00
|
|
|
def main():
|
|
|
|
print("launching please wait...")
|
2022-02-02 22:39:39 +00:00
|
|
|
|
2023-03-06 18:02:39 +00:00
|
|
|
if not os_services.init():
|
|
|
|
print("platform not supported")
|
|
|
|
return
|
|
|
|
|
2021-03-29 10:31:12 +00:00
|
|
|
config.init()
|
2022-02-02 23:45:00 +00:00
|
|
|
if not check_eula():
|
2022-02-02 20:10:18 +00:00
|
|
|
return
|
|
|
|
|
2023-03-06 18:41:19 +00:00
|
|
|
splash = Splash()
|
2023-02-15 07:08:47 +00:00
|
|
|
bot = EngineEventHandler(lambda: gui)
|
2023-03-06 18:33:24 +00:00
|
|
|
gui = GUI(lambda: bot, lambda: on_gui_load(gui, splash, logger))
|
2022-02-02 23:45:00 +00:00
|
|
|
logger = GuiLogger()
|
2021-05-15 22:40:48 +00:00
|
|
|
hotkey.init()
|
2023-02-15 07:08:47 +00:00
|
|
|
active.init()
|
2021-05-15 22:40:48 +00:00
|
|
|
|
2023-02-15 07:08:47 +00:00
|
|
|
try:
|
|
|
|
config.init()
|
|
|
|
if not check_eula():
|
|
|
|
return
|
|
|
|
|
|
|
|
logging.info(f"Fishybot v{fishy.__version__}")
|
|
|
|
|
2023-03-06 18:41:19 +00:00
|
|
|
splash.start()
|
2023-02-15 07:08:47 +00:00
|
|
|
config.start_backup_scheduler()
|
|
|
|
|
2023-03-06 18:37:36 +00:00
|
|
|
initialize()
|
2023-02-15 07:08:47 +00:00
|
|
|
|
|
|
|
hotkey.start()
|
|
|
|
gui.start()
|
|
|
|
active.start()
|
|
|
|
|
|
|
|
bot.start_event_handler() # main thread loop
|
2023-03-06 18:33:24 +00:00
|
|
|
except KeyboardInterrupt:
|
|
|
|
print("caught KeyboardInterrupt, Stopping main thread")
|
2023-02-15 07:08:47 +00:00
|
|
|
finally:
|
2023-03-06 18:33:24 +00:00
|
|
|
gui.stop()
|
2023-02-15 07:08:47 +00:00
|
|
|
hotkey.stop()
|
|
|
|
active.stop()
|
|
|
|
config.stop()
|
|
|
|
bot.stop()
|
2020-04-15 11:27:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|