astilectron

package module
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2019 License: MIT Imports: 32 Imported by: 0

README

GoReportCard GoDoc Travis Coveralls

Thanks to go-astilectron build cross platform GUI apps with GO and HTML/JS/CSS. It is the official GO bindings of astilectron and is powered by Electron.

Demo

To see a minimal Astilectron app, checkout out the demo.

It uses the bootstrap and the bundler.

Real-life examples

Here's a list of awesome projects using go-astilectron (if you're using go-astilectron and want your project to be listed here please submit a PR):

  • go-astivid Video tools written in GO
  • GroupMatcher Program to allocate persons to groups while trying to fulfill all the given wishes as good as possible
  • ipeye-onvif ONVIF Search Tool
  • Stellite GUI Miner An easy to use GUI cryptocurrency miner for Stellite

Bootstrap

For convenience purposes, a bootstrap has been implemented.

The bootstrap allows you to quickly create a one-window application.

There's no obligation to use it, but it's strongly recommended.

If you decide to use it, read thoroughly the documentation as you'll have to structure your project in a specific way.

Bundler

Still for convenience purposes, a bundler has been implemented.

The bundler allows you to bundle your app for every os/arch combinations and get a nice set of files to send your users.

Quick start

WARNING: the code below doesn't handle errors for readibility purposes. However you SHOULD!

Import go-astilectron

To import go-astilectron run:

$ go get -u github.com/asticode/go-astilectron

Start go-astilectron

// Initialize astilectron
var a, _ = astilectron.New(astilectron.Options{
    AppName: "<your app name>",
    AppIconDefaultPath: "<your .png icon>", // If path is relative, it must be relative to the data directory
    AppIconDarwinPath:  "<your .icns icon>", // Same here
    BaseDirectoryPath: "<where you want the provisioner to install the dependencies>",
    VersionAstilectron: "<version of Astilectron to utilize such as `0.33.0`>",
    VersionElectron: "<version of Electron to utilize such as `4.0.1` | `6.1.2`>",
})
defer a.Close()

// Start astilectron
a.Start()

// Blocking pattern
a.Wait()

For everything to work properly we need to fetch 2 dependencies : astilectron and Electron. .Start() takes care of it by downloading the sources and setting them up properly.

In case you want to embed the sources in the binary to keep a unique binary you can use the NewDisembedderProvisioner function to get the proper Provisioner and attach it to go-astilectron with .SetProvisioner(p Provisioner). Or you can use the bootstrap and the bundler. Check out the demo to see how to use them.

Beware when trying to add your own app icon as you'll need 2 icons : one compatible with MacOSX (.icns) and one compatible with the rest (.png for instance).

If no BaseDirectoryPath is provided, it defaults to the executable's directory path.

The majority of methods are synchrone which means that when executing them go-astilectron will block until it receives a specific Electron event or until the overall context is cancelled. This is the case of .Start() which will block until it receives the app.event.ready astilectron event or until the overall context is cancelled.

Create a window

// Create a new window
var w, _ = a.NewWindow("http://127.0.0.1:4000", &astilectron.WindowOptions{
    Center: astilectron.PtrBool(true),
    Height: astilectron.PtrInt(600),
    Width:  astilectron.PtrInt(600),
})
w.Create()

When creating a window you need to indicate a URL as well as options such as position, size, etc.

This is pretty straightforward except the astilectron.Ptr* methods so let me explain: GO doesn't do optional fields when json encoding unless you use pointers whereas Electron does handle optional fields. Therefore I added helper methods to convert int, bool and string into pointers and used pointers in structs sent to Electron.

Open the dev tools

When developing in JS, it's very convenient to debug your code using the browser window's dev tools:

// Open dev tools
w.OpenDevTools()

// Close dev tools
w.CloseDevTools()

Add listeners

// Add a listener on Astilectron
a.On(astilectron.EventNameAppCrash, func(e astilectron.Event) (deleteListener bool) {
    astilog.Error("App has crashed")
    return
})

// Add a listener on the window
w.On(astilectron.EventNameWindowEventResize, func(e astilectron.Event) (deleteListener bool) {
    astilog.Info("Window resized")
    return
})

Nothing much to say here either except that you can add listeners to Astilectron as well.

Play with the window

// Play with the window
w.Resize(200, 200)
time.Sleep(time.Second)
w.Maximize()

Check out the Window doc for a list of all exported methods

Send messages from GO to Javascript

Javascript
// This will wait for the astilectron namespace to be ready
document.addEventListener('astilectron-ready', function() {
    // This will listen to messages sent by GO
    astilectron.onMessage(function(message) {
        // Process message
        if (message === "hello") {
            return "world";
        }
    });
})
GO
// This will send a message and execute a callback
// Callbacks are optional
w.SendMessage("hello", func(m *astilectron.EventMessage) {
        // Unmarshal
        var s string
        m.Unmarshal(&s)

        // Process message
        astilog.Debugf("received %s", s)
})

This will print received world in the GO output

Send messages from Javascript to GO

GO
// This will listen to messages sent by Javascript
w.OnMessage(func(m *astilectron.EventMessage) interface{} {
        // Unmarshal
        var s string
        m.Unmarshal(&s)

        // Process message
        if s == "hello" {
                return "world"
        }
        return nil
})
Javascript
// This will wait for the astilectron namespace to be ready
document.addEventListener('astilectron-ready', function() {
    // This will send a message to GO
    astilectron.sendMessage("hello", function(message) {
        console.log("received " + message)
    });
})

This will print "received world" in the Javascript output

Play with the window's session

// Clear window's HTTP cache
w.Session.ClearCache()

Handle several screens/displays

// If several displays, move the window to the second display
var displays = a.Displays()
if len(displays) > 1 {
    time.Sleep(time.Second)
    w.MoveInDisplay(displays[1], 50, 50)
}

Menus

// Init a new app menu
// You can do the same thing with a window
var m = a.NewMenu([]*astilectron.MenuItemOptions{
    {
        Label: astilectron.PtrStr("Separator"),
        SubMenu: []*astilectron.MenuItemOptions{
            {Label: astilectron.PtrStr("Normal 1")},
            {
                Label: astilectron.PtrStr("Normal 2"),
                OnClick: func(e astilectron.Event) (deleteListener bool) {
                    astilog.Info("Normal 2 item has been clicked")
                    return
                },
            },
            {Type: astilectron.MenuItemTypeSeparator},
            {Label: astilectron.PtrStr("Normal 3")},
        },
    },
    {
        Label: astilectron.PtrStr("Checkbox"),
        SubMenu: []*astilectron.MenuItemOptions{
            {Checked: astilectron.PtrBool(true), Label: astilectron.PtrStr("Checkbox 1"), Type: astilectron.MenuItemTypeCheckbox},
            {Label: astilectron.PtrStr("Checkbox 2"), Type: astilectron.MenuItemTypeCheckbox},
            {Label: astilectron.PtrStr("Checkbox 3"), Type: astilectron.MenuItemTypeCheckbox},
        },
    },
    {
        Label: astilectron.PtrStr("Radio"),
        SubMenu: []*astilectron.MenuItemOptions{
            {Checked: astilectron.PtrBool(true), Label: astilectron.PtrStr("Radio 1"), Type: astilectron.MenuItemTypeRadio},
            {Label: astilectron.PtrStr("Radio 2"), Type: astilectron.MenuItemTypeRadio},
            {Label: astilectron.PtrStr("Radio 3"), Type: astilectron.MenuItemTypeRadio},
        },
    },
    {
        Label: astilectron.PtrStr("Roles"),
        SubMenu: []*astilectron.MenuItemOptions{
            {Label: astilectron.PtrStr("Minimize"), Role: astilectron.MenuItemRoleMinimize},
            {Label: astilectron.PtrStr("Close"), Role: astilectron.MenuItemRoleClose},
        },
    },
})

// Retrieve a menu item
// This will retrieve the "Checkbox 1" item
mi, _ := m.Item(1, 0)

