diff --git a/svc/src/hudctrl/api.py b/svc/src/hudctrl/api.py index 82d0478..c41f986 100644 --- a/svc/src/hudctrl/api.py +++ b/svc/src/hudctrl/api.py @@ -75,12 +75,18 @@ async def list_screens(): @app.post( - '/screen/{number}/refresh', + '/screen/{name}/refresh', response_class=fastapi.Response, status_code=fastapi.status.HTTP_204_NO_CONTENT, ) -async def refresh_screen(number: int): - await svc.refresh_screen(number) +async def refresh_screen(name: str): + try: + await svc.refresh_screen(name) + except KeyError: + raise fastapi.HTTPException( + fastapi.status.HTTP_404_NOT_FOUND, + detail=f'No such screen: {name}', + ) from None @app.on_event('shutdown') diff --git a/svc/src/hudctrl/hud.py b/svc/src/hudctrl/hud.py index ee85686..85e21c7 100644 --- a/svc/src/hudctrl/hud.py +++ b/svc/src/hudctrl/hud.py @@ -31,6 +31,7 @@ class HUDService: self.monitor_config: Optional[MonitorConfig] = None self.marionette: Optional[Marionette] = None self.urls: Dict[str, str] = {} + self.windows: Dict[str, str] = {} self.urls_file = Path('urls.json') @@ -49,6 +50,7 @@ class HUDService: async def initialize(self) -> None: assert self.marionette + self.windows.clear() if not self.monitor_config: raise NoMonitorConfig( 'Cannot initialize display: No monitor config supplied' @@ -71,6 +73,7 @@ class HUDService: continue if window is None: window = await self.marionette.new_window('window') + self.windows[monitor.name] = window await self.marionette.switch_to_window(window) await self.marionette.set_window_rect( x=monitor.pos_x, @@ -107,10 +110,9 @@ class HUDService: dict, ) - async def refresh_screen(self, number: int) -> None: + async def refresh_screen(self, name: str) -> None: assert self.marionette - windows = await self.marionette.get_window_handles() - await self.marionette.switch_to_window(windows[number]) + await self.marionette.switch_to_window(self.windows[name]) await self.marionette.refresh() async def set_display(self, host: str, port: int) -> None: