Skip to content

Commit

Permalink
feat: open README.md file when a project is first opened
Browse files Browse the repository at this point in the history
  • Loading branch information
abose committed Jan 7, 2024
1 parent 7550aa8 commit d94e7c3
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/extensions/default/Phoenix-live-preview/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@ define(function (require, exports, module) {
LiveDevServerManager = brackets.getModule("LiveDevelopment/LiveDevServerManager"),
NativeApp = brackets.getModule("utils/NativeApp"),
StringUtils = brackets.getModule("utils/StringUtils"),
FileSystem = brackets.getModule("filesystem/FileSystem"),
StaticServer = require("StaticServer"),
TrustProjectHTML = require("text!trust-project.html"),
utils = require('utils');

const PREVIEW_TRUSTED_PROJECT_KEY = "preview_trusted";
const PREVIEW_PROJECT_README_KEY = "preview_readme";

const LIVE_PREVIEW_PANEL_ID = "live-preview-panel";
const LIVE_PREVIEW_IFRAME_HTML = `
Expand Down Expand Up @@ -112,6 +114,18 @@ define(function (require, exports, module) {
_loadPreview(true);
};

function _setProjectReadmePreviewdOnce() {
const projectPath = ProjectManager.getProjectRoot().fullPath;
const previewReadmeKey = `${PREVIEW_PROJECT_README_KEY}-${projectPath}`;
PhStore.setItem(previewReadmeKey, true);
}

function _isProjectReadmePreviewdOnce() {
const projectPath = ProjectManager.getProjectRoot().fullPath;
const previewReadmeKey = `${PREVIEW_PROJECT_README_KEY}-${projectPath}`;
return !!PhStore.getItem(previewReadmeKey);
}

ExtensionInterface.registerExtensionInterface(
ExtensionInterface._DEFAULT_EXTENSIONS_INTERFACE_NAMES.PHOENIX_LIVE_PREVIEW, exports);

Expand Down Expand Up @@ -333,7 +347,21 @@ define(function (require, exports, module) {
}
}

function _openReadmeMDIfFirstTime() {
if(!_isProjectReadmePreviewdOnce() && !Phoenix.isTestWindow){
const readmePath = `${ProjectManager.getProjectRoot().fullPath}README.md`;
const fileEntry = FileSystem.getFileForPath(readmePath);
fileEntry.exists(function (err, exists) {
if (!err && exists) {
CommandManager.execute(Commands.FILE_ADD_TO_WORKING_SET, {fullPath: readmePath});
_setProjectReadmePreviewdOnce();
}
});
}
}

async function _projectOpened(_evt) {
_openReadmeMDIfFirstTime();
if(!LiveDevelopment.isActive()
&& (panel.isVisible() || StaticServer.hasActiveLivePreviews())) {
// we do this only once after project switch if live preview for a doc is not active.
Expand Down

0 comments on commit d94e7c3

Please sign in to comment.