ctucx.git: mqtt-webui

webui for mqtt, can be used to control/display data in mqtt-topics

commit fcd1f8ccf4bcc6c52a5598b28f0c0fa36f025d56
parent d5de508664c81a64b1412dbb6f23379215e60191
Author: Leah (ctucx) <git@ctu.cx>
Date: Tue, 13 Dec 2022 16:19:00 +0100

webui.js: add option to configure app-name via config
5 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/config.json b/config.json
@@ -1,4 +1,5 @@
 {
+  "appName": "Smart-Home",
   "disableAuth": false,
   "pages": [
     {
diff --git a/config.nix b/config.nix
@@ -38,6 +38,7 @@ let
 
 in {
 
+  appName     = "Smart-Home";
   disableAuth = false;
   pages =  [
     {
diff --git a/src/webui.js b/src/webui.js
@@ -364,6 +364,11 @@ window.addEventListener('DOMContentLoaded', async (event) => {
 
 	localStorage.setItem('instanceId', mqttOptions.clientId);
 
+	if (typeof config.appName === 'string') {
+		document.getElementsByTagName('title')[0].textContent                     = config.appName;
+		document.querySelector('meta[name="apple-mobile-web-app-title"]').content = config.appName;
+	}
+
 	// create UI
 	render(renderPages(config), document.body);
 	document.getElementById("loading").style.display = 'none';
diff --git a/www/index.html b/www/index.html
@@ -1,13 +1,13 @@
 <!doctype html>
 <html lang="en">
 	<head>
-		<title>Smart-Home</title>
+		<title>mqtt-webui</title>
 
 		<meta charset="utf-8">
 		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
 
 		<meta name="apple-mobile-web-app-capable" content="yes">
-		<meta name="apple-mobile-web-app-title" content="Smart-Home">
+		<meta name="apple-mobile-web-app-title" content="mqtt-webui">
 		<link rel="apple-touch-icon" href="./favicon-512x512.png">
 
 		<meta name="theme-color" content="#f8f9fa" media="(prefers-color-scheme: light)">
diff --git a/www/manifest.json b/www/manifest.json
@@ -1,13 +1,13 @@
 {
-	"name": "Smart Home",
-	"short_name": "Smart Home",
+	"name": "mqtt-webui",
+	"short_name": "mqtt-webui",
 	"start_url": ".",
+	"display": "standalone",
 	"icons": [
 		{
 			"src": "favicon-512x512.png",
 			"sizes": "512x512",
 			"type": "image/png"
 		}
-	],
-	"display": "standalone"
+	]
 }