theme: persist active design preset across settings reopen
The <select> element survives settings open/close, so its lingering value masked the otherwise-empty restore path on the second open and the dropdown always reverted to whatever was last picked in the *current* session. Track the active preset in localStorage on every change / save, restore from localStorage first (it's the source of truth), and clear the entry on delete. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
ff3e0e8736
commit
ccd0477841
1 file changed
+11
-2
@@ -232,7 +232,10 @@ function saveUserPresets(p) {
|
||||
function refreshPresetSelect() {
|
||||
const sel = $('design-preset-select');
|
||||
if (!sel) return;
|
||||
const cur = sel.value;
|
||||
// localStorage wins over sel.value: the <select> survives settings
|
||||
// close/reopen, so its lingering value would otherwise mask the
|
||||
// persisted selection on the next refresh.
|
||||
const cur = localStorage.getItem('hyprcrd-design-active-preset') || sel.value || '';
|
||||
sel.innerHTML = '';
|
||||
const builtinGroup = document.createElement('optgroup');
|
||||
builtinGroup.label = 'built-in';
|
||||
@@ -254,7 +257,7 @@ function refreshPresetSelect() {
|
||||
}
|
||||
sel.appendChild(userGroup);
|
||||
}
|
||||
if (cur) sel.value = cur;
|
||||
if (cur && sel.querySelector(`option[value="${CSS.escape(cur)}"]`)) sel.value = cur;
|
||||
}
|
||||
|
||||
function getSelectedPreset() {
|
||||
@@ -274,6 +277,8 @@ function loadSelectedPreset() {
|
||||
syncControlsFromPending();
|
||||
commitDesign();
|
||||
renderThemes();
|
||||
const sel = $('design-preset-select');
|
||||
if (sel?.value) localStorage.setItem('hyprcrd-design-active-preset', sel.value);
|
||||
}
|
||||
$('design-preset-select')?.addEventListener('change', loadSelectedPreset);
|
||||
|
||||
@@ -288,6 +293,7 @@ $('design-preset-save')?.addEventListener('click', () => {
|
||||
refreshPresetSelect();
|
||||
const sel = $('design-preset-select');
|
||||
if (sel) sel.value = 'user:' + name;
|
||||
localStorage.setItem('hyprcrd-design-active-preset', 'user:' + name);
|
||||
const status = $('design-status');
|
||||
if (status) { status.textContent = `preset "${name}" saved`; status.style.color = 'var(--t-accent)'; }
|
||||
});
|
||||
@@ -299,6 +305,9 @@ $('design-preset-delete')?.addEventListener('click', () => {
|
||||
const presets = loadUserPresets();
|
||||
delete presets[name];
|
||||
saveUserPresets(presets);
|
||||
if (localStorage.getItem('hyprcrd-design-active-preset') === 'user:' + name) {
|
||||
localStorage.removeItem('hyprcrd-design-active-preset');
|
||||
}
|
||||
refreshPresetSelect();
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user