Skip to content

Commit df4d1f7

Browse files
committed
chore: show bannew in live preview when custom server is in use
1 parent 7087bf0 commit df4d1f7

File tree

5 files changed

+42
-0
lines changed

5 files changed

+42
-0
lines changed

src/extensionsIntegrated/Phoenix-live-preview/LivePreviewSettings.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,10 @@ define(function (require, exports, module) {
211211
return PreferencesManager.get(PREFERENCE_PROJECT_SERVER_PATH) || "/";
212212
}
213213

214+
function getCustomServeBaseURL() {
215+
return PreferencesManager.get(PREFERENCE_PROJECT_SERVER_URL) || "";
216+
}
217+
214218
function getCustomServerConfig(fullPath) {
215219
const customServer = _resolveServer();
216220
if(!customServer || !ProjectManager.isWithinProject(fullPath)) {
@@ -260,6 +264,7 @@ define(function (require, exports, module) {
260264

261265
exports.showSettingsDialog = showSettingsDialog;
262266
exports.getCustomServerConfig = getCustomServerConfig;
267+
exports.getCustomServeBaseURL = getCustomServeBaseURL;
263268
exports.getCustomServeRoot = getCustomServeRoot;
264269
exports.isUsingCustomServer = isUsingCustomServer;
265270
exports.getCustomServerFramework = getCustomServerFramework;

src/extensionsIntegrated/Phoenix-live-preview/main.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ define(function (require, exports, module) {
122122
$firefoxButtonBallast,
123123
$panelTitle;
124124

125+
let customLivePreviewBannerShown = false;
126+
125127
StaticServer.on(EVENT_EMBEDDED_IFRAME_WHO_AM_I, function () {
126128
if($iframe && $iframe[0]) {
127129
const iframeDom = $iframe[0];
@@ -398,6 +400,14 @@ define(function (require, exports, module) {
398400
$firefoxButtonBallast = $panel.find("#firefoxButtonBallast");
399401
$panelTitle = $panel.find("#panel-live-preview-title");
400402
$settingsIcon = $panel.find("#livePreviewSettingsBtn");
403+
404+
$panel.find(".live-preview-settings-banner-btn").on("click", ()=>{
405+
CommandManager.execute(Commands.FILE_LIVE_FILE_PREVIEW_SETTINGS);
406+
Metrics.countEvent(Metrics.EVENT_TYPE.LIVE_PREVIEW, "settingsBtnBanner", "click");
407+
});
408+
$panel.find(".custom-server-banner-close-icon").on("click", ()=>{
409+
$panel.find(".live-preview-custom-banner").addClass("forced-hidden");
410+
});
401411
$iframe[0].onload = function () {
402412
$iframe.attr('srcdoc', null);
403413
};
@@ -492,6 +502,15 @@ define(function (require, exports, module) {
492502
_setTitle(relativeOrFullPath, currentPreviewFile,
493503
previewDetails.isCustomServer ? currentLivePreviewURL : "");
494504
if(panel.isVisible()) {
505+
if(!customLivePreviewBannerShown && LivePreviewSettings.isUsingCustomServer()
506+
&& previewDetails.isCustomServer) {
507+
customLivePreviewBannerShown = true;
508+
$panel.find(".live-preview-custom-banner").removeClass("forced-hidden");
509+
$panel.find(".live-preview-banner-message").text(
510+
StringUtils.format(Strings.LIVE_PREVIEW_CUSTOM_SERVER_BANNER,
511+
LivePreviewSettings.getCustomServeBaseURL())
512+
);
513+
}
495514
let newIframe = $(LIVE_PREVIEW_IFRAME_HTML);
496515
newIframe.insertAfter($iframe);
497516
$iframe.remove();
@@ -556,6 +575,7 @@ define(function (require, exports, module) {
556575
}
557576

558577
async function _projectOpened(_evt) {
578+
customLivePreviewBannerShown = false;
559579
_openReadmeMDIfFirstTime();
560580
_customServerMetrics();
561581
if(!LiveDevelopment.isActive()

src/extensionsIntegrated/Phoenix-live-preview/panel.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@
4747
hidden>
4848
</iframe>
4949
</div>
50+
<div class="live-preview-custom-banner forced-hidden">
51+
<span class="live-preview-banner-message">{{Strings.LIVE_PREVIEW_CUSTOM_SERVER_BANNER}}</span>
52+
<button class="live-preview-settings-banner-btn btn btn-mini primary" style="margin-left: 10px;">{{Strings.LIVE_DEV_SETTINGS}}</button>
53+
<i class="fa fa-close custom-server-banner-close-icon"
54+
style="margin-left: 10px;margin-right: 10px;cursor: pointer;"
55+
title="{{Strings.CLOSE}}"></i>
56+
</div>
5057
<div class="frame-container">
5158
<div style="width: 3px;"></div>
5259
<iframe id="panel-live-preview-frame" title="Live Preview" style="border: none"

src/nls/root/strings.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ define({
171171
"LIVE_DEV_SETTINGS_FRAMEWORK": "Server Framework",
172172
"LIVE_DEV_SETTINGS_FRAMEWORK_CUSTOM": "Custom",
173173
"LIVE_DEV_SETTINGS_FRAMEWORK_PREFERENCES": "Server Framework, currently supports only docusaurus",
174+
"LIVE_PREVIEW_CUSTOM_SERVER_BANNER": "Getting preview from your custom server {0}",
174175

175176
"LIVE_DEV_DETACHED_REPLACED_WITH_DEVTOOLS": "Live Preview was canceled because the browser's developer tools were opened",
176177
"LIVE_DEV_DETACHED_TARGET_CLOSED": "Live Preview was canceled because the page was closed in the browser",

src/styles/brackets.less

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3002,6 +3002,15 @@ label input {
30023002

30033003
/* Live Preview */
30043004

3005+
.live-preview-custom-banner {
3006+
display: flex;
3007+
flex-direction: row;
3008+
background-color: #1E90FF;
3009+
color: white;
3010+
justify-content: flex-end;
3011+
align-items: center;
3012+
}
3013+
30053014
// CodeMirror uses inline styles for active line number, so must use !important here to override
30063015
.live-preview-sync-error .CodeMirror-linenumber {
30073016
background-color: @live-preview-sync-error-background !important;

0 commit comments

Comments
 (0)