This commit is contained in:
Devaev Maxim
2021-04-16 23:45:11 +03:00
parent ba1e636686
commit 5794fb1c46
7 changed files with 134 additions and 60 deletions

View File

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