beta.blog

Go: Create Cross-Platform GUI Applications Using Astilectron

by on Feb.13, 2019, under Programming

Astilectron

Astilectron is a framework allowing us to build cross platform GUI apps with GO and HTML/JS/CSS powered by Electron. While it enables us to create neat looking frontends it also comes with a bootstrap allowing us to create a one-window application using Astilectron. The GUI is rendered in an embedded Chromium environment.

Getting started

Getting started is fairly simple because a demo application is provided on github. It is recommended to utilise the bundler for building applications and we proceed as follows in order to install it:

go get -u github.com/asticode/go-astilectron-demo/…

We may then proceed with cloning and building the demo as follows:

git clone git@github.com:asticode/go-astilectron-demo.git

cd go-astilectron-demo

rm bind.go

~/go/bin/astilectron-bundler -v

The last command assumes your $GOPATH is ~/go/. Feel free to substitute this bit according to your actual system setup. If the commands were executed successfully, a target/ directory was created containing a runnable native application for the current operating system.

Cross-Platform Builds

In order to build for other environments we could simply add the following bit to the file bundler.json:

“environments”: [ {“arch”: “amd64”, “os”: “linux”}, {“arch”: “386”, “os”: “windows”} ]

It should now look similar to this:

{
  "app_name": "Astilectron demo",
  "icon_path_darwin": "resources/icon.icns",
  "icon_path_linux": "resources/icon.png",
  "icon_path_windows": "resources/icon.ico",
  "environments": [
    {"arch": "amd64", "os": "darwin"},
    {"arch": "amd64", "os": "linux"},
    {"arch": "386", "os": "windows"}
  ]
}

This means we’d like to build for macOS (64-bit), linux (64-bit) and Windows (32-bit). Again, use astilectron-bundler to build the packages. This time we might encounter an error, though:

FATA[0040] bundling failed: bundling for environment windows/386 failed: building failed

cannot find package “github.com/konsorten/go-windows-terminal-sequences”

or probably:

cannot find package “github.com/mattn/go-colorable”

The solution to this kind of issues is always the same:

go get -u github.com/konsorten/go-windows-terminal-sequences

go get -u github.com/mattn/go-colorable

Finally, run astilectron-bundler in order to cross-build the demo:

~/go/bin/astilectron-bundler -v

The output/ directory should contain binaries for multiple operating systems. For instance, if you built the entire thing on macOS, you should now have three folders: darwin-amd64, linux-amd64, windows-386.

:,

Leave a Reply

*

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!