|
441 | 441 | let alertQueue = [], confirmCalled = false, promptCalled = false; |
442 | 442 | let addToQueue = true; |
443 | 443 | window.__PHOENIX_APP_INFO = {isTauri, platform}; |
| 444 | + const _embeddedInfoCallbacks = []; |
444 | 445 | if(!isExternalBrowser){ |
445 | 446 | // this is an embedded iframe we always take hold of the alert api for better ux within the live preivew frame. |
446 | | - window.__PHOENIX_EMBED_INFO = {isTauri, platform}; |
| 447 | + // __PHOENIX_EMBED_INFO will be present in browser popped out windows as its actually an embedded |
| 448 | + // iframe inside phcode.live server, so to detect if its a truly embedded iframe within phoenix code |
| 449 | + // itself, rely on the isEmbeddedIframe which will be set with `WHO_AM_I_RESPONSE` handshake |
| 450 | + window.__PHOENIX_EMBED_INFO = {isTauri, platform, isPhoenixEmbeddedIframe: undefined}; |
| 451 | + /** |
| 452 | + * Register a callback to be notified when `isPhoenixEmbeddedIframe` is resolved. |
| 453 | + * The callback is guaranteed to fire in embedded iframes, but NOT guaranteed to fire |
| 454 | + * in non-embedded (popped out) frames. Do not rely on this to confirm non-embedded state; |
| 455 | + * instead, assume non-embedded by default and use this only to detect embedded iframes. |
| 456 | + * If `isPhoenixEmbeddedIframe` is already determined, the callback fires immediately. |
| 457 | + * @param {function(boolean): void} callback - receives `true` if embedded, `false` if popped out. |
| 458 | + */ |
| 459 | + window.__PHOENIX_EMBED_INFO.onPhoenixEmbeddedInfoAvailable = function (callback) { |
| 460 | + if (window.__PHOENIX_EMBED_INFO.isPhoenixEmbeddedIframe !== undefined) { |
| 461 | + callback(window.__PHOENIX_EMBED_INFO.isPhoenixEmbeddedIframe); |
| 462 | + } else { |
| 463 | + _embeddedInfoCallbacks.push(callback); |
| 464 | + } |
| 465 | + }; |
447 | 466 | const shouldPatchAlert = (isTauri && platform === "mac"); |
448 | 467 | if(shouldPatchAlert){ |
449 | 468 | // In Mac embedded live preview iframe in tauri, alert, prompt, and confirm apis |
|
493 | 512 | // this is set from transport config. We should be here |
494 | 513 | console.error("Expected window.__PHOENIX_EMBED_INFO to be set, but not???"); |
495 | 514 | } |
| 515 | + // all embedded iframes will have this set to distinguish between embedded iframes and popped out iframes |
| 516 | + const isPhoenixEmbeddedIframe = !!event.data.isPhoenixEmbeddedIframe; |
| 517 | + window.__PHOENIX_EMBED_INFO.isPhoenixEmbeddedIframe = isPhoenixEmbeddedIframe; |
| 518 | + for (let i = 0; i < _embeddedInfoCallbacks.length; i++) { |
| 519 | + _embeddedInfoCallbacks[i](isPhoenixEmbeddedIframe); |
| 520 | + } |
| 521 | + _embeddedInfoCallbacks.length = 0; |
496 | 522 | } |
497 | 523 | }); |
498 | 524 | if(window.self !== window.parent){ |
|
0 commit comments