diff options
author | Devaev Maxim <[email protected]> | 2021-04-16 23:45:11 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2021-04-16 23:45:11 +0300 |
commit | 5794fb1c4604095c0080cb5056fde363e500a202 (patch) | |
tree | ebd692373998105a873af439eaafe5c6c0cdab51 /kvmd | |
parent | ba1e636686c827a76c00ed137b16731082dfe4c9 (diff) |
pikvm/pikvm#231, pikvm/pikvm#279: pak options
Diffstat (limited to 'kvmd')
-rw-r--r-- | kvmd/apps/kvmd/api/hid.py | 11 | ||||
-rw-r--r-- | kvmd/apps/kvmd/server.py | 4 |
2 files changed, 10 insertions, 5 deletions
diff --git a/kvmd/apps/kvmd/api/hid.py b/kvmd/apps/kvmd/api/hid.py index 418e065d..71e711ff 100644 --- a/kvmd/apps/kvmd/api/hid.py +++ b/kvmd/apps/kvmd/api/hid.py @@ -108,19 +108,22 @@ class HidApi: # ===== - @exposed_http("GET", "/hid/keymaps") - async def __keymaps_handler(self, _: Request) -> Response: + def get_keymaps(self) -> Dict: # Ugly hack to generate hid_keymaps_state (see server.py) keymaps: Set[str] = set() for keymap_name in os.listdir(self.__keymaps_dir_path): path = os.path.join(self.__keymaps_dir_path, keymap_name) if os.access(path, os.R_OK) and stat.S_ISREG(os.stat(path).st_mode): keymaps.add(keymap_name) - return make_json_response({ + return { "keymaps": { "default": self.__default_keymap_name, "available": sorted(keymaps), }, - }) + } + + @exposed_http("GET", "/hid/keymaps") + async def __keymaps_handler(self, _: Request) -> Response: + return make_json_response(self.get_keymaps()) @exposed_http("POST", "/hid/print") async def __print_handler(self, request: Request) -> Response: diff --git a/kvmd/apps/kvmd/server.py b/kvmd/apps/kvmd/server.py index 84f21c08..fcd21ae0 100644 --- a/kvmd/apps/kvmd/server.py +++ b/kvmd/apps/kvmd/server.py @@ -195,6 +195,7 @@ class KvmdServer(HttpServer): # pylint: disable=too-many-arguments,too-many-ins ], ] + self.__hid_api = HidApi(hid, keymap_path, mouse_x_range, mouse_y_range) # Ugly hack to get keymaps state self.__apis: List[object] = [ self, AuthApi(auth_manager), @@ -202,7 +203,7 @@ class KvmdServer(HttpServer): # pylint: disable=too-many-arguments,too-many-ins LogApi(log_reader), WolApi(wol), UserGpioApi(user_gpio), - HidApi(hid, keymap_path, mouse_x_range, mouse_y_range), + self.__hid_api, AtxApi(atx), MsdApi(msd, sync_chunk_size), StreamerApi(streamer), @@ -263,6 +264,7 @@ class KvmdServer(HttpServer): # pylint: disable=too-many-arguments,too-many-ins await self.__register_ws_client(client) try: await self.__send_event(client.ws, "gpio_model_state", await self.__user_gpio.get_model()) + await self.__send_event(client.ws, "hid_keymaps_state", self.__hid_api.get_keymaps()) await asyncio.gather(*[ self.__send_event(client.ws, component.event_type, await component.get_state()) for component in self.__components |