feat: full implementation - switcher, device watcher, hotkeys, tray, settings UI
This commit is contained in:
34
core/hotkey_manager.py
Normal file
34
core/hotkey_manager.py
Normal file
@@ -0,0 +1,34 @@
|
||||
import logging
|
||||
import keyboard
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class HotkeyManager:
|
||||
def __init__(self, config_manager, switcher):
|
||||
self._config_manager = config_manager
|
||||
self._switcher = switcher
|
||||
self._registered: list[str] = []
|
||||
|
||||
def register_all(self) -> None:
|
||||
self.unregister_all()
|
||||
config = self._config_manager.get()
|
||||
for profile in config.get("profiles", []):
|
||||
hotkey = profile.get("hotkey", "").strip()
|
||||
if not hotkey:
|
||||
continue
|
||||
profile_id = profile["id"]
|
||||
try:
|
||||
keyboard.add_hotkey(hotkey, self._switcher.apply_profile, args=[profile_id])
|
||||
self._registered.append(hotkey)
|
||||
logger.info("Hotkey '%s' -> profile '%s'", hotkey, profile_id)
|
||||
except Exception as exc:
|
||||
logger.warning("Failed to register hotkey '%s': %s", hotkey, exc)
|
||||
|
||||
def unregister_all(self) -> None:
|
||||
for hotkey in self._registered:
|
||||
try:
|
||||
keyboard.remove_hotkey(hotkey)
|
||||
except Exception:
|
||||
pass
|
||||
self._registered.clear()
|
||||
Reference in New Issue
Block a user