Skip to content

Commit

Permalink
Fix crash when launching multiple previews with a pop-up blocker
Browse files Browse the repository at this point in the history
  • Loading branch information
4ian committed Jun 17, 2024
1 parent da940ab commit 9a705b9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
registerNewPreviewWindow,
} from './BrowserPreviewDebuggerServer';
import Window from '../../../Utils/Window';
import { displayBlackLoadingScreen } from '../../../Utils/BrowserExternalWindowUtils';
import { displayBlackLoadingScreenOrThrow } from '../../../Utils/BrowserExternalWindowUtils';
import { getGDevelopResourceJwtToken } from '../../../Utils/GDevelopServices/Project';
import { isNativeMobileApp } from '../../../Utils/Platform';
const gd: libGDevelop = global.gd;
Expand Down Expand Up @@ -48,8 +48,13 @@ export const immediatelyOpenNewPreviewWindow = (
targetId,
`width=${width},height=${height},left=${left},top=${top}`
);
if (!previewWindow) {
throw new Error(
"Can't open the preview window because of browser restrictions."
);
}

displayBlackLoadingScreen(previewWindow);
displayBlackLoadingScreenOrThrow(previewWindow);

return previewWindow;
};
Expand Down Expand Up @@ -118,9 +123,17 @@ export default class BrowserS3PreviewLauncher extends React.Component<

const previewWindows = existingPreviewWindow
? [existingPreviewWindow]
: Array.from({ length: numberOfWindows }, () =>
immediatelyOpenNewPreviewWindow(project)
);
: Array.from({ length: numberOfWindows }, () => {
try {
return immediatelyOpenNewPreviewWindow(project);
} catch (error) {
console.error(
'Unable to open a new preview window - this window will be ignored:',
error
);
return null;
}
}).filter(Boolean);

try {
await this.getPreviewDebuggerServer().startServer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
type ItemResult,
} from '../Utils/BlobDownloader';
import { showWarningBox } from '../UI/Messages/MessageBox';
import { displayBlackLoadingScreen } from '../Utils/BrowserExternalWindowUtils';
import { displayBlackLoadingScreenOrThrow } from '../Utils/BrowserExternalWindowUtils';
import { UserCancellationError } from '../LoginProvider/Utils';
let nextExternalEditorWindowId = 0;

Expand Down Expand Up @@ -350,7 +350,7 @@ const immediatelyOpenLoadingWindowForExternalEditor = () => {
);
}

displayBlackLoadingScreen(externalEditorWindow);
displayBlackLoadingScreenOrThrow(externalEditorWindow);

return externalEditorWindow;
};
Expand Down
4 changes: 3 additions & 1 deletion newIDE/app/src/Utils/BrowserExternalWindowUtils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// @flow
const spinnerImgSrc = `data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGZpbGw9Im5vbmUiIHZpZXdCb3g9IjAgMCAyNCAyNCI+CjxjaXJjbGUgb3BhY2l0eT0nMC4yNScgY3g9IjEyIiBjeT0iMTIiIHI9IjEwIiBzdHJva2U9IiNGRkZGRkYiIHN0cm9rZS13aWR0aD0iNCI+PC9jaXJjbGU+CjxwYXRoIG9wYWNpdHk9JzAuNzUnIGZpbGw9IiNGRkZGRkYiIGQ9Ik00IDEyYTggOCAwIDAxOC04VjBDNS4zNzMgMCAwIDUuMzczIDAgMTJoNHptMiA1LjI5MUE3Ljk2MiA3Ljk2MiAwIDAxNCAxMkgwYzAgMy4wNDIgMS4xMzUgNS44MjQgMyA3LjkzOGwzLTIuNjQ3eiI+PC9wYXRoPgo8L3N2Zz4=`;

export const displayBlackLoadingScreen = (externalWindow: WindowProxy) => {
export const displayBlackLoadingScreenOrThrow = (
externalWindow: WindowProxy
) => {
externalWindow.document.write(
`<html>
<head>
Expand Down

0 comments on commit 9a705b9

Please sign in to comment.