From 1efac974d24458cfe0829c8e4aa57d686450606b Mon Sep 17 00:00:00 2001 From: captaincrazybro Date: Mon, 5 Aug 2024 13:44:58 -0400 Subject: [PATCH 1/2] feat: implemented network event emitter for when extension reload is finished --- src/extension-host/services/extension.service.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/extension-host/services/extension.service.ts b/src/extension-host/services/extension.service.ts index c0a5bf9668..671fcb4ea2 100644 --- a/src/extension-host/services/extension.service.ts +++ b/src/extension-host/services/extension.service.ts @@ -14,7 +14,7 @@ import * as platformBibleUtils from 'platform-bible-utils'; import logger from '@shared/services/logger.service'; import { getCommandLineArgumentsGroup, COMMAND_LINE_ARGS } from '@node/utils/command-line.util'; import { setExtensionUris } from '@extension-host/services/extension-storage.service'; -import papi, { fetch as papiFetch } from '@extension-host/services/papi-backend.service'; +import papi, { network, fetch as papiFetch } from '@extension-host/services/papi-backend.service'; import executionTokenService from '@node/services/execution-token.service'; import { ExecutionActivationContext } from '@extension-host/extension-types/extension-activation-context.model'; import { @@ -152,6 +152,12 @@ let initializePromise: Promise | undefined; */ let availableExtensions: ExtensionInfo[]; +/** + * Event emitter to tell any extension listening that the extensions finished reloading. The boolean + * indicates whether it succeeded. + */ +let reloadFinishedEventEmitter: platformBibleUtils.PlatformEventEmitter; + /** Parse string extension manifest into an object and perform any transformations needed */ function parseManifest(extensionManifestJson: string): ExtensionManifest { const extensionManifest: ExtensionManifest = deserialize(extensionManifestJson); @@ -572,7 +578,9 @@ function watchForExtensionChanges(): UnsubscriberAsync { try { logger.debug('Reload extensions from watching'); await reloadExtensions(shouldDeactivateExtensions); + reloadFinishedEventEmitter.emit(true); } catch (e) { + reloadFinishedEventEmitter.emit(false); throw new LogError(`Reload extensions from watching failed. Investigate: ${e}`); } }); @@ -1116,6 +1124,10 @@ export const initialize = () => { initializePromise = (async (): Promise => { if (isInitialized) return; + reloadFinishedEventEmitter = network.createNetworkEventEmitter( + 'extension-services.reloadFinished', + ); + await normalizeExtensionFileNames(); await reloadExtensions(false); From 73491db3cd943631dfe5c9404d077523ef6b9adc Mon Sep 17 00:00:00 2001 From: captaincrazybro Date: Tue, 6 Aug 2024 08:12:51 -0400 Subject: [PATCH 2/2] fix: changed name of reload finished event emitter --- src/extension-host/services/extension.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/extension-host/services/extension.service.ts b/src/extension-host/services/extension.service.ts index 671fcb4ea2..d6f61719d0 100644 --- a/src/extension-host/services/extension.service.ts +++ b/src/extension-host/services/extension.service.ts @@ -1125,7 +1125,7 @@ export const initialize = () => { if (isInitialized) return; reloadFinishedEventEmitter = network.createNetworkEventEmitter( - 'extension-services.reloadFinished', + 'platform.onDidReloadExtensions', ); await normalizeExtensionFileNames();