Skip to content

Commit

Permalink
Resolve issue with promises not resolving
Browse files Browse the repository at this point in the history
Because the registration for the response from the dialog was only done once it only had a reference to the initial variables for resolving the promise rather than the latest resolve/reject functions for the last promise that has been awaited.
  • Loading branch information
johnman committed Jun 19, 2024
1 parent 59fd6a4 commit f3c5373
Showing 1 changed file with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ export class IntentResolverHelper {

private _dialogClient: OpenFin.ChannelClient | null = null;

private _resolveAppSelection: ((value: IntentResolverResponse) => void) | undefined;

private _rejectAppSelection: ((reason?: string) => void) | undefined;

/**
* Create an instance of the Intent Resolver Helper.
* @param intentResolverOptions options for the helper
Expand Down Expand Up @@ -79,13 +83,6 @@ export class IntentResolverHelper {
},
clientIdentity: OpenFin.ClientIdentity
): Promise<IntentResolverResponse> {
// launch a new window and optionally pass the available intents as customData.apps as part of the window
// options the window can then use raiseIntent against a specific app (the selected one). this logic runs in
// the provider so we are using it as a way of determining the root (so it works with root hosting and
// subdirectory based hosting if a url is not provided)
// try {
let resolveAppSelection: (value: IntentResolverResponse) => void;
let rejectAppSelection: (reason?: string) => void;
if (this._dialogElement) {
this._dialogElement.showModal();
}
Expand All @@ -101,12 +98,14 @@ export class IntentResolverHelper {
errorMessage?: string;
};
this._logger.info("Received intent resolver message", payload);
if (response.errorMessage) {
rejectAppSelection(response.errorMessage);
if (this._rejectAppSelection === undefined || this._resolveAppSelection === undefined) {
this._logger.error("No resolve or reject function set for intent resolver");
} else if (response.errorMessage) {
this._rejectAppSelection(response.errorMessage);
} else if (response.intentResolverResponse === undefined) {
rejectAppSelection(ResolveError.ResolverUnavailable);
this._rejectAppSelection(ResolveError.ResolverUnavailable);
} else {
resolveAppSelection(response.intentResolverResponse);
this._resolveAppSelection(response.intentResolverResponse);
}
if (this._dialogElement) {
this._dialogElement.close();
Expand All @@ -124,8 +123,8 @@ export class IntentResolverHelper {
});
}
return new Promise((resolve, reject) => {
resolveAppSelection = resolve;
rejectAppSelection = reject;
this._resolveAppSelection = resolve;
this._rejectAppSelection = reject;
});
}
}

0 comments on commit f3c5373

Please sign in to comment.