From d7a4f8822962e4bd0775994b0817cb0fe29d98db Mon Sep 17 00:00:00 2001
From: Stephen Jianu <stephen@stephenjianu.com>
Date: Sat, 25 Nov 2023 22:46:45 -0600
Subject: [PATCH] Output HTML when not running under CLI in order to get a
 web-based version of the script

---
 steam_shader_stats.php | 30 ++++++++++++++++++++++++++----
 1 file changed, 26 insertions(+), 4 deletions(-)

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>';
 }
 
 ?>
-- 
2.39.5