Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion src/LiveDevelopment/BrowserScripts/LivePreviewTransportRemote.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,9 +441,28 @@
let alertQueue = [], confirmCalled = false, promptCalled = false;
let addToQueue = true;
window.__PHOENIX_APP_INFO = {isTauri, platform};
const _embeddedInfoCallbacks = [];
if(!isExternalBrowser){
// this is an embedded iframe we always take hold of the alert api for better ux within the live preivew frame.
window.__PHOENIX_EMBED_INFO = {isTauri, platform};
// __PHOENIX_EMBED_INFO will be present in browser popped out windows as its actually an embedded
// iframe inside phcode.live server, so to detect if its a truly embedded iframe within phoenix code
// itself, rely on the isEmbeddedIframe which will be set with `WHO_AM_I_RESPONSE` handshake
window.__PHOENIX_EMBED_INFO = {isTauri, platform, isPhoenixEmbeddedIframe: undefined};

Check warning on line 450 in src/LiveDevelopment/BrowserScripts/LivePreviewTransportRemote.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `globalThis` over `window`.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ0KtT1eg2wgUSNrNQT8&open=AZ0KtT1eg2wgUSNrNQT8&pullRequest=2756
/**
* Register a callback to be notified when `isPhoenixEmbeddedIframe` is resolved.
* The callback is guaranteed to fire in embedded iframes, but NOT guaranteed to fire
* in non-embedded (popped out) frames. Do not rely on this to confirm non-embedded state;
* instead, assume non-embedded by default and use this only to detect embedded iframes.
* If `isPhoenixEmbeddedIframe` is already determined, the callback fires immediately.
* @param {function(boolean): void} callback - receives `true` if embedded, `false` if popped out.
*/
window.__PHOENIX_EMBED_INFO.onPhoenixEmbeddedInfoAvailable = function (callback) {

Check warning on line 459 in src/LiveDevelopment/BrowserScripts/LivePreviewTransportRemote.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `globalThis` over `window`.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ0KtT1eg2wgUSNrNQT9&open=AZ0KtT1eg2wgUSNrNQT9&pullRequest=2756
if (window.__PHOENIX_EMBED_INFO.isPhoenixEmbeddedIframe !== undefined) {

Check warning on line 460 in src/LiveDevelopment/BrowserScripts/LivePreviewTransportRemote.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected negated condition.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ0KtT1eg2wgUSNrNQT_&open=AZ0KtT1eg2wgUSNrNQT_&pullRequest=2756

Check warning on line 460 in src/LiveDevelopment/BrowserScripts/LivePreviewTransportRemote.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `globalThis` over `window`.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ0KtT1eg2wgUSNrNQT-&open=AZ0KtT1eg2wgUSNrNQT-&pullRequest=2756
callback(window.__PHOENIX_EMBED_INFO.isPhoenixEmbeddedIframe);

Check warning on line 461 in src/LiveDevelopment/BrowserScripts/LivePreviewTransportRemote.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `globalThis` over `window`.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ0KtT1eg2wgUSNrNQUA&open=AZ0KtT1eg2wgUSNrNQUA&pullRequest=2756
} else {
_embeddedInfoCallbacks.push(callback);
}
};
const shouldPatchAlert = (isTauri && platform === "mac");
if(shouldPatchAlert){
// In Mac embedded live preview iframe in tauri, alert, prompt, and confirm apis
Expand Down Expand Up @@ -493,6 +512,13 @@
// this is set from transport config. We should be here
console.error("Expected window.__PHOENIX_EMBED_INFO to be set, but not???");
}
// all embedded iframes will have this set to distinguish between embedded iframes and popped out iframes
const isPhoenixEmbeddedIframe = !!event.data.isPhoenixEmbeddedIframe;
window.__PHOENIX_EMBED_INFO.isPhoenixEmbeddedIframe = isPhoenixEmbeddedIframe;

Check warning on line 517 in src/LiveDevelopment/BrowserScripts/LivePreviewTransportRemote.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `globalThis` over `window`.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ0KtT1eg2wgUSNrNQUB&open=AZ0KtT1eg2wgUSNrNQUB&pullRequest=2756
for (let i = 0; i < _embeddedInfoCallbacks.length; i++) {
_embeddedInfoCallbacks[i](isPhoenixEmbeddedIframe);
}

Check warning on line 520 in src/LiveDevelopment/BrowserScripts/LivePreviewTransportRemote.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Expected a `for-of` loop instead of a `for` loop with this simple iteration.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ0KtT1eg2wgUSNrNQUC&open=AZ0KtT1eg2wgUSNrNQUC&pullRequest=2756
_embeddedInfoCallbacks.length = 0;
}
});
if(window.self !== window.parent){
Expand Down
22 changes: 14 additions & 8 deletions src/extensionsIntegrated/Phoenix-live-preview/live-preview.css
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,20 @@
align-items: center;
margin: 3.5px 4px 0 3px;
cursor: pointer;
background: #3C3F41;
background: transparent;
box-shadow: none;
border: 1px solid #3C3F41;
border: 1px solid transparent;
box-sizing: border-box;
color: #a0a0a0;
padding: 0 0.35em;
}

.lp-device-size-icon:hover {
border: 1px solid rgba(0, 0, 0, 0.24) !important;
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12) !important;
.lp-device-size-icon:hover,
.lp-device-size-icon:focus,
.lp-device-size-icon:active {
background: transparent !important;
border: 1px solid rgba(255, 255, 255, 0.1) !important;
box-shadow: none !important;
}

#deviceSizeBtn.btn-dropdown::after {
Expand Down Expand Up @@ -178,9 +181,12 @@
padding: 0 0.35em;
}

#livePreviewModeBtn:hover {
border: 1px solid rgba(0, 0, 0, 0.24) !important;
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12) !important;
#livePreviewModeBtn:hover,
#livePreviewModeBtn:focus,
#livePreviewModeBtn:active {
background: transparent !important;
border: 1px solid rgba(255, 255, 255, 0.1) !important;
box-shadow: none !important;
}

#livePreviewModeBtn.btn-dropdown::after {
Expand Down
3 changes: 2 additions & 1 deletion src/extensionsIntegrated/Phoenix-live-preview/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ define(function (require, exports, module) {
iframeDom.contentWindow.postMessage({
type: "WHO_AM_I_RESPONSE",
isTauri: Phoenix.isNativeApp,
platform: Phoenix.platform
platform: Phoenix.platform,
isPhoenixEmbeddedIframe: true
}, "*"); // this is not sensitive info, and is only dispatched if requested by the iframe
}
});
Expand Down
3 changes: 2 additions & 1 deletion src/extensionsIntegrated/Phoenix-live-preview/markdown.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
if(event.data.type === "WHO_AM_I_RESPONSE") {
window.__PHOENIX_EMBED_INFO = {
isTauri: event.data.isTauri,
platform: event.data.platform
platform: event.data.platform,
isPhoenixEmbeddedIframe: event.data.isPhoenixEmbeddedIframe
};
} else if(event.data.type === "_TEST_FOCUS_CLICK") { // for integ tests
document.body.click();
Expand Down
2 changes: 1 addition & 1 deletion tracking-repos.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"phoenixPro": {
"commitID": "e5f085888f6c875a8c0013eed9ce97491cbcb250"
"commitID": "6f0ac36ce36ff5d524590442ef6e16320fa904f1"
}
}
Loading