Skip to content

Commit

Permalink
feat: implemented papi event to indicate when file watcher finished r…
Browse files Browse the repository at this point in the history
…eloading extensions (#1041)
  • Loading branch information
captaincrazybro authored Aug 6, 2024
2 parents 8306c1a + 73491db commit e2f33b7
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/extension-host/services/extension.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -152,6 +152,12 @@ let initializePromise: Promise<void> | 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<boolean>;

/** Parse string extension manifest into an object and perform any transformations needed */
function parseManifest(extensionManifestJson: string): ExtensionManifest {
const extensionManifest: ExtensionManifest = deserialize(extensionManifestJson);
Expand Down Expand Up @@ -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}`);
}
});
Expand Down Expand Up @@ -1116,6 +1124,10 @@ export const initialize = () => {
initializePromise = (async (): Promise<void> => {
if (isInitialized) return;

reloadFinishedEventEmitter = network.createNetworkEventEmitter<boolean>(
'platform.onDidReloadExtensions',
);

await normalizeExtensionFileNames();

await reloadExtensions(false);
Expand Down

0 comments on commit e2f33b7

Please sign in to comment.