Skip to content

Commit e2988ae

Browse files
committed
fix: not working in browser
1 parent c356c1a commit e2988ae

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
# Extension Template
22

33
Quick start and create a new `node.js extension` by using this template. This
4-
template extension works in browser as well as desktop builds.
4+
template extension works in browser as well as desktop builds. In browser, it
5+
will not use node, and node.js based functionalities are not available. Desktop
6+
builds will use node capabilities.
57

6-
In desktop builds, there is an additional capability to execute node.js code. This
7-
is helpful if you want to extend the functionality of Phoenix Code using the
8-
vast npm library.
8+
In desktop builds, there is an additional capability to execute node.js code.
9+
This is helpful if you want to extend the functionality of Phoenix Code using
10+
the vast npm library.
911

1012
For creating extensions that do not need node, follow this link:
1113
https://github.com/phcode-dev/extension-template
@@ -68,6 +70,7 @@ extension components.
6870
event trigger/listen within node.
6971

7072
# Using this template
73+
7174
Follow the below 4 steps to start using this template:
7275

7376
Refer this

main.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ define(function (require, exports, module) {
2020
Menus = brackets.getModule("command/Menus"),
2121
NodeConnector = brackets.getModule("NodeConnector");
2222

23-
const nodeConnector = NodeConnector.createNodeConnector(
24-
"your-extension-id-1",
25-
exports
26-
);
23+
let nodeConnector;
2724

2825
async function fetchImage() {
2926
const imageUrl = "https://picsum.photos/536/354";
@@ -40,6 +37,10 @@ define(function (require, exports, module) {
4037

4138
// Function to run when the menu item is clicked
4239
async function handleHelloWorld() {
40+
if (!Phoenix.isNativeApp) {
41+
alert("Node Features only works in desktop apps.");
42+
return;
43+
}
4344
let html = "<b>Image conversion failed</b>";
4445
try {
4546
alert("downloading image...");
@@ -86,6 +87,10 @@ define(function (require, exports, module) {
8687
console.log("hello world");
8788

8889
if (Phoenix.isNativeApp) {
90+
nodeConnector = NodeConnector.createNodeConnector(
91+
"your-extension-id-1",
92+
exports
93+
);
8994
// you can also execute nodejs code in dekstop builds
9095
// below code will execute the function `echoTest` defined in `node/index.js`
9196
nodeConnector.execPeer("echoTest", "yo!").then(console.log);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"main.js"
1818
],
1919
"nodeConfig": {
20-
"nodeIsRequired": true,
20+
"nodeIsRequired": false,
2121
"main": "node/index.js",
2222
"npmInstall": "node/"
2323
}

0 commit comments

Comments
 (0)