fix(tray): handle missing tkinter
This commit is contained in:
parent
d9bd6f0e44
commit
55ff0bbd06
39
windows.py
39
windows.py
|
|
@ -9,13 +9,27 @@ import sys
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
import webbrowser
|
import webbrowser
|
||||||
import pystray
|
|
||||||
import pyperclip
|
import pyperclip
|
||||||
import asyncio as _asyncio
|
import asyncio as _asyncio
|
||||||
import customtkinter as ctk
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Dict, Optional
|
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
|
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 — Ошибка"):
|
def _show_error(text: str, title: str = "TG WS Proxy — Ошибка"):
|
||||||
|
if sys.platform == "win32":
|
||||||
|
try:
|
||||||
ctypes.windll.user32.MessageBoxW(0, text, title, 0x10)
|
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"):
|
def _show_info(text: str, title: str = "TG WS Proxy"):
|
||||||
|
if sys.platform == "win32":
|
||||||
|
try:
|
||||||
ctypes.windll.user32.MessageBoxW(0, text, title, 0x40)
|
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):
|
def _on_open_in_telegram(icon=None, item=None):
|
||||||
|
|
@ -656,6 +682,13 @@ def run_tray():
|
||||||
log.info("Config: %s", _config)
|
log.info("Config: %s", _config)
|
||||||
log.info("Log file: %s", LOG_FILE)
|
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:
|
if pystray is None or Image is None:
|
||||||
log.error("pystray or Pillow not installed; "
|
log.error("pystray or Pillow not installed; "
|
||||||
"running in console mode")
|
"running in console mode")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue