Create cross-platform GUI apps with Golang + Elm!

README

About

Create GUI apps with Wails + Elm!

Dev env requirements

Create a project

Run the following command:

wails init -n wails-hello-world -t https://github.com/benjamin-thomas/wails-elm-template

Live Development

Inside the project folder, run: wails dev. This setup provides auto-reloading of backend+frontend code.

It's also possible to keep the frontend reloading process separated by:

  • deleting the frontend:dev:watcher entry in ./wails.json
  • then run cd ./frontend && npm run dev:watch in a separate terminal (this triggers the elm-live toolchain)

Debugging

It's possible to debug and inspect javascript code at: http://localhost:34115.

This URL also allows the inspection of state change provided by elm's '--debug' compile flag.

Building

To build a production binary, use wails build.

Note on performance/alternatives

I feel this stack could be a great combo for GUI programming. Elm's promise to eliminate runtime errors could turn out to be invaluable.

I evaluated other technologies, here's my list pros and cons while trying to build a hello world app on an old computer:

| Technology               | Pros                                                                                            | Cons                                                                                                         |
| ------------------------ | ----------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ |
| JavaFX (with modules)    | Easy cross platform development                                                                 | Hard cross platform distribution (tooling is still a little rough)                                           |
|                          |                                                                                                 | Packaged app remains rather large (~30-90MB)                                                                 |
| ------------------------ | ----------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ |
| JavaFX (without modules) | Easier distribution if using Bellsoft/Liberica JDK                                              | What are the security implications for the end user?                                                         |
|                          |                                                                                                 | The distributed package is even larger (~150MB)                                                              |
| ------------------------ | ----------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ |
| JavaFX                   | Interesting ecosystem for building business apps (see: ControlsFX,etc.)                         | Slow app startup (2s)                                                                                        |
| ------------------------ | ----------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ |
| JavaFX                   | Potentially tiny binaries if distributes as .jar                                                | The end user needs an SDK, that's a pretty heavy requirement (+ becomes a security concern to manage)        |
| ------------------------ | ----------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ |
| JavaFX                   | Can achieve a rather native look.                                                               | Task manager reports a javaw.exe binary, not my-app.exe.                                                     |
|                          |                                                                                                 | I could not find how to circumvent this although I'm pretty sure it's doable                                 |
| ------------------------ | ----------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ |
| Electron                 | Easy dev setup, easy distribution with extra packages                                           | Distributed package remains quite large (~70-120MB)                                                          |
| ------------------------ | ----------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ |
| Electron                 | I saw a small memory footprint in my simple test (has there been improvements here?)            | Memory usage is said to be a problem, memory leaks could easy to introduce and hard to find/debug            |
| ------------------------ | ----------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ |
| Electron                 | Very slow app startup (4s)                                                                      | Microsoft documented the high memory usage of Microsoft Teams for their users (ouch!).                       |
|                          |                                                                                                 | Then announced moving off Electron for this reason.                                                          |
| ------------------------ | ----------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ |
| Flutter (Dart)           | Cross-device development (mobile+desktop) by Google. Fast startup and dev hot-reload (< 1s).    | Apps look pretty tied up to Google's material design. Some community projects like `fluent_ui` try           |
|                          | Binary bundle could downsized if zipped from ~20MB                                              | to address this but are still at an early stage.                                                             |
| ------------------------ | ----------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ |
| .Net MAUI (C#, F#, VB)           | Multi-platform App UI by Microsoft: almost cross-platform (cross-device) dev.                   | No Linux support :(                                                                                          |
|                          |                                                                                                 | Seems to require a Windows dev machine (no dotnet core support)                                              |
| ------------------------ | ----------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ |
| Avalonia (C#, F#, VB)            | Community driven cross-device development                                                       | Binary size remains fairly large. Incorporates DLLs that got wrongly tagged as viruses by AV companies, etc. |
| ------------------------ | ----------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ |
| Tauri (Rust based)       | Very similar to Wails.                                                                          | Rust compile times make hot-reload so slow (30-40s!)                                                         |
| ------------------------ | ----------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ |
| Wails + Elm              | Fast startup (1s), very fast auto-reload (instant), small binary (4MB), small memory footprint. | v2 of the project is a little early, but the project has been around for many years.                         |
|                          | The architecture and final output feel much simpler than the other solutions.                   |                                                                                                              |
| ------------------------ | ----------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ |

If you feel I got things wrong, or want to add to this list, don't hesitate to open a PR!

Improve this template

Go one level above this project. Then run these two commands and ensure hot-reload works.

rm -r ./wails-elm-test;wails init -n wails-elm-test -t ./wails-elm-template/
cd ./wails-elm-test/ && code . && wails dev
Similar Resources

Clean Architecture template for Golang services

Go Clean template Clean Architecture template for Golang services Overview The purpose of the template is to show: how to organize a project and preve

Nov 30, 2021

Callable Ajax / http requests inside Golang templates

jaco Callable Ajax / http requests inside Golang templates Examples Examples #1 {{ define "content" }} div id="myTodos"/div script

Dec 5, 2021

A Go Template Library. A bunch of utils and collections that are not part of the Golang standard library.

gotl A Go Template Library. A bunch of utils and collections that are not part of the Golang standard library. Prerequisites This library is using ext

Dec 15, 2021

Competitive Programming Template for Golang

Go Competitive Programming Template How to use this repo? Check the commit histo

Dec 19, 2021

Template user CRUD operations with golang, JWT, postgres

user-api-golang A CRUD API template for perform operations on users. Written in golang. Components Server: Golang with go-chi as mux and zap for loggi

Dec 26, 2021

An example of implementation of Clean Architecture in Golang

Golang Template Description This is an example of implementation of Clean Archit

Dec 29, 2021

Go-project-template - Template for a golang project

This is a template repository for golang project Usage Go to github: https://git

Oct 25, 2022

Template for depency injection in golang (no libraries)

Go Dependency Injection (No libraries) Project template based on the most common layered architecture style, made to explain how to do dependency inje

Mar 30, 2022

Golang Service Template

Golang Service Template Golang back-end service template. Using this template, you can get started with back-end projects quickly. Web Framework ORM D

Jun 8, 2022
Comments
  • Template broken since I updated MacOS

    Template broken since I updated MacOS

    Hello.

    First of all, thanks for creating and sharing this template!

    I used it a few months ago to create a new Wails app. Everything went smooth. I was working on this project until one week ago. However, since I upgraded the OS of my 2013 Macbook to MacOS BigSur, the project does not compile anymore. I created a new project from scratch and reproduced the problem:

    wails init -n wails-hello-world -t https://github.com/benjamin-thomas/wails-elm-template
    cd wails-hello-world/
    wails build
    

    results in

    Wails CLI v2.2.0
    
    App Type: 		desktop
    Platforms: 		darwin/amd64
    Compiler: 		/usr/local/bin/go
    Skip Bindings: 		false
    Build Mode: 		Production
    Frontend Directory: 	/Users/peal6230/Documents/dev/projects/fileorganizer/wails-hello-world/frontend
    Obfuscated: 		false
    Skip Frontend: 		false
    Compress: 		false
    Package: 		true
    Clean Bin Dir: 		false
    LDFlags: 		""
    Tags: 			[]
    Race Detector: 		false
    
    Building target: darwin/amd64
    -----------------------------
      - Generating bindings: Error: 
    # changeme
    ./main.go:38:3: unknown field 'RGBA' in struct literal of type options.App
    
    exit status 2
    

    Here is the output of wails doctor:

    System
    ------
    OS:		MacOS
    Version: 	11.7.1
    ID:		20G918
    Go Version:	go1.18.3
    Platform:	darwin
    Architecture:	amd64
    
    Wails
    ------
    Version: 	v2.2.0
    
    Dependency			Package Name	Status		Version
    ----------			------------	------		-------
    xcode command line tools  	N/A 		Installed 	2384
    npm  				N/A 		Installed 	6.14.13
    *upx  				N/A 		Available 	
    *nsis  				N/A 		Available 	
    
    * - Optional Dependency
    
    Diagnosis
    ---------
    Your system is ready for Wails development!
    Optional package(s) installation details: 
      - upx : Available at https://upx.github.io/
      - nsis : Available at https://nsis.sourceforge.io/Download
    

    Creating a new Wails project with the Vanilla JS template works as expected, the problem is with this template only. Maybe it needs an update since Wails 2 was released?

A maroto way to create PDFs. Maroto is inspired in Bootstrap and uses gofpdf. Fast and simple.
A maroto way to create PDFs. Maroto is inspired in Bootstrap and uses gofpdf. Fast and simple.

Maroto A Maroto way to create PDFs. Maroto is inspired in Bootstrap and uses Gofpdf. Fast and simple. Maroto definition: Brazilian expression, means a

Jan 7, 2023
A scaffold to quickly create a go project

OpenMix 出品:https://openmix.org Mix CLI 一个快速创建 go 项目的脚手架 A scaffold to quickly create a go project Installation 安装 go get -u github.com/mix-go/mixcli

Nov 16, 2022
"to be defined" - a really simple way to create text templates with placeholders

tbd "to be defined" A really simple way to create text templates with placeholders. This tool is deliberately simple and trivial, no advanced features

Sep 27, 2022
Goview is a lightweight, minimalist and idiomatic template library based on golang html/template for building Go web application.

goview Goview is a lightweight, minimalist and idiomatic template library based on golang html/template for building Go web application. Contents Inst

Dec 25, 2022
Handlebars for golang

raymond Handlebars for golang with the same features as handlebars.js 3.0. The full API documentation is available here: http://godoc.org/github.com/a

Jan 5, 2023
A general purpose golang CLI template for Github and Gitlab

golang-cli-template A general purpose project template for golang CLI applications This template serves as a starting point for golang commandline app

Dec 2, 2022
Clean Architecture using Golang.
Clean Architecture using Golang.

Golang Template Description This is an example of implementation of Clean Architecture in Go (Golang) projects. Rule of Clean Architecture by Uncle Bo

Nov 1, 2022
Clean arch Golang template project

Template No previous versions, still working on this one to reach v1. API Service for pssword app mobilde based on : https://github.com/bxcodec/go-cle

Sep 15, 2021
Template for Golang rest API using Fiber

Rest API Setup DB sudo -S docker-compose -f db.yml up -d Build container sudo -S docker build -t rest-api-image . Run container from image sudo -S doc

Dec 5, 2021
Clean Architecture template for Golang services
Clean Architecture template for Golang services

Go Clean template Clean Architecture template for Golang services Overview The purpose of the template is to show: how to organize a project and preve

Jul 11, 2022