forked from CastroFidel/winehelper
added notification when closing the WH when the application is running
This commit is contained in:
@@ -3491,7 +3491,7 @@ class WineHelperGUI(QMainWindow):
|
||||
QMessageBox.critical(self, "Ошибка", f"Не удалось модифицировать команду для отладки: {e}")
|
||||
return
|
||||
|
||||
process = QProcess(self)
|
||||
process = QProcess()
|
||||
env = QProcessEnvironment.systemEnvironment()
|
||||
|
||||
cmd_start_index = 0
|
||||
@@ -3509,7 +3509,10 @@ class WineHelperGUI(QMainWindow):
|
||||
arguments = clean_command[cmd_start_index + 1:]
|
||||
|
||||
process.setProcessEnvironment(env)
|
||||
process.finished.connect(lambda: self._on_app_process_finished(desktop_path))
|
||||
# Используем functools.partial для надежной передачи аргументов
|
||||
# и избегания проблем с замыканием в lambda.
|
||||
process.finished.connect(partial(self._on_app_process_finished, desktop_path))
|
||||
|
||||
|
||||
try:
|
||||
process.start(program, arguments)
|
||||
@@ -3528,6 +3531,36 @@ class WineHelperGUI(QMainWindow):
|
||||
QMessageBox.critical(self, "Ошибка",
|
||||
f"Не удалось обработать команду запуска:\n{command_str}\n\nОшибка: {str(e)}")
|
||||
|
||||
def closeEvent(self, event):
|
||||
"""Обрабатывает событие закрытия главного окна."""
|
||||
if self.running_apps:
|
||||
msg_box = QMessageBox(self)
|
||||
msg_box.setWindowTitle('Подтверждение выхода')
|
||||
msg_box.setTextFormat(Qt.RichText)
|
||||
msg_box.setText('<font color="red">Все запущенные приложения будут закрыты вместе с WineHelper.</font><br><br>'
|
||||
"Вы уверены, что хотите выйти?")
|
||||
msg_box.setIcon(QMessageBox.Question)
|
||||
|
||||
yes_button = msg_box.addButton("Да", QMessageBox.YesRole)
|
||||
no_button = msg_box.addButton("Нет", QMessageBox.NoRole)
|
||||
msg_box.setDefaultButton(no_button)
|
||||
|
||||
msg_box.exec_()
|
||||
|
||||
if msg_box.clickedButton() == yes_button:
|
||||
# Корректно завершаем все дочерние процессы
|
||||
for desktop_path, process in list(self.running_apps.items()):
|
||||
if process.state() == QProcess.Running:
|
||||
print(f"Завершение процесса для {desktop_path}...")
|
||||
process.terminate()
|
||||
if not process.waitForFinished(2000): # Ждем 2 сек
|
||||
process.kill() # Если не закрылся, убиваем
|
||||
event.accept()
|
||||
else:
|
||||
event.ignore()
|
||||
else:
|
||||
super().closeEvent(event)
|
||||
|
||||
def uninstall_app(self):
|
||||
"""Удаляет выбранное установленное приложение и его префикс"""
|
||||
if not self.current_selected_app or 'desktop_path' not in self.current_selected_app:
|
||||
|
Reference in New Issue
Block a user