diff --git a/pyproject.toml b/pyproject.toml index 145dc2b..2c3964b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,7 +12,7 @@ keywords = ["palworld", "editor", "pal"] license = {file = "LICENSE"} requires-python = ">=3.11" readme = "README.md" -version = "0.3.4" +version = "0.3.5" dependencies = [ "setuptools==69.1.0", "palworld_save_tools==0.19.0", @@ -21,7 +21,8 @@ dependencies = [ "pyinstaller==6.4.0", "waitress==3.0.0", "Flask-JWT-Extended==4.6.0", - "pywebview==4.4.1" + "PySide6==6.6.3", + "requests==2.31.0" ] classifiers = [ "Programming Language :: Python :: 3", diff --git a/requirements.txt b/requirements.txt index 731e067..8764469 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,3 @@ -# customtkinter==5.2.2 setuptools==69.1.0 palworld_save_tools==0.19.0 wheel==0.42.0 @@ -7,4 +6,5 @@ Flask==3.0.2 pyinstaller==6.4.0 waitress==3.0.0 Flask-JWT-Extended==4.6.0 -pywebview==4.4.1 \ No newline at end of file +PySide6==6.6.3 +requests==2.31.0 \ No newline at end of file diff --git a/src/palworld_pal_editor/gui.py b/src/palworld_pal_editor/gui.py index 5dee4c2..78bee59 100644 --- a/src/palworld_pal_editor/gui.py +++ b/src/palworld_pal_editor/gui.py @@ -1,27 +1,40 @@ import sys import threading import time -import traceback -import webbrowser -import webview +import requests +from PySide6.QtWidgets import QApplication +from PySide6.QtWebEngineWidgets import QWebEngineView from palworld_pal_editor.config import VERSION, Config from palworld_pal_editor.utils import LOGGER from palworld_pal_editor.webui import main as web_main +class MainWindow(QWebEngineView): + def __init__(self, url): + super().__init__() + self.setWindowTitle(f"Palworld Pal Editor, developed by _connlost with ❤️. VERSION: {VERSION}") + self.setMinimumSize(1280, 720) + self.load(url) + self.resize(1600, 900) def main(): t = threading.Thread(target=web_main) t.daemon = True t.start() - 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.start() - except: - LOGGER.warning(f"Failed Launching pywebview: {traceback.format_exc()}") - LOGGER.info("Fallback to web browser...") - threading.Timer(1, lambda: webbrowser.open(f"http://127.0.0.1:{Config.port}") ).start() - t.join() - sys.exit() + + 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) + + app = QApplication(sys.argv) + window = MainWindow(f"http://127.0.0.1:{Config.port}/") + window.show() + sys.exit(app.exec()) if __name__ == "__main__": main() diff --git a/src/palworld_pal_editor/webui.py b/src/palworld_pal_editor/webui.py index 7928752..d02c03b 100644 --- a/src/palworld_pal_editor/webui.py +++ b/src/palworld_pal_editor/webui.py @@ -46,6 +46,11 @@ def serve(path): return send_from_directory(str(static_folder_path), 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