cryptojo avatar

Building Electron Application (cryptocurrency wallet) with Snap/Snapcraft

cryptojo

Published: 24 Aug 2017 › Updated: 24 Aug 2017Building Electron Application (cryptocurrency wallet) with Snap/Snapcraft

Building Electron Application (cryptocurrency wallet) with Snap/Snapcraft

Why write this?

  • The examples I've found are outdated and/or wrong.
  • There isn't much information on snapping electron apps.
  • Found people asking the same question without any acceptable answers.

Note: electron-packager can build directly to snap packages and avoid these steps completely.

Setup the Build Process

Compiling NodeJS

Unfortunately, the build process quite work using just the nodejs plugin. So, you have to override the build and install process with manual operations to get it going.

parts:
  node-app:
    plugin: nodejs
    source: .
    build: |
      npm run build &&
      ./node_modules/.bin/electron-packager . --overwrite --platform=linux --arch=x64 --output=release-build --prune=true
    install: |
      cp -v -r SafexWallet-linux-x64 $SNAPCRAFT_PART_INSTALL/wallet

More info on parts like build and install, check out the following link
https://snapcraft.io/docs/reference/plugins/common

To find out more details about the plugin, snapcraft details
snapcraft help nodejs

Adding GTK Dependancies

Electron uses the GTK toolkit to build it's GUI. Snapcraft includes functionality to help you add the necessary dependencies.

Example

parts:
  node-app:
    plugin: nodejs
    source: .
    build: |
      npm run build &&
      ./node_modules/.bin/electron-packager . --overwrite --platform=linux --arch=x64 --output=release-build --prune=true
    install: |
      cp -v -r SafexWallet-linux-x64 $SNAPCRAFT_PART_INSTALL/wallet
    after: [ desktop-gtk2 ]

If you want to learn more about exactly desktop-gtk2 is doing, what dependencies it adds and what plugs are recommended, use this command.

snapcraft define desktop-gtk2

Add a Launch

Adding a Wrapper

You'll need a wrapper to load all gtk libraries necessary to run the binary. The good thing is snapcraft has prebuilt functionality for this. All you need to do is prefix your command with desktop-launch

app:
  test:
    command: desktop-launch $SNAP/my-node-command

Build your Snap

Build it.

snapcraft clean && snapcraft

Finished!

Examples

https://github.com/jeteokeeffe/safex-wallet-snap.git

Leave Building Electron Application (cryptocurrency wallet) with Snap/Snapcraft to:

Written by

Read more #cryptocurrency posts


Best Posts From cryptojo

We have not curated any of cryptojo's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From cryptojo