78 lines
2.3 KiB
Python
78 lines
2.3 KiB
Python
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""" |