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
parent
dbf266de5b
commit
78169c06f0
|
@ -75,12 +75,18 @@ async def list_screens():
|
||||||
|
|
||||||
|
|
||||||
@app.post(
|
@app.post(
|
||||||
'/screen/{number}/refresh',
|
'/screen/{name}/refresh',
|
||||||
response_class=fastapi.Response,
|
response_class=fastapi.Response,
|
||||||
status_code=fastapi.status.HTTP_204_NO_CONTENT,
|
status_code=fastapi.status.HTTP_204_NO_CONTENT,
|
||||||
)
|
)
|
||||||
async def refresh_screen(number: int):
|
async def refresh_screen(name: str):
|
||||||
await svc.refresh_screen(number)
|
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')
|
@app.on_event('shutdown')
|
||||||
|
|
|
@ -31,6 +31,7 @@ class HUDService:
|
||||||
self.monitor_config: Optional[MonitorConfig] = None
|
self.monitor_config: Optional[MonitorConfig] = None
|
||||||
self.marionette: Optional[Marionette] = None
|
self.marionette: Optional[Marionette] = None
|
||||||
self.urls: Dict[str, str] = {}
|
self.urls: Dict[str, str] = {}
|
||||||
|
self.windows: Dict[str, str] = {}
|
||||||
|
|
||||||
self.urls_file = Path('urls.json')
|
self.urls_file = Path('urls.json')
|
||||||
|
|
||||||
|
@ -49,6 +50,7 @@ class HUDService:
|
||||||
|
|
||||||
async def initialize(self) -> None:
|
async def initialize(self) -> None:
|
||||||
assert self.marionette
|
assert self.marionette
|
||||||
|
self.windows.clear()
|
||||||
if not self.monitor_config:
|
if not self.monitor_config:
|
||||||
raise NoMonitorConfig(
|
raise NoMonitorConfig(
|
||||||
'Cannot initialize display: No monitor config supplied'
|
'Cannot initialize display: No monitor config supplied'
|
||||||
|
@ -71,6 +73,7 @@ class HUDService:
|
||||||
continue
|
continue
|
||||||
if window is None:
|
if window is None:
|
||||||
window = await self.marionette.new_window('window')
|
window = await self.marionette.new_window('window')
|
||||||
|
self.windows[monitor.name] = window
|
||||||
await self.marionette.switch_to_window(window)
|
await self.marionette.switch_to_window(window)
|
||||||
await self.marionette.set_window_rect(
|
await self.marionette.set_window_rect(
|
||||||
x=monitor.pos_x,
|
x=monitor.pos_x,
|
||||||
|
@ -107,10 +110,9 @@ class HUDService:
|
||||||
dict,
|
dict,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def refresh_screen(self, number: int) -> None:
|
async def refresh_screen(self, name: str) -> None:
|
||||||
assert self.marionette
|
assert self.marionette
|
||||||
windows = await self.marionette.get_window_handles()
|
await self.marionette.switch_to_window(self.windows[name])
|
||||||
await self.marionette.switch_to_window(windows[number])
|
|
||||||
await self.marionette.refresh()
|
await self.marionette.refresh()
|
||||||
|
|
||||||
async def set_display(self, host: str, port: int) -> None:
|
async def set_display(self, host: str, port: int) -> None:
|
||||||
|
|
Loading…
Reference in New Issue