From cf9f0d44b2b816eeb50e272cb6987d3bc6f82865 Mon Sep 17 00:00:00 2001 From: doronz Date: Tue, 21 Nov 2023 01:01:13 +0200 Subject: [PATCH] cdp_server: fix fastapi deprecation warning --- .../services/web_protocol/cdp_server.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/pymobiledevice3/services/web_protocol/cdp_server.py b/pymobiledevice3/services/web_protocol/cdp_server.py index f71d80342..f15910ff0 100644 --- a/pymobiledevice3/services/web_protocol/cdp_server.py +++ b/pymobiledevice3/services/web_protocol/cdp_server.py @@ -1,5 +1,6 @@ import asyncio import uuid +from contextlib import asynccontextmanager from fastapi import FastAPI, WebSocket from fastapi.logger import logger @@ -8,16 +9,18 @@ from pymobiledevice3.services.web_protocol.session_protocol import SessionProtocol from pymobiledevice3.services.webinspector import WirTypes -app = FastAPI() - -@app.on_event("startup") -async def startup_event(): +@asynccontextmanager +async def lifespan(app: FastAPI): app.state.inspector.connect() + yield + + +app = FastAPI(lifespan=lifespan) -@app.get('/json') -async def available_targets(): +@app.get('/json{_:path}') +async def available_targets(_: str): app.state.inspector.get_open_pages() targets = [] for app_id in app.state.inspector.application_pages: