Skip to content

Commit

Permalink
fix: not working in browser
Browse files Browse the repository at this point in the history
  • Loading branch information
abose committed May 4, 2024
1 parent c356c1a commit e2988ae
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
13 changes: 9 additions & 4 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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 = "<b>Image conversion failed</b>";
try {
alert("downloading image...");
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"main.js"
],
"nodeConfig": {
"nodeIsRequired": true,
"nodeIsRequired": false,
"main": "node/index.js",
"npmInstall": "node/"
}
Expand Down

0 comments on commit e2988ae

Please sign in to comment.