1
0
Fork 0

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
Dustin 2022-12-18 12:53:06 -06:00
parent f9eaf9f9d7
commit debce63bba
2 changed files with 16 additions and 1 deletions

View File

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

View File

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