Skip to content

Commit

Permalink
Add workarounds in case Steam was killed on Linux (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
FrogTheFrog committed Nov 8, 2023
1 parent 2750ebf commit 322d54f
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 7 deletions.
15 changes: 12 additions & 3 deletions src/lib/os/linux/steamprocesslistobserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,21 @@ SteamProcessListObserver::SteamProcessListObserver()
//---------------------------------------------------------------------------------------------------------------------

// NOLINTNEXTLINE(*-static)
uint SteamProcessListObserver::findSteamProcess() const
uint SteamProcessListObserver::findSteamProcess(uint previous_pid) const
{
NativeProcessHandler proc_handler;
static const QRegularExpression exec_regex{".*?Steam.+?steam$", QRegularExpression::CaseInsensitiveOption};
NativeProcessHandler proc_handler;

const auto pids{proc_handler.getPids()};
if (std::find(std::begin(pids), std::end(pids), previous_pid) != std::end(pids))
{
const QString exec_path{proc_handler.getExecPath(previous_pid)};
if (!exec_path.isEmpty() && exec_path.contains(exec_regex))
{
return previous_pid;
}
}

for (const auto pid : pids)
{
const QString exec_path{proc_handler.getExecPath(pid)};
Expand All @@ -36,7 +46,6 @@ uint SteamProcessListObserver::findSteamProcess() const
continue;
}

static const QRegularExpression exec_regex{".*?Steam.+?steam", QRegularExpression::CaseInsensitiveOption};
if (exec_path.contains(exec_regex))
{
return pid;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/os/linux/steamprocesslistobserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class SteamProcessListObserver : public QObject
explicit SteamProcessListObserver();
~SteamProcessListObserver() override = default;

uint findSteamProcess() const;
uint findSteamProcess(uint previous_pid) const;
void observePid(uint pid);
void stopObserving();

Expand Down
35 changes: 32 additions & 3 deletions src/lib/os/linux/steamregistryobserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// system/Qt includes
#include <QDir>
#include <QFile>
#include <chrono>

// local includes
#include "shared/loggingcategories.h"
Expand Down Expand Up @@ -144,8 +145,27 @@ void SteamRegistryObserver::slotRegistryChanged()
{
if (pid != 0)
{
const uint actual_steam_pid{m_process_list_observer.findSteamProcess()};
if (actual_steam_pid != pid && actual_steam_pid != 0)
const uint actual_steam_pid{m_process_list_observer.findSteamProcess(m_pid)};
if (actual_steam_pid == 0)
{
using namespace std::chrono_literals;
const bool do_recheck{m_recheck_counter++ < 10};

qCWarning(lc::os).nospace() << "Steam PID from registry.vdf indicates that the Steam process is "
"running, but it's not"
<< (do_recheck ? "... Rechecking in 5 seconds." : "...");

if (do_recheck)
{
QTimer::singleShot(5s, this, &SteamRegistryObserver::slotRegistryChanged);
}
else
{
// Something else has triggered the slots, let's reset the counter.
m_recheck_counter = 0;
}
}
else if (actual_steam_pid != pid)
{
if (m_pid != actual_steam_pid)
{
Expand All @@ -154,9 +174,18 @@ void SteamRegistryObserver::slotRegistryChanged()
"outdated data)! Using PID "
<< actual_steam_pid << " (instead of " << pid << ") to track Steam process.";
}
}

pid = actual_steam_pid;
if (actual_steam_pid != 0)
{
m_recheck_counter = 0;
}

pid = actual_steam_pid;
}
else
{
m_recheck_counter = 0;
}

if (pid != m_pid)
Expand Down
1 change: 1 addition & 0 deletions src/lib/os/linux/steamregistryobserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ private slots:
QString m_steam_exec;
uint m_pid{0};
uint m_global_app_id{0};
uint m_recheck_counter{0};
std::optional<TrackedAppData> m_tracked_app_data;
SteamProcessListObserver m_process_list_observer;
};
Expand Down

0 comments on commit 322d54f

Please sign in to comment.