DEV Community

Alex Spinov
Alex Spinov

Posted on

Wails Has a Free API You're Not Using

Wails builds desktop apps using Go + any web frontend. It's like Electron but with Go's performance and a 10MB binary instead of 150MB.

The Free APIs You're Missing

1. Bindings — Auto-Generated TypeScript from Go

// app.go
type App struct {
    ctx context.Context
}

func (a *App) GetUsers() ([]User, error) {
    return db.QueryUsers()
}

func (a *App) CreateUser(name, email string) (*User, error) {
    return db.CreateUser(name, email)
}
Enter fullscreen mode Exit fullscreen mode
// Frontend — auto-generated TypeScript bindings!
import { GetUsers, CreateUser } from "../wailsjs/go/main/App";

const users = await GetUsers(); // Fully typed!
const newUser = await CreateUser("Alice", "alice@example.com");
Enter fullscreen mode Exit fullscreen mode

Wails auto-generates TypeScript types from your Go structs. Zero manual binding code.

2. Events — Bidirectional Communication

// Emit from Go
runtime.EventsEmit(a.ctx, "file-processed", FileResult{
    Name: "report.pdf",
    Size: 1024,
    Status: "complete",
})

// Listen in Go
runtime.EventsOn(a.ctx, "user-action", func(data ...interface{}) {
    action := data[0].(string)
    log.Printf("User did: %s", action)
})
Enter fullscreen mode Exit fullscreen mode
import { EventsOn, EventsEmit } from "../wailsjs/runtime";

EventsOn("file-processed", (result) => {
  console.log(`Processed: ${result.Name}`);
});

EventsEmit("user-action", "clicked-export");
Enter fullscreen mode Exit fullscreen mode

3. Native Dialogs — OS-Level UI

import "github.com/wailsapp/wails/v2/pkg/runtime"

func (a *App) OpenFile() string {
    file, _ := runtime.OpenFileDialog(a.ctx, runtime.OpenDialogOptions{
        Title: "Select a file",
        Filters: []runtime.FileFilter{
            {DisplayName: "Images", Pattern: "*.png;*.jpg;*.gif"},
            {DisplayName: "All Files", Pattern: "*.*"},
        },
    })
    return file
}

func (a *App) Confirm(msg string) bool {
    result, _ := runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
        Type:    runtime.QuestionDialog,
        Title:   "Confirm",
        Message: msg,
    })
    return result == "Yes"
}
Enter fullscreen mode Exit fullscreen mode

4. System Tray — Background Apps

app := wails.NewApp()
app.SetSystemTray(&options.SystemTray{
    LightModeIcon: iconLight,
    DarkModeIcon:  iconDark,
    Menu:          trayMenu,
    OnClick:       func() { runtime.WindowShow(ctx) },
})
Enter fullscreen mode Exit fullscreen mode

5. Build System — Cross-Platform

wails build -platform darwin/amd64    # macOS Intel
wails build -platform darwin/arm64    # macOS Apple Silicon
wails build -platform windows/amd64   # Windows
wails build -platform linux/amd64     # Linux
wails build -nsis                     # Windows installer
Enter fullscreen mode Exit fullscreen mode

Getting Started

go install github.com/wailsapp/wails/v2/cmd/wails@latest
wails init -n my-app -t react-ts
wails dev
Enter fullscreen mode Exit fullscreen mode

Need data from any website delivered as clean JSON? I build production web scrapers that handle anti-bot, proxies, and rate limits. 77 scrapers running in production. Email me: Spinov001@gmail.com

Check out my awesome-web-scraping list for the best scraping tools and resources.

Top comments (0)