|
99 | 99 |
|
100 | 100 | ' Called when reset button is selected in HexKeyboard |
101 | 101 | sub onHexResetRequested() |
102 | | - m.global.sceneManager.callFunc("optionDialog", tr("Reset Setting"), tr("Are you sure? This will reset the setting to its default value."), [tr("Yes"), tr("No")]) |
| 102 | + m.global.sceneManager.callFunc("optionDialog", tr("Reset Setting"), tr("Are you sure? This will reset the setting to its default value."), [tr("Cancel"), tr("Reset")]) |
103 | 103 | m.global.sceneManager.observeFieldScoped("dataReturned", "onResetDialogResponse") |
104 | 104 | end sub |
105 | 105 |
|
|
110 | 110 | returnData = m.global.sceneManager.returnData |
111 | 111 | if not isValid(returnData) then return |
112 | 112 |
|
113 | | - ' User selected "No" or closed dialog |
114 | | - if returnData.indexSelected <> 0 |
| 113 | + ' User selected "Cancel" or closed dialog |
| 114 | + if returnData.indexSelected <> 1 |
115 | 115 | m.hexSetting.findNode("resetButton").setFocus(true) |
116 | 116 | return |
117 | 117 | end if |
|
177 | 177 |
|
178 | 178 | ' Called when reset button is selected in AlphaKeyboard |
179 | 179 | sub onAlphaResetRequested() |
180 | | - m.global.sceneManager.callFunc("optionDialog", tr("Reset Setting"), tr("Are you sure? This will reset the setting to its default value."), [tr("Yes"), tr("No")]) |
| 180 | + m.global.sceneManager.callFunc("optionDialog", tr("Reset Setting"), tr("Are you sure? This will reset the setting to its default value."), [tr("Cancel"), tr("Reset")]) |
181 | 181 | m.global.sceneManager.observeFieldScoped("dataReturned", "onAlphaResetDialogResponse") |
182 | 182 | end sub |
183 | 183 |
|
|
188 | 188 | returnData = m.global.sceneManager.returnData |
189 | 189 | if not isValid(returnData) then return |
190 | 190 |
|
191 | | - ' User selected "No" or closed dialog |
192 | | - if returnData.indexSelected <> 0 |
| 191 | + ' User selected "Cancel" or closed dialog |
| 192 | + if returnData.indexSelected <> 1 |
193 | 193 | m.alphaSetting.findNode("resetButton").setFocus(true) |
194 | 194 | return |
195 | 195 | end if |
|
244 | 244 | listItem.id = item.id |
245 | 245 | end for |
246 | 246 |
|
| 247 | + ' Inject "Reset User Settings" action at root level only |
| 248 | + if m.userLocation.Count() = 1 |
| 249 | + resetItem = { |
| 250 | + title: "Reset User Settings", |
| 251 | + description: "Reset all settings to their default values. Your login session will not be affected.", |
| 252 | + type: "action", |
| 253 | + actionId: "resetUserSettings" |
| 254 | + } |
| 255 | + filteredChildren.push(resetItem) |
| 256 | + listItem = result.CreateChild("ContentNode") |
| 257 | + listItem.title = tr(resetItem.title) |
| 258 | + listItem.Description = tr(resetItem.description) |
| 259 | + listItem.id = "resetUserSettings" |
| 260 | + end if |
| 261 | + |
247 | 262 | m.settingsMenu.content = result |
248 | 263 |
|
249 | 264 | if isValid(configSection.selectedIndex) and configSection.selectedIndex > -1 |
|
332 | 347 | m.alphaSetting.text = "" |
333 | 348 | end if |
334 | 349 | m.alphaSetting.visible = true |
| 350 | + else if selectedSetting.type = "action" |
| 351 | + ' Action items show description only, no setting controls |
335 | 352 | else |
336 | 353 | m.log.warn("Unknown setting type", selectedSetting.type) |
337 | 354 | end if |
|
343 | 360 |
|
344 | 361 | selectedItem = m.userLocation.peek().filteredChildren[m.settingsMenu.itemFocused] |
345 | 362 |
|
| 363 | + ' Handle action items (e.g., Reset User Settings) |
| 364 | + if isValid(selectedItem.actionId) and selectedItem.actionId = "resetUserSettings" |
| 365 | + confirmResetUserSettings() |
| 366 | + return |
| 367 | + end if |
| 368 | + |
346 | 369 | if isValid(selectedItem.type) ' Show setting |
347 | 370 | if selectedItem.type = "bool" |
348 | 371 | m.boolSetting.setFocus(true) |
|
470 | 493 | listItem.Description = tr(item.description) |
471 | 494 | listItem.id = item.id |
472 | 495 | end for |
| 496 | + |
| 497 | + ' Re-inject reset button at root level |
| 498 | + if m.userLocation.Count() = 1 |
| 499 | + resetItem = { |
| 500 | + title: "Reset User Settings", |
| 501 | + description: "Reset all settings to their default values. Your login session will not be affected.", |
| 502 | + type: "action", |
| 503 | + actionId: "resetUserSettings" |
| 504 | + } |
| 505 | + filteredChildren.push(resetItem) |
| 506 | + listItem = result.CreateChild("ContentNode") |
| 507 | + listItem.title = tr(resetItem.title) |
| 508 | + listItem.Description = tr(resetItem.description) |
| 509 | + listItem.id = "resetUserSettings" |
| 510 | + end if |
| 511 | + |
473 | 512 | m.settingsMenu.content = result |
474 | 513 |
|
475 | 514 | ' Restore focus, clamping to new list bounds |
|
517 | 556 | return false |
518 | 557 | end function |
519 | 558 |
|
| 559 | +' Show confirmation dialog before resetting all user settings |
| 560 | +sub confirmResetUserSettings() |
| 561 | + m.global.sceneManager.callFunc("optionDialog", tr("Reset User Settings"), tr("Are you sure you want to reset all settings to their default values? Your login session will not be affected."), [tr("Cancel"), tr("Reset")]) |
| 562 | + m.global.sceneManager.observeFieldScoped("dataReturned", "onResetUserSettingsResponse") |
| 563 | +end sub |
| 564 | + |
| 565 | +' Handle user response from reset user settings confirmation dialog |
| 566 | +sub onResetUserSettingsResponse() |
| 567 | + m.global.sceneManager.unobserveFieldScoped("dataReturned") |
| 568 | + |
| 569 | + returnData = m.global.sceneManager.returnData |
| 570 | + if not isValid(returnData) or returnData.indexSelected <> 1 |
| 571 | + ' User selected "Cancel" or closed dialog |
| 572 | + m.settingsMenu.setFocus(true) |
| 573 | + return |
| 574 | + end if |
| 575 | + |
| 576 | + executeResetUserSettings() |
| 577 | +end sub |
| 578 | + |
| 579 | +' Reset all user settings to defaults from settings.json |
| 580 | +' Preserves session keys (authToken, username, serverId, primaryImageTag, LastRunVersion) |
| 581 | +sub executeResetUserSettings() |
| 582 | + localUser = m.global.user |
| 583 | + userId = localUser.id |
| 584 | + if not isValid(userId) or userId = "" |
| 585 | + m.log.warn("Cannot reset settings - user ID is invalid") |
| 586 | + m.settingsMenu.setFocus(true) |
| 587 | + return |
| 588 | + end if |
| 589 | + |
| 590 | + m.log.info("Resetting all user settings to defaults") |
| 591 | + |
| 592 | + ' Disable auto-sync to prevent observers from firing during cleanup |
| 593 | + localUser.settings.callFunc("disableAutoSync") |
| 594 | + |
| 595 | + ' Delete all non-session keys from user registry |
| 596 | + sessionKeys = ["authToken", "username", "serverId", "primaryImageTag", "LastRunVersion"] |
| 597 | + allRegistryData = RegistryReadAll(userId) |
| 598 | + keysToDelete = getSettingKeysToDelete(allRegistryData, sessionKeys) |
| 599 | + |
| 600 | + for each key in keysToDelete |
| 601 | + registry_delete(key, userId) |
| 602 | + end for |
| 603 | + |
| 604 | + ' Reload all defaults from settings.json onto the settings node |
| 605 | + user.settings.SaveDefaults() |
| 606 | + |
| 607 | + ' globalRememberMe was reset to false — clear auto-login state |
| 608 | + unset_setting("active_user") |
| 609 | + |
| 610 | + ' Clear per-library display settings |
| 611 | + localUser.settings.displaySettings = {} |
| 612 | + |
| 613 | + ' Re-enable auto-sync for future changes |
| 614 | + localUser.settings.callFunc("enableAutoSync") |
| 615 | + |
| 616 | + ' Theme colors were reset to defaults - flag for refresh on exit |
| 617 | + m.themeColorsChanged = true |
| 618 | + |
| 619 | + m.log.info("User settings reset complete", { deletedKeys: keysToDelete.Count() }) |
| 620 | + |
| 621 | + ' Show success feedback (toast lives on JRScene, persists across scene transitions) |
| 622 | + m.top.getScene().callFunc("showToast", tr("Settings reset to defaults"), "success") |
| 623 | + |
| 624 | + ' Exit settings and reload home with fresh theme colors |
| 625 | + performSettingsExit() |
| 626 | +end sub |
| 627 | + |
520 | 628 | ' JRScreen hook that gets ran when the screen is shown. |
521 | 629 | sub OnScreenShown() |
522 | 630 | ' Clear backdrop on settings screens |
|
0 commit comments