From 3e5ee9c77e78517d91c97275ea97902c7f7328c5 Mon Sep 17 00:00:00 2001 From: PaulVua Date: Tue, 17 Feb 2026 12:19:05 +0100 Subject: [PATCH] Add Screen control features: Screen tab in sidebar, Kivy script, and backend logic --- html/assets/js/topbar-logo.js | 74 +++- html/index.html | 697 +++++++++++++++++----------------- html/launcher.php | 14 + html/screen.html | 173 +++++++++ html/sidebar.html | 8 + screen_control/screen.py | 18 + 6 files changed, 627 insertions(+), 357 deletions(-) create mode 100644 html/screen.html create mode 100644 screen_control/screen.py diff --git a/html/assets/js/topbar-logo.js b/html/assets/js/topbar-logo.js index 75df120..a599dcc 100644 --- a/html/assets/js/topbar-logo.js +++ b/html/assets/js/topbar-logo.js @@ -1,19 +1,57 @@ -// Switch topbar logo based on device_type config -// Uses MutationObserver to detect when topbar is dynamically loaded -(function() { - var observer = new MutationObserver(function() { - var logo = document.getElementById('topbar-logo'); - if (logo) { - observer.disconnect(); - fetch('launcher.php?type=get_config_sqlite') - .then(function(r) { return r.json(); }) - .then(function(config) { - if (config.device_type === 'moduleair_pro') { - logo.src = 'assets/img/logoModuleAir.png'; - } - }) - .catch(function() {}); - } + +/** + * Global configuration handler for UI elements + * - Updates Topbar Logo based on device type + * - Shows/Hides "Screen" sidebar tab based on device type + */ +document.addEventListener('DOMContentLoaded', () => { + let config = null; + + // Fetch config once + fetch('launcher.php?type=get_config_sqlite') + .then(response => response.json()) + .then(data => { + config = data; + applyConfig(); // Apply immediately if elements are ready + }) + .catch(error => console.error('Error loading config:', error)); + + // Observe DOM changes to handle dynamically loaded elements (sidebar, topbar) + const observer = new MutationObserver(() => { + if (config) applyConfig(); }); - observer.observe(document.body || document.documentElement, { childList: true, subtree: true }); -})(); + + observer.observe(document.body, { childList: true, subtree: true }); + + function applyConfig() { + if (!config) return; + + const isModuleAirPro = (config.device_type === 'moduleair_pro' || config.type === 'moduleair_pro'); + + // 1. Topbar Logo Logic + const logo = document.getElementById('topbar-logo'); + if (logo && isModuleAirPro) { + // prevent unnecessary re-assignments + if (!logo.src.includes('logoModuleAir.png')) { + logo.src = 'assets/img/logoModuleAir.png'; + } + } + + // 2. Sidebar Screen Tab Logic + const navScreen = document.getElementById('nav-screen'); + if (navScreen) { + if (isModuleAirPro) { + // Ensure it's visible (bootstrap nav-link usually block or flex) + // Using removeProperty to let CSS/Bootstrap handle it, or force display + if (navScreen.style.display === 'none') { + navScreen.style.display = 'flex'; + } + } else { + // Hide if not pro + if (navScreen.style.display !== 'none') { + navScreen.style.display = 'none'; + } + } + } + } +}); diff --git a/html/index.html b/html/index.html index 52f57fc..2aa940e 100755 --- a/html/index.html +++ b/html/index.html @@ -1,5 +1,6 @@ + @@ -11,44 +12,52 @@ body { overflow-x: hidden; } + #sidebar a.nav-link { - position: relative; - display: flex; - align-items: center; + position: relative; + display: flex; + align-items: center; } + #sidebar a.nav-link:hover { - background-color: rgba(0, 0, 0, 0.5); + background-color: rgba(0, 0, 0, 0.5); } + #sidebar a.nav-link svg { - margin-right: 8px; /* Add spacing between icons and text */ + margin-right: 8px; + /* Add spacing between icons and text */ } + #sidebar { transition: transform 0.3s ease-in-out; } + .offcanvas-backdrop { z-index: 1040; } + - + -
+
NebuleAir
- +

Votre capteur

@@ -58,33 +67,36 @@
-
-
-
Mesures PM
- +
+
+
Mesures PM
+ +
-
Statistiques Linux
-

Utilisation du disque (taille totale Gb)

+

Utilisation du disque (taille totale Gb)

-

Utilisation de la mémoire (taille totale Mb)

+

Utilisation de la mémoire (taille totale + Mb)

-

Taille de la base de données:

+

Taille de la base de données:

- -
- + - - - - - - - + + + + + + + - + + + + } + + - + + \ No newline at end of file diff --git a/html/launcher.php b/html/launcher.php index 39945a8..c1b5d21 100755 --- a/html/launcher.php +++ b/html/launcher.php @@ -1751,3 +1751,17 @@ if ($type == "set_cpu_power_mode") { ]); } } + +if ($type == "screen_control") { + $action = $_GET['action']; + if ($action == "start") { + // Run as background process + $command = 'export DISPLAY=:0 && nohup /usr/bin/python3 /home/aircarto/nebuleair_pro_4g/screen_control/screen.py > /dev/null 2>&1 &'; + shell_exec($command); + echo "Started"; + } elseif ($action == "stop") { + $command = 'sudo pkill -f "screen_control/screen.py"'; + shell_exec($command); + echo "Stopped"; + } +} diff --git a/html/screen.html b/html/screen.html new file mode 100644 index 0000000..86e68c1 --- /dev/null +++ b/html/screen.html @@ -0,0 +1,173 @@ + + + + + + + Screen Control + + + + + + + + + + +
+
+
NebuleAir
+ +
+ +
+ +
+
+ + +
+

Contrôle de l'écran

+

Gérer l'affichage sur l'écran HDMI.

+ +
+
+
+
+
Actions
+

Démarrer ou arrêter l'application d'affichage sur l'écran HDMI.

+ + +
+
+
+
+ +
+ +
+
+
+ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/html/sidebar.html b/html/sidebar.html index e7c6a58..2c07391 100755 --- a/html/sidebar.html +++ b/html/sidebar.html @@ -62,6 +62,14 @@ Admin + + +