feat: added handle egs games to toggleGame
Signed-off-by: Boris Yumankulov <boria138@altlinux.org>
This commit is contained in:
@ -1822,11 +1822,67 @@ class MainWindow(QMainWindow):
|
|||||||
self.target_exe = None
|
self.target_exe = None
|
||||||
|
|
||||||
def toggleGame(self, exec_line, button=None):
|
def toggleGame(self, exec_line, button=None):
|
||||||
|
# Обработка Steam-игр
|
||||||
if exec_line.startswith("steam://"):
|
if exec_line.startswith("steam://"):
|
||||||
url = QUrl(exec_line)
|
url = QUrl(exec_line)
|
||||||
QDesktopServices.openUrl(url)
|
QDesktopServices.openUrl(url)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# Обработка EGS-игр
|
||||||
|
if exec_line.startswith("legendary:launch:"):
|
||||||
|
# Извлекаем app_name из exec_line
|
||||||
|
app_name = exec_line.split("legendary:launch:")[1]
|
||||||
|
legendary_path = self.legendary_path # Путь к legendary
|
||||||
|
|
||||||
|
# Формируем переменные окружения
|
||||||
|
env_vars = os.environ.copy()
|
||||||
|
env_vars['START_FROM_STEAM'] = '1'
|
||||||
|
env_vars['LEGENDARY_CONFIG_PATH'] = self.legendary_config_path
|
||||||
|
|
||||||
|
wrapper = "flatpak run ru.linux_gaming.PortProton"
|
||||||
|
if self.portproton_location is not None and ".var" not in self.portproton_location:
|
||||||
|
start_sh = os.path.join(self.portproton_location, "data", "scripts", "start.sh")
|
||||||
|
wrapper = start_sh
|
||||||
|
|
||||||
|
# Формируем команду
|
||||||
|
cmd = [
|
||||||
|
legendary_path, "launch", app_name, "--no-wine", "--wrapper", wrapper
|
||||||
|
]
|
||||||
|
|
||||||
|
current_exe = os.path.basename(legendary_path)
|
||||||
|
if self.game_processes and self.target_exe is not None and self.target_exe != current_exe:
|
||||||
|
QMessageBox.warning(self, _("Error"), _("Cannot launch game while another game is running"))
|
||||||
|
return
|
||||||
|
|
||||||
|
# Обновляем кнопку
|
||||||
|
update_button = button if button is not None else self.current_play_button
|
||||||
|
self.current_running_button = update_button
|
||||||
|
self.target_exe = current_exe
|
||||||
|
exe_name = app_name # Используем app_name для EGS-игр
|
||||||
|
|
||||||
|
# Запускаем процесс
|
||||||
|
try:
|
||||||
|
process = subprocess.Popen(cmd, env=env_vars, shell=False, preexec_fn=os.setsid)
|
||||||
|
self.game_processes.append(process)
|
||||||
|
save_last_launch(exe_name, datetime.now())
|
||||||
|
if update_button:
|
||||||
|
update_button.setText(_("Launching"))
|
||||||
|
icon = self.theme_manager.get_icon("stop")
|
||||||
|
if isinstance(icon, str):
|
||||||
|
icon = QIcon(icon)
|
||||||
|
elif icon is None:
|
||||||
|
icon = QIcon()
|
||||||
|
update_button.setIcon(icon)
|
||||||
|
|
||||||
|
self.checkProcessTimer = QTimer(self)
|
||||||
|
self.checkProcessTimer.timeout.connect(self.checkTargetExe)
|
||||||
|
self.checkProcessTimer.start(500)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Failed to launch EGS game {app_name}: {e}")
|
||||||
|
QMessageBox.warning(self, _("Error"), _("Failed to launch game: {0}").format(str(e)))
|
||||||
|
return
|
||||||
|
|
||||||
|
# Обработка PortProton-игр
|
||||||
entry_exec_split = shlex.split(exec_line)
|
entry_exec_split = shlex.split(exec_line)
|
||||||
if entry_exec_split[0] == "env":
|
if entry_exec_split[0] == "env":
|
||||||
if len(entry_exec_split) < 3:
|
if len(entry_exec_split) < 3:
|
||||||
@ -1840,18 +1896,20 @@ class MainWindow(QMainWindow):
|
|||||||
file_to_check = entry_exec_split[3]
|
file_to_check = entry_exec_split[3]
|
||||||
else:
|
else:
|
||||||
file_to_check = entry_exec_split[0]
|
file_to_check = entry_exec_split[0]
|
||||||
|
|
||||||
if not os.path.exists(file_to_check):
|
if not os.path.exists(file_to_check):
|
||||||
QMessageBox.warning(self, _("Error"), _("File not found: {0}").format(file_to_check))
|
QMessageBox.warning(self, _("Error"), _("File not found: {0}").format(file_to_check))
|
||||||
return
|
return
|
||||||
current_exe = os.path.basename(file_to_check)
|
|
||||||
|
|
||||||
|
current_exe = os.path.basename(file_to_check)
|
||||||
if self.game_processes and self.target_exe is not None and self.target_exe != current_exe:
|
if self.game_processes and self.target_exe is not None and self.target_exe != current_exe:
|
||||||
QMessageBox.warning(self, _("Error"), _("Cannot launch game while another game is running"))
|
QMessageBox.warning(self, _("Error"), _("Cannot launch game while another game is running"))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# Обновляем кнопку
|
||||||
update_button = button if button is not None else self.current_play_button
|
update_button = button if button is not None else self.current_play_button
|
||||||
|
|
||||||
# Если игра уже запущена для этого exe – останавливаем её по нажатию кнопки
|
# Если игра уже запущена для этого exe – останавливаем её
|
||||||
if self.game_processes and self.target_exe == current_exe:
|
if self.game_processes and self.target_exe == current_exe:
|
||||||
for proc in self.game_processes:
|
for proc in self.game_processes:
|
||||||
try:
|
try:
|
||||||
@ -1885,17 +1943,16 @@ class MainWindow(QMainWindow):
|
|||||||
self.current_running_button = None
|
self.current_running_button = None
|
||||||
self.target_exe = None
|
self.target_exe = None
|
||||||
self._gameLaunched = False
|
self._gameLaunched = False
|
||||||
#self._uninhibit_screensaver()
|
return
|
||||||
else:
|
|
||||||
# Сохраняем ссылку на кнопку для сброса после завершения игры
|
# Запускаем игру
|
||||||
self.current_running_button = update_button
|
self.current_running_button = update_button
|
||||||
self.target_exe = current_exe
|
self.target_exe = current_exe
|
||||||
exe_name = os.path.splitext(current_exe)[0]
|
exe_name = os.path.splitext(current_exe)[0]
|
||||||
env_vars = os.environ.copy()
|
env_vars = os.environ.copy()
|
||||||
if entry_exec_split[0] == "env" and len(entry_exec_split) > 1 and 'data/scripts/start.sh' in entry_exec_split[1]:
|
env_vars['START_FROM_STEAM'] = '1'
|
||||||
env_vars['START_FROM_STEAM'] = '1'
|
|
||||||
elif entry_exec_split[0] == "flatpak":
|
try:
|
||||||
env_vars['START_FROM_STEAM'] = '1'
|
|
||||||
process = subprocess.Popen(entry_exec_split, env=env_vars, shell=False, preexec_fn=os.setsid)
|
process = subprocess.Popen(entry_exec_split, env=env_vars, shell=False, preexec_fn=os.setsid)
|
||||||
self.game_processes.append(process)
|
self.game_processes.append(process)
|
||||||
save_last_launch(exe_name, datetime.now())
|
save_last_launch(exe_name, datetime.now())
|
||||||
@ -1911,6 +1968,9 @@ class MainWindow(QMainWindow):
|
|||||||
self.checkProcessTimer = QTimer(self)
|
self.checkProcessTimer = QTimer(self)
|
||||||
self.checkProcessTimer.timeout.connect(self.checkTargetExe)
|
self.checkProcessTimer.timeout.connect(self.checkTargetExe)
|
||||||
self.checkProcessTimer.start(500)
|
self.checkProcessTimer.start(500)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Failed to launch game {exe_name}: {e}")
|
||||||
|
QMessageBox.warning(self, _("Error"), _("Failed to launch game: {0}").format(str(e)))
|
||||||
|
|
||||||
def closeEvent(self, event):
|
def closeEvent(self, event):
|
||||||
for proc in self.game_processes:
|
for proc in self.game_processes:
|
||||||
|
Reference in New Issue
Block a user