-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix broken running Steam App detection on linux (#40)
- Loading branch information
1 parent
0639c69
commit 47b3aff
Showing
9 changed files
with
271 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// header file include | ||
#include "steamprocesslistobserver.h" | ||
|
||
// system/Qt includes | ||
#include <QRegularExpression> | ||
|
||
// local includes | ||
#include "nativeprocesshandler.h" | ||
|
||
//--------------------------------------------------------------------------------------------------------------------- | ||
|
||
namespace os | ||
{ | ||
SteamProcessListObserver::SteamProcessListObserver() | ||
{ | ||
connect(&m_check_timer, &QTimer::timeout, this, &SteamProcessListObserver::slotCheckProcessList); | ||
|
||
const int interval_ms{2000}; | ||
m_check_timer.setInterval(interval_ms); | ||
m_check_timer.setSingleShot(true); | ||
} | ||
|
||
//--------------------------------------------------------------------------------------------------------------------- | ||
|
||
void SteamProcessListObserver::observePid(uint pid) | ||
{ | ||
stopObserving(); | ||
|
||
if (pid != 0) | ||
{ | ||
m_steam_pid = pid; | ||
slotCheckProcessList(); | ||
} | ||
} | ||
|
||
//--------------------------------------------------------------------------------------------------------------------- | ||
|
||
void SteamProcessListObserver::stopObserving() | ||
{ | ||
m_check_timer.stop(); | ||
m_steam_pid = 0; | ||
} | ||
|
||
//--------------------------------------------------------------------------------------------------------------------- | ||
|
||
const std::set<uint>& SteamProcessListObserver::getAppIds() const | ||
{ | ||
return m_app_ids; | ||
} | ||
|
||
//--------------------------------------------------------------------------------------------------------------------- | ||
|
||
void SteamProcessListObserver::slotCheckProcessList() | ||
{ | ||
std::set<uint> running_apps; | ||
|
||
if (m_steam_pid != 0) | ||
{ | ||
NativeProcessHandler proc_handler; | ||
|
||
const auto pids{proc_handler.getChildrenPids(m_steam_pid)}; | ||
for (auto pid : pids) | ||
{ | ||
static const QRegularExpression app_id_matcher{R"(AppId=([0-9]+))", | ||
QRegularExpression::CaseInsensitiveOption}; | ||
const auto match{app_id_matcher.match(proc_handler.getCmdline(pid))}; | ||
if (!match.hasCaptured(1)) | ||
{ | ||
continue; | ||
} | ||
|
||
const QString captured{match.captured(1)}; | ||
|
||
bool success{false}; | ||
const auto result{captured.toUInt(&success)}; | ||
|
||
if (!success) | ||
{ | ||
continue; | ||
} | ||
|
||
running_apps.insert(result); | ||
} | ||
} | ||
|
||
if (running_apps != m_app_ids) | ||
{ | ||
std::swap(running_apps, m_app_ids); | ||
emit signalListChanged(); | ||
} | ||
|
||
if (m_steam_pid != 0) | ||
{ | ||
m_check_timer.start(); | ||
} | ||
} | ||
} // namespace os |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#pragma once | ||
|
||
// system/Qt includes | ||
#include <QTimer> | ||
#include <set> | ||
|
||
//--------------------------------------------------------------------------------------------------------------------- | ||
|
||
namespace os | ||
{ | ||
class SteamProcessListObserver : public QObject | ||
{ | ||
Q_OBJECT | ||
Q_DISABLE_COPY(SteamProcessListObserver) | ||
|
||
public: | ||
explicit SteamProcessListObserver(); | ||
~SteamProcessListObserver() override = default; | ||
|
||
void observePid(uint pid); | ||
void stopObserving(); | ||
|
||
const std::set<uint>& getAppIds() const; | ||
|
||
signals: | ||
void signalListChanged(); | ||
|
||
private slots: | ||
void slotCheckProcessList(); | ||
|
||
private: | ||
std::set<uint> m_app_ids; | ||
QTimer m_check_timer; | ||
uint m_steam_pid{0}; | ||
}; | ||
} // namespace os |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.