diff --git a/README.md b/README.md index 6e587d6..d347832 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,13 @@ # Extension Template Quick start and create a new `node.js extension` by using this template. This -template extension works in browser as well as desktop builds. +template extension works in browser as well as desktop builds. In browser, it +will not use node, and node.js based functionalities are not available. Desktop +builds will use node capabilities. -In desktop builds, there is an additional capability to execute node.js code. This -is helpful if you want to extend the functionality of Phoenix Code using the -vast npm library. +In desktop builds, there is an additional capability to execute node.js code. +This is helpful if you want to extend the functionality of Phoenix Code using +the vast npm library. For creating extensions that do not need node, follow this link: https://github.com/phcode-dev/extension-template @@ -68,6 +70,7 @@ extension components. event trigger/listen within node. # Using this template + Follow the below 4 steps to start using this template: Refer this diff --git a/main.js b/main.js index 956580d..0397ec2 100644 --- a/main.js +++ b/main.js @@ -20,10 +20,7 @@ define(function (require, exports, module) { Menus = brackets.getModule("command/Menus"), NodeConnector = brackets.getModule("NodeConnector"); - const nodeConnector = NodeConnector.createNodeConnector( - "your-extension-id-1", - exports - ); + let nodeConnector; async function fetchImage() { const imageUrl = "https://picsum.photos/536/354"; @@ -40,6 +37,10 @@ define(function (require, exports, module) { // Function to run when the menu item is clicked async function handleHelloWorld() { + if (!Phoenix.isNativeApp) { + alert("Node Features only works in desktop apps."); + return; + } let html = "Image conversion failed"; try { alert("downloading image..."); @@ -86,6 +87,10 @@ define(function (require, exports, module) { console.log("hello world"); if (Phoenix.isNativeApp) { + nodeConnector = NodeConnector.createNodeConnector( + "your-extension-id-1", + exports + ); // you can also execute nodejs code in dekstop builds // below code will execute the function `echoTest` defined in `node/index.js` nodeConnector.execPeer("echoTest", "yo!").then(console.log); diff --git a/package.json b/package.json index 67e1e0c..385d060 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "main.js" ], "nodeConfig": { - "nodeIsRequired": true, + "nodeIsRequired": false, "main": "node/index.js", "npmInstall": "node/" }