Skip to content

Commit

Permalink
chore: showing project name when asking to trust project
Browse files Browse the repository at this point in the history
  • Loading branch information
abose committed Jan 6, 2024
1 parent 255e1d2 commit edec64a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
23 changes: 21 additions & 2 deletions src/live-preview-loader.html
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
'https://staging.phcode.dev': true,
'https://create.phcode.dev': true
};
let okMessageTemplate;

function isTrustedURL(url) {
if(!url){
Expand All @@ -116,6 +117,23 @@
let previewURL;
let trustedProjects = [];
let currentProjectRoot;

function getTrustOkButton() {
if(! okMessageTemplate){
return "Trust Project?";
}
if(!currentProjectRoot){
return okMessageTemplate.replace("{0}", "");
}
let projectName = currentProjectRoot;
if(projectName.endsWith("/")){
projectName = projectName.slice(0, -1);
}
projectName = projectName.split("/");
projectName = projectName[projectName.length-1];
return okMessageTemplate.replace("{0}", projectName);
}

function setupNavigationWatcher(controllingPhoenixInstanceID) {
let livepreviewServerIframe = document.getElementById("live-preview-server-iframe");
const LOG_LIVE_PREVIEW_KEY= "logLivePreview";
Expand Down Expand Up @@ -164,6 +182,7 @@
return;
case "PROJECT_SWITCH":
currentProjectRoot = event.data.projectRoot;
document.getElementById('okButton').textContent = getTrustOkButton();
if(trustedProjects[currentProjectRoot] && dialog){
dialog.style.display = 'none';
if(isTrustedURL(previewURL)){
Expand Down Expand Up @@ -233,7 +252,7 @@
const phoenixInstanceID = queryParams.get('phoenixInstanceID');
const virtualServerURL = queryParams.get('virtualServerURL');
const localiseMessage = queryParams.get('localMessage');
const okMessage = queryParams.get('okMessage');
okMessageTemplate = decodeURIComponent(queryParams.get('okMessage'));
currentProjectRoot = queryParams.get('initialProjectRoot');

if(!phoenixInstanceID || !initialURL || !virtualServerURL){
Expand All @@ -247,7 +266,7 @@
livepreviewServerIframe.setAttribute("src", serverURL);
}

okMessage && (document.getElementById('okButton').textContent = decodeURIComponent(okMessage));
document.getElementById('okButton').textContent = getTrustOkButton();
localiseMessage && (document.getElementById('dialog-message').textContent = decodeURIComponent(localiseMessage));
previewURL = decodeURIComponent(initialURL);
}
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 @@ -905,7 +905,7 @@ define({
"DESCRIPTION_LIVEDEV_MAIN_SPAN": "Get the best live preview experience by downloading our native apps for Windows, Mac, and Linux from <a href=\"https://phcode.io\" style=\"color: white\">phcode.io</a>.<br>",
"DESCRIPTION_LIVEDEV_SECURITY": "Security Warning from phcode.dev<br><br> This live preview attempted to access a non-project file. Access was denied for your safety. Please exercise caution when working on untrusted projects.",
"DESCRIPTION_LIVEDEV_SECURITY_POPOUT_MESSAGE": "You are about to open a file for live preview. Please proceed only if you trust the source of this project. Click 'Trust Project' to continue, or close this window if you do not trust the source.",
"TRUST_PROJECT": "Trust Project",
"TRUST_PROJECT": "Trust Project - {0}",

// Strings for Auto Update
"DOWNLOAD_FAILED": "Download failed.",
Expand Down

0 comments on commit edec64a

Please sign in to comment.