Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
chore: alert api patch only in tauri mac embedded live preview
  • Loading branch information
abose committed Aug 28, 2024
commit 35733478daaf31d5a9cf595cf7e6fdfd25114b6a
28 changes: 17 additions & 11 deletions src/LiveDevelopment/BrowserScripts/LivePreviewTransportRemote.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@
}
});

function alertPatch(message) {
function alertPatch(message, titleText) {
// Create the modal container
const modal = document.createElement('div');
modal.style.position = 'fixed';
Expand All @@ -354,7 +354,7 @@

// Add title to the modal with the current page URL
const title = document.createElement('h3');
title.textContent = "alert"; // not translated as window.alert is same in all languages.
title.textContent = titleText || "alert"; // not translated as window.alert is same in all languages.
title.style.marginBottom = '10px';

// Add text to the modal
Expand Down Expand Up @@ -384,8 +384,11 @@
document.body.appendChild(modal);
}

function unsupported() {
alertPatch(TRANSPORT_CONFIG.STRINGS.UNSUPPORTED_DOM_APIS_CONFIRM);
function unsupportedConfirm() {
alertPatch(TRANSPORT_CONFIG.STRINGS.UNSUPPORTED_DOM_APIS_CONFIRM, "window.confirm");
}
function unsupportedPrompt() {
alertPatch(TRANSPORT_CONFIG.STRINGS.UNSUPPORTED_DOM_APIS_CONFIRM, "window.prompt");
}

// all externally opened live previews have the phcodeLivePreview="true" query string parameter set.
Expand All @@ -395,7 +398,7 @@
const isTauri = TRANSPORT_CONFIG.IS_NATIVE_APP;
const platform = TRANSPORT_CONFIG.PLATFORM;

let alertQueue = [], confirmOrPromptCalled = false;
let alertQueue = [], confirmCalled = false, promptCalled = false;
let addToQueue = true;
if(!isExternalBrowser){
// this is an embedded iframe we always take hold of the alert api for better ux within the live preivew frame.
Expand All @@ -411,23 +414,26 @@
window.confirm = function () {
// confirm and prompt is no-op in mac, we just need to show that the api is not supported, so we just
// keep a flag.
confirmOrPromptCalled = true;
confirmCalled = true;
};
window.prompt = function () {
confirmOrPromptCalled = true;
promptCalled = true;
};
function drainAlertQueues() {
addToQueue = false;
if(confirmOrPromptCalled) {
unsupported();
if(confirmCalled) {
unsupportedConfirm();
}
if(promptCalled) {
unsupportedPrompt();
}
for(let i=0; i<alertQueue.length; i++) {
alertPatch(alertQueue[i]);
}
alertQueue = [];
window.alert = alertPatch;
window.confirm = unsupported;
window.prompt = unsupported;
window.confirm = unsupportedConfirm;
window.prompt = unsupportedPrompt;
}

document.addEventListener('DOMContentLoaded', function() {
Expand Down
2 changes: 1 addition & 1 deletion src/nls/root/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ 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
"UNSUPPORTED_DOM_APIS_CONFIRM": "window.confirm and window.prompt APIS are not available in embedded Live Preview in {APP_NAME}. Please popout Live Preview to use these APIs in the browser.",
"UNSUPPORTED_DOM_APIS_CONFIRM": "The `window.confirm` and `window.prompt` APIs are unavailable in the embedded Live Preview of {APP_NAME}. Please popout Live Preview to use these APIs in the browser.",
"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