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 d78f506
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ dependencies = [
"pyinstaller==6.4.0",
"waitress==3.0.0",
"Flask-JWT-Extended==4.6.0",
"pywebview==4.4.1"
"pywebview==4.4.1",
"requests==2.31.0"
]
classifiers = [
"Programming Language :: Python :: 3",
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ Flask==3.0.2
pyinstaller==6.4.0
waitress==3.0.0
Flask-JWT-Extended==4.6.0
pywebview==4.4.1
pywebview==4.4.1
requests==2.31.0
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 d78f506

Please sign in to comment.