From e56f1591b47f3fa5b76148318ad3a1c4df584ce8 Mon Sep 17 00:00:00 2001 From: connlost <4348524953.h@gmail.com> Date: Mon, 1 Apr 2024 14:56:00 +0800 Subject: [PATCH] Log info about Issue #4 when running in GUI mode --- src/palworld_pal_editor/gui.py | 18 ++++++++++++++++-- src/palworld_pal_editor/webui.py | 3 +++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/palworld_pal_editor/gui.py b/src/palworld_pal_editor/gui.py index 5dee4c2..29d2f99 100644 --- a/src/palworld_pal_editor/gui.py +++ b/src/palworld_pal_editor/gui.py @@ -1,6 +1,7 @@ import sys import threading import time +import requests import traceback import webbrowser import webview @@ -13,12 +14,25 @@ def main(): t = threading.Thread(target=web_main) t.daemon = True t.start() + + while True: + LOGGER.info("Waiting for backend response...") + try: + response = requests.get(f"http://127.0.0.1:{Config.port}/api/ready") + if response.status_code == 200: + LOGGER.info("Backend ready, launching GUI...") + break + except requests.exceptions.ConnectionError: + time.sleep(0.5) + + LOGGER.info("If GUI doesn't work for you, check out this post: https://github.com/KrisCris/Palworld-Pal-Editor/issues/4") + try: - webview.create_window(f"Palworld Pal Editor, developed by _connlost with ❤️. VERSION: {VERSION}", url=f"http://localhost:{Config.port}/", width=1600, height=1000, min_size=(960, 600)) + webview.create_window(f"Palworld Pal Editor, developed by _connlost with ❤️. VERSION: {VERSION}", url=f"http://127.0.0.1:{Config.port}/", width=1600, height=1000, min_size=(960, 600)) webview.start() except: LOGGER.warning(f"Failed Launching pywebview: {traceback.format_exc()}") - LOGGER.info("Fallback to web browser...") + LOGGER.info(f"Fallback to web browser, opening http://127.0.0.1:{Config.port} ...") threading.Timer(1, lambda: webbrowser.open(f"http://127.0.0.1:{Config.port}") ).start() t.join() sys.exit() diff --git a/src/palworld_pal_editor/webui.py b/src/palworld_pal_editor/webui.py index 7928752..797700a 100644 --- a/src/palworld_pal_editor/webui.py +++ b/src/palworld_pal_editor/webui.py @@ -47,6 +47,9 @@ def serve(path): else: return send_from_directory(str(static_folder_path), 'index.html') +@app.route('/api/ready') +def ready(): + return reply(status=0), 200 @jwt.invalid_token_loader def invalid_token_callback(error_string):