mirror of
https://github.com/ranaldsgift/KefinTweaks.git
synced 2026-11-05 15:52:47 +01:00
Ensure default kefin sections sync custom items in addition to queries
This commit is contained in:
@@ -243,22 +243,22 @@ span.listItemBodyText.secondary.seasonal-tag {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
[data-modal-id="kefin-homescreen-config-main"] #global-settings-content .hsc-settings-grid {
|
||||
.hsc-settings-grid {
|
||||
display: grid;
|
||||
gap: 0.75em;
|
||||
align-items: stretch;
|
||||
}
|
||||
|
||||
[data-modal-id="kefin-homescreen-config-main"] #global-settings-content .hsc-settings-grid-2 {
|
||||
.hsc-settings-grid-2 {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
grid-auto-rows: 1fr;
|
||||
}
|
||||
|
||||
[data-modal-id="kefin-homescreen-config-main"] #global-settings-content .hsc-settings-grid-3 {
|
||||
.hsc-settings-grid-3 {
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
}
|
||||
|
||||
[data-modal-id="kefin-homescreen-config-main"] #global-settings-content .hsc-settings-span-2 {
|
||||
.hsc-settings-span-2 {
|
||||
grid-column: 1 / -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -1283,6 +1283,44 @@ window.KefinTweaksConfig = ${JSON.stringify(configToBackup, null, 2)};`;
|
||||
return changed;
|
||||
}
|
||||
|
||||
/** Identity for static section items — cardUrl only (no Name fallback). */
|
||||
function itemIdentity(item) {
|
||||
const cardUrl = item?.cardUrl;
|
||||
if (cardUrl == null || cardUrl === '') return null;
|
||||
return String(cardUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure saved section has at least the canonical default items (append-only).
|
||||
* @returns {boolean} whether section.items changed
|
||||
*/
|
||||
function syncItemsFromCanonical(savedSection, canonicalItems) {
|
||||
if (!savedSection || !Array.isArray(canonicalItems) || !canonicalItems.length) return false;
|
||||
|
||||
if (!Array.isArray(savedSection.items) || savedSection.items.length === 0) {
|
||||
savedSection.items = JSON.parse(JSON.stringify(canonicalItems));
|
||||
return true;
|
||||
}
|
||||
|
||||
const existingIds = new Set();
|
||||
for (const item of savedSection.items) {
|
||||
const id = itemIdentity(item);
|
||||
if (id) existingIds.add(id);
|
||||
}
|
||||
|
||||
const toAppend = [];
|
||||
for (const canonicalItem of canonicalItems) {
|
||||
const id = itemIdentity(canonicalItem);
|
||||
if (!id || existingIds.has(id)) continue;
|
||||
toAppend.push(JSON.parse(JSON.stringify(canonicalItem)));
|
||||
existingIds.add(id);
|
||||
}
|
||||
|
||||
if (!toAppend.length) return false;
|
||||
savedSection.items = savedSection.items.concat(toAppend);
|
||||
return true;
|
||||
}
|
||||
|
||||
function syncKefinTweaksDefaultSections(config) {
|
||||
const recentlyAddedTemplate = getRecentlyAddedCanonicalQuery();
|
||||
let hasChanges = false;
|
||||
@@ -1298,18 +1336,28 @@ window.KefinTweaksConfig = ${JSON.stringify(configToBackup, null, 2)};`;
|
||||
if (!canonical && section.id.startsWith('recently-added-')) {
|
||||
canonical = { queries: [recentlyAddedTemplate] };
|
||||
}
|
||||
if (!canonical?.queries?.length) continue;
|
||||
if (!canonical) continue;
|
||||
|
||||
if (!Array.isArray(section.queries)) section.queries = [];
|
||||
const hasCanonicalQueries = !!canonical.queries?.length;
|
||||
const hasCanonicalItems = Array.isArray(canonical.items) && canonical.items.length > 0;
|
||||
if (!hasCanonicalQueries && !hasCanonicalItems) continue;
|
||||
|
||||
for (let i = 0; i < canonical.queries.length; i++) {
|
||||
if (!section.queries[i]) {
|
||||
section.queries[i] = { queryOptions: {} };
|
||||
}
|
||||
if (syncQueryFromCanonical(section.queries[i], canonical.queries[i])) {
|
||||
hasChanges = true;
|
||||
if (hasCanonicalQueries) {
|
||||
if (!Array.isArray(section.queries)) section.queries = [];
|
||||
|
||||
for (let i = 0; i < canonical.queries.length; i++) {
|
||||
if (!section.queries[i]) {
|
||||
section.queries[i] = { queryOptions: {} };
|
||||
}
|
||||
if (syncQueryFromCanonical(section.queries[i], canonical.queries[i])) {
|
||||
hasChanges = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (hasCanonicalItems && syncItemsFromCanonical(section, canonical.items)) {
|
||||
hasChanges = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -1361,16 +1409,16 @@ window.KefinTweaksConfig = ${JSON.stringify(configToBackup, null, 2)};`;
|
||||
prunedOrphans = pruneOrphanKefinDefaultSections(config);
|
||||
}
|
||||
|
||||
const queryChanges = syncKefinTweaksDefaultSections(config);
|
||||
const defaultSyncChanges = syncKefinTweaksDefaultSections(config);
|
||||
const seasonalThemeChanges = syncSeasonalThemesFromDefaults(config);
|
||||
|
||||
if (libraryChanges || addedDefaults || prunedOrphans || queryChanges || seasonalThemeChanges) {
|
||||
if (libraryChanges || addedDefaults || prunedOrphans || defaultSyncChanges || seasonalThemeChanges) {
|
||||
await saveConfig(config);
|
||||
LOG('KefinTweaks default home sections synced on startup', {
|
||||
libraryChanges,
|
||||
addedDefaults,
|
||||
prunedOrphans,
|
||||
queryChanges,
|
||||
defaultSyncChanges,
|
||||
seasonalThemeChanges
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user