mirror of
https://github.com/Textualize/textual-web.git
synced 2025-10-17 02:36:40 +03:00
When open_url meta is read from the child process stdout, send the OpenUrl packet to Ganglion
This commit is contained in:
@@ -191,7 +191,7 @@ class AppSession(Session):
|
||||
)
|
||||
|
||||
async def run(self) -> None:
|
||||
"""This loop reads the processes standard output, and relays it to the websocket."""
|
||||
"""This loop reads stdout from the process and relays it through the websocket."""
|
||||
|
||||
self.state = ProcessState.RUNNING
|
||||
|
||||
@@ -236,8 +236,9 @@ class AppSession(Session):
|
||||
await on_data(payload)
|
||||
elif type_bytes == META:
|
||||
meta_data = json.loads(payload)
|
||||
if meta_data.get("type") in {"exit", "blur", "focus"}:
|
||||
await self.send_meta({"type": meta_data["type"]})
|
||||
meta_type = meta_data.get("type")
|
||||
if meta_type in {"exit", "blur", "focus"}:
|
||||
await self.send_meta({"type": meta_type})
|
||||
else:
|
||||
await on_meta(json.loads(payload))
|
||||
|
||||
|
||||
@@ -65,7 +65,17 @@ class _ClientConnector(SessionConnector):
|
||||
await self.client.send(packets.SessionData(self.route_key, data))
|
||||
|
||||
async def on_meta(self, meta: Meta) -> None:
|
||||
pass
|
||||
"""On receiving a meta dict from the running process, send it to the Ganglion server."""
|
||||
meta_type = meta.get("type")
|
||||
if meta_type == "open_url":
|
||||
await self.client.send(
|
||||
packets.OpenUrl(url=meta["url"], new_tab=meta["new_tab"])
|
||||
)
|
||||
else:
|
||||
log.warning(
|
||||
f"Unknown meta type: {meta_type!r}. Full meta: {meta!r}.\n"
|
||||
"You may be running a version of Textual unsupported by this version of Textual Web."
|
||||
)
|
||||
|
||||
async def on_close(self) -> None:
|
||||
await self.client.send(packets.SessionClose(self.session_id, self.route_key))
|
||||
@@ -437,6 +447,3 @@ class GanglionClient(Handlers):
|
||||
)
|
||||
if session_process is not None:
|
||||
await session_process.send_meta({"type": "blur"})
|
||||
|
||||
async def on_open_url(self, packet: OpenUrl) -> None:
|
||||
return await super().on_open_url(packet)
|
||||
|
||||
@@ -1042,10 +1042,6 @@ class Handlers:
|
||||
"""App was blurred."""
|
||||
await self.on_default(packet)
|
||||
|
||||
async def on_open_url(self, packet: OpenUrl) -> None:
|
||||
"""Open a URL in the browser."""
|
||||
await self.on_default(packet)
|
||||
|
||||
async def on_default(self, packet: Packet) -> None:
|
||||
"""Called when a packet is not handled."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user