Skip to content

Commit

Permalink
fix: remove alert patch as tauri fixed alert issue in windows
Browse files Browse the repository at this point in the history
  • Loading branch information
abose committed Aug 26, 2024
1 parent d09dfd5 commit a686ee4
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 28 deletions.
26 changes: 2 additions & 24 deletions src/LiveDevelopment/BrowserScripts/LivePreviewTransportRemote.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,38 +329,16 @@
}
});

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
}
if(event.data.type === "WHO_AM_I_RESPONSE") {
window.__PHOENIX_EMBED_INFO = {
isTauri: event.data.isTauri
isTauri: event.data.isTauri,
platform: event.data.platform
};
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){
Expand Down
4 changes: 1 addition & 3 deletions src/extensionsIntegrated/Phoenix-live-preview/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,7 @@ define(function (require, exports, module) {
iframeDom.contentWindow.postMessage({
type: "WHO_AM_I_RESPONSE",
isTauri: Phoenix.isNativeApp,
platform: Phoenix.platform,
alertStr: Strings.ALERT,
confirmStr: Strings.CONFIRM
platform: Phoenix.platform
}, "*"); // 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 @@ -27,7 +27,8 @@

if(event.data.type === "WHO_AM_I_RESPONSE") {
window.__PHOENIX_EMBED_INFO = {
isTauri: event.data.isTauri
isTauri: event.data.isTauri,
platform: event.data.platform
};
} else if(event.data.type === "_TEST_FOCUS_CLICK") { // for integ tests
document.body.click();
Expand Down

0 comments on commit a686ee4

Please sign in to comment.