|
7 | 7 | frompathlibimportPath
|
8 | 8 | importsubprocess
|
9 | 9 | importwinshell
|
10 |
| -fromPyQt6.QtWidgetsimportQSystemTrayIcon,QMenu,QMessageBox |
| 10 | +fromPyQt6.QtWidgetsimportQSystemTrayIcon,QMenu,QMessageBox,QApplication |
11 | 11 | fromPyQt6.QtGuiimportQIcon,QGuiApplication
|
12 |
| -fromPyQt6.QtCoreimportQCoreApplication,QSize,Qt,pyqtSlot,QProcess |
| 12 | +fromPyQt6.QtCoreimportQCoreApplication,QSize,Qt,pyqtSlot,QProcess,QEvent |
13 | 13 | fromcore.bar_managerimportBarManager
|
14 | 14 | fromsettingsimportGITHUB_URL,SCRIPT_PATH,APP_NAME,APP_NAME_FULL,DEFAULT_CONFIG_DIRECTORY,GITHUB_THEME_URL,BUILD_VERSION
|
15 | 15 | fromcore.configimportget_config
|
@@ -42,6 +42,18 @@ def __init__(self, bar_manager: BarManager):
|
42 | 42 | self.cli_pipi_handler=CliPipeHandler(self.stop_or_reload_application)
|
43 | 43 | self.start_cli_server()
|
44 | 44 |
|
| 45 | +defeventFilter(self,obj,event): |
| 46 | +ifevent.type()==QEvent.Type.MouseButtonPress: |
| 47 | +ifself.menuandself.menu.isVisible(): |
| 48 | +global_pos=event.globalPosition().toPoint() |
| 49 | +all_menus= [self.menu] |
| 50 | +all_menus+= [act.menu()foractinself.menu.actions()ifact.menu()andact.menu().isVisible()] |
| 51 | +ifnotany(m.geometry().contains(global_pos)forminall_menus): |
| 52 | +self.menu.hide() |
| 53 | +self.menu.deleteLater() |
| 54 | +returnTrue |
| 55 | +returnsuper().eventFilter(obj,event) |
| 56 | + |
45 | 57 | def_load_config(self):
|
46 | 58 | try:
|
47 | 59 | config=get_config(show_error_dialog=True)
|
@@ -160,6 +172,8 @@ def _load_context_menu(self):
|
160 | 172 | exit_action.triggered.connect(self._exit_application)
|
161 | 173 |
|
162 | 174 | self.setContextMenu(self.menu)
|
| 175 | +# Connect the activated signal to show the menu |
| 176 | +self.activated.connect(lambdareason:self.menu.activateWindow()ifreason==QSystemTrayIcon.ActivationReason.ContextelseNone) |
163 | 177 |
|
164 | 178 | @pyqtSlot()
|
165 | 179 | defremove_tray_icon(self):
|
@@ -236,10 +250,15 @@ def run_komorebi_reload():
|
236 | 250 | threading.Thread(target=run_komorebi_reload).start()
|
237 | 251 |
|
238 | 252 | def_reload_application(self):
|
239 |
| -self.remove_tray_icon() |
240 |
| -logging.info("Reloading Application...") |
241 |
| -QProcess.startDetached(sys.executable,sys.argv) |
242 |
| -sys.exit() |
| 253 | +try: |
| 254 | +self.remove_tray_icon() |
| 255 | +QApplication.processEvents() |
| 256 | +logging.info("Reloading Application...") |
| 257 | +QProcess.startDetached(sys.executable,sys.argv) |
| 258 | +QCoreApplication.exit(0) |
| 259 | +exceptExceptionase: |
| 260 | +logging.error(f"Error during reload:{e}") |
| 261 | +os._exit(0) |
243 | 262 |
|
244 | 263 | def_exit_application(self):
|
245 | 264 | self.remove_tray_icon()
|
|