From 753e821afc434e4fa03e6d460bc8df0efb0d5d7d Mon Sep 17 00:00:00 2001 From: abose Date: Sat, 6 Jan 2024 11:38:34 +0530 Subject: [PATCH] chore: showing project name when asking to trust project --- src/live-preview-loader.html | 23 +++++++++++++++++++++-- src/nls/root/strings.js | 2 +- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/live-preview-loader.html b/src/live-preview-loader.html index 16dedc57b0..3d1aa19f99 100644 --- a/src/live-preview-loader.html +++ b/src/live-preview-loader.html @@ -98,6 +98,7 @@ 'https://staging.phcode.dev': true, 'https://create.phcode.dev': true }; + let okMessageTemplate; function isTrustedURL(url) { if(!url){ @@ -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"; @@ -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)){ @@ -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){ @@ -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); } diff --git a/src/nls/root/strings.js b/src/nls/root/strings.js index ae718d5cb0..19404aadf2 100644 --- a/src/nls/root/strings.js +++ b/src/nls/root/strings.js @@ -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 phcode.io.
", "DESCRIPTION_LIVEDEV_SECURITY": "Security Warning from phcode.dev

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.",