// Add listener manually
// An OnClick listener has already been added in the options directly for another menu item
mi.On(astilectron.EventNameMenuItemEventClicked, func(e astilectron.Event) bool {
    astilog.Infof("Menu item has been clicked. 'Checked' status is now %t", *e.MenuItemOptions.Checked)
    return false
})

// Create the menu
m.Create()

// Manipulate a menu item
mi.SetChecked(true)

// Init a new menu item
var ni = m.NewItem(&astilectron.MenuItemOptions{
    Label: astilectron.PtrStr("Inserted"),
    SubMenu: []*astilectron.MenuItemOptions{
        {Label: astilectron.PtrStr("Inserted 1")},
        {Label: astilectron.PtrStr("Inserted 2")},
    },
})

// Insert the menu item at position "1"
m.Insert(1, ni)

// Fetch a sub menu
s, _ := m.SubMenu(0)

// Init a new menu item
ni = s.NewItem(&astilectron.MenuItemOptions{
    Label: astilectron.PtrStr("Appended"),
    SubMenu: []*astilectron.MenuItemOptions{
        {Label: astilectron.PtrStr("Appended 1")},
        {Label: astilectron.PtrStr("Appended 2")},
    },
})

// Append menu item dynamically
s.Append(ni)

// Pop up sub menu as a context menu
s.Popup(&astilectron.MenuPopupOptions{PositionOptions: astilectron.PositionOptions{X: astilectron.PtrInt(50), Y: astilectron.PtrInt(50)}})

// Close popup
s.ClosePopup()

// Destroy the menu
m.Destroy()

A few things to know:

  • when assigning a role to a menu item, go-astilectron won't be able to capture its click event
  • on MacOS there's no such thing as a window menu, only app menus therefore my advice is to stick to one global app menu instead of creating separate window menus

Tray

// New tray
var t = a.NewTray(&astilectron.TrayOptions{
    Image:   astilectron.PtrStr("/path/to/image.png"),
    Tooltip: astilectron.PtrStr("Tray's tooltip"),
})

// Create tray
t.Create()

// New tray menu
var m = t.NewMenu([]*astilectron.MenuItemOptions{
    {
        Label: astilectron.PtrStr("Root 1"),
        SubMenu: []*astilectron.MenuItemOptions{
            {Label: astilectron.PtrStr("Item 1")},
            {Label: astilectron.PtrStr("Item 2")},
            {Type: astilectron.MenuItemTypeSeparator},
            {Label: astilectron.PtrStr("Item 3")},
        },
    },
    {
        Label: astilectron.PtrStr("Root 2"),
        SubMenu: []*astilectron.MenuItemOptions{
            {Label: astilectron.PtrStr("Item 1")},
            {Label: astilectron.PtrStr("Item 2")},
        },
    },
})

// Create the menu
m.Create()

// Change tray's image
time.Sleep(time.Second)
t.SetImage("/path/to/image-2.png")

Notifications

// Create the notification
var n = a.NewNotification(&astilectron.NotificationOptions{
	Body: "My Body",
	HasReply: astilectron.PtrBool(true), // Only MacOSX
	Icon: "/path/to/icon",
	ReplyPlaceholder: "type your reply here", // Only MacOSX
	Title: "My title",
})

// Add listeners
n.On(astilectron.EventNameNotificationEventClicked, func(e astilectron.Event) (deleteListener bool) {
	astilog.Debug("the notification has been clicked!")
	return
})
// Only for MacOSX
n.On(astilectron.EventNameNotificationEventReplied, func(e astilectron.Event) (deleteListener bool) {
	astilog.Debugf("the user has replied to the notification: %s", e.Reply)
	return
})

// Create notification
n.Create()

// Show notification
n.Show()

Dock (MacOSX only)

// Get the dock
var d = a.Dock()

// Hide and show the dock
d.Hide()
d.Show()

// Make the Dock bounce
id, _ := d.Bounce(astilectron.DockBounceTypeCritical)

// Cancel the bounce
d.CancelBounce(id)

// Update badge and icon
d.SetBadge("test")
d.SetIcon("/path/to/icon")

// New dock menu
var m = d.NewMenu([]*astilectron.MenuItemOptions{
    {
        Label: astilectron.PtrStr("Root 1"),
        SubMenu: []*astilectron.MenuItemOptions{
            {Label: astilectron.PtrStr("Item 1")},
            {Label: astilectron.PtrStr("Item 2")},
            {Type: astilectron.MenuItemTypeSeparator},
            {Label: astilectron.PtrStr("Item 3")},
        },
    },
        {
        Label: astilectron.PtrStr("Root 2"),
        SubMenu: []*astilectron.MenuItemOptions{
            {Label: astilectron.PtrStr("Item 1")},
            {Label: astilectron.PtrStr("Item 2")},
        },
    },
})

// Create the menu
m.Create()

Dialogs

Error box
// This will wait for the astilectron namespace to be ready
document.addEventListener('astilectron-ready', function() {
    // This will open the dialog
    astilectron.showErrorBox("My Title", "My content")
})
Message box
// This will wait for the astilectron namespace to be ready
document.addEventListener('astilectron-ready', function() {
    // This will open the dialog
    astilectron.showMessageBox({message: "My message", title: "My Title"})
})
Open dialog
// This will wait for the astilectron namespace to be ready
document.addEventListener('astilectron-ready', function() {
    // This will open the dialog
    astilectron.showOpenDialog({properties: ['openFile', 'multiSelections'], title: "My Title"}, function(paths) {
        console.log("chosen paths are ", paths)
    })
})
Save dialog
// This will wait for the astilectron namespace to be ready
document.addEventListener('astilectron-ready', function() {
    // This will open the dialog
    astilectron.showSaveDialog({title: "My title"}, function(filename) {
        console.log("chosen filename is ", filename)
    })
})

Basic auth

// Listen to login events
w.OnLogin(func(i astilectron.Event) (username, password string, err error) {
	// Process the request and auth info
	if i.Request.Method == "GET" && i.AuthInfo.Scheme == "http://" {
		username = "username"
		password = "password"
	}
    return
})

Features and roadmap

  • custom branding (custom app name, app icon, etc.)
  • window basic methods (create, show, close, resize, minimize, maximize, ...)
  • window basic events (close, blur, focus, unresponsive, crashed, ...)
  • remote messaging (messages between GO and Javascript)
  • single binary distribution
  • multi screens/displays
  • menu methods and events (create, insert, append, popup, clicked, ...)
  • bootstrap
  • dialogs (open or save file, alerts, ...)
  • tray
  • bundler
  • session
  • accelerators (shortcuts)
  • dock
  • notifications
  • loader
  • file methods (drag & drop, ...)
  • clipboard methods
  • power monitor events (suspend, resume, ...)
  • desktop capturer (audio and video)
  • window advanced options (add missing ones)
  • window advanced methods (add missing ones)
  • window advanced events (add missing ones)
  • child windows

Cheers to

go-thrust which is awesome but unfortunately not maintained anymore. It inspired this project.

Documentation

Index

Constants

View Source
const (
	DefaultAcceptTCPTimeout   = 30 * time.Second
	DefaultVersionAstilectron = "0.33.0"
	DefaultVersionElectron    = "4.0.1"
)

Versions

View Source
const (
	EventNameAppClose         = "app.close"
	EventNameAppCmdQuit       = "app.cmd.quit" // Sends an event to Electron to properly quit the app
	EventNameAppCmdStop       = "app.cmd.stop" // Cancel the context which results in exiting abruptly Electron's app
	EventNameAppCrash         = "app.crash"
	EventNameAppErrorAccept   = "app.error.accept"
	EventNameAppEventReady    = "app.event.ready"
	EventNameAppNoAccept      = "app.no.accept"
	EventNameAppTooManyAccept = "app.too.many.accept"
)

App event names

