Skip to content

Commit a762b71

Browse files
committed
feat: how to inspect node menu item and dialog
1 parent 8502388 commit a762b71

File tree

5 files changed

+46
-2
lines changed

5 files changed

+46
-2
lines changed

src/document/DocumentCommandHandlers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1901,7 +1901,7 @@ define(function (require, exports, module) {
19011901
event.preventDefault();
19021902
_handleWindowGoingAway(null, closeSuccess=>{
19031903
console.log('close success: ', closeSuccess);
1904-
window.PhNodeEngine.terminateNode();
1904+
window.PhNodeEngine && window.PhNodeEngine.terminateNode();
19051905
Phoenix.app.closeWindow();
19061906
}, closeFail=>{
19071907
console.log('close fail: ', closeFail);

src/extensions/default/DebugCommands/main.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ define(function (require, exports, module) {
3535
PerfUtils = brackets.getModule("utils/PerfUtils"),
3636
StringUtils = brackets.getModule("utils/StringUtils"),
3737
Dialogs = brackets.getModule("widgets/Dialogs"),
38+
DefaultDialogs = brackets.getModule("widgets/DefaultDialogs"),
3839
Strings = brackets.getModule("strings"),
3940
PreferencesManager = brackets.getModule("preferences/PreferencesManager"),
4041
LocalizationUtils = brackets.getModule("utils/LocalizationUtils"),
@@ -72,6 +73,7 @@ define(function (require, exports, module) {
7273
DEBUG_SWITCH_LANGUAGE = "debug.switchLanguage",
7374
DEBUG_ENABLE_LOGGING = "debug.enableLogging",
7475
DEBUG_ENABLE_PHNODE_INSPECTOR = "debug.enablePhNodeInspector",
76+
DEBUG_GET_PHNODE_INSPECTOR_URL = "debug.getPhNodeInspectorURL",
7577
DEBUG_LIVE_PREVIEW_LOGGING = "debug.livePreviewLogging",
7678
DEBUG_OPEN_VFS = "debug.openVFS",
7779
DEBUG_OPEN_EXTENSION_FOLDER = "debug.openExtensionFolders",
@@ -702,6 +704,25 @@ define(function (require, exports, module) {
702704
_updateLogToConsoleMenuItemChecked();
703705
}
704706

707+
function _handleGetPhNodeInspectURL() {
708+
Dialogs.showModalDialog(DefaultDialogs.DIALOG_ID_INFO, Strings.CMD_GET_PHNODE_INSPECTOR_URL,
709+
`<div id="instructions">
710+
<p>
711+
1. Go to <a href="chrome://inspect/" target="_blank">chrome://inspect/#devices</a>
712+
<button onclick="Phoenix.app.copyToClipboard('chrome://inspect/')">
713+
<i class="fas fa-copy"></i> Copy
714+
</button>
715+
</p>
716+
<p>2. Select Option 'Open dedicated DevTools for Node'</p>
717+
<p>
718+
3. Use the URL in connection tab'<code>localhost:${window.PhNodeEngine.getInspectPort()}</code>'
719+
<button onclick="Phoenix.app.copyToClipboard('localhost:${window.PhNodeEngine.getInspectPort()}')">
720+
<i class="fas fa-copy"></i> Copy
721+
</button>
722+
</p>
723+
</div>`);
724+
}
725+
705726
function _handleLivePreviewLogging() {
706727
window.toggleLoggingKey(LOG_LIVE_PREVIEW_KEY);
707728
_updateLogToConsoleMenuItemChecked();
@@ -757,6 +778,7 @@ define(function (require, exports, module) {
757778

758779
CommandManager.register(Strings.CMD_ENABLE_LOGGING, DEBUG_ENABLE_LOGGING, _handleLogging);
759780
CommandManager.register(Strings.CMD_ENABLE_PHNODE_INSPECTOR, DEBUG_ENABLE_PHNODE_INSPECTOR, _handlePhNodeInspectEnable);
781+
CommandManager.register(Strings.CMD_GET_PHNODE_INSPECTOR_URL, DEBUG_GET_PHNODE_INSPECTOR_URL, _handleGetPhNodeInspectURL);
760782
CommandManager.register(Strings.CMD_ENABLE_LIVE_PREVIEW_LOGS, DEBUG_LIVE_PREVIEW_LOGGING, _handleLivePreviewLogging);
761783
CommandManager.register(Strings.CMD_OPEN_VFS, DEBUG_OPEN_VFS, _openVFS);
762784
CommandManager.register(Strings.CMD_OPEN_EXTENSIONS_FOLDER, DEBUG_OPEN_EXTENSION_FOLDER, _openExtensionsFolder);
@@ -782,6 +804,9 @@ define(function (require, exports, module) {
782804
debugMenu.addMenuItem(DEBUG_ENABLE_PHNODE_INSPECTOR, undefined, undefined, undefined, {
783805
hideWhenCommandDisabled: true
784806
});
807+
debugMenu.addMenuItem(DEBUG_GET_PHNODE_INSPECTOR_URL, undefined, undefined, undefined, {
808+
hideWhenCommandDisabled: true
809+
});
785810
debugMenu.addMenuItem(DEBUG_LIVE_PREVIEW_LOGGING);
786811
debugMenu.addMenuDivider();
787812
debugMenu.addMenuItem(DEBUG_OPEN_VFS);
@@ -798,6 +823,8 @@ define(function (require, exports, module) {
798823
.setEnabled(Phoenix.browser.isTauri); // only show in tauri
799824
CommandManager.get(DEBUG_ENABLE_PHNODE_INSPECTOR)
800825
.setEnabled(Phoenix.browser.isTauri); // only show in tauri
826+
CommandManager.get(DEBUG_GET_PHNODE_INSPECTOR_URL)
827+
.setEnabled(Phoenix.browser.isTauri); // only show in tauri
801828
CommandManager.get(DEBUG_OPEN_VIRTUAL_SERVER)
802829
.setEnabled(!Phoenix.browser.isTauri); // don't show in tauri as there is no virtual server in tauri
803830

src/nls/root/strings.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,7 @@ define({
697697
"CMD_SHOW_PERF_DATA": "Show Performance Data",
698698
"CMD_ENABLE_LOGGING": "Enable Detailed Logs",
699699
"CMD_ENABLE_PHNODE_INSPECTOR": "Enable PhNode Inspector",
700+
"CMD_GET_PHNODE_INSPECTOR_URL": "How to Inspect PhNode",
700701
"CMD_ENABLE_LIVE_PREVIEW_LOGS": "Live Preview Logs",
701702
"CMD_OPEN_BRACKETS_SOURCE": "Open {APP_NAME} Source",
702703

src/node-loader.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,14 @@ if(Phoenix.browser.isTauri) {
4444
return !!prefs.inspectEnabled;
4545
}
4646

47+
function getRandomNumber(min, max) {
48+
return Math.floor(Math.random() * (max - min + 1)) + min;
49+
}
50+
4751
window.__TAURI__.path.resolveResource("src-node/index.js")
4852
.then(async nodeSrcPath=>{
49-
const argsArray = isInspectEnabled() ? ['--inspect', nodeSrcPath] : [nodeSrcPath, ''];
53+
const inspectPort = Phoenix.isTestWindow ? getRandomNumber(5000, 50000) : 9229;
54+
const argsArray = isInspectEnabled() ? [`--inspect=${inspectPort}`, nodeSrcPath] : [nodeSrcPath, ''];
5055
command = window.__TAURI__.shell.Command.sidecar('phnode', argsArray);
5156
command.on('close', data => {
5257
window.isNodeTerminated = true;
@@ -88,6 +93,9 @@ if(Phoenix.browser.isTauri) {
8893
isInspectEnabled,
8994
terminateNode: function () {
9095
execNode(NODE_COMMANDS.TERMINATE);
96+
},
97+
getInspectPort: function () {
98+
return inspectPort;
9199
}
92100
};
93101

src/phoenix/shell.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,14 @@ Phoenix.app = {
155155
nativeWindow.isTauriWindow = false;
156156
return nativeWindow;
157157
},
158+
copyToClipboard: function (textToCopy) {
159+
const textArea = document.createElement("textarea");
160+
textArea.value = textToCopy;
161+
document.body.appendChild(textArea);
162+
textArea.select();
163+
document.execCommand("copy");
164+
document.body.removeChild(textArea);
165+
},
158166
getApplicationSupportDirectory: Phoenix.VFS.getAppSupportDir,
159167
getExtensionsDirectory: Phoenix.VFS.getExtensionDir,
160168
getUserDocumentsDirectory: Phoenix.VFS.getUserDocumentsDirectory,

0 commit comments

Comments
 (0)