Skip to content

A live bird collage card for your Home Assistant dashboard.

If behind by more than 50 commits, show update badge on "Tools"

ehpersonal38201f705517d0
diff --git a/homepage/style.css b/homepage/style.css
index e5ddda3d..aafb3ba8 100644
--- a/homepage/style.css
+++ b/homepage/style.css
@@ -700,4 +700,9 @@ dialog::backdrop {
border-radius:12px;
text-align:center;
font-size:small;
+}
+
+form#views button .updatenumber {
+ position:initial;
+ margin-left:0px;
}
\ No newline at end of file
diff --git a/homepage/views.php b/homepage/views.php
index cc5d30ad..30468c2f 100644
--- a/homepage/views.php
+++ b/homepage/views.php
@@ -1,3 +1,19 @@
+<?php
+session_start();
+$user = shell_exec("awk -F: '/1000/{print $1}' /etc/passwd");
+$home = shell_exec("awk -F: '/1000/{print $6}' /etc/passwd");
+$home = trim($home);
+if(!isset($_SESSION['behind'])) {
+ $_SESSION['behind'] = trim(shell_exec("sudo git -C ".$home."/BirdNET-Pi fetch > /dev/null 2>&1 && git -C ".$home."/BirdNET-Pi status | sed -n '2 p' | cut -d ' ' -f 7"));
+}
+if(intval($_SESSION['behind']) >= 99) {?>
+<style>
+.updatenumber {
+ width:30px !important;
+}
+</style>
+<?php }
+?>
<link rel="stylesheet" href="style.css">
<style>
body::-webkit-scrollbar {
@@ -31,7 +47,7 @@ body::-webkit-scrollbar {
<button type="submit" name="view" value="View Log" form="views">View Log</button>
</form>
<form action="" method="GET" id="views">
- <button type="submit" name="view" value="Tools" form="views">Tools</button>
+ <button type="submit" name="view" value="Tools" form="views">Tools<?php if(intval($_SESSION['behind']) >= 50){ $updatediv = ' <div class="updatenumber">'.$_SESSION["behind"].'</div>'; } else { $updatediv = ""; } echo $updatediv; ?></button>
</form>
<button href="javascript:void(0);" class="icon" onclick="myFunction()"><img src="images/menu.png"></button>
</div>
@@ -94,7 +110,7 @@ if(isset($_GET['view'])){
<form action=\"\" method=\"GET\" id=\"views\">
<button type=\"submit\" name=\"view\" value=\"Settings\" form=\"views\">Settings</button>
<button type=\"submit\" name=\"view\" value=\"System Info\" form=\"views\">System Info</button>
- <button type=\"submit\" name=\"view\" value=\"System Controls\" form=\"views\">System Controls</button>
+ <button type=\"submit\" name=\"view\" value=\"System Controls\" form=\"views\">System Controls".$updatediv."</button>
<button type=\"submit\" name=\"view\" value=\"Services\" form=\"views\">Services</button>
<button type=\"submit\" name=\"view\" value=\"File\" form=\"views\">File Manager</button>
<a href=\"scripts/adminer.php\" target=\"_top\"><button type=\"submit\" form=\"\">Database Maintenance</button></a>
@@ -264,6 +280,9 @@ if(isset($_GET['view'])){
$tmp = explode(" ",trim($command));
$command .= "& sleep 3;sudo systemctl status ".end($tmp);
}
+ if($initcommand == "update_birdnet.sh") {
+ unset($_SESSION['behind']);
+ }
$results = shell_exec("$command 2>&1");
$results = str_replace("FAILURE", "<span style='color:red'>FAILURE</span>", $results);
$results = str_replace("failed", "<span style='color:red'>failed</span>",$results);
diff --git a/scripts/system_controls.php b/scripts/system_controls.php
index 6abc7144..84931fe2 100644
--- a/scripts/system_controls.php
+++ b/scripts/system_controls.php
@@ -1,9 +1,3 @@
-<?php
-$user = shell_exec("awk -F: '/1000/{print $1}' /etc/passwd");
-$home = shell_exec("awk -F: '/1000/{print $6}' /etc/passwd");
-$home = trim($home);
-$behind = trim(shell_exec("sudo git -C ".$home."/BirdNET-Pi fetch > /dev/null 2>&1 && git -C ".$home."/BirdNET-Pi status | sed -n '2 p' | cut -d ' ' -f 7"));
-?>
<html>
<meta name="viewport" content="width=device-width, initial-scale=1">
<br>
@@ -13,7 +7,7 @@ $behind = trim(shell_exec("sudo git -C ".$home."/BirdNET-Pi fetch > /dev/null 2>
<button type="submit" name="submit" value="sudo reboot" onclick="return confirm('Are you sure you want to reboot?')">Reboot</button>
</form>
<form action="" method="GET">
- <button type="submit" name="submit" value="update_birdnet.sh" onclick="return confirm('Are you sure you want to update?')">Update <?php if($behind != "0" && $behind != "with"){?><div class="updatenumber"><?php echo $behind; ?></div><?php } ?></button>
+ <button type="submit" name="submit" value="update_birdnet.sh" onclick="return confirm('Are you sure you want to update?')">Update <?php if($_SESSION['behind'] != "0" && $_SESSION['behind'] != "with"){?><div class="updatenumber"><?php echo $_SESSION['behind']; ?></div><?php } ?></button>
</form>
<form action="" method="GET">
<button type="submit" name="submit" value="sudo shutdown now" onclick="return confirm('Are you sure you want to shutdown?')">Shutdown</button>