Show a warning on the Connect screen if the changes were not saved

This commit is contained in:
Mathias Malmqvist
2025-11-23 20:52:20 +01:00
parent f9d43626e7
commit e63eb47374
2 changed files with 18 additions and 4 deletions

View File

@@ -386,6 +386,11 @@
<div id="lastConnected" class="gap-2"> <div id="lastConnected" class="gap-2">
<span class="text-muted"><i class="fas fa-history"></i>&nbsp;&nbsp;<span class="ds-i18n">Last connected</span>:</span> <span class="text-muted"><i class="fas fa-history"></i>&nbsp;&nbsp;<span class="ds-i18n">Last connected</span>:</span>
<span id="lastConnectedInfo"></span> <span id="lastConnectedInfo"></span>
<div id="lastConnectedWarning" style="display: none;">
<p class="text-danger" style="margin-top: 8px; margin-bottom: 0;">
<i class="fas fa-regular fa-triangle-exclamation"></i>&nbsp;&nbsp;<span class="ds-i18n">This controller has unsaved changes that will be lost when the controller is rebooted.</span>
</p>
</div>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -295,15 +295,14 @@ async function continue_connection({data, device}) {
// Save controller info to local storage // Save controller info to local storage
const lastConnectedInfo = { const lastConnectedInfo = {
deviceName: deviceName, deviceName: deviceName,
timestamp: new Date().toISOString() timestamp: new Date().toISOString(),
serialNumber: await controllerInstance.getSerialNumber(),
}; };
// Extract info from infoItems // Extract info from infoItems
if (info.infoItems && Array.isArray(info.infoItems)) { if (info.infoItems && Array.isArray(info.infoItems)) {
for (const item of info.infoItems) { for (const item of info.infoItems) {
if (item.key === l("Serial Number")) { if (item.key === l("Board Model")) {
lastConnectedInfo.serialNumber = item.value;
} else if (item.key === l("Board Model")) {
lastConnectedInfo.boardModel = item.value; lastConnectedInfo.boardModel = item.value;
} else if (item.key === l("Color")) { } else if (item.key === l("Color")) {
lastConnectedInfo.color = item.value; lastConnectedInfo.color = item.value;
@@ -428,6 +427,16 @@ function updateLastConnectedInfo() {
} }
$infoDiv.text(text); $infoDiv.text(text);
if (info.serialNumber) {
const storageKey = `changes_${info.serialNumber}`;
const savedChangesState = localStorage.getItem(storageKey);
const hasChanges = savedChangesState ? JSON.parse(savedChangesState) : false;
const $warning = $("#lastConnectedWarning");
$warning.toggle(hasChanges);
}
$lastConnected.show(); $lastConnected.show();
} catch (error) { } catch (error) {
console.error("Error parsing last connected info:", error); console.error("Error parsing last connected info:", error);