Exemplo n.º 1
0
 async def launch(
     self,
     bundle_id: str,
     args: Optional[List[str]] = None,
     env: Optional[Dict[str, str]] = None,
     foreground_if_running: bool = False,
     stop: Optional[asyncio.Event] = None,
 ) -> None:
     async with self.get_stub() as stub, stub.launch.open() as stream:
         request = LaunchRequest(
             start=LaunchRequest.Start(
                 bundle_id=bundle_id,
                 env=env,
                 app_args=args,
                 foreground_if_running=foreground_if_running,
                 wait_for=True if stop else False,
             )
         )
         await stream.send_message(request)
         if stop:
             await asyncio.gather(
                 drain_launch_stream(stream), end_launch_stream(stream, stop)
             )
         else:
             await stream.end()
             await drain_launch_stream(stream)
Exemplo n.º 2
0
async def client(
    client: CompanionClient,
    bundle_id: str,
    args: Optional[List[str]] = None,
    env: Optional[Dict[str, str]] = None,
    foreground_if_running: bool = False,
    stop: Optional[asyncio.Event] = None,
) -> None:
    async with client.stub.launch.open() as stream:
        request = LaunchRequest(start=Start(
            bundle_id=bundle_id,
            env=env,
            app_args=args,
            foreground_if_running=foreground_if_running,
            wait_for=True if stop else False,
        ))
        if stop:
            await stream.send_message(request)
            await asyncio.gather(_drain_stream(stream),
                                 _end_stream(stream, stop))
        else:
            await stream.send_message(request, end=True)
            await _drain_stream(stream)
Exemplo n.º 3
0
async def _end_stream(stream: Stream[LaunchRequest, LaunchResponse],
                      stop: asyncio.Event) -> None:
    await stop.wait()
    await stream.send_message(LaunchRequest(stop=Stop()), end=True)
Exemplo n.º 4
0
async def end_launch_stream(stream: Stream[LaunchRequest, LaunchResponse],
                            stop: asyncio.Event) -> None:
    await stop.wait()
    await stream.send_message(LaunchRequest(stop=LaunchRequest.Stop()))
    await stream.end()