Skip to content

Commit c77796c

Browse files
committed
chore: alert api patch only in tauri mac embedded live preview
1 parent 1644144 commit c77796c

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

src/LiveDevelopment/BrowserScripts/LivePreviewTransportRemote.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@
329329
}
330330
});
331331

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

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

360360
// Add text to the modal
@@ -384,8 +384,11 @@
384384
document.body.appendChild(modal);
385385
}
386386

387-
function unsupported() {
388-
alertPatch(TRANSPORT_CONFIG.STRINGS.UNSUPPORTED_DOM_APIS_CONFIRM);
387+
function unsupportedConfirm() {
388+
alertPatch(TRANSPORT_CONFIG.STRINGS.UNSUPPORTED_DOM_APIS_CONFIRM, "window.confirm");
389+
}
390+
function unsupportedPrompt() {
391+
alertPatch(TRANSPORT_CONFIG.STRINGS.UNSUPPORTED_DOM_APIS_CONFIRM, "window.prompt");
389392
}
390393

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

398-
let alertQueue = [], confirmOrPromptCalled = false;
401+
let alertQueue = [], confirmCalled = false, promptCalled = false;
399402
let addToQueue = true;
400403
if(!isExternalBrowser){
401404
// this is an embedded iframe we always take hold of the alert api for better ux within the live preivew frame.
@@ -411,23 +414,26 @@
411414
window.confirm = function () {
412415
// confirm and prompt is no-op in mac, we just need to show that the api is not supported, so we just
413416
// keep a flag.
414-
confirmOrPromptCalled = true;
417+
confirmCalled = true;
415418
};
416419
window.prompt = function () {
417-
confirmOrPromptCalled = true;
420+
promptCalled = true;
418421
};
419422
function drainAlertQueues() {
420423
addToQueue = false;
421-
if(confirmOrPromptCalled) {
422-
unsupported();
424+
if(confirmCalled) {
425+
unsupportedConfirm();
426+
}
427+
if(promptCalled) {
428+
unsupportedPrompt();
423429
}
424430
for(let i=0; i<alertQueue.length; i++) {
425431
alertPatch(alertQueue[i]);
426432
}
427433
alertQueue = [];
428434
window.alert = alertPatch;
429-
window.confirm = unsupported;
430-
window.prompt = unsupported;
435+
window.confirm = unsupportedConfirm;
436+
window.prompt = unsupportedPrompt;
431437
}
432438

433439
document.addEventListener('DOMContentLoaded', function() {

src/nls/root/strings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ define({
128128
"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>.",
129129

130130
// Live Preview error strings
131-
"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.",
131+
"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.",
132132
"ERROR_LAUNCHING_BROWSER_TITLE": "Error Launching Browser",
133133
"ERROR_CANT_FIND_CHROME": "The Google Chrome browser could not be found. Please make sure it is installed.",
134134
"ERROR_LAUNCHING_BROWSER": "An error occurred when launching the browser. (error {0})",

0 commit comments

Comments
 (0)