Files
MrBlakeandClaude Opus 5.5 7e276912da K65 Studio: Linux control app for the Corsair K65 PLUS Wireless
Bragi protocol over hidraw, device service with heartbeat and
notifications, PySide6 UI with animated preview, profiles, tray,
autostart, udev rule and installer.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-23 21:02:59 +02:00

66 lines
2.1 KiB
Python

"""Profiles and app settings, stored as JSON in ~/.config/k65studio/config.json."""
from __future__ import annotations
import json
import os
from dataclasses import asdict, dataclass, field
from pathlib import Path
CONFIG_DIR = Path(os.environ.get("XDG_CONFIG_HOME", Path.home() / ".config")) / "k65studio"
CONFIG_FILE = CONFIG_DIR / "config.json"
@dataclass
class Profile:
effect: str = "static"
colors: list[str] = field(default_factory=lambda: ["#00e5ff", "#ff2d95"])
random_colors: bool = False
speed: str = "medium"
brightness: int = 100 # percent
sleep_minutes: int = 15
game_mode: bool = False
lock_win: bool = True
lock_alt_tab: bool = False
lock_alt_f4: bool = False
lock_shift_tab: bool = False
@classmethod
def from_dict(cls, data: dict) -> "Profile":
known = {k: v for k, v in data.items() if k in cls.__dataclass_fields__}
return cls(**known)
@dataclass
class Config:
active: str = "Standard"
profiles: dict[str, Profile] = field(default_factory=lambda: {"Standard": Profile()})
start_minimized: bool = False
restore_hardware_on_exit: bool = True
@property
def profile(self) -> Profile:
if self.active not in self.profiles:
self.active = next(iter(self.profiles))
return self.profiles[self.active]
@classmethod
def load(cls) -> "Config":
try:
data = json.loads(CONFIG_FILE.read_text())
except (OSError, ValueError):
return cls()
profiles = {name: Profile.from_dict(p) for name, p in data.get("profiles", {}).items()}
return cls(
active=data.get("active", "Standard"),
profiles=profiles or {"Standard": Profile()},
start_minimized=data.get("start_minimized", False),
restore_hardware_on_exit=data.get("restore_hardware_on_exit", True),
)
def save(self) -> None:
CONFIG_DIR.mkdir(parents=True, exist_ok=True)
tmp = CONFIG_FILE.with_suffix(".tmp")
tmp.write_text(json.dumps(asdict(self), indent=2, ensure_ascii=False))
tmp.replace(CONFIG_FILE)