element-web/docs/native_node_modules.md

51 lines
2.1 KiB
Markdown

# Native Node Modules
Since v???, the electron version of Riot can make use of native node modules. These allow Riot to integrate with the desktop in ways that a browser cannot.
While handy, these modules must be compiled and are thus downloaded pre-compiled during build so that a single OS can compile Riot for all platforms. If you would like to compile the native node modules from source, as is done for Riot releases, instead of trusting binaries hosted on npm, then please read on.
Do note that compiling a module for a particular operating system (Linux/Mac/Windows) and architecture (x64/x86) will need to be done on a system that is currently running that
## Compiling iohook
[iohook](https://github.com/matrix-org/iohook/) is a native node module written in C/C++ that allows for cross-platform capturing of keystrokes. This is used for providing Push-to-Talk functionality (pressing a key to toggle the microphone in a call) and is ONLY enabled during a call and while setting the keybinding in settings.
If you would like to rebuild the module yourself and replace the downloaded binaries, use the following commands from Riot's root directory:
```bash
cd electron_app
npm i
cd node_modules
rm -rf iohook
git clone https://github.com/matrix-org/iohook
cd iohook
npm i
rm -rf builds/* # Delete any downloaded binaries
npm run build # This builds libuiohook
node build.js --runtime electron --version 4.1.3 --abi 69 --no-upload # This builds the module for the current OS
```
You then need to copy the built module to the correct folder depending on the operating system and architecture you're building for:
```bash
# Run one of the following depending on your architecture:
# 64-bit
osarch="64"
# 32-bit
osarch="32"
# Run one of the following depending on your operating system:
# Windows
ostype="win32"
# Linux
ostype="linux"
# MacOS
ostype="darwin"
# Finally, copy the module:
folder="electron-v69-$ostype-x$osarch"
mkdir -p builds/$folder/build/Release
cp build/Release/iohook.node builds/$folder/build/Release/
```
The electron version of Riot can then be built normally according to the [build instructions](../README.md#running-as-a-desktop-app).