add wp_app_config.py for central configuration

This commit is contained in:
Désiré Werner Menrath 2025-04-30 09:48:40 +02:00
parent 18ed97bf20
commit 2e94a324a6

78
app_config.py Normal file
View File

@ -0,0 +1,78 @@
from pathlib import Path
from typing import Dict, Any
class AppConfig:
"""Central configuration class for the application"""
# Base paths
BASE_DIR = Path.home()
CONFIG_DIR = BASE_DIR / ".config/wire_py"
TEMP_DIR = Path("/tmp/tlecdcwg")
# Configuration files
SETTINGS_FILE = CONFIG_DIR / "settings"
KEYS_FILE = CONFIG_DIR / "keys"
AUTOSTART_SERVICE = Path.home() / ".config/systemd/user/wg_start.service"
# Localization
APP_NAME = "wirepy"
LOCALE_DIR = "/usr/share/locale/"
# Default settings
DEFAULT_SETTINGS = {
"updates": "on",
"theme": "light",
"tooltip": True,
"autostart": "off"
}
# UI configuration
UI_CONFIG = {
"window_title": "Wire-Py",
"window_size": (800, 600),
"font_family": "Ubuntu",
"font_size": 11
}
# System-dependent paths
SYSTEM_PATHS = {
"ssl_decrypt": "/usr/local/bin/ssl_decrypt.py",
"ssl_encrypt": "/usr/local/bin/ssl_encrypt.py"
}
@classmethod
def ensure_directories(cls) -> None:
"""Ensures that all required directories exist"""
cls.CONFIG_DIR.mkdir(parents=True, exist_ok=True)
cls.TEMP_DIR.mkdir(parents=True, exist_ok=True)
@classmethod
def create_default_settings(cls) -> None:
"""Creates default settings if they don't exist"""
if not cls.SETTINGS_FILE.exists():
content = "\n".join(f"[{k.upper()}]\n{v}" for k, v in cls.DEFAULT_SETTINGS.items())
cls.SETTINGS_FILE.write_text(content)
@classmethod
def get_image_paths(cls) -> Dict[str, Path]:
"""Returns paths to UI images"""
return {
"main_icon": cls.CONFIG_DIR / "images/main.png",
"warning": cls.CONFIG_DIR / "images/warning.png",
"success": cls.CONFIG_DIR / "images/success.png",
"error": cls.CONFIG_DIR / "images/error.png"
}
@classmethod
def get_autostart_content(cls) -> str:
"""Returns the content for the autostart service file"""
return """[Unit]
Description=Automatic Tunnel Start
After=network-online.target
[Service]
Type=oneshot
ExecStartPre=/bin/sleep 5
ExecStart=/usr/local/bin/start_wg.py
[Install]
WantedBy=default.target"""