Skip to content

Commit

Permalink
Log info about Issue #4 when running in GUI mode
Browse files Browse the repository at this point in the history
  • Loading branch information
KrisCris committed Apr 1, 2024
1 parent 0a95321 commit e56f159
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/palworld_pal_editor/gui.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import sys
import threading
import time
import requests
import traceback
import webbrowser
import webview
Expand All @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions src/palworld_pal_editor/webui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit e56f159

Please sign in to comment.