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
|
||||
|
||||
//device name_side bar
|
||||
// Function to update sidebar device name
|
||||
function updateSidebarDeviceName(deviceName) {
|
||||
const elements = document.querySelectorAll('.sideBar_sensorName');
|
||||
if (elements.length > 0) {
|
||||
elements.forEach((element) => {
|
||||
element.innerText = response.deviceName;
|
||||
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
|
||||
createSensorCards(mainConfig);
|
||||
|
||||
@@ -299,14 +299,26 @@ function get_internet(){
|
||||
//get device Name
|
||||
const deviceName = data.deviceName;
|
||||
|
||||
// Function to update sidebar device name
|
||||
function updateSidebarDeviceName(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
|
||||
if (response.deviceName) {
|
||||
document.title = response.deviceName;
|
||||
document.title = deviceName;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user