Skip to content

Commit e5f92bf

Browse files
committed
fix: opening text files with open with opens live preview on startup
1 parent 3b7154a commit e5f92bf

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -588,13 +588,22 @@ define(function (require, exports, module) {
588588

589589
function _getExternalPreviewURL(fullPath) {
590590
if(utils.isHTMLFile(fullPath)) {
591-
return getNoPreviewURL(Strings.DESCRIPTION_LIVEDEV_PREVIEW_RESTRICTED,
592-
Strings.DESCRIPTION_LIVEDEV_PREVIEW_RESTRICTED_DETAILS);
591+
return {
592+
url: getNoPreviewURL(Strings.DESCRIPTION_LIVEDEV_PREVIEW_RESTRICTED,
593+
Strings.DESCRIPTION_LIVEDEV_PREVIEW_RESTRICTED_DETAILS),
594+
isNoPreview: true
595+
};
593596
}
594597
if(!utils.isPreviewableFile(fullPath)){
595-
return getNoPreviewURL();
598+
return {
599+
url: getNoPreviewURL(),
600+
isNoPreview: true
601+
};
596602
}
597-
return `${staticServerURL}externalProject/${path.basename(fullPath)}`;
603+
return {
604+
url: `${staticServerURL}externalProject/${path.basename(fullPath)}`,
605+
isNoPreview: false
606+
};
598607
}
599608

600609
function getTabPopoutURL(url) {
@@ -635,8 +644,10 @@ define(function (require, exports, module) {
635644
let fullPath = currentFile.fullPath;
636645
if(!ProjectManager.isWithinProject(fullPath)){
637646
// external project file. Use secure external preview link.
647+
const preview = _getExternalPreviewURL(fullPath);
638648
resolve({
639-
URL: _getExternalPreviewURL(fullPath),
649+
URL: preview.url,
650+
isNoPreview: preview.isNoPreview,
640651
filePath: fullPath,
641652
fullPath: fullPath,
642653
isMarkdownFile: utils.isMarkdownFile(fullPath),

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

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -589,16 +589,6 @@ define(function (require, exports, module) {
589589
_togglePinUrl();
590590
}
591591
$iframe.attr('src', StaticServer.getNoPreviewURL());
592-
if(!panelShownAtStartup && !isBrowser){
593-
// we dont do this in browser as the virtual server may not yet be started on app start
594-
// project open and a 404 page will briefly flash in the browser!
595-
const currentDocument = DocumentManager.getCurrentDocument();
596-
const currentFile = currentDocument? currentDocument.file : ProjectManager.getSelectedItem();
597-
const isPreviewable = currentFile ? utils.isPreviewableFile(currentFile.fullPath) : false;
598-
if(isPreviewable){
599-
_setPanelVisibility(true);
600-
}
601-
}
602592
if(!panel.isVisible()){
603593
return;
604594
}
@@ -661,10 +651,14 @@ define(function (require, exports, module) {
661651
}
662652
if(changedFile && (utils.isPreviewableFile(fullPath) ||
663653
utils.isServerRenderedFile(fullPath))){
654+
_loadPreview();
664655
if(!panelShownAtStartup){
665-
_setPanelVisibility(true);
656+
let previewDetails = await StaticServer.getPreviewDetails();
657+
if(previewDetails && !previewDetails.isNoPreview) {
658+
_setPanelVisibility(true);
659+
_loadPreview();
660+
}
666661
}
667-
_loadPreview();
668662
}
669663
}
670664

@@ -748,6 +742,8 @@ define(function (require, exports, module) {
748742
return;
749743
}
750744
panelShownAtStartup = !LivePreviewSettings.shouldShowLivePreviewAtStartup();
745+
Metrics.countEvent(Metrics.EVENT_TYPE.LIVE_PREVIEW, "atStart",
746+
LivePreviewSettings.shouldShowLivePreviewAtStartup() ? "show" : "hide");
751747
_createExtensionPanel();
752748
StaticServer.init();
753749
LiveDevServerManager.registerServer({ create: _createStaticServer }, 5);

0 commit comments

Comments
 (0)