fishyboteso/fishy/__main__.py

99 lines
2.3 KiB
Python
Raw Normal View History

import ctypes
import logging
import os
import sys
2021-05-09 07:05:51 +00:00
import win32con
import win32gui
import fishy
from fishy.gui import GUI, splash, update_dialog, check_eula
from fishy import helper, web
from fishy.engine.common.event_handler import EngineEventHandler
from fishy.gui.log_config import GuiLogger
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
from fishy.helper.migration import Migration
from fishy.osservices.os_services import os_services
def check_window_name(title):
titles = ["Command Prompt", "PowerShell", "Fishy"]
for t in titles:
if t in title:
return True
return False
# noinspection PyBroadException
2020-10-17 19:06:07 +00:00
def initialize(window_to_hide):
Migration.migrate()
2020-10-17 19:06:07 +00:00
helper.create_shortcut_first()
2020-10-17 19:06:07 +00:00
new_session = web.get_session()
if new_session is None:
logging.error("Couldn't create a session, some features might not work")
logging.debug(f"created session {new_session}")
try:
is_admin = os.getuid() == 0
except AttributeError:
is_admin = ctypes.windll.shell32.IsUserAnAdmin() != 0
if is_admin:
logging.info("Running with admin privileges")
2020-10-17 19:06:07 +00:00
if not config.get("debug", False) and check_window_name(win32gui.GetWindowText(window_to_hide)):
win32gui.ShowWindow(window_to_hide, win32con.SW_HIDE)
helper.install_thread_excepthook()
sys.excepthook = helper.unhandled_exception_logging
helper.install_required_addons()
def main():
print("launching please wait...")
os_services.init()
config.init()
if not check_eula():
return
finish_splash = splash.start()
logger = GuiLogger()
config.start_backup_scheduler()
active.init()
2021-05-15 22:40:48 +00:00
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)
2021-05-15 22:40:48 +00:00
hotkey.start()
logging.info(f"Fishybot v{fishy.__version__}")
2020-10-17 19:06:07 +00:00
initialize(window_to_hide)
gui.start()
2021-05-16 03:04:35 +00:00
active.start()
2021-02-14 18:07:12 +00:00
bot.start_event_handler() # main thread loop
2021-05-15 22:40:48 +00:00
hotkey.stop()
2021-05-16 03:04:35 +00:00
active.stop()
config.stop()
bot.stop()
if __name__ == "__main__":
main()