From 1b4dd1b718d543a2b6bf29e3209629542744babf Mon Sep 17 00:00:00 2001 From: SulfurNitride Date: Sun, 15 Mar 2026 05:34:27 -0500 Subject: Add Steam Linux Runtime (SLR) support + fix Use Proton default Steam Linux Runtime: - New Rust module (libs/nak/src/slr.rs): download SteamLinuxRuntime_sniper from repo.steampowered.com, SHA256 verification, BUILD_ID update checks - nak_ffi exports: nak_slr_is_installed, nak_slr_get_run_script, nak_download_slr - ProtonLauncher: wraps Proton launch inside SLR pressure-vessel container when enabled (run -- proton waitforexitandrun game.exe) - Instance Manager: SLR checkbox (default on) beside Steam DRM checkbox - Main window: pre-check downloads SLR before launch if needed - Proton settings tab: "Download Steam Linux Runtime" button - spawn.cpp: reads fluorine/use_slr per-instance INI key - Logs "Final command:" showing full assembled launch command Bug fixes: - Fix Use Proton off by default for plugin executables (executableslist.cpp) - Fix Use Proton off by default for file tree right-click (filetree.cpp) - Fix Fedora 43 Qt platform plugin crash: explicit QT_QPA_PLATFORM_PLUGIN_PATH - Add Qt6::Concurrent to CMakeLists for QtConcurrent background downloads Co-Authored-By: Claude Sonnet 4.6 --- src/src/CMakeLists.txt | 3 +- src/src/executableslist.cpp | 2 +- src/src/filetree.cpp | 3 +- src/src/instancemanagerdialog.cpp | 92 +++++++++++++++++++++++++++++++++++++++ src/src/instancemanagerdialog.h | 5 +++ src/src/instancemanagerdialog.ui | 13 ++++++ src/src/mainwindow.cpp | 52 ++++++++++++++++++++++ src/src/protonlauncher.cpp | 53 +++++++++++++++++++++- src/src/protonlauncher.h | 2 + src/src/settingsdialog.ui | 20 ++++++--- src/src/settingsdialogproton.cpp | 57 ++++++++++++++++++++++++ src/src/settingsdialogproton.h | 1 + src/src/spawn.cpp | 9 ++-- 13 files changed, 300 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/src/CMakeLists.txt b/src/src/CMakeLists.txt index 30dd8b5..146183d 100644 --- a/src/src/CMakeLists.txt +++ b/src/src/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.16) find_package(Qt6 REQUIRED COMPONENTS - Widgets WebSockets Network) + Widgets WebSockets Network Concurrent) if(WIN32) find_package(Qt6 REQUIRED COMPONENTS WebEngineWidgets) endif() @@ -101,6 +101,7 @@ target_link_libraries(organizer PRIVATE mo2::nak_ffi # Qt6 Qt6::Widgets + Qt6::Concurrent $<$:Qt6::WebEngineWidgets> Qt6::WebSockets Qt6::Network diff --git a/src/src/executableslist.cpp b/src/src/executableslist.cpp index 5410c81..f12a74c 100644 --- a/src/src/executableslist.cpp +++ b/src/src/executableslist.cpp @@ -155,7 +155,7 @@ ExecutablesList::getPluginExecutables(MOBase::IPluginGame const* game) const continue; } - v.push_back({info, Executable::UseApplicationIcon}); + v.push_back({info, Executable::UseApplicationIcon | Executable::UseProton}); } const QFileInfo eppBin(QCoreApplication::applicationDirPath() + diff --git a/src/src/filetree.cpp b/src/src/filetree.cpp index d89cf52..32f9ea3 100644 --- a/src/src/filetree.cpp +++ b/src/src/filetree.cpp @@ -287,7 +287,8 @@ void FileTree::addAsExecutable(FileTreeItem* item) .title(name) .binaryInfo(fec.binary) .arguments(fec.arguments) - .workingDirectory(target.absolutePath())); + .workingDirectory(target.absolutePath()) + .flags(Executable::UseProton)); emit executablesChanged(); } diff --git a/src/src/instancemanagerdialog.cpp b/src/src/instancemanagerdialog.cpp index 5cdaecf..5f46402 100644 --- a/src/src/instancemanagerdialog.cpp +++ b/src/src/instancemanagerdialog.cpp @@ -11,9 +11,16 @@ #include #include #include +#include +#include +#include +#include #include #include +#include #include +#include +#include #include #include @@ -224,6 +231,18 @@ InstanceManagerDialog::InstanceManagerDialog(PluginContainer& pc, QWidget* paren s.setValue("fluorine/steam_drm", checked); }); + connect(ui->steamLinuxRuntimeCheckBox, &QCheckBox::toggled, [&](bool checked) { + const auto* inst = singleSelection(); + if (!inst) return; + const QString ini = inst->iniPath(); + if (ini.isEmpty()) return; + QSettings s(ini, QSettings::IniFormat); + s.setValue("fluorine/use_slr", checked); + if (checked) { + downloadSLRIfNeeded(); + } + }); + connect(ui->switchToInstance, &QPushButton::clicked, [&] { openSelectedInstance(); }); @@ -793,12 +812,19 @@ void InstanceManagerDialog::fillData(const Instance& ii) ui->steamDrmCheckBox->blockSignals(true); ui->steamDrmCheckBox->setChecked(s.value("fluorine/steam_drm", true).toBool()); ui->steamDrmCheckBox->blockSignals(false); + + ui->steamLinuxRuntimeCheckBox->blockSignals(true); + ui->steamLinuxRuntimeCheckBox->setChecked(s.value("fluorine/use_slr", true).toBool()); + ui->steamLinuxRuntimeCheckBox->blockSignals(false); } else { ui->prefixPath->clear(); ui->protonVersion->clear(); ui->steamDrmCheckBox->blockSignals(true); ui->steamDrmCheckBox->setChecked(false); ui->steamDrmCheckBox->blockSignals(false); + ui->steamLinuxRuntimeCheckBox->blockSignals(true); + ui->steamLinuxRuntimeCheckBox->setChecked(true); + ui->steamLinuxRuntimeCheckBox->blockSignals(false); } } @@ -898,3 +924,69 @@ void InstanceManagerDialog::openExistingPortable() } } } + +void InstanceManagerDialog::downloadSLRIfNeeded() +{ + if (nak_slr_is_installed()) { + return; + } + + // Indeterminate progress dialog — SLR download logs internally via nak_init_logging. + // We can't pass capturing C++ lambdas as C function pointers, so we let the + // Rust side handle progress logging and just show a spinner here. + auto* progress = new QProgressDialog( + tr("Downloading Steam Linux Runtime (~180 MB)...\n" + "This only happens once. Check the MO2 log for details."), + tr("Cancel"), 0, 0, this); // 0,0 = indeterminate + progress->setWindowTitle(tr("Steam Linux Runtime")); + progress->setWindowModality(Qt::WindowModal); + progress->setMinimumDuration(0); + + auto* cancelFlag = new int(0); + + connect(progress, &QProgressDialog::canceled, this, [cancelFlag] { + *cancelFlag = 1; + }); + + using Result = char*; + auto* watcher = new QFutureWatcher(this); + + connect(watcher, &QFutureWatcher::finished, this, + [this, watcher, progress, cancelFlag] { + progress->close(); + watcher->deleteLater(); + progress->deleteLater(); + + char* err = watcher->result(); + if (err) { + const QString msg = QString::fromUtf8(err); + nak_string_free(err); + MOBase::log::error("[SLR] Download failed: {}", msg); + QMessageBox::warning(this, tr("Steam Linux Runtime"), + tr("Download failed:\n%1\n\nSLR has been disabled for this instance.") + .arg(msg)); + ui->steamLinuxRuntimeCheckBox->blockSignals(true); + ui->steamLinuxRuntimeCheckBox->setChecked(false); + ui->steamLinuxRuntimeCheckBox->blockSignals(false); + const auto* inst = singleSelection(); + if (inst) { + const QString ini = inst->iniPath(); + if (!ini.isEmpty()) { + QSettings s(ini, QSettings::IniFormat); + s.setValue("fluorine/use_slr", false); + } + } + } else { + MOBase::log::info("[SLR] Steam Linux Runtime installed successfully"); + progress->setLabelText(tr("Steam Linux Runtime is ready.")); + } + delete cancelFlag; + }); + + int* cancelPtr = cancelFlag; + watcher->setFuture(QtConcurrent::run([cancelPtr]() -> Result { + return nak_download_slr(nullptr, nullptr, cancelPtr); + })); + + progress->show(); +} diff --git a/src/src/instancemanagerdialog.h b/src/src/instancemanagerdialog.h index c8862fd..fec48ff 100644 --- a/src/src/instancemanagerdialog.h +++ b/src/src/instancemanagerdialog.h @@ -148,6 +148,11 @@ private: // deletes the given files, returns false on error // bool doDelete(const QStringList& files, bool recycle); + + // downloads SLR if not already installed; called when the SLR checkbox is + // toggled on + // + void downloadSLRIfNeeded(); }; #endif // MODORGANIZER_INSTANCEMANAGERDIALOG_INCLUDED diff --git a/src/src/instancemanagerdialog.ui b/src/src/instancemanagerdialog.ui index 2a1d136..6039edc 100644 --- a/src/src/instancemanagerdialog.ui +++ b/src/src/instancemanagerdialog.ui @@ -324,6 +324,19 @@ + + + + Use Steam Linux Runtime (SLR) + + + Run games inside the Steam Linux Runtime container (pressure-vessel). Provides GStreamer, 32-bit libs, and other dependencies for non-FHS distros like NixOS. Requires Steam to be installed. + + + true + + + diff --git a/src/src/mainwindow.cpp b/src/src/mainwindow.cpp index 457a3dd..882ecd7 100644 --- a/src/src/mainwindow.cpp +++ b/src/src/mainwindow.cpp @@ -92,6 +92,7 @@ along with Mod Organizer. If not, see . #include "shared/fileentry.h" #include "shared/filesorigin.h" +#include #include #include #include @@ -2365,6 +2366,57 @@ void MainWindow::on_startButton_clicked() ui->startButton->setEnabled(true); }); + // Pre-check: if this executable uses Proton and the current instance has SLR + // enabled, download SLR before launching if it isn't installed yet. + if (selectedExecutable->useProton()) { + const auto* s = Settings::maybeInstance(); + bool useSLR = true; + if (s) { + QSettings instanceIni(s->filename(), QSettings::IniFormat); + useSLR = instanceIni.value("fluorine/use_slr", true).toBool(); + } + if (useSLR && !nak_slr_is_installed()) { + auto* progress = new QProgressDialog( + tr("Downloading Steam Linux Runtime (~180 MB)...\n" + "This is required to launch games. Check the MO2 log for details."), + tr("Cancel"), 0, 0, this); + progress->setWindowTitle(tr("Steam Linux Runtime")); + progress->setWindowModality(Qt::WindowModal); + progress->setMinimumDuration(0); + + int cancelFlag = 0; + connect(progress, &QProgressDialog::canceled, this, [&cancelFlag] { + cancelFlag = 1; + }); + + // Run download synchronously using an event loop so the dialog stays responsive. + QFutureWatcher watcher; + QEventLoop loop; + connect(&watcher, &QFutureWatcher::finished, &loop, &QEventLoop::quit); + watcher.setFuture(QtConcurrent::run([&cancelFlag]() -> char* { + return nak_download_slr(nullptr, nullptr, &cancelFlag); + })); + progress->show(); + loop.exec(); + progress->close(); + progress->deleteLater(); + + char* err = watcher.result(); + if (cancelFlag) { + return; // user cancelled, don't launch + } + if (err) { + const QString msg = QString::fromUtf8(err); + nak_string_free(err); + log::error("[SLR] Download failed: {}", msg); + QMessageBox::warning(this, tr("Steam Linux Runtime"), + tr("Steam Linux Runtime download failed:\n%1\n\n" + "You can disable SLR in the Instance Manager and try again.").arg(msg)); + return; + } + } + } + if (selectedExecutable->minimizeToSystemTray()) { m_SystemTrayManager->minimizeToSystemTray(); } diff --git a/src/src/protonlauncher.cpp b/src/src/protonlauncher.cpp index 3d1741e..f25d355 100644 --- a/src/src/protonlauncher.cpp +++ b/src/src/protonlauncher.cpp @@ -135,6 +135,30 @@ QString detectSteamPath() return {}; } +// Find the Steam Linux Runtime (sniper) run script. +// SLR wraps the Proton launch in a pressure-vessel container that provides +// GStreamer, 32-bit libs, and an FHS-compliant environment — required on +// NixOS and other non-FHS distros. +// Returns empty string if SLR is not installed. +QString detectSLRRunScript() +{ + const QString steamPath = detectSteamPath(); + + // Common SLR sniper locations relative to Steam install + const QStringList candidates = { + steamPath + "/steamapps/common/SteamLinuxRuntime_sniper/run", + QDir::home().filePath(".local/share/Steam/steamapps/common/SteamLinuxRuntime_sniper/run"), + "/usr/lib/pressure-vessel/wrap", + }; + + for (const QString& path : candidates) { + if (!path.isEmpty() && QFileInfo::exists(path)) { + return path; + } + } + return {}; +} + // Detect an available terminal emulator on the system. QString findTerminal() { @@ -365,6 +389,12 @@ ProtonLauncher& ProtonLauncher::setSteamDrm(bool useSteamDrm) return *this; } +ProtonLauncher& ProtonLauncher::setUseSLR(bool useSLR) +{ + m_useSLR = useSLR; + return *this; +} + ProtonLauncher& ProtonLauncher::setStoreVariant(const QString& variant) { m_storeVariant = variant.trimmed(); @@ -418,9 +448,28 @@ bool ProtonLauncher::launchWithProton(qint64& pid) const // before starting a new one. const QStringList protonArgs = QStringList() << "waitforexitandrun" << m_binary << m_arguments; + // If SLR is enabled, wrap the whole proton invocation inside the + // pressure-vessel container provided by SteamLinuxRuntime_sniper. + // The `run` script accepts `-- [args...]` and re-executes the + // command inside the container. QString program; QStringList arguments; - wrapProgram(m_wrapperCommands, protonScript, protonArgs, program, arguments); + if (m_useSLR) { + if (char* slrScript = nak_slr_get_run_script(); slrScript != nullptr) { + const QString runScript = QString::fromUtf8(slrScript); + nak_string_free(slrScript); + MOBase::log::info("SLR: wrapping launch with {}", runScript); + // Build: [wrappers] run_script -- proton_script protonArgs + QStringList slrArgs; + slrArgs << "--" << protonScript << protonArgs; + wrapProgram(m_wrapperCommands, runScript, slrArgs, program, arguments); + } else { + MOBase::log::warn("SLR enabled but run script not found — launching without SLR"); + wrapProgram(m_wrapperCommands, protonScript, protonArgs, program, arguments); + } + } else { + wrapProgram(m_wrapperCommands, protonScript, protonArgs, program, arguments); + } QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); env.remove("PYTHONHOME"); @@ -476,6 +525,8 @@ bool ProtonLauncher::launchWithProton(qint64& pid) const } MOBase::log::info("Proton launch: '{}' run '{}'", protonScript, m_binary); + MOBase::log::info("Final command: '{}' {}", program, + arguments.join(" ").toStdString()); if (!m_workingDir.isEmpty()) { env.insert("PWD", m_workingDir); diff --git a/src/src/protonlauncher.h b/src/src/protonlauncher.h index 11d942a..13be35a 100644 --- a/src/src/protonlauncher.h +++ b/src/src/protonlauncher.h @@ -21,6 +21,7 @@ public: ProtonLauncher& setSteamAppId(uint32_t id); ProtonLauncher& setWrapper(const QString& wrapperCmd); ProtonLauncher& setSteamDrm(bool useSteamDrm); + ProtonLauncher& setUseSLR(bool useSLR); ProtonLauncher& setStoreVariant(const QString& variant); ProtonLauncher& addEnvVar(const QString& key, const QString& value); ProtonLauncher& setUseTerminal(bool useTerminal); @@ -41,6 +42,7 @@ private: uint32_t m_steamAppId; QStringList m_wrapperCommands; bool m_useSteamDrm; + bool m_useSLR = true; QString m_storeVariant; // "GOG", "Epic", or empty for Steam QMap m_envVars; QMap m_wrapperEnvVars; diff --git a/src/src/settingsdialog.ui b/src/src/settingsdialog.ui index 646b9b6..3e1c54a 100644 --- a/src/src/settingsdialog.ui +++ b/src/src/settingsdialog.ui @@ -1803,28 +1803,38 @@ If you disable this feature, MO will only display official DLCs this way. Please - + + + + Download Steam Linux Runtime + + + Download SteamLinuxRuntime_sniper (~180 MB) from Valve's servers. Provides GStreamer, 32-bit libs, and an FHS environment for non-FHS distros (NixOS, etc.). Required for the "Use SLR" option in the Instance Manager. + + + + Status: - + No Prefix - + 0 - + Show Install Log @@ -1837,7 +1847,7 @@ If you disable this feature, MO will only display official DLCs this way. Please - + true diff --git a/src/src/settingsdialogproton.cpp b/src/src/settingsdialogproton.cpp index 8aa2481..bd14944 100644 --- a/src/src/settingsdialogproton.cpp +++ b/src/src/settingsdialogproton.cpp @@ -23,8 +23,11 @@ #include #include #include +#include +#include #include #include +#include #include #include #include @@ -95,6 +98,8 @@ ProtonSettingsTab::ProtonSettingsTab(Settings& s, SettingsDialog& d) &ProtonSettingsTab::onWinetricks); QObject::connect(ui->prefixLocationBrowseButton, &QPushButton::clicked, this, &ProtonSettingsTab::onBrowsePrefixLocation); + QObject::connect(ui->downloadSLRButton, &QPushButton::clicked, this, + &ProtonSettingsTab::onDownloadSLR); QObject::connect(&m_installWatcher, &QFutureWatcher::finished, this, &ProtonSettingsTab::onInstallFinished); @@ -297,6 +302,58 @@ void ProtonSettingsTab::onOpenPrefixFolder() MOBase::shell::Explore(QDir(*path)); } +void ProtonSettingsTab::onDownloadSLR() +{ + if (nak_slr_is_installed()) { + QMessageBox::information(parentWidget(), tr("Steam Linux Runtime"), + tr("Steam Linux Runtime is already installed.")); + return; + } + + ui->downloadSLRButton->setEnabled(false); + auto* progress = new QProgressDialog( + tr("Downloading Steam Linux Runtime (~180 MB)...\n" + "Check the MO2 log for progress details."), + tr("Cancel"), 0, 0, parentWidget()); + progress->setWindowTitle(tr("Steam Linux Runtime")); + progress->setWindowModality(Qt::WindowModal); + progress->setMinimumDuration(0); + + auto* cancelFlag = new int(0); + connect(progress, &QProgressDialog::canceled, this, [cancelFlag] { + *cancelFlag = 1; + }); + + auto* watcher = new QFutureWatcher(this); + connect(watcher, &QFutureWatcher::finished, this, + [this, watcher, progress, cancelFlag] { + progress->close(); + watcher->deleteLater(); + progress->deleteLater(); + ui->downloadSLRButton->setEnabled(true); + + char* err = watcher->result(); + if (err) { + const QString msg = QString::fromUtf8(err); + nak_string_free(err); + MOBase::log::error("[SLR] Download failed: {}", msg); + QMessageBox::warning(parentWidget(), tr("Steam Linux Runtime"), + tr("Download failed:\n%1").arg(msg)); + } else { + MOBase::log::info("[SLR] Steam Linux Runtime installed successfully"); + QMessageBox::information(parentWidget(), tr("Steam Linux Runtime"), + tr("Steam Linux Runtime installed successfully.")); + } + delete cancelFlag; + }); + + int* cancelPtr = cancelFlag; + watcher->setFuture(QtConcurrent::run([cancelPtr]() -> char* { + return nak_download_slr(nullptr, nullptr, cancelPtr); + })); + progress->show(); +} + void ProtonSettingsTab::onBrowsePrefixLocation() { const QString dir = QFileDialog::getExistingDirectory( diff --git a/src/src/settingsdialogproton.h b/src/src/settingsdialogproton.h index a1221c7..d5f0188 100644 --- a/src/src/settingsdialogproton.h +++ b/src/src/settingsdialogproton.h @@ -33,6 +33,7 @@ private: void onFixGameRegistries(); void onWinetricks(); void onBrowsePrefixLocation(); + void onDownloadSLR(); void showGameRegistryDialog(); QString ensureWinetricks(); diff --git a/src/src/spawn.cpp b/src/src/spawn.cpp index b0e7eea..4a4d32b 100644 --- a/src/src/spawn.cpp +++ b/src/src/spawn.cpp @@ -647,16 +647,19 @@ int spawn(const SpawnParameters &sp, pid_t &processId) { // QSettings). const Settings *instanceForLaunch = Settings::maybeInstance(); bool useSteamDrm = true; // default + bool useSLR = true; // default on QString storeVariant; if (instanceForLaunch) { const QSettings instanceIni(instanceForLaunch->filename(), QSettings::IniFormat); - useSteamDrm = instanceIni.value("fluorine/steam_drm", true).toBool(); - storeVariant = instanceIni.value("game_edition").toString().trimmed(); + useSteamDrm = instanceIni.value("fluorine/steam_drm", true).toBool(); + useSLR = instanceIni.value("fluorine/use_slr", true).toBool(); + storeVariant = instanceIni.value("game_edition").toString().trimmed(); } launcher.setSteamDrm(useSteamDrm) - .setStoreVariant(storeVariant); + .setStoreVariant(storeVariant) + .setUseSLR(useSLR); const QString prefixPath = resolvePrefixPath(); if (prefixPath.isEmpty()) { -- cgit v1.3.1