Falko Schindler 1 anno fa
parent
commit
55f51098af
3 ha cambiato i file con 7 aggiunte e 8 eliminazioni
  1. 1 2
      nicegui/globals.py
  2. 3 3
      nicegui/nicegui.py
  3. 3 3
      nicegui/outbox.py

+ 1 - 2
nicegui/globals.py

@@ -15,7 +15,6 @@ from .language import Language
 
 if TYPE_CHECKING:
     from .air import Air
-    from .app import App
     from .client import Client
     from .slot import Slot
 
@@ -27,7 +26,7 @@ class State(Enum):
     STOPPING = 3
 
 
-app: 'App'
+app: App
 sio: AsyncServer
 server: Server
 loop: Optional[asyncio.AbstractEventLoop] = None

+ 3 - 3
nicegui/nicegui.py

@@ -57,7 +57,7 @@ def get_components(name: str):
 
 
 @app.on_event('startup')
-async def handle_startup(with_welcome_message: bool = True) -> None:
+def handle_startup(with_welcome_message: bool = True) -> None:
     if not globals.ui_run_has_been_called:
         raise RuntimeError('\n\n'
                            'You must call ui.run() to start the server.\n'
@@ -85,6 +85,8 @@ async def handle_startup(with_welcome_message: bool = True) -> None:
     globals.state = globals.State.STARTED
     if with_welcome_message:
         print_welcome_message()
+    if globals.air:
+        background_tasks.create(globals.air.connect())
 
 
 def print_welcome_message():
@@ -101,8 +103,6 @@ def print_welcome_message():
     if len(addresses) >= 2:
         addresses[-1] = 'and ' + addresses[-1]
     print(f'NiceGUI ready to go on {", ".join(addresses)}')
-    if globals.air:
-        background_tasks.create(globals.air.connect())
 
 
 @app.on_event('shutdown')

+ 3 - 3
nicegui/outbox.py

@@ -32,10 +32,10 @@ async def loop() -> None:
         coros = []
         try:
             for client_id, elements in update_queue.items():
-                elements = {element_id: element._to_dict() for element_id, element in elements.items()}
-                coros.append(globals.sio.emit('update', elements, room=client_id))
+                data = {element_id: element._to_dict() for element_id, element in elements.items()}
+                coros.append(globals.sio.emit('update', data, room=client_id))
                 if is_target_on_air(client_id):
-                    coros.append(globals.air.emit('update', elements, room=client_id))
+                    coros.append(globals.air.emit('update', data, room=client_id))
 
             update_queue.clear()
             for target_id, message_type, data in message_queue: