Fix device name not showing in page title and sidebar
Fixed race condition issues where device name wasn't displaying properly: Page title fixes: - Added document.title update to sensors.html (was missing) - wifi.html already had it but improved reliability Sidebar device name fixes: - Created updateSidebarDeviceName() function with retry logic - Attempts update immediately, then at 100ms and 500ms delays - Handles async sidebar loading timing issues - Added console logging for debugging - Both sensors.html and wifi.html now reliably show device name This ensures the device ID/name always appears in: 1. Browser tab title (e.g., "NebuleAir_001") 2. Sidebar footer (bottom of navigation) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -319,11 +319,27 @@ $.ajax({
|
|||||||
|
|
||||||
mainConfig = response; // Store for later use
|
mainConfig = response; // Store for later use
|
||||||
|
|
||||||
//device name_side bar
|
// Function to update sidebar device name
|
||||||
const elements = document.querySelectorAll('.sideBar_sensorName');
|
function updateSidebarDeviceName(deviceName) {
|
||||||
elements.forEach((element) => {
|
const elements = document.querySelectorAll('.sideBar_sensorName');
|
||||||
element.innerText = response.deviceName;
|
if (elements.length > 0) {
|
||||||
});
|
elements.forEach((element) => {
|
||||||
|
element.innerText = deviceName;
|
||||||
|
});
|
||||||
|
console.log("Device name updated in sidebar:", deviceName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update device name immediately and with retries to handle async sidebar loading
|
||||||
|
if (response.deviceName) {
|
||||||
|
updateSidebarDeviceName(response.deviceName);
|
||||||
|
// Retry after delays to catch async sidebar load
|
||||||
|
setTimeout(() => updateSidebarDeviceName(response.deviceName), 100);
|
||||||
|
setTimeout(() => updateSidebarDeviceName(response.deviceName), 500);
|
||||||
|
|
||||||
|
// Set page title
|
||||||
|
document.title = response.deviceName;
|
||||||
|
}
|
||||||
|
|
||||||
// After getting main config, create sensor cards
|
// After getting main config, create sensor cards
|
||||||
createSensorCards(mainConfig);
|
createSensorCards(mainConfig);
|
||||||
|
|||||||
@@ -298,16 +298,28 @@ function get_internet(){
|
|||||||
|
|
||||||
//get device Name
|
//get device Name
|
||||||
const deviceName = data.deviceName;
|
const deviceName = data.deviceName;
|
||||||
|
|
||||||
const elements = document.querySelectorAll('.sideBar_sensorName');
|
|
||||||
elements.forEach((element) => {
|
|
||||||
element.innerText = deviceName;
|
|
||||||
});
|
|
||||||
|
|
||||||
//device name html page title
|
// Function to update sidebar device name
|
||||||
if (response.deviceName) {
|
function updateSidebarDeviceName(deviceName) {
|
||||||
document.title = response.deviceName;
|
const elements = document.querySelectorAll('.sideBar_sensorName');
|
||||||
}
|
if (elements.length > 0) {
|
||||||
|
elements.forEach((element) => {
|
||||||
|
element.innerText = deviceName;
|
||||||
|
});
|
||||||
|
console.log("Device name updated in sidebar:", deviceName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update device name immediately and with retries to handle async sidebar loading
|
||||||
|
if (deviceName) {
|
||||||
|
updateSidebarDeviceName(deviceName);
|
||||||
|
// Retry after delays to catch async sidebar load
|
||||||
|
setTimeout(() => updateSidebarDeviceName(deviceName), 100);
|
||||||
|
setTimeout(() => updateSidebarDeviceName(deviceName), 500);
|
||||||
|
|
||||||
|
//device name html page title
|
||||||
|
document.title = deviceName;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//get wifi connection status
|
//get wifi connection status
|
||||||
|
|||||||
Reference in New Issue
Block a user