Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 3 additions & 78 deletions src/extensionsIntegrated/Phoenix-live-preview/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,6 @@ define(function (require, exports, module) {
});

const LIVE_PREVIEW_PANEL_ID = "live-preview-panel";
// how long a popout waits for a live preview session that is still starting, and how often it looks
const POPOUT_SESSION_WAIT_MS = 5000;
const POPOUT_SESSION_POLL_MS = 50;

/** Fired with the full path whenever the preview switches to a different file. */
const EVENT_PREVIEWED_FILE_CHANGE = "previewedFileChange";
Expand Down Expand Up @@ -781,78 +778,6 @@ define(function (require, exports, module) {
}
}

/**
* Whether the live preview can be opened in a browser on this platform. No page needs to have been previewed
* yet: `popoutLivePreview` works out the page when it is asked.
* @return {boolean}
*/
function canPopoutLivePreview() {
return Phoenix.isNativeApp || Phoenix.browser.desktop.isChromeBased || Phoenix.browser.desktop.isFirefox;
}

// Whether the live preview session can serve the page a popout is to open. The server has to be up, and a
// page it instruments needs its live document: without one the tab gets the bare file and never connects.
function _canSessionServe(previewDetails) {
if (previewDetails.isServerNotReady) {
return false;
}
if (!previewDetails.isHTMLFile || previewDetails.isCustomServer || previewDetails.isNoPreview) {
return true;
}
const liveDoc = MultiBrowserLiveDev.getCurrentLiveDoc();
return !!liveDoc && liveDoc.doc.file.fullPath === previewDetails.fullPath;
}

/**
* The details of the page a popout is to open, once the live preview session can serve it. A session that
* cannot yet is started and waited for; past the timeout the details come back as they stand.
* @return {Promise<Object>}
*/
async function _getPopoutPreviewDetails() {
let previewDetails = await StaticServer.getPreviewDetails();
if (_canSessionServe(previewDetails)) {
return previewDetails;
}
LiveDevelopment.openLivePreview();
const deadline = Date.now() + POPOUT_SESSION_WAIT_MS;
while (!_canSessionServe(previewDetails) && Date.now() < deadline) {
await new Promise((resolve) => setTimeout(resolve, POPOUT_SESSION_POLL_MS));
previewDetails = await StaticServer.getPreviewDetails();
}
return previewDetails;
}

/**
* Opens the page the live preview would show in the default browser, starting the session if it cannot serve
* that page yet. The page is worked out afresh, as a docked panel that is closed or never opened has none.
* @return {Promise<boolean>} false when the live preview server could not name a page
*/
async function popoutLivePreview() {
if (!canPopoutLivePreview()) {
return false;
}
if (urlPinned && currentLivePreviewURL) {
// a pinned url stays the page, as it does in the docked panel
if (LiveDevelopment.isInactive()) {
LiveDevelopment.openLivePreview();
}
} else {
const previewDetails = await _getPopoutPreviewDetails();
if (previewDetails.isServerNotReady) {
return false;
}
currentLivePreviewURL = encodeURI(previewDetails.URL);
_setPreviewedFile(previewDetails.fullPath);
}
// In the browser a popped out tab ignores the url it opens with and asks which page to show. Only a
// preview load names that page, and none runs while the docked panel is closed and no tab is up yet.
if (!Phoenix.isNativeApp) {
StaticServer.redirectAllTabs(currentLivePreviewURL, false);
}
_popoutLivePreview();
return true;
}

function _setTitle(fileName, fullPath, currentLivePreviewURL) {
let message = Strings.LIVE_DEV_SELECT_FILE_TO_PREVIEW,
tooltip = message;
Expand Down Expand Up @@ -1016,7 +941,9 @@ define(function (require, exports, module) {
Metrics.countEvent(Metrics.EVENT_TYPE.LIVE_PREVIEW, "settingsBtn", "click");
});

if(!canPopoutLivePreview()){
const popoutSupported = Phoenix.isNativeApp
|| Phoenix.browser.desktop.isChromeBased || Phoenix.browser.desktop.isFirefox;
if(!popoutSupported){
// live preview can be popped out currently in only chrome based browsers. The cross domain iframe
// that serves the live preview(phcode.live) is sandboxed to the tab in which phcode.dev resides.
// all iframes in the tab can communicate between each other, but when you popout another tab, it forms
Expand Down Expand Up @@ -1918,8 +1845,6 @@ define(function (require, exports, module) {
exports.getPreviewedFilePath = getPreviewedFilePath;
/** @return {string|null} Transport client of the current embedded HTML preview, never a popout. */
exports.getEmbeddedClientID = function () { return _dockedClientID || null; };
exports.canPopoutLivePreview = canPopoutLivePreview;
exports.popoutLivePreview = popoutLivePreview;
exports.reloadLivePreview = reloadLivePreview;
});

1 change: 0 additions & 1 deletion src/nls/root/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,6 @@ define({
"LIVE_PREVIEW_LAYERS_TAB": "Layers",
"LIVE_PREVIEW_LAYERS_NEEDS_PREVIEW": "The Layers panel needs a live preview.",
"LIVE_PREVIEW_LAYERS_OPEN_PREVIEW": "Open Live Preview",
"LIVE_PREVIEW_LAYERS_OPEN_IN_BROWSER": "Open in Browser",
"LIVE_PREVIEW_LAYERS_NEEDS_HTML": "Open an HTML file to see its layers.",
"LIVE_PREVIEW_LAYERS_CHOOSE_PAGE": "Choose a page",
"LIVE_PREVIEW_LAYERS_PICK_HTML": "Pick an HTML file to see its layers.",
Expand Down
21 changes: 0 additions & 21 deletions src/styles/Extn-LayersPanel.less
Original file line number Diff line number Diff line change
Expand Up @@ -248,27 +248,6 @@
}
}

.layers-message-btn-secondary {
background: transparent;
border-color: @layers-border-strong;
box-shadow: none;
color: @project-panel-text-1;

i {
font-size: 11px;
color: @project-panel-text-2;
}

&:hover {
background: @layers-hover-bg;
border-color: rgba(255, 255, 255, 0.22);
}

&:active {
background: @layers-input-bg;
}
}

.layers-files-heading,
.layers-files-intro {
display: contents;
Expand Down
Loading