Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: mitigate alert and confirm apis not working in embeded live preview in windows desktop #1750

Merged
merged 1 commit into from
Jul 15, 2024
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
32 changes: 28 additions & 4 deletions src/LiveDevelopment/BrowserScripts/LivePreviewTransportRemote.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,15 +329,39 @@
}
});

let alertStr = "Alert", confirmStr = "Confirm";

function alertPatch(message) {
// in tauri windows, only the prompt API works. so we use it for alerts as well
// we cant use html alerts here as the alert api will pause js which we cant do via js alone.
prompt(alertStr, message);
}

function confirmPatch(message) {
// in tauri windows, only the prompt API works. so we use it for confirm as well
// we cant use html alerts here as the alert api will pause js which we cant do via js alone.
const response = prompt(confirmStr, message);
// prompt will return null if cancel is pressed
return !!response;
}

// this is for managing who am i context in iframes embedded in phoenix to have special handling.
window.addEventListener('message', function(event) {
if (!TRANSPORT_CONFIG.TRUSTED_ORIGINS_EMBED[event.origin]) {
return; // Ignore messages from unexpected origins
}

window.__PHOENIX_EMBED_INFO = {
isTauri: event.data.isTauri
};
if(event.data.type === "WHO_AM_I_RESPONSE") {
window.__PHOENIX_EMBED_INFO = {
isTauri: event.data.isTauri
};
alertStr = event.data.alertStr || alertStr;
confirmStr = event.data.confirmStr || confirmStr;
if(event.data.isTauri && event.data.platform === 'win') {
// patch alert and confirm as in windows iframes in tauri, these are not present.
window.alert = alertPatch;
window.confirm = confirmPatch;
}
}
});
if(window.self !== window.parent){
// in an iframe
Expand Down
2 changes: 1 addition & 1 deletion src/assets/phoenix-splash/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<img id="logo" src="images/phoenix-logo.svg"/>
<div id="MainText">
<h1>Phoenix Code</h1>
<span>Code Creatively: Visual Editing Tailored for Developers</span>
<span>The text editor designed to make coding as simple and fun as playing a video game</span>
<br><br>
<button id="load-status-display-btn" class="primary-button">Loading Editor...</button>
<p style= "color: white; font-size:13px;" id="load-status-display-text" >...</p>
Expand Down
5 changes: 4 additions & 1 deletion src/extensionsIntegrated/Phoenix-live-preview/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ define(function (require, exports, module) {
const iframeDom = $iframe[0];
iframeDom.contentWindow.postMessage({
type: "WHO_AM_I_RESPONSE",
isTauri: Phoenix.isNativeApp
isTauri: Phoenix.isNativeApp,
platform: Phoenix.platform,
alertStr: Strings.ALERT,
confirmStr: Strings.CONFIRM
}, "*"); // this is not sensitive info, and is only dispatched if requested by the iframe
}
});
Expand Down
2 changes: 2 additions & 0 deletions src/nls/root/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ define({
"ERROR_MAX_FILES": "This project contains more than 30,000 files. Features that operate across multiple files may be disabled or behave as if the project is empty. <a href='https://github.com/adobe/brackets/wiki/Large-Projects'>Read more about working with large projects</a>.",

// Live Preview error strings
"ALERT": "Alert",
"CONFIRM": "Confirm",
"ERROR_LAUNCHING_BROWSER_TITLE": "Error Launching Browser",
"ERROR_CANT_FIND_CHROME": "The Google Chrome browser could not be found. Please make sure it is installed.",
"ERROR_LAUNCHING_BROWSER": "An error occurred when launching the browser. (error {0})",
Expand Down
Loading