Reformat to tabs
This commit is contained in:
parent
8bc434b614
commit
33411f0300
@ -3321,65 +3321,65 @@ function checkVersionUpgrade(info) {
|
|||||||
fetch(getURL('/edit?func=edit&path=/version-info.json'), {
|
fetch(getURL('/edit?func=edit&path=/version-info.json'), {
|
||||||
method: 'get'
|
method: 'get'
|
||||||
})
|
})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
if (res.status === 404) {
|
if (res.status === 404) {
|
||||||
// File doesn't exist - first install, show install prompt
|
// File doesn't exist - first install, show install prompt
|
||||||
showVersionUpgradePrompt(info, null, info.ver);
|
showVersionUpgradePrompt(info, null, info.ver);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
throw new Error('Failed to fetch version-info.json');
|
throw new Error('Failed to fetch version-info.json');
|
||||||
}
|
}
|
||||||
return res.json();
|
return res.json();
|
||||||
})
|
})
|
||||||
.then(versionInfo => {
|
.then(versionInfo => {
|
||||||
if (!versionInfo) return; // 404 case already handled
|
if (!versionInfo) return; // 404 case already handled
|
||||||
|
|
||||||
// Check if user opted out
|
// Check if user opted out
|
||||||
if (versionInfo.neverAsk) return;
|
if (versionInfo.neverAsk) return;
|
||||||
|
|
||||||
// Check if version has changed
|
// Check if version has changed
|
||||||
const currentVersion = info.ver;
|
const currentVersion = info.ver;
|
||||||
const storedVersion = versionInfo.version || '';
|
const storedVersion = versionInfo.version || '';
|
||||||
|
|
||||||
if (storedVersion && storedVersion !== currentVersion) {
|
if (storedVersion && storedVersion !== currentVersion) {
|
||||||
// Version has changed, show upgrade prompt
|
// Version has changed, show upgrade prompt
|
||||||
showVersionUpgradePrompt(info, storedVersion, currentVersion);
|
showVersionUpgradePrompt(info, storedVersion, currentVersion);
|
||||||
} else if (!storedVersion) {
|
} else if (!storedVersion) {
|
||||||
// Empty version in file, show install prompt
|
// Empty version in file, show install prompt
|
||||||
showVersionUpgradePrompt(info, null, currentVersion);
|
showVersionUpgradePrompt(info, null, currentVersion);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
console.log('Failed to load version-info.json', e);
|
console.log('Failed to load version-info.json', e);
|
||||||
// On error, save current version for next time
|
// On error, save current version for next time
|
||||||
if (info && info.ver) {
|
if (info && info.ver) {
|
||||||
updateVersionInfo(info.ver, false);
|
updateVersionInfo(info.ver, false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function showVersionUpgradePrompt(info, oldVersion, newVersion) {
|
function showVersionUpgradePrompt(info, oldVersion, newVersion) {
|
||||||
// Determine if this is an install or upgrade
|
// Determine if this is an install or upgrade
|
||||||
const isInstall = !oldVersion;
|
const isInstall = !oldVersion;
|
||||||
|
|
||||||
// Create overlay and dialog
|
// Create overlay and dialog
|
||||||
const overlay = d.createElement('div');
|
const overlay = d.createElement('div');
|
||||||
overlay.id = 'versionUpgradeOverlay';
|
overlay.id = 'versionUpgradeOverlay';
|
||||||
overlay.style.cssText = 'position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,0.7);z-index:10000;display:flex;align-items:center;justify-content:center;';
|
overlay.style.cssText = 'position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,0.7);z-index:10000;display:flex;align-items:center;justify-content:center;';
|
||||||
|
|
||||||
const dialog = d.createElement('div');
|
const dialog = d.createElement('div');
|
||||||
dialog.style.cssText = 'background:var(--c-1);border-radius:10px;padding:25px;max-width:500px;margin:20px;box-shadow:0 4px 6px rgba(0,0,0,0.3);';
|
dialog.style.cssText = 'background:var(--c-1);border-radius:10px;padding:25px;max-width:500px;margin:20px;box-shadow:0 4px 6px rgba(0,0,0,0.3);';
|
||||||
|
|
||||||
// Build contextual message based on install vs upgrade
|
// Build contextual message based on install vs upgrade
|
||||||
const title = isInstall
|
const title = isInstall
|
||||||
? '🎉 Thank you for installing WLED!'
|
? '🎉 Thank you for installing WLED!'
|
||||||
: '🎉 WLED Upgrade Detected!';
|
: '🎉 WLED Upgrade Detected!';
|
||||||
|
|
||||||
const description = isInstall
|
const description = isInstall
|
||||||
? `You are now running WLED <strong style="text-wrap: nowrap">${newVersion}</strong>.`
|
? `You are now running WLED <strong style="text-wrap: nowrap">${newVersion}</strong>.`
|
||||||
: `Your WLED has been upgraded from <strong style="text-wrap: nowrap">${oldVersion}</strong> to <strong style="text-wrap: nowrap">${newVersion}</strong>.`;
|
: `Your WLED has been upgraded from <strong style="text-wrap: nowrap">${oldVersion}</strong> to <strong style="text-wrap: nowrap">${newVersion}</strong>.`;
|
||||||
|
|
||||||
const question = 'Help make WLED better with a one-time hardware report? It includes only device details like chip type, LED count, etc. — never personal data or your activities.'
|
const question = 'Help make WLED better with a one-time hardware report? It includes only device details like chip type, LED count, etc. — never personal data or your activities.'
|
||||||
|
|
||||||
dialog.innerHTML = `
|
dialog.innerHTML = `
|
||||||
@ -3395,21 +3395,21 @@ function showVersionUpgradePrompt(info, oldVersion, newVersion) {
|
|||||||
<button id="versionReportNever" class="btn">Never Ask</button>
|
<button id="versionReportNever" class="btn">Never Ask</button>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
overlay.appendChild(dialog);
|
overlay.appendChild(dialog);
|
||||||
d.body.appendChild(overlay);
|
d.body.appendChild(overlay);
|
||||||
|
|
||||||
// Add event listeners
|
// Add event listeners
|
||||||
gId('versionReportYes').addEventListener('click', () => {
|
gId('versionReportYes').addEventListener('click', () => {
|
||||||
reportUpgradeEvent(info, oldVersion);
|
reportUpgradeEvent(info, oldVersion);
|
||||||
d.body.removeChild(overlay);
|
d.body.removeChild(overlay);
|
||||||
});
|
});
|
||||||
|
|
||||||
gId('versionReportNo').addEventListener('click', () => {
|
gId('versionReportNo').addEventListener('click', () => {
|
||||||
// Don't update version, will ask again on next load
|
// Don't update version, will ask again on next load
|
||||||
d.body.removeChild(overlay);
|
d.body.removeChild(overlay);
|
||||||
});
|
});
|
||||||
|
|
||||||
gId('versionReportNever').addEventListener('click', () => {
|
gId('versionReportNever').addEventListener('click', () => {
|
||||||
updateVersionInfo(newVersion, true);
|
updateVersionInfo(newVersion, true);
|
||||||
d.body.removeChild(overlay);
|
d.body.removeChild(overlay);
|
||||||
@ -3419,56 +3419,56 @@ function showVersionUpgradePrompt(info, oldVersion, newVersion) {
|
|||||||
|
|
||||||
function reportUpgradeEvent(info, oldVersion) {
|
function reportUpgradeEvent(info, oldVersion) {
|
||||||
showToast('Reporting upgrade...');
|
showToast('Reporting upgrade...');
|
||||||
|
|
||||||
// Fetch fresh data from /json/info endpoint as requested
|
// Fetch fresh data from /json/info endpoint as requested
|
||||||
fetch(getURL('/json/info'), {
|
fetch(getURL('/json/info'), {
|
||||||
method: 'get'
|
method: 'get'
|
||||||
})
|
})
|
||||||
.then(res => res.json())
|
.then(res => res.json())
|
||||||
.then(infoData => {
|
.then(infoData => {
|
||||||
// Map to UpgradeEventRequest structure per OpenAPI spec
|
// Map to UpgradeEventRequest structure per OpenAPI spec
|
||||||
// Required fields: deviceId, version, previousVersion, releaseName, chip, ledCount, isMatrix, bootloaderSHA256
|
// Required fields: deviceId, version, previousVersion, releaseName, chip, ledCount, isMatrix, bootloaderSHA256
|
||||||
const upgradeData = {
|
const upgradeData = {
|
||||||
deviceId: infoData.deviceId, // Use anonymous unique device ID
|
deviceId: infoData.deviceId, // Use anonymous unique device ID
|
||||||
version: infoData.ver || '', // Current version string
|
version: infoData.ver || '', // Current version string
|
||||||
previousVersion: oldVersion || '', // Previous version from version-info.json
|
previousVersion: oldVersion || '', // Previous version from version-info.json
|
||||||
releaseName: infoData.release || '', // Release name (e.g., "WLED 0.15.0")
|
releaseName: infoData.release || '', // Release name (e.g., "WLED 0.15.0")
|
||||||
chip: infoData.arch || '', // Chip architecture (esp32, esp8266, etc)
|
chip: infoData.arch || '', // Chip architecture (esp32, esp8266, etc)
|
||||||
ledCount: infoData.leds ? infoData.leds.count : 0, // Number of LEDs
|
ledCount: infoData.leds ? infoData.leds.count : 0, // Number of LEDs
|
||||||
isMatrix: !!(infoData.leds && infoData.leds.matrix), // Whether it's a 2D matrix setup
|
isMatrix: !!(infoData.leds && infoData.leds.matrix), // Whether it's a 2D matrix setup
|
||||||
bootloaderSHA256: infoData.bootloaderSHA256 || '', // Bootloader SHA256 hash
|
bootloaderSHA256: infoData.bootloaderSHA256 || '', // Bootloader SHA256 hash
|
||||||
brand: infoData.brand, // Device brand (always present)
|
brand: infoData.brand, // Device brand (always present)
|
||||||
product: infoData.product, // Product name (always present)
|
product: infoData.product, // Product name (always present)
|
||||||
flashSize: infoData.flash // Flash size (always present)
|
flashSize: infoData.flash // Flash size (always present)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Add optional fields if available
|
// Add optional fields if available
|
||||||
if (infoData.psram !== undefined) upgradeData.psramSize = infoData.psram;
|
if (infoData.psram !== undefined) upgradeData.psramSize = infoData.psram;
|
||||||
// Note: partitionSizes not currently available in /json/info endpoint
|
// Note: partitionSizes not currently available in /json/info endpoint
|
||||||
|
|
||||||
// Make AJAX call to postUpgradeEvent API
|
// Make AJAX call to postUpgradeEvent API
|
||||||
return fetch('https://usage.wled.me/api/usage/upgrade', {
|
return fetch('https://usage.wled.me/api/usage/upgrade', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
},
|
},
|
||||||
body: JSON.stringify(upgradeData)
|
body: JSON.stringify(upgradeData)
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
showToast('Thank you for reporting!');
|
showToast('Thank you for reporting!');
|
||||||
updateVersionInfo(info.ver, false);
|
updateVersionInfo(info.ver, false);
|
||||||
} else {
|
} else {
|
||||||
|
showToast('Report failed. Please try again later.', true);
|
||||||
|
// Do NOT update version info on failure - user will be prompted again
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(e => {
|
||||||
|
console.log('Failed to report upgrade', e);
|
||||||
showToast('Report failed. Please try again later.', true);
|
showToast('Report failed. Please try again later.', true);
|
||||||
// Do NOT update version info on failure - user will be prompted again
|
// Do NOT update version info on error - user will be prompted again
|
||||||
}
|
});
|
||||||
})
|
|
||||||
.catch(e => {
|
|
||||||
console.log('Failed to report upgrade', e);
|
|
||||||
showToast('Report failed. Please try again later.', true);
|
|
||||||
// Do NOT update version info on error - user will be prompted again
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateVersionInfo(version, neverAsk) {
|
function updateVersionInfo(version, neverAsk) {
|
||||||
@ -3476,23 +3476,23 @@ function updateVersionInfo(version, neverAsk) {
|
|||||||
version: version,
|
version: version,
|
||||||
neverAsk: neverAsk
|
neverAsk: neverAsk
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create a Blob with JSON content and use /upload endpoint
|
// Create a Blob with JSON content and use /upload endpoint
|
||||||
const blob = new Blob([JSON.stringify(versionInfo)], { type: 'application/json' });
|
const blob = new Blob([JSON.stringify(versionInfo)], {type: 'application/json'});
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('data', blob, 'version-info.json');
|
formData.append('data', blob, 'version-info.json');
|
||||||
|
|
||||||
fetch(getURL('/upload'), {
|
fetch(getURL('/upload'), {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: formData
|
body: formData
|
||||||
})
|
})
|
||||||
.then(res => res.text())
|
.then(res => res.text())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
console.log('Version info updated', data);
|
console.log('Version info updated', data);
|
||||||
})
|
})
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
console.log('Failed to update version-info.json', e);
|
console.log('Failed to update version-info.json', e);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
size();
|
size();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user