11from asyncio import to_thread
2- from traceback import print_exc
2+ from contextlib import closing
3+
34import inject
4- import win32gui
5- from win32con import SW_HIDE , SW_SHOW
65import win32console
6+ import win32gui
77from PIL import Image
88from pystray import Menu , MenuItem , Icon
9+ from win32con import SW_HIDE , SW_SHOW
10+
911import _meta as app
1012from active_window_checker import AppMode
11- from tray .utils import ref , make_toggle , make_radiobutton
12- from uac import has_admin_rights
1313from app_close import AppCloseManager
1414from auto_update import AutoUpdater
1515from interaction import InteractionManager
1616from inversion_rules import InversionRulesController
17- from settings import UserSettingsController , UserSettings , OPTION_PATH , OPTION_CHANGE_HANDLER , T
18- from utils import explore , app_abs_path
17+ from settings import UserSettingsController , OPTION_PATH , OPTION_CHANGE_HANDLER , T
18+ from tray .utils import ref , make_toggle , make_radiobutton
19+ from uac import has_admin_rights
20+ from utils import explore , app_abs_path , show_exceptions
1921
2022
2123class Tray :
@@ -39,23 +41,18 @@ def setup(self):
3941 ))
4042 win32gui .ShowWindow (self .console_hwnd , SW_HIDE )
4143
44+ @show_exceptions ()
4245 def run (self ):
43- try :
44- self .tray = Icon (
45- app .__product_name__ ,
46- Image .open (app_abs_path (app .__icon__ )),
47- menu = self .build_menu ()
48- )
49- self .tray .run ()
50- except :
51- print_exc ()
52- raise
46+ self .tray = Icon (
47+ app .__product_name__ ,
48+ Image .open (app_abs_path (app .__icon__ )),
49+ menu = self .build_menu ()
50+ )
51+ self .tray .run ()
5352
5453 async def run_async (self ):
55- try :
54+ with closing ( self ) :
5655 await to_thread (self .run )
57- finally :
58- self .close ()
5956
6057 def close (self ):
6158 if self .tray :
0 commit comments