wails

package module
v0.12.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 6, 2019 License: MIT Imports: 21 Imported by: 65

README


A framework for building desktop applications using Go & Web Technologies.

CodeFactor CodeFactor

The traditional method of providing web interfaces to Go programs is via a built-in web server. Wails offers a different approach: it provides the ability to wrap both Go code and a web frontend into a single binary. Tools are provided to make this easy for you by handling project creation, compilation and bundling. All you have to do is get creative!

Features

  • Use standard Go libraries/frameworks for the backend
  • Use any frontend technology to build your UI
  • Expose Go methods/functions to the frontend via a single bind command
  • Uses native rendering engines - no embedded browser
  • Shared events system
  • Native file dialogs
  • Powerful cli tool
  • Multiplatform

Project Status

Wails is currently in Beta. Please make sure you read the Project Status if you are interested in using this project.

Installation

Wails uses cgo to bind to the native rendering engines so a number of platform dependent libraries are needed as well as an installation of Go. The basic requirements are:

  • Go 1.11 or above
  • npm

MacOS

Make sure you have the xcode command line tools installed. This can be done by running:

xcode-select --install

Linux

Ubuntu 18.04

sudo apt install pkg-config build-essential libgtk-3-dev libwebkit2gtk-4.0-dev

Arch Linux

sudo pacman -S webkit2gtk gtk3

Note: If you have successfully installed these dependencies on a different flavour of Linux, please consider submitting a PR.

Windows

Windows requires gcc and related tooling. The recommended download is from http://tdm-gcc.tdragon.net/download. Once this is installed, you are good to go.

Installation

Installation is as simple as running the following command:

go get -u github.com/wailsapp/wails/cmd/wails

Next Steps

It is recommended at this stage to read the comprehensive documentation at https://wails.app.

FAQ

  • Is this an alternative to Electron?

    Depends on your requirements. It's designed to make it easy for Go programmers to make lightweight desktop applications or add a frontend to their existing applications. Whilst Wails does not currently offer hooks into native elements such as menus, this may change in the future.

  • Who is this project aimed at?

    Go programmers who want to bundle an HTML/JS/CSS frontend with their applications, without resorting to creating a server and opening a browser to view it.

  • What's with the name?

    When I saw WebView, I thought "What I really want is tooling around building a WebView app, a bit like Rails is to Ruby". So initially it was a play on words (Webview on Rails). It just so happened to also be a homophone of the English name for the Country I am from. So it stuck.

Shoulders of Giants

Without the following people, this project would never have existed:

  • Dustin Krysak - His support and feedback has been immense. More patience than you can throw a stick at (Not long now Dustin!).
  • Serge Zaitsev - Creator of Webview which Wails uses for the windowing.

And without these people, it wouldn't be what it is today.

Special Mentions:

  • Bill Kennedy - Go guru, encourager and all-round nice guy, whose infectious energy and inspiration powered me on when I had none left.
  • Mark Bates - Creator of Packr, inspiration for packing strategies which fed into some of the tooling.

This project was mainly coded to the following albums:

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BuildMode = cmd.BuildModeProd

BuildMode indicates what mode we are in

Functions

This section is empty.

Types

type App

type App struct {
	// contains filtered or unexported fields
}

App defines the main application struct

func CreateApp

func CreateApp(optionalConfig ...*AppConfig) *App

CreateApp creates the application window with the given configuration If none given, the defaults are used

func (*App) AddCSS

func (a *App) AddCSS(js string)

AddCSS adds a CSS string to a cache that gets injected at runtime

func (*App) AddJS

func (a *App) AddJS(js string)

AddJS adds a piece of Javascript to a cache that gets injected at runtime

func (*App) Bind

func (a *App) Bind(object interface{})

Bind allows the user to bind the given object with the application

func (*App) Run

func (a *App) Run() error

Run the app

type AppConfig

type AppConfig struct {
	Width, Height int
	Title         string

	HTML             string
	JS               string
	CSS              string
	Colour           string
	Resizable        bool
	DisableInspector bool
	// contains filtered or unexported fields
}

