From 55ff0bbd069428a46285ae7833fbdb13b351b4de Mon Sep 17 00:00:00 2001 From: IMDelewer Date: Tue, 17 Mar 2026 09:51:29 +0300 Subject: [PATCH] fix(tray): handle missing tkinter --- windows.py | 43 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/windows.py b/windows.py index 64e581b..33dab3a 100644 --- a/windows.py +++ b/windows.py @@ -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 -from PIL import Image, ImageDraw, ImageFont + +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 — Ошибка"): - ctypes.windll.user32.MessageBoxW(0, text, title, 0x10) + 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"): - ctypes.windll.user32.MessageBoxW(0, text, title, 0x40) + 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")