222 return trackedProcessName_;
237 return lastLaunchInfo_;
261 onStateChanged_ = callback;
270 void setOnExit(std::function<
void(
int exitCode)> callback)
295 onNotification_ = callback;
319 void updateState(
State newState);
320 std::string buildLaunchCommand()
const;
321 std::string buildDirectProtonCommand(
const std::string& protonExe);
326 bool launchScummVM();
327 bool checkProcessRunning();
330 void checkLaunchOptionConflicts();
333 bool executeCommand(
const std::string& command);
336 std::string findProtonExecutable(
const std::string& versionName)
const;
337 std::string findProtonPath(
const std::string& versionName)
const;
338 std::string resolveProtonExecutable()
const;
341 static bool isUmuLauncherAvailable();
342 bool launchProtonWithUmu();
343 bool launchProtonDirect();
344 bool launchProtonSteamGame();
345 bool launchViaSteamApplaunch();
348 static bool isSteamRunning();
349 static bool ensureSteamRunning();
352 std::vector<int> getChildProcesses(
int parentPid)
const;
353 std::string getProcessName(
int pid)
const;
354 std::string getWineExecutableName(
int pid)
const;
355 bool isExcludedProcess(
const std::string& processName)
const;
356 int findGameProcess()
const;
359 void killWinePrefix(
bool force)
const;
369 std::string trackedProcessName_;
371 bool isAttachedProcess_;
376 std::function<void(
State)> onStateChanged_;
377 std::function<void(
int)> onExit_;
389class GameProcessManager
396 static GameProcessManager&
instance();
408 bool stopGame(
const std::string& gameId,
Game* game =
nullptr,
bool force =
false);
438 int getLastExitCode(
const std::string& gameId,
int defaultCode = 0)
const;
445 std::function<void(
const std::string& gameId, std::function<
void(
Game&)>)>;
487 GameProcessManager();
488 ~GameProcessManager();
489 GameProcessManager(
const GameProcessManager&) =
delete;
490 GameProcessManager& operator=(
const GameProcessManager&) =
delete;
501 std::map<std::string, std::unique_ptr<GameProcess>> runningProcesses_;
502 mutable std::mutex runningProcessesMutex_;
505 std::map<int, std::string> runningSteamGames_;
506 mutable std::mutex steamGamesMutex_;
509 std::map<int, time_t> steamGameStartTimes_;
510 mutable std::mutex steamStartTimesMutex_;
516 std::map<int, double> steamGameBasePlaytime_;
519 std::thread detectionThread_;
520 std::atomic<bool> shouldStopDetection_;
523 std::map<int, std::string> steamAppIdToGameId_;
524 std::mutex appIdMapMutex_;
527 std::map<std::string, int> lastExitCodes_;
528 mutable std::mutex exitCodesMutex_;
530 void storeExitCode(
const std::string& gameId,
int code);
542 std::function<void(
const std::string& gameId)> onGameStatsUpdated_;
546 mutable std::mutex callbacksMutex_;
549 time_t lastHeartbeat_ = 0;
552 time_t lastSteamHeartbeat_ = 0;
558 void detectionThreadFunction();
561 void scanForRunningWineGames(
const std::vector<Game*>& games);
564 void pollRunningSteamGames();
567 bool isSteamGameRunningOnSystem(
int steamAppId)
const;
570 bool isSteamRunning()
const;
573 bool ensureSteamRunning();
576 bool killSteamGame(
int steamAppId);
585 std::vector<int> findGamePidsByAppId(
int steamAppId)
const;
589 std::string detectSteamGameExitReason(
int steamAppId, time_t startTime)
const;
592 static std::string buildLaunchCommand(
const Game& game);
void setOnGameStatsUpdated(std::function< void(const std::string &gameId)> callback)
const GameProcess * getRunningProcess(const std::string &gameId) const
std::function< void(GameProcess::NotificationType, const std::string &)> getOnNotification() const
int getLastExitCode(const std::string &gameId, int defaultCode=0) const
bool launchGame(const std::string &gameId, Game &game)
std::function< void(const std::string &)> getOnGameStatsUpdated() const
bool stopGame(const std::string &gameId, Game *game=nullptr, bool force=false)
void scanForRunningGames(const std::vector< Game * > &games, GameAccessCallback gameAccessCallback)
std::function< void(const std::string &gameId, std::function< void(Game &)>)> GameAccessCallback
bool isGameRunning(const std::string &gameId) const
void setOnNotification(std::function< void(GameProcess::NotificationType, const std::string &)> callback)
std::vector< std::string > getRunningGameIds() const
ProcessSnapshot getRunningProcessSnapshot(const std::string &gameId) const
std::chrono::seconds getGameSessionDuration(const std::string &gameId) const
static GameProcessManager & instance()
Manages a single running game process.
void update()
Check if process is still running and update statistics.
bool stop()
Stop the game process gracefully.
int getTrackedProcessId() const
Get the tracked game process ID.
GameProcess(const Game &game)
Constructor - creates a process for the given game.
int getProcessId() const
Get the process ID.
double getRunningTimeSeconds() const
Get how long the process has been running.
State
Current state of the game process.
@ Running
Process is running normally.
@ Stopping
Process is being stopped (graceful shutdown).
@ Error
Process encountered an error during launch.
@ Stopped
Process has stopped (either normally or was killed).
@ Starting
Process is in the process of starting.
@ NotStarted
Process has not been started yet.
void setOnExit(std::function< void(int exitCode)> callback)
Set callback for process exit.
const LaunchInfo & getLastLaunchInfo() const
Get information about what was applied during the last launch.
const std::string & getTrackedProcessName() const
Get the name of the tracked game process.
bool isRunning() const
Check if process is currently running.
void setOnNotification(std::function< void(NotificationType, const std::string &)> callback)
Set callback for notifications.
bool launch()
Launch the game process.
void notify(NotificationType type, const std::string &message) const
State getState() const
Get current process state.
bool kill()
Force kill the game process.
~GameProcess()
Destructor - stops the process if still running.
void attachToRunningProcess(int pid, const std::string &processName="")
Attach to an already-running process.
void setOnStateChanged(std::function< void(State)> callback)
Set callback for state changes.
NotificationType
Type of notification to display.
const Game & getGame() const
Get the game associated with this process.
Complete representation of a game in the library.
std::string trackedProcessName
Information about optimizations and settings applied during game launch.