|
| 1 | +# Desktop Helper Example |
| 2 | + |
| 3 | +This sample has two components, a UXP plugin and an Electron application built in React. |
| 4 | + |
| 5 | +For developers who have used `create-react-app` before, the folder structure and tools used in the Electron application will be familiar. |
| 6 | + |
| 7 | +Both components must be running for the example to work correctly. |
| 8 | + |
| 9 | +# Configuration |
| 10 | + |
| 11 | +The following steps will help you load the plugin into Photoshop and get the Electron app up and running. |
| 12 | + |
| 13 | +## UXP Plugin |
| 14 | + |
| 15 | +### 1. Install Node.js dependencies |
| 16 | + |
| 17 | +``` |
| 18 | +$ cd uxp |
| 19 | +$ yarn install # or npm install |
| 20 | +``` |
| 21 | + |
| 22 | +### 2. Run plugin in watch or build mode |
| 23 | + |
| 24 | +``` |
| 25 | +$ cd uxp |
| 26 | +$ yarn watch # or npm run watch |
| 27 | +
|
| 28 | +# OR |
| 29 | +
|
| 30 | +$ yarn build # or npm run build |
| 31 | +``` |
| 32 | + |
| 33 | +- `yarn watch` or `npm run watch` will build a development version of the plugin, and recompile everytime you make a change to the source files. The result is placed in `uxp/dist`. |
| 34 | +- `yarn build` or `npm run build` will build a production version of the plugin and place it in `uxp/dist`. It will not update every time you make a change to the source files. |
| 35 | + |
| 36 | +> You **must** run either `watch` or `build` prior to trying to use within Photoshop! |
| 37 | +
|
| 38 | +## Electron Helper |
| 39 | + |
| 40 | +### 1. Install Node.js dependencies |
| 41 | + |
| 42 | +``` |
| 43 | +$ cd helper |
| 44 | +$ yarn install # or npm install |
| 45 | +``` |
| 46 | + |
| 47 | +### 2. Run helper app |
| 48 | + |
| 49 | +``` |
| 50 | +$ cd helper |
| 51 | +$ yarn start |
| 52 | +``` |
| 53 | + |
| 54 | +### 3. (Optional) Build the helper app |
| 55 | + |
| 56 | +``` |
| 57 | +$ cd helper |
| 58 | +$ yarn build |
| 59 | +``` |
| 60 | + |
| 61 | +**Warning:** This command will take quite some time to execute. |
| 62 | + |
| 63 | +In Electron, production builds compile JavaScript into a binary executable on the target platform for distribution or personal use. It is recommended that you build for production when you finish development. |
| 64 | + |
| 65 | +Once built, navigate to the `helper/dist` folder and double click the `UXP Helper App Setup 1.0.0` installer. Upon installation, the helper app can be run locally. Please note, the Electron project will have to be rebuilt and reinstalled for any future changes to take effect in production. |
| 66 | + |
| 67 | +# Load the Plugin |
| 68 | + |
| 69 | +You can use the UXP Developer Tools to load the plugin into Photoshop. |
| 70 | + |
| 71 | +If the plugin hasn't already been added to your workspace in the UXP Developer Tools, you can add it by clicking "Add Plugin..." and selecting `uxp/dist/manifest.json`. **DO NOT** select the `manifest.json` file inside the `uxp/plugin` folder. |
| 72 | + |
| 73 | +Once added, you can load it into Photoshop by clicking the ••• button on the corresponding row, and clicking "Load". Switch to Photoshop and you should see the sample panel. |
| 74 | + |
| 75 | +# Using the Plugin |
| 76 | + |
| 77 | +This plugin uses an embedded websocket server to communicate between the Electron helper app and UXP. |
| 78 | + |
| 79 | +Files for the server and electron configuration are located in the `helper/public` folder and are served as entrypoints for Electron on build. |
| 80 | + |
| 81 | +Once both components are launched, you should be greeted with `'Connected'` status' on both components. If one component disconnects, the other will automatically recognize this disconnect as well, and the changes should be reflected with a `'Disconnected'` status. |
| 82 | + |
| 83 | + |
| 84 | + |
| 85 | +Since it's an embedded server, its worth noting that this only runs on `localhost` and only administers communication between a single instance of the helper app and the UXP plugin. By default, the websocket server runs on port `4040` and the Electron helper app is served from port `3000`. |
| 86 | + |
| 87 | +Other than connecting with one another, the two components can also pass strings of text which get reflected in their `Received data from the helper` and `Received data from UXP` sections. |
0 commit comments