AppConfig is the configuration structure used when creating a Wails App object

type CustomLogger

type CustomLogger struct {
	// contains filtered or unexported fields
}

CustomLogger is a wrapper object to logrus

func (*CustomLogger) Debug

func (c *CustomLogger) Debug(message string)

Debug level message

func (*CustomLogger) DebugFields

func (c *CustomLogger) DebugFields(message string, fields Fields)

DebugFields - message with fields

func (*CustomLogger) Debugf

func (c *CustomLogger) Debugf(message string, args ...interface{})

Debugf - formatted message

func (*CustomLogger) Error

func (c *CustomLogger) Error(message string)

Error level message

func (*CustomLogger) ErrorFields

func (c *CustomLogger) ErrorFields(message string, fields Fields)

ErrorFields - message with fields

func (*CustomLogger) Errorf

func (c *CustomLogger) Errorf(message string, args ...interface{})

Errorf - formatted message

func (*CustomLogger) Fatal

func (c *CustomLogger) Fatal(message string)

Fatal level message

func (*CustomLogger) FatalFields

func (c *CustomLogger) FatalFields(message string, fields Fields)

FatalFields - message with fields

func (*CustomLogger) Fatalf

func (c *CustomLogger) Fatalf(message string, args ...interface{})

Fatalf - formatted message

func (*CustomLogger) Info

func (c *CustomLogger) Info(message string)

Info level message

func (*CustomLogger) InfoFields

func (c *CustomLogger) InfoFields(message string, fields Fields)

InfoFields - message with fields

func (*CustomLogger) Infof

func (c *CustomLogger) Infof(message string, args ...interface{})

Infof - formatted message

func (*CustomLogger) Panic

func (c *CustomLogger) Panic(message string)

Panic level message

func (*CustomLogger) PanicFields

func (c *CustomLogger) PanicFields(message string, fields Fields)

PanicFields - message with fields

func (*CustomLogger) Panicf

func (c *CustomLogger) Panicf(message string, args ...interface{})

Panicf - formatted message

func (*CustomLogger) Warn

func (c *CustomLogger) Warn(message string)

Warn level message

func (*CustomLogger) WarnFields

func (c *CustomLogger) WarnFields(message string, fields Fields)

WarnFields - message with fields

func (*CustomLogger) Warnf

func (c *CustomLogger) Warnf(message string, args ...interface{})

Warnf - formatted message

type Fields

type Fields map[string]interface{}

Fields is used by the customLogger object to output fields along with a message

type Headless

type Headless struct {
	// contains filtered or unexported fields
}

Headless is a backend that opens a local web server and renders the files over a websocket

func (*Headless) AddCSSList

func (h *Headless) AddCSSList(cssCache []string)

AddCSSList adds a slice of CSS strings to the list of css files injected at startup

func (*Headless) AddJSList

func (h *Headless) AddJSList(jsCache []string)

AddJSList adds a slice of JS strings to the list of js files injected at startup

func (*Headless) Callback

func (h *Headless) Callback(data string) error

Callback sends a callback to the frontend

func (*Headless) Close

func (h *Headless) Close()

Close is unsupported for Headless but required for the Renderer interface

func (*Headless) Fullscreen

func (h *Headless) Fullscreen()

Fullscreen is unsupported for Headless but required for the Renderer interface

func (*Headless) Initialise

func (h *Headless) Initialise(appConfig *AppConfig, ipcManager *ipcManager, eventManager *eventManager) error

Initialise the Headless Renderer

func (*Headless) NewBinding

func (h *Headless) NewBinding(methodName string) error

NewBinding creates a new binding with the frontend

func (*Headless) NotifyEvent

func (h *Headless) NotifyEvent(event *eventData) error

NotifyEvent notifies the frontend of an event

func (*Headless) Run

func (h *Headless) Run() error

Run the app in headless mode!

func (*Headless) SelectDirectory

func (h *Headless) SelectDirectory() string

SelectDirectory is unsupported for Headless but required for the Renderer interface

func (*Headless) SelectFile

func (h *Headless) SelectFile() string

