浏览代码

only create app.native.main_window for native mode

Rodja Trappe 2 年之前
父节点
当前提交
64a91e7bfe
共有 2 个文件被更改,包括 6 次插入4 次删除
  1. 2 2
      nicegui/native.py
  2. 4 2
      nicegui/run.py

+ 2 - 2
nicegui/native.py

@@ -4,7 +4,7 @@ import logging
 from dataclasses import dataclass, field
 from functools import partial
 from multiprocessing import Queue
-from typing import Any, Dict, Tuple
+from typing import Any, Dict, Optional, Tuple
 
 import webview
 from webview.window import FixPoint
@@ -113,4 +113,4 @@ class WindowProxy(webview.Window):
 class Native:
     start_args: Dict[str, Any] = field(default_factory=dict)
     window_args: Dict[str, Any] = field(default_factory=dict)
-    main_window: WindowProxy = WindowProxy()
+    main_window: Optional[WindowProxy] = None

+ 4 - 2
nicegui/run.py

@@ -23,6 +23,8 @@ class Server(uvicorn.Server):
         globals.server = self
         app_native.method_queue = self.config.method_queue
         app_native.response_queue = self.config.response_queue
+        if app_native.method_queue is not None:
+            globals.app.native.main_window = app_native.WindowProxy()
         super().run(sockets=sockets)
 
 
@@ -128,8 +130,8 @@ def run(*,
         log_level=uvicorn_logging_level,
         **kwargs,
     )
-    config.method_queue = app_native.method_queue
-    config.response_queue = app_native.response_queue
+    config.method_queue = app_native.method_queue if native else None
+    config.response_queue = app_native.response_queue if native else None
     globals.server = Server(config=config)
     if (reload or config.workers > 1) and not isinstance(config.app, str):
         logging.warning('You must pass the application as an import string to enable "reload" or "workers".')