View Source
const (
	MessageBoxTypeError    = "error"
	MessageBoxTypeInfo     = "info"
	MessageBoxTypeNone     = "none"
	MessageBoxTypeQuestion = "question"
	MessageBoxTypeWarning  = "warning"
)

Message box types

View Source
const (
	EventNameDisplayEventAdded          = "display.event.added"
	EventNameDisplayEventMetricsChanged = "display.event.metrics.changed"
	EventNameDisplayEventRemoved        = "display.event.removed"
)

Display event names

View Source
const (
	DockBounceTypeCritical      = "critical"
	DockBounceTypeInformational = "informational"
)

Dock bounce types

View Source
const (
	EventNameMenuCmdCreate      = "menu.cmd.create"
	EventNameMenuCmdDestroy     = "menu.cmd.destroy"
	EventNameMenuEventCreated   = "menu.event.created"
	EventNameMenuEventDestroyed = "menu.event.destroyed"
)

Menu event names

View Source
const (
	EventNameMenuItemCmdSetChecked   = "menu.item.cmd.set.checked"
	EventNameMenuItemCmdSetEnabled   = "menu.item.cmd.set.enabled"
	EventNameMenuItemCmdSetLabel     = "menu.item.cmd.set.label"
	EventNameMenuItemCmdSetVisible   = "menu.item.cmd.set.visible"
	EventNameMenuItemEventCheckedSet = "menu.item.event.checked.set"
	EventNameMenuItemEventClicked    = "menu.item.event.clicked"
	EventNameMenuItemEventEnabledSet = "menu.item.event.enabled.set"
	EventNameMenuItemEventLabelSet   = "menu.item.event.label.set"
	EventNameMenuItemEventVisibleSet = "menu.item.event.visible.set"
)

Menu item event names

View Source
const (
	EventNameNotificationEventClicked = "notification.event.clicked"
	EventNameNotificationEventClosed  = "notification.event.closed"
	EventNameNotificationEventCreated = "notification.event.created"
	EventNameNotificationEventReplied = "notification.event.replied"
	EventNameNotificationEventShown   = "notification.event.shown"
)

Notification event names

View Source
const (
	EventNameSessionCmdClearCache     = "session.cmd.clear.cache"
	EventNameSessionEventClearedCache = "session.event.cleared.cache"
	EventNameSessionEventWillDownload = "session.event.will.download"
)

Session event names

View Source
const (
	EventNameSubMenuCmdAppend        = "sub.menu.cmd.append"
	EventNameSubMenuCmdClosePopup    = "sub.menu.cmd.close.popup"
	EventNameSubMenuCmdInsert        = "sub.menu.cmd.insert"
	EventNameSubMenuCmdPopup         = "sub.menu.cmd.popup"
	EventNameSubMenuEventAppended    = "sub.menu.event.appended"
	EventNameSubMenuEventClosedPopup = "sub.menu.event.closed.popup"
	EventNameSubMenuEventInserted    = "sub.menu.event.inserted"
	EventNameSubMenuEventPoppedUp    = "sub.menu.event.popped.up"
)

Sub menu event names

View Source
const (
	EventNameTrayCmdCreate          = "tray.cmd.create"
	EventNameTrayCmdDestroy         = "tray.cmd.destroy"
	EventNameTrayCmdSetImage        = "tray.cmd.set.image"
	EventNameTrayEventClicked       = "tray.event.clicked"
	EventNameTrayEventCreated       = "tray.event.created"
	EventNameTrayEventDestroyed     = "tray.event.destroyed"
	EventNameTrayEventDoubleClicked = "tray.event.double.clicked"
	EventNameTrayEventImageSet      = "tray.event.image.set"
	EventNameTrayEventRightClicked  = "tray.event.right.clicked"
)

Tray event names

View Source
const (
	EventNameWebContentsEventLogin         = "web.contents.event.login"
	EventNameWebContentsEventLoginCallback = "web.contents.event.login.callback"
	EventNameWindowCmdBlur                 = "window.cmd.blur"
	EventNameWindowCmdCenter               = "window.cmd.center"
	EventNameWindowCmdClose                = "window.cmd.close"
	EventNameWindowCmdCreate               = "window.cmd.create"
	EventNameWindowCmdDestroy              = "window.cmd.destroy"
	EventNameWindowCmdFocus                = "window.cmd.focus"
	EventNameWindowCmdHide                 = "window.cmd.hide"
	EventNameWindowCmdLog                  = "window.cmd.log"
	EventNameWindowCmdMaximize             = "window.cmd.maximize"

	EventNameWindowCmdMinimize                 = "window.cmd.minimize"
	EventNameWindowCmdMove                     = "window.cmd.move"
	EventNameWindowCmdResize                   = "window.cmd.resize"
	EventNameWindowCmdSetBounds                = "window.cmd.set.bounds"
	EventNameWindowCmdRestore                  = "window.cmd.restore"
	EventNameWindowCmdShow                     = "window.cmd.show"
	EventNameWindowCmdUnmaximize               = "window.cmd.unmaximize"
	EventNameWindowCmdWebContentsCloseDevTools = "window.cmd.web.contents.close.dev.tools"
	EventNameWindowCmdWebContentsOpenDevTools  = "window.cmd.web.contents.open.dev.tools"
	EventNameWindowEventBlur                   = "window.event.blur"
	EventNameWindowEventClosed                 = "window.event.closed"
	EventNameWindowEventDidFinishLoad          = "window.event.did.finish.load"
	EventNameWindowEventFocus                  = "window.event.focus"
	EventNameWindowEventHide                   = "window.event.hide"
	EventNameWindowEventMaximize               = "window.event.maximize"

	EventNameWindowEventMinimize              = "window.event.minimize"
	EventNameWindowEventMove                  = "window.event.move"
	EventNameWindowEventReadyToShow           = "window.event.ready.to.show"
	EventNameWindowEventResize                = "window.event.resize"
	EventNameWindowEventRestore               = "window.event.restore"
	EventNameWindowEventShow                  = "window.event.show"
	EventNameWindowEventUnmaximize            = "window.event.unmaximize"
	EventNameWindowEventUnresponsive          = "window.event.unresponsive"
	EventNameWindowEventDidGetRedirectRequest = "window.event.did.get.redirect.request"
	EventNameWindowEventWillNavigate          = "window.event.will.navigate"
)

Window event names

Variables

View Source
var (
	// All
	MenuItemRoleClose              = PtrStr("close")
	MenuItemRoleCopy               = PtrStr("copy")
	MenuItemRoleCut                = PtrStr("cut")
	MenuItemRoleDelete             = PtrStr("delete")
	MenuItemRoleEditMenu           = PtrStr("editMenu")
	MenuItemRoleForceReload        = PtrStr("forcereload")
	MenuItemRoleMinimize           = PtrStr("minimize")
	MenuItemRolePaste              = PtrStr("paste")
	MenuItemRolePasteAndMatchStyle = PtrStr("pasteandmatchstyle")
	MenuItemRoleQuit               = PtrStr("quit")
	MenuItemRoleRedo               = PtrStr("redo")
	MenuItemRoleReload             = PtrStr("reload")
	MenuItemRoleResetZoom          = PtrStr("resetzoom")
	MenuItemRoleSelectAll          = PtrStr("selectall")
	MenuItemRoleToggleDevTools     = PtrStr("toggledevtools")
	MenuItemRoleToggleFullScreen   = PtrStr("togglefullscreen")
	MenuItemRoleUndo               = PtrStr("undo")
	MenuItemRoleWindowMenu         = PtrStr("windowMenu")
	MenuItemRoleZoomOut            = PtrStr("zoomout")
	MenuItemRoleZoomIn             = PtrStr("zoomin")

	// MacOSX
	MenuItemRoleAbout         = PtrStr("about")
	MenuItemRoleHide          = PtrStr("hide")
	MenuItemRoleHideOthers    = PtrStr("hideothers")
	MenuItemRoleUnhide        = PtrStr("unhide")
	MenuItemRoleStartSpeaking = PtrStr("startspeaking")
	MenuItemRoleStopSpeaking  = PtrStr("stopspeaking")
	MenuItemRoleFront         = PtrStr("front")
	MenuItemRoleZoom          = PtrStr("zoom")
	MenuItemRoleWindow        = PtrStr("window")
	MenuItemRoleHelp          = PtrStr("help")
	MenuItemRoleServices      = PtrStr("services")
)

