From 56825e3744e40d51efc01d5b2ae82a7a8d748acb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=86=8A=E8=B0=B7=20=E5=87=8C?= Date: Thu, 26 Dec 2024 12:56:30 +0800 Subject: [PATCH] Allow `refreshBlocks()` to specify extension (#228) --- src/extension-support/extension-manager.js | 28 +++++++++++++--------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/extension-support/extension-manager.js b/src/extension-support/extension-manager.js index a092af35482..5268ad938e8 100644 --- a/src/extension-support/extension-manager.js +++ b/src/extension-support/extension-manager.js @@ -277,19 +277,25 @@ class ExtensionManager { /** * Regenerate blockinfo for any loaded extensions + * @param {string} [optExtensionId] Optional extension ID for refreshing * @returns {Promise} resolved once all the extensions have been reinitialized */ - refreshBlocks () { - const allPromises = Array.from(this._loadedExtensions.values()).map(serviceName => - dispatch.call(serviceName, 'getInfo') - .then(info => { - info = this._prepareExtensionInfo(serviceName, info); - dispatch.call('runtime', '_refreshExtensionPrimitives', info); - }) - .catch(e => { - log.error('Failed to refresh built-in extension primitives', e); - }) - ); + refreshBlocks (optExtensionId) { + const refresh = serviceName => dispatch.call(serviceName, 'getInfo') + .then(info => { + info = this._prepareExtensionInfo(serviceName, info); + dispatch.call('runtime', '_refreshExtensionPrimitives', info); + }) + .catch(e => { + log.error('Failed to refresh built-in extension primitives', e); + }); + if (optExtensionId) { + if (!this._loadedExtensions.has(optExtensionId)) { + return Promise.reject(new Error(`Unknown extension: ${optExtensionId}`)); + } + return refresh(this._loadedExtensions.get(optExtensionId)); + } + const allPromises = Array.from(this._loadedExtensions.values()).map(refresh); return Promise.all(allPromises); }