feat(android): embed python runtime and boot proxy service inside foreground service

This commit is contained in:
Dark-Avery
2026-03-16 21:13:35 +03:00
parent 47e5c6241d
commit ec6de3afb3
13 changed files with 366 additions and 14 deletions

1
proxy/__init__.py Normal file
View File

@@ -0,0 +1 @@
"""TG WS Proxy core package."""

View File

@@ -80,11 +80,20 @@ class ProxyAppRuntime:
root = logging.getLogger()
root.setLevel(logging.DEBUG if verbose else logging.INFO)
for handler in list(root.handlers):
if getattr(handler, "_tg_ws_proxy_runtime_handler", False):
root.removeHandler(handler)
try:
handler.close()
except Exception:
pass
fh = logging.FileHandler(str(self.log_file), encoding="utf-8")
fh.setLevel(logging.DEBUG)
fh.setFormatter(logging.Formatter(
"%(asctime)s %(levelname)-5s %(name)s %(message)s",
datefmt="%Y-%m-%d %H:%M:%S"))
fh._tg_ws_proxy_runtime_handler = True
root.addHandler(fh)
if not getattr(sys, "frozen", False):
@@ -93,6 +102,7 @@ class ProxyAppRuntime:
ch.setFormatter(logging.Formatter(
"%(asctime)s %(levelname)-5s %(message)s",
datefmt="%H:%M:%S"))
ch._tg_ws_proxy_runtime_handler = True
root.addHandler(ch)
def prepare(self) -> dict:
@@ -168,3 +178,6 @@ class ProxyAppRuntime:
self.stop_proxy()
time.sleep(delay_seconds)
return self.start_proxy()
def is_proxy_running(self) -> bool:
return bool(self._proxy_thread and self._proxy_thread.is_alive())