Refacto, enum, utils, WIP

This commit is contained in:
2026-03-16 13:47:30 +01:00
parent 5b065dddfc
commit e922825481
8 changed files with 46 additions and 47 deletions

View File

@@ -2,20 +2,7 @@ import json
from pathlib import Path
from typing import Any, Callable, NotRequired, TypedDict, cast
# Configuration du chemin du fichier de configuration avec son nom.
def _get_config_path() -> Path:
from sys import argv, executable
import os
import sys
from pathlib import Path
# Si l'app est packagée (PyInstaller)
if getattr(sys, "frozen", False):
base_path = Path(executable).parent
else:
base_path = Path(os.path.realpath(argv[0])).parent
return base_path / "config.json"
from utils import get_bundle_dir
class ConfigData(TypedDict):
discord_user_id: NotRequired[str]
@@ -29,7 +16,7 @@ class ConfigField(TypedDict):
validator: Validator
normalizer: Normalizer
CONFIG_PATH = _get_config_path()
CONFIG_PATH = get_bundle_dir() / "config.json"
DISCORD_USER_KEY = "discord_user_id"
VOLUME_KEY = "volume"
@@ -49,7 +36,7 @@ CONFIG_SCHEMA: dict[str, ConfigField] = {
class ConfigManager:
def __init__(self, path: Path | None = None) -> None:
self.path = path or _get_config_path()
self.path = path or CONFIG_PATH
self._data: ConfigData = self._load()
self._dirty = False