Show SD-card info only if requested
This commit is contained in:
@@ -26,6 +26,7 @@ void SystemInformationActivity::onEnter() {
|
||||
Activity::onEnter();
|
||||
status_.reset();
|
||||
sdStatusReady_ = false;
|
||||
sdLoadRequested_ = false;
|
||||
requestUpdate();
|
||||
}
|
||||
|
||||
@@ -36,6 +37,7 @@ void SystemInformationActivity::loop() {
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
// Collect fast fields first so this page appears immediately.
|
||||
if (!status_.has_value()) {
|
||||
status_ = SystemStatus::collectFast();
|
||||
@@ -43,11 +45,18 @@ void SystemInformationActivity::loop() {
|
||||
return;
|
||||
}
|
||||
|
||||
// SD stats can be slower to compute on large cards.
|
||||
// SD stats can be slower to compute on large cards. Load them only when the
|
||||
// user explicitly confirms.
|
||||
if (!sdStatusReady_) {
|
||||
SystemStatus::fillSdStatus(*status_);
|
||||
sdStatusReady_ = true;
|
||||
requestUpdate();
|
||||
if (sdLoadRequested_) {
|
||||
SystemStatus::fillSdStatus(*status_);
|
||||
sdStatusReady_ = true;
|
||||
sdLoadRequested_ = false;
|
||||
requestUpdate();
|
||||
} else if (mappedInput.wasPressed(MappedInputManager::Button::Confirm)) {
|
||||
sdLoadRequested_ = true;
|
||||
requestUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,14 +118,15 @@ void SystemInformationActivity::render(RenderLock&&) {
|
||||
drawRow(8, tr(STR_UPTIME), uptimeBuf);
|
||||
|
||||
if (!sdStatusReady_) {
|
||||
drawRow(9, tr(STR_SD_CARD), tr(STR_READING));
|
||||
const char* sdMessage = sdLoadRequested_ ? tr(STR_READING) : tr(STR_SD_UPDATE_PROMPT);
|
||||
drawRow(9, tr(STR_SD_CARD), sdMessage);
|
||||
} else if (status.sdTotalBytes > 0) {
|
||||
drawRow(9, tr(STR_SD_CARD), formatBytes(status.sdUsedBytes) + " / " + formatBytes(status.sdTotalBytes));
|
||||
} else {
|
||||
drawRow(9, tr(STR_SD_CARD), tr(STR_NOT_SET));
|
||||
}
|
||||
|
||||
const auto labels = mappedInput.mapLabels(tr(STR_BACK), "", "", "");
|
||||
const auto labels = mappedInput.mapLabels(tr(STR_BACK), tr(STR_UPDATE), "", "");
|
||||
GUI.drawButtonHints(renderer, labels.btn1, labels.btn2, labels.btn3, labels.btn4);
|
||||
|
||||
renderer.displayBuffer();
|
||||
|
||||
@@ -18,4 +18,5 @@ class SystemInformationActivity final : public Activity {
|
||||
private:
|
||||
std::optional<SystemStatus> status_;
|
||||
bool sdStatusReady_ = false;
|
||||
bool sdLoadRequested_ = false;
|
||||
};
|
||||
|
||||
@@ -110,6 +110,26 @@
|
||||
background-color: var(--accent-hover-color);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.action-row {
|
||||
text-align: center;
|
||||
margin-top: 16px;
|
||||
}
|
||||
|
||||
.action-row button {
|
||||
padding: 10px 18px;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
background-color: var(--accent-color);
|
||||
color: white;
|
||||
font-size: 1rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.action-row button:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: default;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
@@ -174,7 +194,10 @@
|
||||
</div>
|
||||
<div class="info-row">
|
||||
<span class="label">SD Card</span>
|
||||
<span class="value" id="sd-space">Loading...</span>
|
||||
<span class="value" id="sd-space">Not loaded</span>
|
||||
</div>
|
||||
<div class="action-row">
|
||||
<button id="load-sd-button">Load SD info</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -231,6 +254,8 @@
|
||||
document.getElementById('sd-space').textContent = data.sdTotal
|
||||
? formatBytes(data.sdUsed) + ' / ' + formatBytes(data.sdTotal)
|
||||
: 'N/A';
|
||||
} else {
|
||||
document.getElementById('sd-space').textContent = 'Not loaded';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -242,21 +267,43 @@
|
||||
}
|
||||
const fastData = await fastResponse.json();
|
||||
applyStatus(fastData, false);
|
||||
document.getElementById('sd-space').textContent = 'Reading...';
|
||||
|
||||
const response = await fetch('/api/status');
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to fetch full status: ' + response.status + ' ' + response.statusText);
|
||||
}
|
||||
const data = await response.json();
|
||||
applyStatus(data, true);
|
||||
setSdButtonState(true);
|
||||
} catch (error) {
|
||||
console.error('Error fetching status:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch status on page load
|
||||
window.onload = fetchStatus;
|
||||
async function fetchSdStatus() {
|
||||
const button = document.getElementById('load-sd-button');
|
||||
button.disabled = true;
|
||||
button.textContent = 'Loading...';
|
||||
document.getElementById('sd-space').textContent = 'Loading...';
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/status');
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to fetch SD status: ' + response.status + ' ' + response.statusText);
|
||||
}
|
||||
const data = await response.json();
|
||||
applyStatus(data, true);
|
||||
button.style.display = 'none';
|
||||
} catch (error) {
|
||||
console.error('Error fetching SD status:', error);
|
||||
button.disabled = false;
|
||||
button.textContent = 'Load SD info';
|
||||
}
|
||||
}
|
||||
|
||||
function setSdButtonState(enabled) {
|
||||
const button = document.getElementById('load-sd-button');
|
||||
button.disabled = !enabled;
|
||||
button.textContent = enabled ? 'Load SD info' : 'Loading...';
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
document.getElementById('load-sd-button').addEventListener('click', fetchSdStatus);
|
||||
fetchStatus();
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user