fix(tray): handle missing tkinter

This commit is contained in:
IMDelewer 2026-03-17 09:51:29 +03:00
parent d9bd6f0e44
commit 55ff0bbd06
1 changed files with 38 additions and 5 deletions

View File

@ -9,13 +9,27 @@ import sys
import threading
import time
import webbrowser
import pystray
import pyperclip
import asyncio as _asyncio
import customtkinter as ctk
from pathlib import Path
from typing import Dict, Optional
try:
import pystray
except Exception:
pystray = None
try:
import customtkinter as ctk
except Exception:
ctk = None
try:
from PIL import Image, ImageDraw, ImageFont
except Exception:
Image = None
ImageDraw = None
ImageFont = None
import proxy.tg_ws_proxy as tg_ws_proxy
@ -264,11 +278,23 @@ def restart_proxy():
def _show_error(text: str, title: str = "TG WS Proxy — Ошибка"):
if sys.platform == "win32":
try:
ctypes.windll.user32.MessageBoxW(0, text, title, 0x10)
return
except Exception:
pass
print(f"{title}: {text}", file=sys.stderr)
def _show_info(text: str, title: str = "TG WS Proxy"):
if sys.platform == "win32":
try:
ctypes.windll.user32.MessageBoxW(0, text, title, 0x40)
return
except Exception:
pass
print(f"{title}: {text}", file=sys.stdout)
def _on_open_in_telegram(icon=None, item=None):
@ -656,6 +682,13 @@ def run_tray():
log.info("Config: %s", _config)
log.info("Log file: %s", LOG_FILE)
if ctk is None:
_show_error(
"Для tray-режима требуется tkinter (Tcl/Tk).\n\n"
"Windows: переустановите Python с включённым Tcl/Tk.\n"
"Linux: установите пакет python3-tk / tk.")
return
if pystray is None or Image is None:
log.error("pystray or Pillow not installed; "
"running in console mode")