53 lines
1.5 KiB
Python
53 lines
1.5 KiB
Python
import json
|
|
import os
|
|
from pathlib import Path
|
|
|
|
DEFAULT_CONFIG = {
|
|
"app_title": "FJLA Gateway",
|
|
"checks": {
|
|
"network_targets": [["1.1.1.1", 53], ["8.8.8.8", 53]],
|
|
"ziti_target": ["127.0.0.1", 3020],
|
|
},
|
|
"services": [
|
|
{
|
|
"id": "helloworld",
|
|
"title": "Test Service",
|
|
"desc": "Test Service",
|
|
"type": "browser",
|
|
"target": "https://www.example.com",
|
|
},
|
|
],
|
|
}
|
|
|
|
def get_config_path():
|
|
"""Determines standard user config path: ~/.config/launcher/config.json"""
|
|
config_dir = Path.home() / ".config" / "launcher"
|
|
config_dir.mkdir(parents=True, exist_ok=True)
|
|
return config_dir / "config.json"
|
|
|
|
def load_launcher_config(config_path=None):
|
|
path = Path(config_path) if config_path else get_config_path()
|
|
|
|
if not path.exists():
|
|
save_default_config(path)
|
|
return DEFAULT_CONFIG
|
|
|
|
try:
|
|
with open(path, "r", encoding="utf-8") as f:
|
|
user_config = json.load(f)
|
|
merged = DEFAULT_CONFIG.copy()
|
|
merged.update(user_config)
|
|
return merged
|
|
except Exception as e:
|
|
print(
|
|
f"Error loading config from {path}: {e}. Running with default config"
|
|
)
|
|
return DEFAULT_CONFIG
|
|
|
|
def save_default_config(path):
|
|
try:
|
|
with open(path, "w", encoding="utf-8") as f:
|
|
json.dump(DEFAULT_CONFIG, f, indent=4)
|
|
print(f"Created default configuration at: {path}")
|
|
except Exception as e:
|
|
print(f"Failed to save default config: {e}") |