SelectFile is unsupported for Headless but required for the Renderer interface

func (*Headless) SelectSaveFile

func (h *Headless) SelectSaveFile() string

SelectSaveFile is unsupported for Headless but required for the Renderer interface

func (*Headless) SetColour

func (h *Headless) SetColour(colour string) error

SetColour is unsupported for Headless but required for the Renderer interface

func (*Headless) SetTitle

func (h *Headless) SetTitle(title string)

SetTitle is currently unsupported for Headless but required for the Renderer interface

func (*Headless) UnFullscreen

func (h *Headless) UnFullscreen()

UnFullscreen is unsupported for Headless but required for the Renderer interface

type Renderer

type Renderer interface {
	Initialise(*AppConfig, *ipcManager, *eventManager) error
	Run() error

	// Binding
	NewBinding(bindingName string) error
	Callback(data string) error

	// Events
	NotifyEvent(eventData *eventData) error

	// Injection
	AddJSList(js []string)
	AddCSSList(css []string)

	// Dialog Runtime
	SelectFile() string
	SelectDirectory() string
	SelectSaveFile() string

	// Window Runtime
	SetColour(string) error
	Fullscreen()
	UnFullscreen()
	SetTitle(title string)
	Close()
}

Renderer is an interface describing a Wails target to render the app to

type Runtime

type Runtime struct {
	Events     *RuntimeEvents
	Log        *RuntimeLog
	Dialog     *RuntimeDialog
	Window     *RuntimeWindow
	FileSystem *RuntimeFileSystem
}

Runtime is the Wails Runtime Interface, given to a user who has defined the WailsInit method

type RuntimeDialog

type RuntimeDialog struct {
	// contains filtered or unexported fields
}

RuntimeDialog exposes an interface to native dialogs

func (*RuntimeDialog) SelectDirectory

func (r *RuntimeDialog) SelectDirectory() string

SelectDirectory prompts the user to select a directory

func (*RuntimeDialog) SelectFile

func (r *RuntimeDialog) SelectFile() string

SelectFile prompts the user to select a file

func (*RuntimeDialog) SelectSaveFile

func (r *RuntimeDialog) SelectSaveFile() string

SelectSaveFile prompts the user to select a file for saving

type RuntimeEvents

type RuntimeEvents struct {
	// contains filtered or unexported fields
}

RuntimeEvents exposes the events interface

func (*RuntimeEvents) Emit

func (r *RuntimeEvents) Emit(eventName string, optionalData ...interface{})

Emit pass through

func (*RuntimeEvents) On

func (r *RuntimeEvents) On(eventName string, callback func(optionalData ...interface{}))

On pass through

type RuntimeFileSystem added in v0.11.1

type RuntimeFileSystem struct {
}

RuntimeFileSystem exposes file system utilities to the runtime

func (*RuntimeFileSystem) HomeDir added in v0.11.1

func (r *RuntimeFileSystem) HomeDir() (string, error)

HomeDir returns the user's home directory

type RuntimeLog

type RuntimeLog struct {
}

RuntimeLog exposes the logging interface to the runtime

func (*RuntimeLog) New

func (r *RuntimeLog) New(prefix string) *CustomLogger

New creates a new logger

type RuntimeWindow

type RuntimeWindow struct {
	// contains filtered or unexported fields
}

RuntimeWindow exposes an interface for manipulating the window

func (*RuntimeWindow) Close

func (r *RuntimeWindow) Close()

Close shuts down the window and therefore the app

func (*RuntimeWindow) Fullscreen

func (r *RuntimeWindow) Fullscreen()

Fullscreen makes the window fullscreen

func (*RuntimeWindow) SetColour

func (r *RuntimeWindow) SetColour(colour string) error

SetColour sets the the window colour

func (*RuntimeWindow) SetTitle

func (r *RuntimeWindow) SetTitle(title string)

SetTitle sets the the window title

func (*RuntimeWindow) UnFullscreen

func (r *RuntimeWindow) UnFullscreen()

UnFullscreen attempts to restore the window to the size/position before fullscreen

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL