Skip to content

Commit 5dc44e7

Browse files
committed
chore: remove redundant live preview framework init
1 parent 0fa3b5e commit 5dc44e7

File tree

1 file changed

+29
-13
lines changed
  • src/extensionsIntegrated/Phoenix-live-preview

1 file changed

+29
-13
lines changed

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

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -575,8 +575,8 @@ define(function (require, exports, module) {
575575
}
576576
}
577577

578-
let startupFilesLoadHandled = false;
579-
async function _projectOpened(_evt) {
578+
let startupFilesLoadHandled = false, livePreviewStartCalled = false;
579+
async function _projectOpened() {
580580
customLivePreviewBannerShown = false;
581581
$panel.find(".live-preview-custom-banner").addClass("forced-hidden");
582582
_openReadmeMDIfFirstTime();
@@ -590,13 +590,12 @@ define(function (require, exports, module) {
590590
_togglePinUrl();
591591
}
592592
$iframe.attr('src', StaticServer.getNoPreviewURL());
593-
if(ProjectManager.isStartupFilesLoaded()){
594-
startupFilesLoadHandled = true;
595-
}
593+
livePreviewStartCalled = true;
596594
if(!panelShownAtStartup && !isBrowser && ProjectManager.isStartupFilesLoaded()){
597595
// we dont do this in browser as the virtual server may not yet be started on app start
598596
// project open and a 404 page will briefly flash in the browser!
599597
// this mainly applies when phoenix is started with a preview file already open in previous exit
598+
startupFilesLoadHandled = true;
600599
const currentDocument = DocumentManager.getCurrentDocument();
601600
const currentFile = currentDocument? currentDocument.file : ProjectManager.getSelectedItem();
602601
const isPreviewable = currentFile ? utils.isPreviewableFile(currentFile.fullPath) : false;
@@ -610,6 +609,30 @@ define(function (require, exports, module) {
610609
_loadPreview(true);
611610
}
612611

612+
function _startupFilesLoaded() {
613+
if(startupFilesLoadHandled) {
614+
return;
615+
// we have to use this handled flag as there is no ordering of EVENT_AFTER_STARTUP_FILES_LOADED
616+
// and EVENT_PROJECT_OPEN. if _projectOpened has already shown the live preview panel when it saw that
617+
// ProjectManager.isStartupFilesLoaded() is true, we should not call project opened again at boot.
618+
}
619+
if(!livePreviewStartCalled){
620+
_projectOpened();
621+
return;
622+
}
623+
if(!panelShownAtStartup && !isBrowser && ProjectManager.isStartupFilesLoaded()){
624+
// we dont do this in browser as the virtual server may not yet be started on app start
625+
// project open and a 404 page will briefly flash in the browser!
626+
// this mainly applies when phoenix is started with a preview file already open in previous exit
627+
const currentDocument = DocumentManager.getCurrentDocument();
628+
const currentFile = currentDocument? currentDocument.file : ProjectManager.getSelectedItem();
629+
const isPreviewable = currentFile ? utils.isPreviewableFile(currentFile.fullPath) : false;
630+
if(isPreviewable){
631+
_setPanelVisibility(true);
632+
}
633+
}
634+
}
635+
613636
function _projectClosed() {
614637
if(urlPinned) {
615638
_togglePinUrl();
@@ -767,14 +790,7 @@ define(function (require, exports, module) {
767790
ProjectManager.on(ProjectManager.EVENT_PROJECT_OPEN, _projectOpened);
768791
ProjectManager.on(ProjectManager.EVENT_PROJECT_CLOSE, _projectClosed);
769792
EditorManager.on("activeEditorChange", _activeDocChanged);
770-
ProjectManager.on(ProjectManager.EVENT_AFTER_STARTUP_FILES_LOADED, ()=>{
771-
if(!startupFilesLoadHandled){
772-
// we have to use this handled flag as there is no ordering of EVENT_AFTER_STARTUP_FILES_LOADED
773-
// and EVENT_PROJECT_OPEN. if _projectOpened has already shown the live preview panel when it saw that
774-
// ProjectManager.isStartupFilesLoaded() is true, we should not call project opened again at boot.
775-
_projectOpened();
776-
}
777-
});
793+
ProjectManager.on(ProjectManager.EVENT_AFTER_STARTUP_FILES_LOADED, _startupFilesLoaded);
778794
CommandManager.register(Strings.CMD_LIVE_FILE_PREVIEW, Commands.FILE_LIVE_FILE_PREVIEW, function () {
779795
_toggleVisibilityOnClick();
780796
});

0 commit comments

Comments
 (0)