From be0b8717602584b6aafa83f42ce25481e98094bf Mon Sep 17 00:00:00 2001 From: "NGnius (Graham)" Date: Mon, 23 May 2022 18:23:26 -0400 Subject: [PATCH] Update README, fix some per-game profile functionality --- README.md | 20 +++++++++++++++++++- main.py | 3 +++ server.py | 6 ++++-- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ee847bf..3d18495 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ You will need that installed for this plugin to work. - Set some GPU power parameters (fastPPT & slowPPT) - Set the fan RPM (unsupported on SteamOS beta) - Display supplementary battery info -- Keep settings between restarts (stored in `~/.config/powertools.json`) +- Keep settings between restarts (stored in `~/.config/powertools/.json`) ## Cool, but that's too much work @@ -79,6 +79,24 @@ This is how I figured out how the fan stuff works. I've only scratched the surface of what this code allows, I'm sure it has more useful information. https://lkml.org/lkml/2022/2/5/391 +### Game launch detection + +The biggest limitation right now is it can't detect a game closing -- only opening -- and only after PowerTools is looked at at least once (per SteamOS restart). + +From a plugin, this can be accomplished by running some front-end Javascript. + +```javascript +await execute_in_tab("SP", false, + `SteamClient.Apps.RegisterForGameActionStart((actionType, data) => { + console.log("start game", appStore.GetAppOverviewByGameID(data)); + });` +); +``` + +In PowerTools, the callback (the part surrounded by `{` and `}`, containing `console.log(...)`) sends a message to a local HTTP server to notify the PowerTools back-end that a game has been launched. + +If you go to `http://127.0.0.1:5030` on your Steam Deck with PowerTools >=0.6.0, you can see some info about the last game you launched. + ## License This is licensed under GNU GPLv3. diff --git a/main.py b/main.py index 1cdc206..4cd2a64 100644 --- a/main.py +++ b/main.py @@ -406,6 +406,9 @@ class Plugin: self.current_gameid = current_game.gameid self.modified_settings = True else: + if not enabled and current_game is not None and current_game.has_settings(): + # delete settings; disable settings loading + os.remove(current_game.settings_path()) self.current_gameid = None async def get_per_game_profile(self) -> bool: diff --git a/server.py b/server.py index 3ce6db6..3e2e799 100644 --- a/server.py +++ b/server.py @@ -64,11 +64,13 @@ class Server(web.Application): logging.debug("Debug index page accessed") current_game = None if self.current_game is None else self.current_game.gameid game_info = None if self.current_game is None else self.current_game.game_info + settings_info = None if self.current_game is None else self.current_game.load_settings() return web.json_response({ "name": "PowerTools", "version": self.version, "latest_game_id": current_game, - "game_info": game_info + "game_info": game_info, + "settings": settings_info }, headers={"Access-Control-Allow-Origin": "*"}) async def on_game_start(self, request): @@ -125,7 +127,7 @@ async def start(version): http_server = Server(version) http_runner = web.AppRunner(http_server) await http_runner.setup() - site = web.TCPSite(http_runner, '0.0.0.0', 5030) + site = web.TCPSite(http_runner, '127.0.0.1', 5030) await site.start() async def shutdown(): # never really called