1
0
Fork 0

api: Refresh screen by monitor name

In order to be more precise about which screen will be refreshed, the
*POST /screen/{number}/refresh* path operation has been changed to *POST
/screen/{name}/refresh*.  It takes a monitor name as the key instead of
an array index.
master
Dustin 2022-04-30 14:15:10 -05:00
parent dbf266de5b
commit 78169c06f0
2 changed files with 14 additions and 6 deletions

View File

@ -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')

View File

@ -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: