fix: fix CloseEvent on native package

Signed-off-by: Boris Yumankulov <boria138@altlinux.org>
This commit is contained in:
2025-10-18 21:06:23 +05:00
parent 567203b0b0
commit 2d39a4c740

View File

@@ -3057,15 +3057,33 @@ class MainWindow(QMainWindow):
Если True — сворачиваем в трей (по умолчанию). Иначе — полностью закрываем. Если True — сворачиваем в трей (по умолчанию). Иначе — полностью закрываем.
""" """
minimize_to_tray = read_minimize_to_tray() minimize_to_tray = read_minimize_to_tray()
if minimize_to_tray:
# Просто сворачиваем в трей
event.ignore()
self.hide()
return
# Полное закрытие приложения
self.is_exiting = True
event.accept()
# Скрываем и удаляем иконку трея
if hasattr(self, "tray_manager") and self.tray_manager.tray_icon:
self.tray_manager.tray_icon.hide()
self.tray_manager.tray_icon.deleteLater()
# Сохраняем размеры карточек
save_card_size(self.card_width) save_card_size(self.card_width)
save_auto_card_size(self.auto_card_width) save_auto_card_size(self.auto_card_width)
# Сохраняем настройки окна
# Сохраняем размеры окна (если не в полноэкранном режиме)
if not read_fullscreen_config(): if not read_fullscreen_config():
logger.debug(f"Saving window geometry: {self.width()}x{self.height()}") logger.debug(f"Saving window geometry: {self.width()}x{self.height()}")
save_window_geometry(self.width(), self.height()) save_window_geometry(self.width(), self.height())
if hasattr(self, 'is_exiting') and self.is_exiting or not minimize_to_tray:
# Принудительное закрытие: завершаем процессы и приложение # Завершаем все игровые процессы
for proc in self.game_processes: for proc in getattr(self, "game_processes", []):
try: try:
parent = psutil.Process(proc.pid) parent = psutil.Process(proc.pid)
children = parent.children(recursive=True) children = parent.children(recursive=True)
@@ -3075,36 +3093,36 @@ class MainWindow(QMainWindow):
child.terminate() child.terminate()
except psutil.NoSuchProcess: except psutil.NoSuchProcess:
logger.debug(f"Child process {child.pid} already terminated") logger.debug(f"Child process {child.pid} already terminated")
psutil.wait_procs(children, timeout=5) psutil.wait_procs(children, timeout=5)
for child in children: for child in children:
if child.is_running(): if child.is_running():
logger.debug(f"Killing child process {child.pid}") logger.debug(f"Killing child process {child.pid}")
child.kill() child.kill()
logger.debug(f"Terminating process group {proc.pid}") logger.debug(f"Terminating process group {proc.pid}")
os.killpg(os.getpgid(proc.pid), signal.SIGTERM) os.killpg(os.getpgid(proc.pid), signal.SIGTERM)
except (psutil.NoSuchProcess, ProcessLookupError) as e: except (psutil.NoSuchProcess, ProcessLookupError) as e:
logger.debug(f"Process {proc.pid} already terminated: {e}") logger.debug(f"Process {getattr(proc, 'pid', '?')} already terminated: {e}")
except Exception as e:
logger.warning(f"Failed to terminate process {getattr(proc, 'pid', '?')}: {e}")
self.game_processes = [] # Очищаем список процессов self.game_processes = []
# Очищаем таймеры # Универсальная остановка и удаление таймеров
if hasattr(self, 'games_load_timer') and self.games_load_timer is not None and self.games_load_timer.isActive(): timers = [
self.games_load_timer.stop() "games_load_timer",
if hasattr(self, 'settingsDebounceTimer') and self.settingsDebounceTimer is not None and self.settingsDebounceTimer.isActive(): "settingsDebounceTimer",
self.settingsDebounceTimer.stop() "searchDebounceTimer",
if hasattr(self, 'searchDebounceTimer') and self.searchDebounceTimer is not None and self.searchDebounceTimer.isActive(): "checkProcessTimer",
self.searchDebounceTimer.stop() "wine_monitor_timer",
if hasattr(self, 'checkProcessTimer') and self.checkProcessTimer is not None and self.checkProcessTimer.isActive(): ]
self.checkProcessTimer.stop()
self.checkProcessTimer.deleteLater()
self.checkProcessTimer = None
if hasattr(self, 'wine_monitor_timer') and self.wine_monitor_timer is not None:
self.wine_monitor_timer.stop()
self.wine_monitor_timer.deleteLater()
self.wine_monitor_timer = None
event.accept() for tname in timers:
else: timer = getattr(self, tname, None)
# Сворачиваем в трей вместо закрытия if timer and timer.isActive():
self.hide() timer.stop()
event.ignore() if timer:
timer.deleteLater()
setattr(self, tname, None)