Menu item roles

View Source
var (
	MenuItemTypeNormal    = PtrStr("normal")
	MenuItemTypeSeparator = PtrStr("separator")
	MenuItemTypeCheckbox  = PtrStr("checkbox")
	MenuItemTypeRadio     = PtrStr("radio")
)

Menu item types

View Source
var (
	ErrCancellerCancelled = errors.New("canceller.cancelled")
	ErrObjectDestroyed    = errors.New("object.destroyed")
)

Object errors

View Source
var (
	TitleBarStyleDefault     = PtrStr("default")
	TitleBarStyleHidden      = PtrStr("hidden")
	TitleBarStyleHiddenInset = PtrStr("hidden-inset")
)

Title bar styles

View Source
var DefaultProvisioner = &defaultProvisioner{
	moverAstilectron: func(ctx context.Context, p Paths) (err error) {
		if err = Download(ctx, defaultHTTPClient, p.AstilectronDownloadSrc(), p.AstilectronDownloadDst()); err != nil {
			return errors.Wrapf(err, "downloading %s into %s failed", p.AstilectronDownloadSrc(), p.AstilectronDownloadDst())
		}
		return
	},
	moverElectron: func(ctx context.Context, p Paths) (err error) {
		if err = Download(ctx, defaultHTTPClient, p.ElectronDownloadSrc(), p.ElectronDownloadDst()); err != nil {
			return errors.Wrapf(err, "downloading %s into %s failed", p.ElectronDownloadSrc(), p.ElectronDownloadDst())
		}
		return
	},
}

DefaultProvisioner represents the default provisioner

Functions

func AstilectronDownloadSrc added in v0.5.0

func AstilectronDownloadSrc(versionAstilectron string) string

AstilectronDownloadSrc returns the download URL of the (currently platform-independent) astilectron zip file

func DefaultExecuter added in v0.6.0

func DefaultExecuter(a *Astilectron, cmd *exec.Cmd) (err error)

DefaultExecuter represents the default executer

func Disembed added in v0.2.0

func Disembed(ctx context.Context, d Disembedder, src, dst string) (err error)

Disembed is a cancellable disembed of an src to a dst using a custom Disembedder

func Download

func Download(ctx context.Context, c *http.Client, src, dst string) (err error)

Download is a cancellable function that downloads a src into a dst using a specific *http.Client and cleans up on failed downloads

func ElectronDownloadSrc added in v0.5.0

func ElectronDownloadSrc(os, arch, versionElectron string) string

ElectronDownloadSrc returns the download URL of the platform-dependant electron zipfile

func IsValidOS added in v0.6.0

func IsValidOS(os string) (ok bool)

IsValidOS validates the OS

func PtrBool

func PtrBool(i bool) *bool

PtrBool transforms a bool into a *bool

func PtrFloat added in v0.2.0

func PtrFloat(i float64) *float64

PtrFloat transforms a float64 into a *float64

func PtrInt

func PtrInt(i int) *int

PtrInt transforms an int into an *int

func PtrInt64 added in v0.5.0

func PtrInt64(i int64) *int64

PtrInt64 transforms an int64 into an *int64

func PtrStr

func PtrStr(i string) *string

PtrStr transforms a string into a *string

func Unzip

func Unzip(ctx context.Context, src, dst string) (err error)

Unzip unzips a src into a dst. Possible src formats are /path/to/zip.zip or /path/to/zip.zip/internal/path.

Types

type Accelerator added in v0.6.0

type Accelerator []string

Accelerator represents an accelerator https://github.com/electron/electron/blob/v1.8.1/docs/api/accelerator.md

func NewAccelerator added in v0.6.0

func NewAccelerator(items ...string) (a *Accelerator)

NewAccelerator creates a new accelerator

func (*Accelerator) MarshalText added in v0.6.0

func (a *Accelerator) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface

func (*Accelerator) UnmarshalText added in v0.6.0

