mirror of
https://github.com/infinition/Bjorn.git
synced 2026-03-19 02:00:24 +00:00
feat: Implement package management utilities with JSON endpoints for listing and uninstalling packages feat: Create plugin management utilities with endpoints for listing, configuring, and installing plugins feat: Develop schedule and trigger management utilities with CRUD operations for schedules and triggers
46 lines
1.2 KiB
Python
46 lines
1.2 KiB
Python
"""__init__.py - Keyboard layout loader for Loki HID subsystem.
|
|
|
|
Caches loaded layouts in memory.
|
|
"""
|
|
import json
|
|
import os
|
|
import logging
|
|
|
|
from logger import Logger
|
|
|
|
logger = Logger(name="loki.layouts", level=logging.DEBUG)
|
|
|
|
_LAYOUT_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
_cache = {}
|
|
|
|
|
|
def load(name: str = "us") -> dict:
|
|
"""Load a keyboard layout by name. Returns char → (modifier, keycode) map."""
|
|
name = name.lower()
|
|
if name in _cache:
|
|
return _cache[name]
|
|
|
|
path = os.path.join(_LAYOUT_DIR, f"{name}.json")
|
|
if not os.path.isfile(path):
|
|
logger.warning("Layout '%s' not found, falling back to 'us'", name)
|
|
path = os.path.join(_LAYOUT_DIR, "us.json")
|
|
name = "us"
|
|
if name in _cache:
|
|
return _cache[name]
|
|
|
|
with open(path, "r") as f:
|
|
data = json.load(f)
|
|
|
|
_cache[name] = data
|
|
logger.debug("Loaded keyboard layout '%s' (%d chars)", name, len(data))
|
|
return data
|
|
|
|
|
|
def available() -> list:
|
|
"""List available layout names."""
|
|
layouts = []
|
|
for f in os.listdir(_LAYOUT_DIR):
|
|
if f.endswith(".json"):
|
|
layouts.append(f[:-5])
|
|
return sorted(layouts)
|