From: Stephen Jianu <stephen@stephenjianu.com>
Date: Sun, 26 Nov 2023 04:46:45 +0000 (-0600)
Subject: Output HTML when not running under CLI in order to get a web-based version of the... 
X-Git-Url: https://www.stephenjianu.com/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Fmaster;p=steam_shader_stats.git

Output HTML when not running under CLI in order to get a web-based version of the script
---

diff --git a/steam_shader_stats.php b/steam_shader_stats.php
index 2b08a90..1259901 100755
--- a/steam_shader_stats.php
+++ b/steam_shader_stats.php
@@ -12,8 +12,10 @@ exec("ps ax | grep shadercache | grep -v grep", $fossilizeList);
 // if the process list ends up returning nothing, Steam isn't currently processing shaders
 if (empty($fossilizeList)) {
     $output = "Steam is not currently processing shaders in the background.\n";
-    exec ("notify-send \"".$output."\"");
-    echo $output;
+    if (defined('STDIN')) {
+        exec ("notify-send \"".$output."\"");
+        echo $output;
+    }
 }
 
 // get each matching appid from the process list output and put it into a list
@@ -35,8 +37,28 @@ if (!empty($appList)) {
     $json = json_decode(file_get_contents($url), true);
     $gameName = $json[$appList[0]]['data']['name'];
     $output = "Steam is processing shaders for app ID ".$appList[0]." (".$gameName.") in the background.\n";
-    exec ("notify-send \"".$output."\"");
-    echo $output;
+    if (defined('STDIN')) {
+        exec ("notify-send \"".$output."\"");
+        echo $output;
+    }
+}
+
+// if we're not running in the CLI, output HTML
+// to get a web-based version of this script.
+// obviously, the web server needs to run on a machine that has Steam running.
+if (!defined('STDIN')) {
+    echo '<html>';
+    echo '<head>';
+    echo '<meta http-equiv="refresh" content="60">';
+    echo '<title>Steam Shader Stats</title>';
+    echo '</head>';
+    echo '<body>';
+    echo '<h1>Steam Shader Stats</h1>';
+    echo '<p>This page displays the current status of Steam shader processing.';
+    echo '<br>The page will be auto-refreshed every minute.</p>';
+    echo '<h3>'.$output.'</h3>';
+    echo '</body>';
+    echo '</html>';
 }
 
 ?>