Skip to content

Commit

Permalink
Revert "refactoring"
Browse files Browse the repository at this point in the history
This reverts commit bf089c2.
  • Loading branch information
falkoschindler committed May 25, 2024
1 parent 3250b23 commit 540dda4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
12 changes: 7 additions & 5 deletions nicegui/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,27 +206,29 @@ def run_javascript(self, code: str, *,
'Now the method automatically returns when receiving a response without checking regularly in an interval. '
'Please remove the "check_interval" argument.')

request_id = str(uuid.uuid4())
target_id = self._temporary_socket_id or self.id

def send_and_forget():
self.outbox.enqueue_message('run_javascript', {'code': code})
self.outbox.enqueue_message('run_javascript', {'code': code}, target_id)

async def send_and_wait():
if self is self.auto_index_client:
raise RuntimeError('Cannot await JavaScript responses on the auto-index page. '
'There could be multiple clients connected and it is not clear which one to wait for.')
request_id = str(uuid.uuid4())
self.outbox.enqueue_message('run_javascript', {'code': code, 'request_id': request_id})
self.outbox.enqueue_message('run_javascript', {'code': code, 'request_id': request_id}, target_id)
return await JavaScriptRequest(request_id, timeout=timeout)

return AwaitableResponse(send_and_forget, send_and_wait)

def open(self, target: Union[Callable[..., Any], str], new_tab: bool = False) -> None:
"""Open a new page in the client."""
path = target if isinstance(target, str) else self.page_routes[target]
self.outbox.enqueue_message('open', {'path': path, 'new_tab': new_tab})
self.outbox.enqueue_message('open', {'path': path, 'new_tab': new_tab}, self.id)

def download(self, src: Union[str, bytes], filename: Optional[str] = None, media_type: str = '') -> None:
"""Download a file from a given URL or raw bytes."""
self.outbox.enqueue_message('download', {'src': src, 'filename': filename, 'media_type': media_type})
self.outbox.enqueue_message('download', {'src': src, 'filename': filename, 'media_type': media_type}, self.id)

def on_connect(self, handler: Union[Callable[..., Any], Awaitable]) -> None:
"""Add a callback to be invoked when the client connects."""
Expand Down
3 changes: 2 additions & 1 deletion nicegui/functions/notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ def notify(message: Any, *,
options = {ARG_MAP.get(key, key): value for key, value in locals().items() if key != 'kwargs' and value is not None}
options['message'] = str(message)
options.update(kwargs)
context.client.outbox.enqueue_message('notify', options)
client = context.client
client.outbox.enqueue_message('notify', options, client.id)
3 changes: 1 addition & 2 deletions nicegui/outbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,9 @@ def enqueue_delete(self, element: Element) -> None:
self.updates[element.id] = None
self._set_enqueue_event()

def enqueue_message(self, message_type: MessageType, data: Any) -> None:
def enqueue_message(self, message_type: MessageType, data: Any, target_id: ClientId) -> None:
"""Enqueue a message for the given client."""
self.client.check_existence()
target_id = self.client._temporary_socket_id or self.client.id # pylint: disable=protected-access
self.messages.append((target_id, message_type, data))
self._set_enqueue_event()

Expand Down

0 comments on commit 540dda4

Please sign in to comment.