nui

package module
v0.0.0-...-ad25c21 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2019 License: MIT Imports: 24 Imported by: 0

README

nui (WIP)

img

nui (naive ui) is a library for creating Go desktop applications with GUIs defined in HTML/CSS/JS.

It works by downloading a copy of Electron on your computer and controlling it through a web server, rather than binding WebKit directly.

nui should work on most major desktop environments.

On Windows it requires a Common Control version 6 manifest, so import ours if you don't already have one:

import _ "github.com/superp00t/nui/winmanifest"

JS->Go RPC calls

To generate a Go binding, first create a model such as this.

type AppModel struct {
  win *Window
}

func (app *AppModel) HandleClick() {
  a.win.Alert("Button clicked!")
}

func (app *AppModel) Ints() ([]int, bool) {
  return []int{1,2,3,4,5}, true
}

Generating the binding:

app := new(AppModel)
app.win = win

// Generates JavaScript interface
win.Bind("app", app)

This will expose AppModel in your nui Electron window as an object in your Window's JavaScript instance:


// invoked after binding is complete
window.NUI = async () => {
  // ints = [ [1,2,3,4,5], true ] 
  let ints = await app.Ints(); 
  console.log(typeof ints); // array
  console.log(typeof ints[0]); // array
  console.log(typeof ints[0][0]); // number
}

This pattern should work with most JSON-serializable return values.

Credits

  • nui is inspired heavily by zserge/webview, and shares much of the same API as it
  • The Electron updater GUI is provided by andlabs/ui
  • nui also is inspired by astilectron.
  • Incorporates Electron.
  • Uses the GitHub API to download Electron.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DisplayFatalError

func DisplayFatalError(err error)

func ShowError

func ShowError(title, data string)

Types

type Args

type Args []interface{}

func (Args) Bool

func (a Args) Bool(arg int) bool

func (Args) Float64

func (a Args) Float64(arg int) float64

func (Args) Int64

func (a Args) Int64(arg int) int64

func (Args) String

func (a Args) String(arg int) string

type Flag

type Flag uint32
const (
	None          Flag = 0
	Borderless    Flag = 1 << 1
	HideMenu      Flag = 1 << 2
	DebugRender   Flag = 1 << 3
	SilentUpdater Flag = 1 << 4
)

type GithubReleases

type GithubReleases struct {
	URL             string `json:"url"`
	AssetsURL       string `json:"assets_url"`
	UploadURL       string `json:"upload_url"`
	HTMLURL         string `json:"html_url"`
	ID              int    `json:"id"`
	NodeID          string `json:"node_id"`
	TagName         string `json:"tag_name"`
	TargetCommitish string `json:"target_commitish"`
	Name            string `json:"name"`
	Draft           bool   `json:"draft"`
	Author          struct {
		Login             string `json:"login"`
		ID                int    `json:"id"`
		NodeID            string `json:"node_id"`
		AvatarURL         string `json:"avatar_url"`
		GravatarID        string `json:"gravatar_id"`
		URL               string `json:"url"`
		HTMLURL           string `json:"html_url"`
		FollowersURL      string `json:"followers_url"`
		FollowingURL      string `json:"following_url"`
		GistsURL          string `json:"gists_url"`
		StarredURL        string `json:"starred_url"`
		SubscriptionsURL  string `json:"subscriptions_url"`
		OrganizationsURL  string `json:"organizations_url"`
		ReposURL          string `json:"repos_url"`
		EventsURL         string `json:"events_url"`
		ReceivedEventsURL string `json:"received_events_url"`
		Type              string `json:"type"`
		SiteAdmin         bool   `json:"site_admin"`
	} `json:"author"`
	Prerelease  bool      `json:"prerelease"`
	CreatedAt   time.Time `json:"created_at"`
	PublishedAt time.Time `json:"published_at"`
	Assets      []struct {
		URL      string `json:"url"`
		ID       int    `json:"id"`
		NodeID   string `json:"node_id"`
		Name     string `json:"name"`
		Label    string `json:"label"`
		Uploader struct {
			Login             string `json:"login"`
			ID                int    `json:"id"`
			NodeID            string `json:"node_id"`
			AvatarURL         string `json:"avatar_url"`
			GravatarID        string `json:"gravatar_id"`
			URL               string `json:"url"`
			HTMLURL           string `json:"html_url"`
			FollowersURL      string `json:"followers_url"`
			FollowingURL      string `json:"following_url"`
			GistsURL          string `json:"gists_url"`
			StarredURL        string `json:"starred_url"`
			SubscriptionsURL  string `json:"subscriptions_url"`
			OrganizationsURL  string `json:"organizations_url"`
			ReposURL          string `json:"repos_url"`
			EventsURL         string `json:"events_url"`
			ReceivedEventsURL string `json:"received_events_url"`
			Type              string `json:"type"`
			SiteAdmin         bool   `json:"site_admin"`
		} `json:"uploader"`
		ContentType        string    `json:"content_type"`
		State              string    `json:"state"`
		Size               int64     `json:"size"`
		DownloadCount      int       `json:"download_count"`
		CreatedAt          time.Time `json:"created_at"`
		UpdatedAt          time.Time `json:"updated_at"`
		BrowserDownloadURL string    `json:"browser_download_url"`
	} `json:"assets"`
	TarballURL string `json:"tarball_url"`
	ZipballURL string `json:"zipball_url"`
	Body       string `json:"body"`
}

type Settings

type Settings struct {
	Title    string `json:"title"`
	Width    int    `json:"width"`
	Height   int    `json:"height"`
	URL      string `json:"-"`
	Flags    Flag   `json:"flags"`
	Icon     []byte `json:"-"`
	IconPath string `json:"icon"`
}

type Window

type Window struct {
	*http.ServeMux

	OnOpen func()
	// contains filtered or unexported fields
}

func New

func New(opts Settings) *Window

func (*Window) Alert

func (w *Window) Alert(s string)

func (*Window) Bind

func (w *Window) Bind(name string, object interface{}) error

func (*Window) CSS

func (w *Window) CSS(css string)

func (*Window) Close

func (w *Window) Close() error

func (*Window) Eval

func (w *Window) Eval(js string)

func (*Window) Evalf

func (n *Window) Evalf(fomt string, args ...interface{})

func (*Window) HTML

func (w *Window) HTML(s string)

func (*Window) Maximize

func (w *Window) Maximize()

func (*Window) Minimize

func (w *Window) Minimize()

func (*Window) Run

func (w *Window) Run() error

func (*Window) Started

func (w *Window) Started() bool

func (*Window) Template

func (n *Window) Template(name, tpls string, v interface{})

func (*Window) UpdateDeps

func (wind *Window) UpdateDeps() error

Directories

Path Synopsis
cmd
Package winmanifest provides a basic manifest for use with package nui.
Package winmanifest provides a basic manifest for use with package nui.

Jump to

Keyboard shortcuts

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