func (a *Accelerator) UnmarshalText(b []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface

type Astilectron

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

Astilectron represents an object capable of interacting with Astilectron

func New

func New(o Options) (a *Astilectron, err error)

New creates a new Astilectron instance

func (*Astilectron) Close

func (a *Astilectron) Close()

Close closes Astilectron properly

func (*Astilectron) Displays added in v0.2.0

func (a *Astilectron) Displays() []*Display

Displays returns the displays

func (*Astilectron) Dock added in v0.6.0

func (a *Astilectron) Dock() *Dock

Dock returns the dock

func (*Astilectron) HandleSignals

func (a *Astilectron) HandleSignals()

HandleSignals handles signals

func (*Astilectron) NewMenu added in v0.2.0

func (a *Astilectron) NewMenu(i []*MenuItemOptions) *Menu

NewMenu creates a new app menu

func (*Astilectron) NewNotification added in v0.6.0

func (a *Astilectron) NewNotification(o *NotificationOptions) *Notification

NewNotification creates a new notification

func (*Astilectron) NewTray added in v0.5.0

func (a *Astilectron) NewTray(o *TrayOptions) *Tray

NewTray creates a new tray

func (*Astilectron) NewWindow

func (a *Astilectron) NewWindow(url string, o *WindowOptions) (*Window, error)

NewWindow creates a new window

func (*Astilectron) NewWindowInDisplay added in v0.2.0

func (a *Astilectron) NewWindowInDisplay(d *Display, url string, o *WindowOptions) (*Window, error)

NewWindowInDisplay creates a new window in a specific display This overrides the center attribute

func (*Astilectron) On

func (a *Astilectron) On(eventName string, l Listener)

On implements the Listenable interface

func (*Astilectron) Paths added in v0.6.0

func (a *Astilectron) Paths() Paths

Paths returns the paths

func (*Astilectron) PrimaryDisplay added in v0.2.0

func (a *Astilectron) PrimaryDisplay() *Display

PrimaryDisplay returns the primary display

func (*Astilectron) Quit added in v0.6.0

func (a *Astilectron) Quit() error

Quit quits the app

func (*Astilectron) SetExecuter added in v0.6.0

func (a *Astilectron) SetExecuter(e Executer) *Astilectron

SetExecuter sets the executer

func (*Astilectron) SetProvisioner

func (a *Astilectron) SetProvisioner(p Provisioner) *Astilectron

SetProvisioner sets the provisioner

func (*Astilectron) Start

func (a *Astilectron) Start() (err error)

Start starts Astilectron

func (*Astilectron) Stop

func (a *Astilectron) Stop()

Stop orders Astilectron to stop

func (*Astilectron) Wait

func (a *Astilectron) Wait()

Wait is a blocking pattern

type CallbackMessage added in v0.6.0

type CallbackMessage func(m *EventMessage)

CallbackMessage represents a message callback

type Disembedder added in v0.2.0

type Disembedder func(src string) ([]byte, error)

Disembedder is a functions that allows to disembed data from a path

type Display added in v0.2.0

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

Display represents a display https://github.com/electron/electron/blob/v1.8.1/docs/api/structures/display.md

func (Display) Bounds added in v0.2.0

func (d Display) Bounds() Rectangle

Bounds returns the display bounds

func (Display) IsPrimary added in v0.2.0

func (d Display) IsPrimary() bool

IsPrimary checks whether the display is the primary display

func (Display) IsTouchAvailable added in v0.2.0

func (d Display) IsTouchAvailable() bool

IsTouchAvailable checks whether touch is available on this display

func (Display) Rotation added in v0.2.0

func (d Display) Rotation() int

Rotation returns the display rotation

func (Display) ScaleFactor added in v0.2.0

func (d Display) ScaleFactor() float64

ScaleFactor returns the display scale factor

func (Display) Size added in v0.2.0

func (d Display) Size() Size

Size returns the display size

func (Display) WorkArea added in v0.2.0

func (d Display) WorkArea() Rectangle

WorkArea returns the display work area

func (Display) WorkAreaSize added in v0.2.0

func (d Display) WorkAreaSize() Size

WorkAreaSize returns the display work area size

type DisplayOptions added in v0.2.0

type DisplayOptions struct {
	Bounds       *RectangleOptions `json:"bounds,omitempty"`
	ID           *int64            `json:"id,omitempty"`
	Rotation     *int              `json:"rotation,omitempty"` // 0, 90, 180 or 270
	ScaleFactor  *float64          `json:"scaleFactor,omitempty"`
	Size         *SizeOptions      `json:"size,omitempty"`
	TouchSupport *string           `json:"touchSupport,omitempty"` // available, unavailable or unknown
	WorkArea     *RectangleOptions `json:"workArea,omitempty"`
	WorkAreaSize *SizeOptions      `json:"workAreaSize,omitempty"`
}

DisplayOptions represents display options https://github.com/electron/electron/blob/v1.8.1/docs/api/structures/display.md

type Dock added in v0.6.0

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

Dock represents a dock https://github.com/electron/electron/blob/v1.8.1/docs/api/app.md#appdockbouncetype-macos

func (*Dock) Bounce added in v0.6.0

func (d *Dock) Bounce(bounceType string) (id int, err error)

Bounce bounces the dock

func (*Dock) BounceDownloads added in v0.6.0

func (d *Dock) BounceDownloads(filePath string) (err error)

BounceDownloads bounces the downloads part of the dock

func (*Dock) CancelBounce added in v0.6.0

func (d *Dock) CancelBounce(id int) (err error)

CancelBounce cancels the dock bounce

func (*Dock) Hide added in v0.6.0

func (d *Dock) Hide() (err error)

Hide hides the dock

func (Dock) IsDestroyed added in v0.6.0

func (o Dock) IsDestroyed() bool

IsDestroyed checks whether the window has been destroyed

func (*Dock) NewMenu added in v0.6.0

func (d *Dock) NewMenu(i []*MenuItemOptions) *Menu

NewMenu creates a new dock menu

func (Dock) On added in v0.6.0

func (o Dock) On(eventName string, l Listener)

On implements the Listenable interface

func (*Dock) SetBadge added in v0.6.0

func (d *Dock) SetBadge(badge string) (err error)

SetBadge sets the badge of the dock

func (*Dock) SetIcon added in v0.6.0

func (d *Dock) SetIcon(image string) (err error)

SetIcon sets the icon of the dock

func (*Dock) Show added in v0.6.0

func (d *Dock) Show() (err error)

Show shows the dock

type Event

type Event struct {
	// This is the base of the event
	Name     string `json:"name"`
	TargetID string `json:"targetID,omitempty"`

	// This is a list of all possible payloads.
	// A choice was made not to use interfaces since it's a pain in the ass asserting each an every payload afterwards
	// We use pointers so that omitempty works
	AuthInfo            *EventAuthInfo       `json:"authInfo,omitempty"`
	Badge               string               `json:"badge,omitempty"`
	BounceType          string               `json:"bounceType,omitempty"`
	Bounds              *RectangleOptions    `json:"bounds,omitempty"`
	CallbackID          string               `json:"callbackId,omitempty"`
	Displays            *EventDisplays       `json:"displays,omitempty"`
	FilePath            string               `json:"filePath,omitempty"`
	ID                  *int                 `json:"id,omitempty"`
	Image               string               `json:"image,omitempty"`
	Index               *int                 `json:"index,omitempty"`
	Menu                *EventMenu           `json:"menu,omitempty"`
	MenuItem            *EventMenuItem       `json:"menuItem,omitempty"`
	MenuItemOptions     *MenuItemOptions     `json:"menuItemOptions,omitempty"`
	MenuItemPosition    *int                 `json:"menuItemPosition,omitempty"`
	MenuPopupOptions    *MenuPopupOptions    `json:"menuPopupOptions,omitempty"`
	Message             *EventMessage        `json:"message,omitempty"`
	NotificationOptions *NotificationOptions `json:"notificationOptions,omitempty"`
	Password            string               `json:"password,omitempty"`
	Reply               string               `json:"reply,omitempty"`
	Request             *EventRequest        `json:"request,omitempty"`
	SessionID           string               `json:"sessionId,omitempty"`
	Supported           *Supported           `json:"supported,omitempty"`
	TrayOptions         *TrayOptions         `json:"trayOptions,omitempty"`
	URL                 string               `json:"url,omitempty"`
	URLNew              string               `json:"newUrl,omitempty"`
	URLOld              string               `json:"oldUrl,omitempty"`
	Username            string               `json:"username,omitempty"`
	WindowID            string               `json:"windowId,omitempty"`
	WindowOptions       *WindowOptions       `json:"windowOptions,omitempty"`
}

Event represents an event

type EventAuthInfo added in v0.6.0

type EventAuthInfo struct {
	Host    string `json:"host,omitempty"`
	IsProxy *bool  `json:"isProxy,omitempty"`
	Port    *int   `json:"port,omitempty"`
	Realm   string `json:"realm,omitempty"`
	Scheme  string `json:"scheme,omitempty"`
}

EventAuthInfo represents an event auth info

type EventDisplays added in v0.2.0

type EventDisplays struct {
	All     []*DisplayOptions `json:"all,omitempty"`
	Primary *DisplayOptions   `json:"primary,omitempty"`
}

EventDisplays represents events displays

type EventMenu added in v0.2.0

type EventMenu struct {
	*EventSubMenu
}

EventMenu represents an event menu

type EventMenuItem added in v0.2.0

type EventMenuItem struct {
	ID      string           `json:"id"`
	Options *MenuItemOptions `json:"options,omitempty"`
	RootID  string           `json:"rootId"`
	SubMenu *EventSubMenu    `json:"submenu,omitempty"`
}

EventMenuItem represents an event menu item

type EventMessage

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

EventMessage represents an event message

func (*EventMessage) MarshalJSON

func (p *EventMessage) MarshalJSON() ([]byte, error)

MarshalJSON implements the JSONMarshaler interface

func (*EventMessage) Unmarshal

func (p *EventMessage) Unmarshal(i interface{}) error

Unmarshal unmarshals the payload into the given interface

func (*EventMessage) UnmarshalJSON

func (p *EventMessage) UnmarshalJSON(i []byte) error

UnmarshalJSON implements the JSONUnmarshaler interface

type EventRequest added in v0.6.0

type EventRequest struct {
	Method   string `json:"method,omitempty"`
	Referrer string `json:"referrer,omitempty"`
	URL      string `json:"url,omitempty"`
}

EventRequest represents an event request

type EventSubMenu added in v0.2.0

type EventSubMenu struct {
	ID     string           `json:"id"`
	Items  []*EventMenuItem `json:"items,omitempty"`
	RootID string           `json:"rootId"`
}

EventSubMenu represents a sub menu event

type Executer added in v0.6.0

type Executer func(a *Astilectron, cmd *exec.Cmd) (err error)

Executer represents an object capable of executing Astilectron run command

type Listener

type Listener func(e Event) (deleteListener bool)

Listener represents a listener executed when an event is dispatched

type ListenerMessage added in v0.6.0

type ListenerMessage func(m *EventMessage) (v interface{})

ListenerMessage represents a message listener executed when receiving a message from the JS

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

Menu represents a menu https://github.com/electron/electron/blob/v1.8.1/docs/api/menu.md

func (m Menu) Append(i *MenuItem) (err error)

Append appends a menu item into the sub menu

func (m Menu) ClosePopup() error

ClosePopup close the context menu in the focused window

func (m Menu) ClosePopupInWindow(w *Window) (err error)

ClosePopupInWindow close the context menu in the specified window

func (m *Menu) Create() (err error)

Create creates the menu

func (m *Menu) Destroy() (err error)

Destroy destroys the menu

func (m Menu) Insert(pos int, i *MenuItem) (err error)

Insert inserts a menu item to the position of the sub menu

func (m Menu) Item(indexes ...int) (mi *MenuItem, err error)

Item returns the item at the specified indexes

func (m Menu) NewItem(o *MenuItemOptions) *MenuItem

NewItem returns a new menu item

func (m Menu) Popup(o *MenuPopupOptions) error

Popup pops up the menu as a context menu in the focused window

func (m Menu) PopupInWindow(w *Window, o *MenuPopupOptions) (err error)

PopupInWindow pops up the menu as a context menu in the specified window

func (m Menu) SubMenu(indexes ...int) (s *SubMenu, err error)

SubMenu returns the sub menu at the specified indexes

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

MenuItem represents a menu item

func (o MenuItem) IsDestroyed() bool

IsDestroyed checks whether the window has been destroyed

func (o MenuItem) On(eventName string, l Listener)

On implements the Listenable interface

func (i *MenuItem) SetChecked(checked bool) (err error)

SetChecked sets the checked attribute

func (i *MenuItem) SetEnabled(enabled bool) (err error)

SetEnabled sets the enabled attribute

func (i *MenuItem) SetLabel(label string) (err error)

SetLabel sets the label attribute

func (i *MenuItem) SetVisible(visible bool) (err error)

SetVisible sets the visible attribute

func (i *MenuItem) SubMenu() *SubMenu

SubMenu returns the menu item sub menu

type MenuItemOptions struct {
	Accelerator *Accelerator       `json:"accelerator,omitempty"`
	Checked     *bool              `json:"checked,omitempty"`
	Enabled     *bool              `json:"enabled,omitempty"`
	Icon        *string            `json:"icon,omitempty"`
	Label       *string            `json:"label,omitempty"`
	OnClick     Listener           `json:"-"`
	Position    *string            `json:"position,omitempty"`
	Role        *string            `json:"role,omitempty"`
	SubLabel    *string            `json:"sublabel,omitempty"`
	SubMenu     []*MenuItemOptions `json:"-"`
	Type        *string            `json:"type,omitempty"`
	Visible     *bool              `json:"visible,omitempty"`
}

MenuItemOptions represents menu item options We must use pointers since GO doesn't handle optional fields whereas NodeJS does. Use PtrBool, PtrInt or PtrStr to fill the struct https://github.com/electron/electron/blob/v1.8.1/docs/api/menu-item.md

type MenuPopupOptions struct {
	PositionOptions
	PositioningItem *int `json:"positioningItem,omitempty"`
}

MenuPopupOptions represents menu pop options

type MessageBoxOptions added in v0.6.0

type MessageBoxOptions struct {
	Buttons         []string `json:"buttons,omitempty"`
	CancelID        *int     `json:"cancelId,omitempty"`
	CheckboxChecked *bool    `json:"checkboxChecked,omitempty"`
	CheckboxLabel   string   `json:"checkboxLabel,omitempty"`
	ConfirmID       *int     `json:"confirmId,omitempty"`
	DefaultID       *int     `json:"defaultId,omitempty"`
	Detail          string   `json:"detail,omitempty"`
	Icon            string   `json:"icon,omitempty"`
	Message         string   `json:"message,omitempty"`
	NoLink          *bool    `json:"noLink,omitempty"`
	Title           string   `json:"title,omitempty"`
	Type            string   `json:"type,omitempty"`
}

MessageBoxOptions represents message box options We must use pointers since GO doesn't handle optional fields whereas NodeJS does. Use PtrBool, PtrInt or PtrStr to fill the struct https://github.com/electron/electron/blob/v1.8.1/docs/api/dialog.md#dialogshowmessageboxbrowserwindow-options-callback

type Notification added in v0.6.0

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

Notification represents a notification https://github.com/electron/electron/blob/v1.8.1/docs/api/notification.md

func (*Notification) Create added in v0.6.0

func (n *Notification) Create() (err error)

Create creates the notification

func (Notification) IsDestroyed added in v0.6.0

func (o Notification) IsDestroyed() bool

IsDestroyed checks whether the window has been destroyed

func (Notification) On added in v0.6.0

func (o Notification) On(eventName string, l Listener)

On implements the Listenable interface

func (*Notification) Show added in v0.6.0

func (n *Notification) Show() (err error)

Show shows the notification

type NotificationOptions added in v0.6.0

type NotificationOptions struct {
	Body             string `json:"body,omitempty"`
	HasReply         *bool  `json:"hasReply,omitempty"`
	Icon             string `json:"icon,omitempty"`
	ReplyPlaceholder string `json:"replyPlaceholder,omitempty"`
	Silent           *bool  `json:"silent,omitempty"`
	Sound            string `json:"sound,omitempty"`
	Subtitle         string `json:"subtitle,omitempty"`
	Title            string `json:"title,omitempty"`
}

NotificationOptions represents notification options

type Options

type Options struct {
	AcceptTCPTimeout   time.Duration
	AppName            string
	AppIconDarwinPath  string // Darwin systems requires a specific .icns file
	AppIconDefaultPath string
	BaseDirectoryPath  string
	DataDirectoryPath  string
	ElectronSwitches   []string
	SingleInstance     bool
	SkipSetup          bool // If true, the user must handle provisioning and executing astilectron.
	TCPPort            *int // The port to listen on.
	VersionAstilectron string
	VersionElectron    string
}

Options represents Astilectron options

type Paths

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

Paths represents the set of paths needed by Astilectron

func (Paths) AppExecutable added in v0.2.0

func (p Paths) AppExecutable() string

AppExecutable returns the app executable path

func (Paths) AppIconDarwinSrc added in v0.2.0

func (p Paths) AppIconDarwinSrc() string

AppIconDarwinSrc returns the darwin app icon path

func (Paths) AppIconDefaultSrc added in v0.6.0

func (p Paths) AppIconDefaultSrc() string

AppIconDefaultSrc returns the default app icon path

func (Paths) AstilectronApplication

func (p Paths) AstilectronApplication() string

AstilectronApplication returns the astilectron application path

func (Paths) AstilectronDirectory

func (p Paths) AstilectronDirectory() string

AstilectronDirectory returns the astilectron directory path

func (Paths) AstilectronDownloadDst

func (p Paths) AstilectronDownloadDst() string

AstilectronDownloadDst returns the astilectron download destination path

func (Paths) AstilectronDownloadSrc

func (p Paths) AstilectronDownloadSrc() string

AstilectronDownloadSrc returns the astilectron download source path

func (Paths) AstilectronUnzipSrc

func (p Paths) AstilectronUnzipSrc() string

AstilectronUnzipSrc returns the astilectron unzip source path

func (Paths) BaseDirectory

func (p Paths) BaseDirectory() string

BaseDirectory returns the base directory path

func (Paths) DataDirectory added in v0.6.0

func (p Paths) DataDirectory() string

DataDirectory returns the data directory path

func (Paths) ElectronDirectory

func (p Paths) ElectronDirectory() string

ElectronDirectory returns the electron directory path

func (Paths) ElectronDownloadDst

func (p Paths) ElectronDownloadDst() string

ElectronDownloadDst returns the electron download destination path

func (Paths) ElectronDownloadSrc

func (p Paths) ElectronDownloadSrc() string

ElectronDownloadSrc returns the electron download source path

func (Paths) ElectronUnzipSrc

func (p Paths) ElectronUnzipSrc() string

ElectronUnzipSrc returns the electron unzip source path

func (Paths) ProvisionStatus added in v0.2.0

func (p Paths) ProvisionStatus() string

ProvisionStatus returns the provision status path

func (Paths) VendorDirectory

func (p Paths) VendorDirectory() string

VendorDirectory returns the vendor directory path

type Position added in v0.2.0

type Position struct {
	X, Y int
}

Position represents a position

type PositionOptions added in v0.2.0

type PositionOptions struct {
	X *int `json:"x,omitempty"`
	Y *int `json:"y,omitempty"`
}

PositionOptions represents position options

type ProvisionStatus added in v0.2.0

type ProvisionStatus struct {
	Astilectron *ProvisionStatusPackage            `json:"astilectron,omitempty"`
	Electron    map[string]*ProvisionStatusPackage `json:"electron,omitempty"`
}

ProvisionStatus represents the provision status

type ProvisionStatusPackage added in v0.2.0

type ProvisionStatusPackage struct {
	Version string `json:"version"`
}

ProvisionStatusPackage represents the provision status of a package

type Provisioner

type Provisioner interface {
	Provision(ctx context.Context, appName, os, arch, versionAstilectron, versionElectron string, p Paths) error
}

Provisioner represents an object capable of provisioning Astilectron

func NewDisembedderProvisioner added in v0.2.0

func NewDisembedderProvisioner(d Disembedder, pathAstilectron, pathElectron string) Provisioner

NewDisembedderProvisioner creates a provisioner that can provision based on embedded data

type Rectangle added in v0.2.0

type Rectangle struct {
	Position
	Size
}

Rectangle represents a rectangle

type RectangleOptions added in v0.2.0

type RectangleOptions struct {
	PositionOptions
	SizeOptions
}

RectangleOptions represents rectangle options

type Session added in v0.6.0

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

Session represents a session TODO Add missing session methods TODO Add missing session events https://github.com/electron/electron/blob/v1.8.1/docs/api/session.md

func (*Session) ClearCache added in v0.6.0

func (s *Session) ClearCache() (err error)

ClearCache clears the Session's HTTP cache

func (Session) IsDestroyed added in v0.6.0

func (o Session) IsDestroyed() bool

IsDestroyed checks whether the window has been destroyed

func (Session) On added in v0.6.0

func (o Session) On(eventName string, l Listener)

On implements the Listenable interface

type Size added in v0.2.0

type Size struct {
	Height, Width int
}

Size represents a size

type SizeOptions added in v0.2.0

type SizeOptions struct {
	Height *int `json:"height,omitempty"`
	Width  *int `json:"width,omitempty"`
}

SizeOptions represents size options

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

SubMenu represents an exported sub menu

func (m SubMenu) Append(i *MenuItem) (err error)

Append appends a menu item into the sub menu

func (m SubMenu) ClosePopup() error

ClosePopup close the context menu in the focused window

func (m SubMenu) ClosePopupInWindow(w *Window) (err error)

ClosePopupInWindow close the context menu in the specified window

func (m SubMenu) Insert(pos int, i *MenuItem) (err error)

Insert inserts a menu item to the position of the sub menu

func (m SubMenu) Item(indexes ...int) (mi *MenuItem, err error)

Item returns the item at the specified indexes

func (m SubMenu) NewItem(o *MenuItemOptions) *MenuItem

NewItem returns a new menu item

func (m SubMenu) Popup(o *MenuPopupOptions) error

Popup pops up the menu as a context menu in the focused window

func (m SubMenu) PopupInWindow(w *Window, o *MenuPopupOptions) (err error)

PopupInWindow pops up the menu as a context menu in the specified window

func (m SubMenu) SubMenu(indexes ...int) (s *SubMenu, err error)

SubMenu returns the sub menu at the specified indexes

type Supported added in v0.6.0

type Supported struct {
	Notification *bool `json:"notification"`
}

Supported represents Astilectron supported features

type Tray added in v0.5.0

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

Tray represents a tray

func (*Tray) Create added in v0.5.0

func (t *Tray) Create() (err error)

Create creates the tray

func (*Tray) Destroy added in v0.5.0

func (t *Tray) Destroy() (err error)

Destroy destroys the tray

func (Tray) IsDestroyed added in v0.5.0

func (o Tray) IsDestroyed() bool

IsDestroyed checks whether the window has been destroyed

func (*Tray) NewMenu added in v0.5.0

func (t *Tray) NewMenu(i []*MenuItemOptions) *Menu

NewMenu creates a new tray menu

func (Tray) On added in v0.5.0

func (o Tray) On(eventName string, l Listener)

On implements the Listenable interface

func (*Tray) SetImage added in v0.6.0

func (t *Tray) SetImage(image string) (err error)

SetImage sets the tray image

type TrayOptions added in v0.5.0

type TrayOptions struct {
	Image   *string `json:"image,omitempty"`
	Tooltip *string `json:"tooltip,omitempty"`
}

TrayOptions represents tray options We must use pointers since GO doesn't handle optional fields whereas NodeJS does. Use PtrBool, PtrInt or PtrStr to fill the struct https://github.com/electron/electron/blob/v1.8.1/docs/api/tray.md

type WebPreferences added in v0.5.0

type WebPreferences struct {
	AllowRunningInsecureContent *bool                  `json:"allowRunningInsecureContent,omitempty"`
	BackgroundThrottling        *bool                  `json:"backgroundThrottling,omitempty"`
	BlinkFeatures               *string                `json:"blinkFeatures,omitempty"`
	ContextIsolation            *bool                  `json:"contextIsolation,omitempty"`
	DefaultEncoding             *string                `json:"defaultEncoding,omitempty"`
	DefaultFontFamily           map[string]interface{} `json:"defaultFontFamily,omitempty"`
	DefaultFontSize             *int                   `json:"defaultFontSize,omitempty"`
	DefaultMonospaceFontSize    *int                   `json:"defaultMonospaceFontSize,omitempty"`
	DevTools                    *bool                  `json:"devTools,omitempty"`
	DisableBlinkFeatures        *string                `json:"disableBlinkFeatures,omitempty"`
	ExperimentalCanvasFeatures  *bool                  `json:"experimentalCanvasFeatures,omitempty"`
	ExperimentalFeatures        *bool                  `json:"experimentalFeatures,omitempty"`
	Images                      *bool                  `json:"images,omitempty"`
	Javascript                  *bool                  `json:"javascript,omitempty"`
	MinimumFontSize             *int                   `json:"minimumFontSize,omitempty"`
	NodeIntegration             *bool                  `json:"nodeIntegration,omitempty"`
	NodeIntegrationInWorker     *bool                  `json:"nodeIntegrationInWorker,omitempty"`
	Offscreen                   *bool                  `json:"offscreen,omitempty"`
	Partition                   *string                `json:"partition,omitempty"`
	Plugins                     *bool                  `json:"plugins,omitempty"`
	Preload                     *string                `json:"preload,omitempty"`
	Sandbox                     *bool                  `json:"sandbox,omitempty"`
	ScrollBounce                *bool                  `json:"scrollBounce,omitempty"`
	Session                     map[string]interface{} `json:"session,omitempty"`
	TextAreasAreResizable       *bool                  `json:"textAreasAreResizable,omitempty"`
	Webaudio                    *bool                  `json:"webaudio,omitempty"`
	Webgl                       *bool                  `json:"webgl,omitempty"`
	WebSecurity                 *bool                  `json:"webSecurity,omitempty"`
	ZoomFactor                  *float64               `json:"zoomFactor,omitempty"`
}

WebPreferences represents web preferences in window options. We must use pointers since GO doesn't handle optional fields whereas NodeJS does. Use PtrBool, PtrInt or PtrStr to fill the struct

type Window

type Window struct {
	Session *Session
	// contains filtered or unexported fields
}

Window represents a window TODO Add missing window options TODO Add missing window methods TODO Add missing window events

func (*Window) Blur

func (w *Window) Blur() (err error)

Blur blurs the window

func (*Window) Center

func (w *Window) Center() (err error)

Center centers the window

func (*Window) Close

func (w *Window) Close() (err error)

Close closes the window

func (*Window) CloseDevTools

func (w *Window) CloseDevTools() (err error)

CloseDevTools closes the dev tools

func (*Window) Create

func (w *Window) Create() (err error)

Create creates the window We wait for EventNameWindowEventDidFinishLoad since we need the web content to be fully loaded before being able to send messages to it

func (*Window) Destroy

func (w *Window) Destroy() (err error)

Destroy destroys the window

func (*Window) Focus

func (w *Window) Focus() (err error)

Focus focuses on the window

func (*Window) Hide

func (w *Window) Hide() (err error)

Hide hides the window

func (Window) IsDestroyed added in v0.2.0

func (o Window) IsDestroyed() bool

IsDestroyed checks whether the window has been destroyed

func (*Window) IsShown added in v0.6.0

func (w *Window) IsShown() bool

IsShown returns whether the window is shown

func (*Window) Log added in v0.6.0

func (w *Window) Log(message string) (err error)

Log logs a message in the JS console of the window

func (*Window) Maximize

func (w *Window) Maximize() (err error)

Maximize maximizes the window

func (*Window) Minimize

func (w *Window) Minimize() (err error)

Minimize minimizes the window

func (*Window) Move

func (w *Window) Move(x, y int) (err error)

Move moves the window

func (*Window) MoveInDisplay added in v0.2.0

func (w *Window) MoveInDisplay(d *Display, x, y int) error

MoveInDisplay moves the window in the proper display

func (*Window) NewMenu added in v0.2.0

func (w *Window) NewMenu(i []*MenuItemOptions) *Menu

NewMenu creates a new window menu

func (Window) On

func (o Window) On(eventName string, l Listener)

On implements the Listenable interface

func (*Window) OnLogin added in v0.6.0

func (w *Window) OnLogin(fn func(i Event) (username, password string, err error))

func (*Window) OnMessage added in v0.6.0

func (w *Window) OnMessage(l ListenerMessage)

OnMessage adds a specific listener executed when receiving a message from the JS This method can be called only once

func (*Window) OpenDevTools

func (w *Window) OpenDevTools() (err error)

OpenDevTools opens the dev tools

func (*Window) Resize

func (w *Window) Resize(width, height int) (err error)

Resize resizes the window

func (*Window) Restore

func (w *Window) Restore() (err error)

Restore restores the window

func (*Window) SendMessage added in v0.6.0

func (w *Window) SendMessage(message interface{}, callbacks ...CallbackMessage) (err error)

SendMessage sends a message to the JS window and execute optional callbacks upon receiving a response from the JS Use astilectron.onMessage method to capture those messages in JS

func (*Window) SetBounds added in v0.9.0

func (w *Window) SetBounds(r RectangleOptions) (err error)

SetBounds set bounds of the window

func (*Window) Show

func (w *Window) Show() (err error)

Show shows the window

func (*Window) Unmaximize

func (w *Window) Unmaximize() (err error)

Unmaximize unmaximize the window

type WindowAppDetails added in v0.9.0

type WindowAppDetails struct {
	AppID               *string `json:"appId,omitempty"`
	AppIconPath         *string `json:"appIconPath,omitempty"`
	RelaunchCommand     *string `json:"relaunchCommand,omitempty"`
	AppIconIndex        *int    `json:"appIconIndex,omitempty"`
	RelaunchDisplayName *string `json:"relaunchDisplayName,omitempty"`
}

WindowAppDetails represents window app details https://github.com/electron/electron/blob/v4.0.1/docs/api/browser-window.md#winsetappdetailsoptions-windows

type WindowCustomOptions added in v0.6.0

type WindowCustomOptions struct {
	HideOnClose       *bool              `json:"hideOnClose,omitempty"`
	MessageBoxOnClose *MessageBoxOptions `json:"messageBoxOnClose,omitempty"`
	MinimizeOnClose   *bool              `json:"minimizeOnClose,omitempty"`
	Script            string             `json:"script,omitempty"`
}

WindowCustomOptions represents window custom options

type WindowLoadOptions added in v0.6.0

type WindowLoadOptions struct {
	ExtraHeaders string `json:"extraHeaders,omitempty"`
	HTTPReferer  string `json:"httpReferrer,omitempty"`
	UserAgent    string `json:"userAgent,omitempty"`
}

WindowLoadOptions represents window load options https://github.com/electron/electron/blob/v1.8.1/docs/api/browser-window.md#winloadurlurl-options

type WindowOptions

type WindowOptions struct {
	AcceptFirstMouse       *bool           `json:"acceptFirstMouse,omitempty"`
	AlwaysOnTop            *bool           `json:"alwaysOnTop,omitempty"`
	AutoHideMenuBar        *bool           `json:"autoHideMenuBar,omitempty"`
	BackgroundColor        *string         `json:"backgroundColor,omitempty"`
	Center                 *bool           `json:"center,omitempty"`
	Closable               *bool           `json:"closable,omitempty"`
	DisableAutoHideCursor  *bool           `json:"disableAutoHideCursor,omitempty"`
	EnableLargerThanScreen *bool           `json:"enableLargerThanScreen,omitempty"`
	Focusable              *bool           `json:"focusable,omitempty"`
	Frame                  *bool           `json:"frame,omitempty"`
	Fullscreen             *bool           `json:"fullscreen,omitempty"`
	Fullscreenable         *bool           `json:"fullscreenable,omitempty"`
	HasShadow              *bool           `json:"hasShadow,omitempty"`
	Height                 *int            `json:"height,omitempty"`
	Icon                   *string         `json:"icon,omitempty"`
	Kiosk                  *bool           `json:"kiosk,omitempty"`
	MaxHeight              *int            `json:"maxHeight,omitempty"`
	Maximizable            *bool           `json:"maximizable,omitempty"`
	MaxWidth               *int            `json:"maxWidth,omitempty"`
	MinHeight              *int            `json:"minHeight,omitempty"`
	Minimizable            *bool           `json:"minimizable,omitempty"`
	MinWidth               *int            `json:"minWidth,omitempty"`
	Modal                  *bool           `json:"modal,omitempty"`
	Movable                *bool           `json:"movable,omitempty"`
	Resizable              *bool           `json:"resizable,omitempty"`
	Show                   *bool           `json:"show,omitempty"`
	SkipTaskbar            *bool           `json:"skipTaskbar,omitempty"`
	Title                  *string         `json:"title,omitempty"`
	TitleBarStyle          *string         `json:"titleBarStyle,omitempty"`
	Transparent            *bool           `json:"transparent,omitempty"`
	UseContentSize         *bool           `json:"useContentSize,omitempty"`
	WebPreferences         *WebPreferences `json:"webPreferences,omitempty"`
	Width                  *int            `json:"width,omitempty"`
	X                      *int            `json:"x,omitempty"`
	Y                      *int            `json:"y,omitempty"`

	// Additional options
	AppDetails *WindowAppDetails    `json:"appDetails,omitempty"`
	Custom     *WindowCustomOptions `json:"custom,omitempty"`
	Load       *WindowLoadOptions   `json:"load,omitempty"`
	Proxy      *WindowProxyOptions  `json:"proxy,omitempty"`
}

WindowOptions represents window options We must use pointers since GO doesn't handle optional fields whereas NodeJS does. Use PtrBool, PtrInt or PtrStr to fill the struct https://github.com/electron/electron/blob/v1.8.1/docs/api/browser-window.md

type WindowProxyOptions added in v0.6.0

type WindowProxyOptions struct {
	BypassRules string `json:"proxyBypassRules,omitempty"`
	PACScript   string `json:"pacScript,omitempty"`
	Rules       string `json:"proxyRules,omitempty"`
}

WindowProxyOptions represents window proxy options https://github.com/electron/electron/blob/v1.8.1/docs/api/session.md#sessetproxyconfig-callback

Jump to

Keyboard shortcuts

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