Aggiunge GUI di configurazione
This commit is contained in:
@@ -6,6 +6,8 @@ from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
import tomli_w
|
||||
|
||||
from .default_config import DEFAULT_CONFIG_TOML
|
||||
from .paths import default_config_path, expand_path
|
||||
|
||||
@@ -78,10 +80,22 @@ def copy_example_config(destination: Path) -> None:
|
||||
|
||||
def load_config(path: Path | None = None) -> AppConfig:
|
||||
config_path = ensure_default_config(path)
|
||||
data = tomllib.loads(config_path.read_text(encoding="utf-8"))
|
||||
data = load_config_data(config_path)
|
||||
return parse_config(data, config_path)
|
||||
|
||||
|
||||
def load_config_data(path: Path | None = None) -> dict[str, Any]:
|
||||
config_path = ensure_default_config(path)
|
||||
return tomllib.loads(config_path.read_text(encoding="utf-8"))
|
||||
|
||||
|
||||
def save_config_data(data: dict[str, Any], path: Path | None = None) -> Path:
|
||||
config_path = path or default_config_path()
|
||||
config_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
config_path.write_text(tomli_w.dumps(data), encoding="utf-8")
|
||||
return config_path
|
||||
|
||||
|
||||
def parse_config(data: dict[str, Any], path: Path) -> AppConfig:
|
||||
service = data.get("service", {})
|
||||
tray = data.get("tray", {})
|
||||
|
||||
Reference in New Issue
Block a user