From 2b25ae027a212a94fe09b383f9fc749a4ae86fc2 Mon Sep 17 00:00:00 2001 From: DianaXWiki <139217939+DianaXWiki@users.noreply.github.com> Date: Sat, 2 Nov 2024 14:59:38 +0200 Subject: [PATCH] Fix admin_category not showing problem --- customize.dist/pages/index.js | 60 ++++------------------------------- www/admin/inner.js | 46 ++++++++++++++------------- www/common/extensions.js | 34 +++++++++++--------- 3 files changed, 50 insertions(+), 90 deletions(-) diff --git a/customize.dist/pages/index.js b/customize.dist/pages/index.js index f827b2541..43e2b44d5 100644 --- a/customize.dist/pages/index.js +++ b/customize.dist/pages/index.js @@ -170,62 +170,16 @@ define([ Extensions.getExtensions('HOMEPAGE_POPUP').forEach(_ext => { _ext.then(ext => { - ext.getContent(utils, content => { - $(popup).append(h('div.cp-extensions-popup', content)); - resolve(); - }); + if (ext) { + ext.getContent(utils, content => { + $(popup).append(h('div.cp-extensions-popup', content)); + }); + } + }).catch(error => { + console.error(error); }); }); - common.getExtensions('ADMIN_CATEGORY').forEach(_ext => { - console.log("category") - _ext.then(ext => { - console.log(ext); - if (!ext || !ext.id || !ext.name || !ext.content) { - return console.error('Invalid extension point', 'ADMIN_CATEGORY', ext); - } - if (categories[ext.id]) { - return console.error('Extension point ID already used', ext); - } - console.log("inside category") - categories[ext.id] = { - icon: ext.icon, - name: ext.name, - content: ext.content - }; - }).catch(error => console.error("Error loading ADMIN_CATEGORY extension:", error)); - }); - - common.getExtensions('ADMIN_ITEM').forEach(_ext => { - console.log("item") - _ext.then(ext => { - console.log("Loading ADMIN_ITEM extension:", ext); // Added log for debugging - if (!ext || !ext.id || typeof(ext.getContent) !== "function") { - return console.error('Invalid extension point', 'ADMIN_ITEM', ext); - } - if (sidebar.hasItem(ext.id)) { - return console.error('Extension point ID already used', ext); - } - - sidebar.addItem(ext.id, cb => { - console.log("inside sidebar") - ext.getContent(common, blocks, utils, content => { - if (!content) { - console.warn("Content is undefined for extension:", ext.id); // Added war - } - console.log("inside getContent: ", content); - cb(content); - }); - }, { - noTitle: !ext.title, - noHint: !ext.description, - title: ext.title, - hint: ext.description - }); - }).catch(error => console.error("Error loading ADMIN_ITEM extension:", error)); - }); - - return [ h('div#cp-main', [ diff --git a/www/admin/inner.js b/www/admin/inner.js index 71f4be310..250aaa24d 100644 --- a/www/admin/inner.js +++ b/www/admin/inner.js @@ -172,23 +172,25 @@ define([ const blocks = sidebar.blocks; // EXTENSION_POINT:ADMIN_CATEGORY - common.getExtensions('ADMIN_CATEGORY').forEach(_ext => { - _ext.then(ext => { - console.log(ext) - if (!ext || !ext.id || !ext.name || !ext.content) { - return console.error('Invalid extension point', 'ADMIN_CATEGORY', ext); - } - if (categories[ext.id]) { - return console.error('Extension point ID already used', ext); - } - //console.error(ext); - categories[ext.id] = { - icon: ext.icon, - name: ext.name, - content: ext.content - }; - }).catch(error => console.error("Error loading ADMIN_CATEGORY extension:", error)); - }); + async function processExtensions(id) { + const extensions = await common.getExtensions(id); + extensions.forEach(_ext => { + _ext.then(ext => { + if (!ext || !ext.id || !ext.name || !ext.content) { + return console.error('Invalid extension point', 'ADMIN_CATEGORY', ext); + } + if (categories[ext.id]) { + return console.error('Extension point ID already used', ext); + } + categories[ext.id] = { + icon: ext.icon, + name: ext.name, + content: ext.content + }; + }) + }) + } + const flushCache = (cb) => { cb = cb || function () {}; @@ -3930,15 +3932,14 @@ define([ h, Util, Hash }; common.getExtensions('ADMIN_ITEM').forEach(_ext => { + // console.log("item") _ext.then(ext => { - console.log(ext); if (!ext || !ext.id || typeof(ext.getContent) !== "function") { return console.error('Invalid extension point', 'ADMIN_CATEGORY', ext); } if (sidebar.hasItem(ext.id)) { return console.error('Extension point ID already used', ext); } - sidebar.addItem(ext.id, cb => { ext.getContent(common, blocks, utils, content => { console.log("Generated content for", ext.id, ":", content); @@ -3953,9 +3954,10 @@ define([ }).catch(error => console.error("Error loading ADMIN_CATEGORY extension:", error)); }); - - - sidebar.makeLeftside(categories); + (async () => { + await processExtensions('ADMIN_CATEGORY'); + sidebar.makeLeftside(categories); + })(); }; diff --git a/www/common/extensions.js b/www/common/extensions.js index 72755c34b..9081b257f 100644 --- a/www/common/extensions.js +++ b/www/common/extensions.js @@ -11,22 +11,26 @@ define([ let e = ext[id]; if (!Array.isArray(e)) { e = []; } return e.map(_ext => { - return new Promise((resolve) => { - if (typeof _ext.check === "function") { - const checkResult = _ext.check(); - if (checkResult && typeof checkResult.then === "function") { - checkResult.then(() => { - resolve(_ext); - }).catch(() => { - console.error("Check failed for extension:", _ext); - resolve(null); - }); - } else { - resolve(_ext); - } - } else { - resolve(_ext); + return new Promise((resolve, reject) => { + // If there's no check function, resolve immediately + if (typeof _ext.check !== "function") { + return resolve(_ext); } + const checkResult = _ext.check(); + + checkResult + .then((extPassed) => { + if (!extPassed) { + // Reject if the check didn't pass + resolve(null); + } else { + // Extension passed the check + resolve(_ext); + } + }) + .catch((error) => { + reject(error); + }); }); }); };