This document explains the purpose and usage of the FlexDesigner SDK.
- Node.js version 18 or higher
- FlexDesigner version 1.0.0 or higher.
Add FlexDesigner SDK to your project
In typical cases, you only need to create a plugin project using
flexcli, and the FlexDesigner SDK will be automatically installed.
npm install @eniactech/flexdesigner-sdk
Starts the WebSocket connection by extracting port and uid from command-line arguments.
- None
- None
Error: If port, uid, or dir are not provided in the command-line arguments.
This method parses the command-line arguments for port, uid, and dir options,
and uses them to establish a WebSocket connection with the server. It sends an
initial "startup" command once connected.
Parses command-line arguments to extract port, uid, and dir.
- None
{ port: <number|string>, uid: <string>, dir: <string> }: An object containing the parsed arguments.
- None
This method uses the minimist library to parse command-line arguments,
returning an object with port, uid, and dir properties.
Sends a request to the server with a specific command and payload.
command: The command to send to the server.payload: The payload to send along with the command.timeout: (Optional) The timeout in milliseconds before rejecting the request. Default is 5000 ms.
Promise<any>: A promise that resolves with the response payload or rejects with an error.
- None
The method creates a PluginCommand and sends it via WebSocket. It also sets a timeout
to reject the request if no response is received.
Handles incoming WebSocket messages.
msg: The received message in string format.
- None
- None
The method processes messages from the server, checking if they are responses to previous requests or if they are broadcasts that need to be handled by registered message handlers.
Registers a handler for incoming messages of a specific type.
type: The message type to handle.handler: The handler function that processes the message payload.
- None
- None
This method allows the registration of handlers for specific message types, which are invoked when a message of that type is received from the server.
Unregisters a handler for a specific message type.
type: The message type to unregister the handler for.
- None
- None
This method unregisters the handler for the specified message type.
Draws an image on a key.
serialNumber: The serial number of the device.key: The key object received from the eventdevice.newPageordevice.userData.type: The type of drawing operation, possible values:"draw" | "base64".base64: (Optional) The base64 image data. Only used iftypeis "base64".
Promise<any>: A promise that resolves with the server response.
- None
This method sends a draw command to the server, allowing the image data in base64 format to be drawn on the specified key.
Sets data for a specific key.
serialNumber: The serial number of the device.key: The key object received from the eventdevice.newPageordevice.userData.data: The data to set on the key. The format ofdatadepends on the key type.
Promise<any>: A promise that resolves with the server response.
Error: If the provided data is invalid for the given key type.
This method sends a command to update the state or value of a specified key based on the key type. It supports "multiState" and "slider" key types.
Shows a snackbar message in the parent window.
color: The color type for the message. Possible values:"success" | "info" | "warning" | "error".message: The message content to display.timeout: (Optional) Duration in milliseconds before hiding the message.
Promise<any>: A promise that resolves with the response.
- None
Displays a transient message (snackbar) with a specified color and timeout.
Calls the Electron API.
api: The Electron API method to call. Possible values include:"dialog.showOpenDialog""dialog.showSaveDialog""dialog.showMessageBox""dialog.showErrorBox""app.getAppPath""app.getPath""screen.getCursorScreenPoint""screen.getPrimaryDisplay""screen.getAllDisplays""screen.getDisplayNearestPoint""screen.getDisplayMatching""screen.screenToDipPoint""screen.dipToScreenPoint"
...args: Arguments to be passed to the Electron API call.
Promise<any>: A promise that resolves exactly as the Electron API returns.
Error: Throws an error if the call fails.
This function allows you to call various Electron APIs through a single interface.
Gets application information.
- None
Promise<Object>: A promise that resolves with the app info in JSON format.
Error: Throws an error if the call fails.
This function retrieves the application version and platform.
Opens a file from the given path.
path: The file path.
Promise<string|Buffer>: A promise that resolves with the file content.
Error: Throws an error if file opening fails.
Retrieves the file content if successful; otherwise throws an error.
Saves data to a specified file path.
path: The file path.data: The file content (string or Buffer).
Promise<Object>: A promise that resolves with the result in JSON format:{ "status": "success" | "error", "error": "Error message if status is 'error'" }
Error: Throws an error if saving fails.
Saves string or Buffer data to the provided file path and returns a status.
Gets the list of opened windows.
- None
Promise<Object[]>: A promise that resolves to an array of window objects.
Error: Throws an error if the call fails.
Retrieves an array of window objects in JSON format, each containing details
such as platform, id, title, owner, bounds, and memoryUsage.
Gets the device status.
- None
Promise<Object>: A promise that resolves to a JSON object containing device status fields.
Error: Throws an error if the call fails.
Returns a JSON object containing various status fields such as connecting,
connected, serialNumber, platform, profileVersion, and fwVersion.
Gets the plugin configuration.
- None
Promise<Object>: A promise that resolves to the plugin configuration object.
Error: Throws an error if the call fails.
Retrieves the plugin configuration.
Sets the plugin configuration.
config: The plugin configuration object.
Promise<Object>: A promise that resolves to the result{ status: 'success' | 'error' }.
Error: Throws an error if the call fails.
Sets the plugin configuration with the provided config object.