-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
53 lines (48 loc) · 1.93 KB
/
config.py
File metadata and controls
53 lines (48 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import json
from pathlib import Path
from typing import Dict, Any
class Config:
def __init__(self, config_file: str = "config.json"):
self.config_file = Path(config_file)
self.defaults = {
"format": "display",
"show_status_icon": True,
"playing_icon": "▶",
"paused_icon": "⏸",
"media_engine_url": "http://localhost:5000",
"vrchat_ip": "127.0.0.1",
"vrchat_port": 9000,
"auto_send_delay": 3000,
"show_music_msg": True,
"show_sys_msg": False,
"sys_msg_separator": " | ",
"show_cpu_usage": True,
"show_ram_usage": True,
"show_cpu_temp": True,
"show_gpu_temp": True
}
self.data = self.load()
def load(self) -> Dict[str, Any]:
"""Загрузить конфиг из файла или создать новый"""
if self.config_file.exists():
try:
with open(self.config_file, 'r', encoding='utf-8') as f:
return json.load(f)
except Exception as e:
print(f"Error loading config: {e}")
return self.defaults.copy()
return self.defaults.copy()
def save(self):
"""Сохранить конфиг в файл"""
try:
with open(self.config_file, 'w', encoding='utf-8') as f:
json.dump(self.data, f, indent=2, ensure_ascii=False)
except Exception as e:
print(f"Error saving config: {e}")
def get(self, key: str, default=None):
"""Получить значение из конфига"""
return self.data.get(key, default if default is not None else self.defaults.get(key))
def set(self, key: str, value: Any):
"""Установить значение в конфиге"""
self.data[key] = value
self.save()