A live bird collage card for your Home Assistant dashboard.
make casual git checking non-blocking-y, also check every 24h
frederik1d2c2d6faa05
diff --git a/homepage/views.php b/homepage/views.phpindex 8b0ea32f..c31b3a5b 100644--- a/homepage/views.php+++ b/homepage/views.php@@ -20,19 +20,22 @@ function service_mount() {$service_mount=trim(shell_exec("systemd-escape -p --suffix=mount ".$home."/BirdSongs/StreamData"));return $service_mount;}-if(!isset($_SESSION['behind'])) {- $fetch = shell_exec("sudo -u".$user." git -C ".$home."/BirdNET-Pi fetch 2>&1");+if(!isset($_SESSION['behind']) || !isset($_SESSION['behind_time']) || time() > $_SESSION['behind_time'] + 86400) {+ shell_exec("sudo -u".$user." git -C ".$home."/BirdNET-Pi fetch > /dev/null 2>/dev/null &");$str = trim(shell_exec("sudo -u".$user." git -C ".$home."/BirdNET-Pi status"));if (preg_match("/behind '.*?' by (\d+) commit(s?)\b/", $str, $matches)) {$num_commits_behind = $matches[1];- $_SESSION['behind'] = $num_commits_behind;}if (preg_match('/\b(\d+)\b and \b(\d+)\b different commits each/', $str, $matches)) {- $num1 = (int) $matches[1];- $num2 = (int) $matches[2];- $sum = $num1 + $num2;- $_SESSION['behind'] = $sum;+ $num1 = (int) $matches[1];+ $num2 = (int) $matches[2];+ $num_commits_behind = $num1 + $num2;}+ if (stripos($str, "Your branch is up to date") !== false) {+ $num_commits_behind = '0';+ }+ $_SESSION['behind'] = $num_commits_behind;+ $_SESSION['behind_time'] = time();}if(isset($_SESSION['behind'])&&intval($_SESSION['behind']) >= 99) {?><style>diff --git a/scripts/system_controls.php b/scripts/system_controls.phpindex 067b3148..e43d0d4d 100644--- a/scripts/system_controls.php+++ b/scripts/system_controls.php@@ -8,14 +8,17 @@ $fetch = shell_exec("sudo -u".$user." git -C ".$home."/BirdNET-Pi fetch 2>&1");$str = trim(shell_exec("sudo -u".$user." git -C ".$home."/BirdNET-Pi status"));if (preg_match("/behind '.*?' by (\d+) commit(s?)\b/", $str, $matches)) {$num_commits_behind = $matches[1];- $_SESSION['behind'] = $num_commits_behind;}if (preg_match('/\b(\d+)\b and \b(\d+)\b different commits each/', $str, $matches)) {$num1 = (int) $matches[1];$num2 = (int) $matches[2];- $sum = $num1 + $num2;- $_SESSION['behind'] = $sum;+ $num_commits_behind = $num1 + $num2;}+if (stripos($str, "Your branch is up to date") !== false) {+ $num_commits_behind = '0';+}+$_SESSION['behind'] = $num_commits_behind;+$_SESSION['behind_time'] = time();?><html><meta name="viewport" content="width=device-width, initial-scale=1"><br>