svc: Save display config on change
When the display host updates its monitor configuration by making the *PUT /display/monitors* HTTP request, the configuration is now saved to disk. This will allow the controller to "remember" the configuration the next time it starts up.master
parent
f9eaf9f9d7
commit
debce63bba
|
@ -54,7 +54,8 @@ async def get_monitor_config():
|
||||||
|
|
||||||
@app.put('/display/monitors')
|
@app.put('/display/monitors')
|
||||||
async def put_monitor_config(
|
async def put_monitor_config(
|
||||||
monitors: str = fastapi.Body(..., media_type='text/plain')
|
bgtasks: fastapi.BackgroundTasks,
|
||||||
|
monitors: str = fastapi.Body(..., media_type='text/plain'),
|
||||||
):
|
):
|
||||||
try:
|
try:
|
||||||
svc.monitor_config = MonitorConfig.from_string(monitors)
|
svc.monitor_config = MonitorConfig.from_string(monitors)
|
||||||
|
@ -64,6 +65,7 @@ async def put_monitor_config(
|
||||||
fastapi.status.HTTP_400_BAD_REQUEST,
|
fastapi.status.HTTP_400_BAD_REQUEST,
|
||||||
detail=f'Invalid monitor config: {e}',
|
detail=f'Invalid monitor config: {e}',
|
||||||
)
|
)
|
||||||
|
bgtasks.add_task(svc.save_config)
|
||||||
return {'monitor_config': svc.monitor_config}
|
return {'monitor_config': svc.monitor_config}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -143,6 +143,19 @@ class HUDService:
|
||||||
await self.marionette.switch_to_window(self.windows[name])
|
await self.marionette.switch_to_window(self.windows[name])
|
||||||
await self.marionette.refresh()
|
await self.marionette.refresh()
|
||||||
|
|
||||||
|
def save_config(self) -> None:
|
||||||
|
log.info('Saving configuration to %s', self.config_file)
|
||||||
|
config = Configuration(
|
||||||
|
monitors=self.monitor_config.monitors
|
||||||
|
if self.monitor_config
|
||||||
|
else [],
|
||||||
|
urls=self.urls,
|
||||||
|
host=self.host,
|
||||||
|
port=self.port,
|
||||||
|
)
|
||||||
|
f = self.config_file.open('w', encoding='utf-8')
|
||||||
|
f.write(config.json())
|
||||||
|
|
||||||
async def set_display(self, host: str, port: int) -> None:
|
async def set_display(self, host: str, port: int) -> None:
|
||||||
if self.marionette:
|
if self.marionette:
|
||||||
log.warning('Closing existing Marionette connection')
|
log.warning('Closing existing Marionette connection')
|
||||||
|
|
Loading…
Reference in New Issue