-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmain.py
More file actions
82 lines (73 loc) · 2.39 KB
/
main.py
File metadata and controls
82 lines (73 loc) · 2.39 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import os
import sys
import ctypes
import threading
from gui.app_window import AppWindow
from utils.logger import get_logger
from config.paths import ensure_runtime_layout
logger = get_logger("main")
def _validate_startup_proxies():
try:
from core.proxy_checker import load_proxies, check_proxies
from core.platforms import ProxyManager
pm = ProxyManager()
proxies = load_proxies(pm.proxies_file)
if proxies:
def _worker():
try:
check_proxies(proxies, workers=min(50, max(5, len(proxies))))
except Exception:
logger.exception("startup_proxy_check_failed")
t = threading.Thread(target=_worker, daemon=True)
t.start()
except Exception:
logger.exception("startup_proxy_validation_failed")
def configure_environment():
ensure_runtime_layout()
if sys.platform == 'darwin':
os.environ.setdefault('TK_SILENCE_DEPRECATION', '1')
if sys.platform.startswith('linux'):
os.environ.setdefault('GTK_THEME', 'Adwaita:dark')
if sys.platform.startswith('win'):
try:
ctypes.windll.shcore.SetProcessDpiAwareness(1)
except:
logger.exception("dpi_awareness_failed")
try:
ensure_runtime_layout()
except Exception:
logger.exception("support_files_creation_failed")
def run_startup_healthcheck():
status = {
"settings_ok": False,
"db_ok": False,
"proxies_file_ok": False,
"proxy_count": 0
}
try:
from config.settings import settings
settings.load()
status["settings_ok"] = True
except Exception:
logger.exception("healthcheck_settings_failed")
try:
from utils.database import db
db.get_statistics(1)
status["db_ok"] = True
except Exception:
logger.exception("healthcheck_db_failed")
try:
from core.platforms import ProxyManager
pm = ProxyManager()
status["proxies_file_ok"] = os.path.exists(pm.proxies_file)
status["proxy_count"] = len(pm.proxies)
except Exception:
logger.exception("healthcheck_proxy_failed")
logger.info("healthcheck=%s", status)
return status
if __name__ == "__main__":
configure_environment()
run_startup_healthcheck()
_validate_startup_proxies()
app = AppWindow()
app.run()