mirror of
https://github.com/ranaldsgift/KefinTweaks.git
synced 2026-11-05 15:52:47 +01:00
Ensure recently added section libraries are automatically added to the KefinTweaksConfig
This commit is contained in:
1 parent
7e9a32d494
commit
5b66658db6
1 file changed
+43
-10
+43
-10
@@ -207,7 +207,7 @@
|
|||||||
* Migrates old homeScreen config format to new format
|
* Migrates old homeScreen config format to new format
|
||||||
* Small, transparent function that runs automatically
|
* Small, transparent function that runs automatically
|
||||||
*/
|
*/
|
||||||
function migrateHomeScreenConfig() {
|
async function migrateHomeScreenConfig() {
|
||||||
if (!window.KefinTweaksConfig || !window.KefinTweaksConfig.homeScreen) {
|
if (!window.KefinTweaksConfig || !window.KefinTweaksConfig.homeScreen) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -746,13 +746,43 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Migrate Recently Added in Library
|
||||||
|
if (!old.recentlyAddedInLibrary) {
|
||||||
|
old.recentlyAddedInLibrary = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// We always check for new libraries to add them as disabled
|
||||||
|
const userId = ApiClient.getCurrentUserId();
|
||||||
|
const result = await window.ApiClient.getUserViews({}, userId);
|
||||||
|
|
||||||
|
if (result && result.Items) {
|
||||||
|
const libraries = result.Items.filter(item =>
|
||||||
|
item.CollectionType === 'movies' || item.CollectionType === 'tvshows'
|
||||||
|
);
|
||||||
|
|
||||||
|
libraries.forEach(lib => {
|
||||||
|
if (!old.recentlyAddedInLibrary[lib.Id]) {
|
||||||
|
old.recentlyAddedInLibrary[lib.Id] = {
|
||||||
|
enabled: false, // Default to disabled for new libraries
|
||||||
|
order: 11,
|
||||||
|
itemLimit: 30,
|
||||||
|
name: `Recently Added in ${lib.Name}`,
|
||||||
|
cardFormat: lib.CollectionType === 'tvshows' ? 'Thumb' : 'Poster'
|
||||||
|
};
|
||||||
|
configChanged = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
WARN('Error checking libraries for migration', e);
|
||||||
|
}
|
||||||
|
|
||||||
if (configChanged && !needsMigration) {
|
if (configChanged && !needsMigration) {
|
||||||
LOG('Applied specific configuration updates (recently released dates / christmas sections)');
|
LOG('Applied specific configuration updates');
|
||||||
// Save updated config back to JS Injector plugin
|
// Save updated config back to JS Injector plugin
|
||||||
if (window.KefinTweaksUtils && window.KefinTweaksUtils.saveConfigToJavaScriptInjector) {
|
if (window.KefinTweaksUtils && window.KefinTweaksUtils.saveConfigToJavaScriptInjector) {
|
||||||
window.KefinTweaksUtils.saveConfigToJavaScriptInjector().catch(err => {
|
await window.KefinTweaksUtils.saveConfigToJavaScriptInjector();
|
||||||
ERR('Failed to save updated config to JS Injector:', err);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1437,20 +1467,23 @@
|
|||||||
* @param {HTMLElement} container - Container to append sections to
|
* @param {HTMLElement} container - Container to append sections to
|
||||||
*/
|
*/
|
||||||
async function renderAllRecentlyAddedInLibrarySections(container) {
|
async function renderAllRecentlyAddedInLibrarySections(container) {
|
||||||
if (!recentlyAddedInLibraryConfig || Object.keys(recentlyAddedInLibraryConfig).length === 0) {
|
// Read fresh config to ensure migration updates are picked up
|
||||||
|
const config = window.KefinTweaksConfig?.homeScreen?.recentlyAddedInLibrary || {};
|
||||||
|
|
||||||
|
if (Object.keys(config).length === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const libraryIds = Object.keys(recentlyAddedInLibraryConfig);
|
const libraryIds = Object.keys(config);
|
||||||
const sectionsToRender = [];
|
const sectionsToRender = [];
|
||||||
|
|
||||||
libraryIds.forEach(libraryId => {
|
libraryIds.forEach(libraryId => {
|
||||||
const config = recentlyAddedInLibraryConfig[libraryId];
|
const sectionConfig = config[libraryId];
|
||||||
if (config && config.enabled !== false) {
|
if (sectionConfig && sectionConfig.enabled !== false) {
|
||||||
// Check if already rendered
|
// Check if already rendered
|
||||||
const sectionId = `recently-added-${libraryId}`;
|
const sectionId = `recently-added-${libraryId}`;
|
||||||
if (!container.querySelector(`[data-custom-section-id="${sectionId}"]`)) {
|
if (!container.querySelector(`[data-custom-section-id="${sectionId}"]`)) {
|
||||||
sectionsToRender.push(renderRecentlyAddedInLibrarySection(libraryId, config, container));
|
sectionsToRender.push(renderRecentlyAddedInLibrarySection(libraryId, sectionConfig, container));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in new issue
Block a user