Skip to content

Commit

Permalink
Fix accidental exception where closing a dialog tries to close the di…
Browse files Browse the repository at this point in the history
…alog again and throws an exception
  • Loading branch information
tjcouch-sil committed Oct 18, 2023
1 parent c969022 commit c5a1bf8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ export default function PlatformDockLayout() {
if (currentTabId && direction === 'remove') {
const removedTab = dockLayoutRef.current.find(currentTabId) as RCDockTabInfo;
if ((removedTab.data as DialogData)?.isDialog && hasDialogRequest(currentTabId))
resolveDialogRequest(currentTabId, null);
resolveDialogRequest(currentTabId, null, false);
}

if (onLayoutChangeRef.current) onLayoutChangeRef.current(...args);
Expand Down
42 changes: 26 additions & 16 deletions src/renderer/services/dialog.service-host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,36 +56,46 @@ export function hasDialogRequest(id: string) {
* @param id the id of the dialog whose request to reject
* @param data the data to resolve the request with. Either the user's response to the dialog or
* `null` if the user canceled
* @param shouldCloseDialog whether we should close the dialog in this function. Should probably
* only be `false` if the dialog is already being closed another way such as in
* `platform-dock-layout.component.tsx`. Defaults to true
*
* Internal function; not exposed on papi
*/
export function resolveDialogRequest<TReturn>(id: string, data: TReturn | null) {
export function resolveDialogRequest<TReturn>(
id: string,
data: TReturn | null,
shouldCloseDialog = true,
) {
const dialogRequest = dialogRequests.get(id);
if (dialogRequest) {
dialogRequests.delete(id);
dialogRequest.resolve(data);
}

// Clean up the dialog
// Close the dialog
// We're not awaiting closing it. Doesn't really matter right now if we do or don't successfully close it
(async () => {
try {
const didClose = await webViewService.removeTab(id);
if (!didClose)

if (shouldCloseDialog) {
// Close the dialog
// We're not awaiting closing it. Doesn't really matter right now if we do or don't successfully close it
(async () => {
try {
const didClose = await webViewService.removeTab(id);
if (!didClose)
logger.error(
`DialogService error: dialog ${id} that was resolved with data ${JSON.stringify(
data,
)} was not found in the dock layout in order to close. Please investigate`,
);
} catch (e) {
logger.error(
`DialogService error: dialog ${id} that was resolved with data ${JSON.stringify(
data,
)} was not found in the dock layout in order to close. Please investigate`,
)} did not successfully close! Please investigate. Error: ${e}`,
);
} catch (e) {
logger.error(
`DialogService error: dialog ${id} that was resolved with data ${JSON.stringify(
data,
)} did not successfully close! Please investigate. Error: ${e}`,
);
}
})();
}
})();
}

// If we didn't find the request, throw
if (!dialogRequest)
Expand Down

0 comments on commit c5a1bf8

Please sign in to comment.