gotron

package module
v0.2.23 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2019 License: MIT Imports: 21 Imported by: 9

README

Build Status

Gotron

Go Api for Electron.

Example Projects

A list of boilerplate projects using gotron.

Prerequisites

go1.11 with modules enabled, nodejs and npm must be available on your system.

Quick Start

On the first run it will download Electron and stores it in .gotron in your working directory.

package main

import (
    "github.com/Equanox/gotron"
)

func main() {
    // Create a new browser window instance
    window, err := gotron.New()
    if err != nil {
        panic(err)
    }

    // Alter default window size and window title.
    window.WindowOptions.Width = 1200
    window.WindowOptions.Height = 980
    window.WindowOptions.Title = "Gotron"

    // Start the browser window.
    // This will establish a golang <=> nodejs bridge using websockets,
    // to control ElectronBrowserWindow with our window object.
    done, err := window.Start()
    if err != nil {
        panic(err)
    }
    
    // Open dev tools must be used after window.Start 
    // window.OpenDevTools()
    
    // Wait for the application to close
    <-done
}

When everything worked you should see this

Hello Gotron
Use Your Own WebUI

gotron expects a folder containing your HTML/JS/CSS code and passes it to electronJS. make sure it contains at least a index.html as entrypoint.

Pass a path to your webUI on gotrons New(uiFolder ...string) function.

window, err := gotron.New("path/to/your/webui")
if err != nil {
    panic(err)
}
Communicate between backend and frontend

Frontend to backend communication is realized through javascript like event driven apporach.

Backend

Handle incoming events

window.On(&gotron.Event{Event: "event-name"}, func(bin []byte) {
	//Handle event here
}

Send event to frontend

// Create a custom event struct that has a pointer to gotron.Event
type CustomEvent struct {
    *gotron.Event
    CustomAttribute string 'json:"AtrNameInFrontend"'
}

window.Send(&CustomEvent{
    Event: &gotron.Event{Event: "event-name"},
    CustomAttribute: "Hello World!",
    })
Frontend

In frontend a websocket needs to be created. Adress is always localhost and port can be taken from global variable global.backendPort

let ws = new WebSocket("ws://localhost:" + global.backendPort + "/web/app/events");

Handle incoming events

// This is being called for all incoming messages
ws.onmessage = (message) => {
    let obj = JSON.parse(message.data);
    
    // event name
    console.log(obj.event);

    // event data
    console.log(obj.AtrNameInFrontend);
}

Send event to backend

ws.send(JSON.stringify({
    "event": "event-name",
    "AtrNameInFrontend": "Hello World!",
}))

Distribution/Packaging

To package a go application together with electornjs use gotron-builder.

Install gotron-builder

We provide executables for Linux, MacOS and Windows.
Download the newest release from https://github.com/Equanox/gotron/releases and add it to your $PATH.

Using gotron-builder

It expects...

  • a directory containing a golang main package
  • and a directory with a webUI containing at least a index.html

By default it will implicitly use...

  • golang main package from the current directory
  • webUI from .gotron/assets

To pack the code from Quick Start use

gotron-builder

in the root of your repo.

Pass your go code and webUI explicitly.

gotron-builder --go=your/go/dir --app=your/webapp/dir

For cross compilation you can use the same flags as electron-builder would expect them

gotron-builder --win 

Read about the requirements for cross-compilation in electron-builders documentation.

Tasks

  • Basic js + webpack example
  • React example
  • Typescript-React example
  • Vue.js example
  • Elm example
  • Flutter Hummingbird example
  • Hide nodejs/Electron behind go api
  • Create executables for Win, Linux, MacOS
  • Hide nodejs/Electron behind go api
  • Msgs between golang and Electron renderer process, abstracted in a javascript/typescript package
  • Implement complete BrowserWindow api see => BrowserWindow.md
  • Implement complete electron-builder api in gotron-builder

Sponsors

benchkram-logo

License

MIT

Except Roboto (ui/js/src/Roboto-Light.ttf , ui/react/src/Roboto-Light.ttf) which is licensed under Apache 2.0
https://github.com/google/roboto

Documentation

Overview

Package gotron :

Rampup electron from golang using only a go api.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func UseLogger

func UseLogger(zl zerolog.Logger)

UseLogger in this library and add a defined logger

Types

type BrowserWindow

type BrowserWindow struct {
	Configuration
	UseZerolog bool
	Running    bool

	WindowOptions WindowOptions
	// contains filtered or unexported fields
}

BrowserWindow Instance for a gotronbrowserwindow

func New

func New(uiFolders ...string) (gbw *BrowserWindow, err error)

New creates a new gotronbrowserwindow, parameter uiFolder must point to a folder containing either an index.htm or an index.html file if empty a default aplication is used

func (*BrowserWindow) AddTabbedWindow

func (gbw *BrowserWindow) AddTabbedWindow(browserwindow *BrowserWindow)

AddTabbedWindow - Adds a window as a tab on this window, after the tab for the window instance.

func (*BrowserWindow) Blur

func (gbw *BrowserWindow) Blur()

Blur - Removes focus from the window.

func (*BrowserWindow) BlurWebView

func (gbw *BrowserWindow) BlurWebView()

BlurWebView - Unsets focus from webView.

func (*BrowserWindow) CapturePage

func (gbw *BrowserWindow) CapturePage(rect []Rectangle, handler func(image string))

CapturePage :

rect Rectangle (optional) - The bounds to capture

callback Function

image NativeImage

Same as webContents.capturePage([rect, ]callback).

func (*BrowserWindow) Center

func (gbw *BrowserWindow) Center()

Center - Moves window to the center of the screen.

func (*BrowserWindow) Close

func (gbw *BrowserWindow) Close()

Close - Try to close the window. This has the same effect as a user manually clicking the close button of the window. The web page may cancel the close though. See the close event.

func (*BrowserWindow) CloseFilePreview

func (gbw *BrowserWindow) CloseFilePreview()

CloseFilePreview - Closes the currently open Quick Look panel.

func (*BrowserWindow) CreateAppStructure

func (gbw *BrowserWindow) CreateAppStructure(forceInstall ...bool) (err error)

CreatAppStructure - Get electron and web files. Put them into gbw.AppFolder (default ".gotron")

func (*BrowserWindow) Destroy

func (gbw *BrowserWindow) Destroy()

Destroy - Force closing the window, the unload and beforeunload event won't be emitted for the web page, and close event will also not be emitted for this window, but it guarantees the closed event will be emitted.

func (*BrowserWindow) FlashFrame

func (gbw *BrowserWindow) FlashFrame(flag bool)

FlashFrame - Starts or stops flashing the window to attract user's attention.

func (*BrowserWindow) Focus

func (gbw *BrowserWindow) Focus()

Focus on the window.

func (*BrowserWindow) FocusOnWebView

func (gbw *BrowserWindow) FocusOnWebView()

FocusOnWebView - Sets focus on webView.

func (*BrowserWindow) GetBounds

func (gbw *BrowserWindow) GetBounds() Rectangle

GetBounds - Returns Rectangle

func (*BrowserWindow) GetBrowserView

func (gbw *BrowserWindow) GetBrowserView() interface{}

GetBrowserView - experimental

func (*BrowserWindow) GetChildWindows

func (gbw *BrowserWindow) GetChildWindows() []BrowserWindow

GetChildWindows - Returns BrowserWindow[] - All child windows.

func (*BrowserWindow) GetContentBounds

func (gbw *BrowserWindow) GetContentBounds() Rectangle

GetContentBounds - Returns Rectangle

func (*BrowserWindow) GetContentSize

func (gbw *BrowserWindow) GetContentSize() []int

GetContentSize - Returns Integer[] - Contains the window's client area's width and height.

func (*BrowserWindow) GetMaximumSize

func (gbw *BrowserWindow) GetMaximumSize() []int

GetMaximumSize - Returns Integer[] - Contains the window's maximum width and height.

func (*BrowserWindow) GetMinimumSize

func (gbw *BrowserWindow) GetMinimumSize() []int

GetMinimumSize - Returns Integer[] - Contains the window's minimum width and height.

func (*BrowserWindow) GetNativeWindowHandle

func (gbw *BrowserWindow) GetNativeWindowHandle()

GetNativeWindowHandle :

Returns Buffer - The platform-specific handle of the window.

The native type of the handle is HWND on Windows, NSView* on macOS, and Window (unsigned long) on Linux.

func (*BrowserWindow) GetNormalBounds

func (gbw *BrowserWindow) GetNormalBounds() Rectangle

GetNormalBounds - Returns Rectangle

Note: whatever the current state of the window : maximized, minimized or in fullscreen, this function always returns the position and size of the window in normal state. In normal state, getBounds and getNormalBounds returns the same Rectangle.

func (*BrowserWindow) GetOpacity

func (gbw *BrowserWindow) GetOpacity() float64

GetOpacity - Returns Number - between 0.0 (fully transparent) and 1.0 (fully opaque)

func (*BrowserWindow) GetParentWindow

func (gbw *BrowserWindow) GetParentWindow() BrowserWindow

GetParentWindow - Returns BrowserWindow - The parent window.

func (*BrowserWindow) GetPosition

func (gbw *BrowserWindow) GetPosition() []int

GetPosition - Returns Integer[] - Contains the window's current position.

func (*BrowserWindow) GetRepresentedFilename

func (gbw *BrowserWindow) GetRepresentedFilename() string

GetRepresentedFilename - Returns String - The pathname of the file the window represents.

func (*BrowserWindow) GetSize

func (gbw *BrowserWindow) GetSize() []int

GetSize - Returns Integer[] - Contains the window's width and height.

func (*BrowserWindow) GetTitle

func (gbw *BrowserWindow) GetTitle() string

GetTitle - Returns String - The title of the native window.

Note: The title of web page can be different from the title of the native window.

func (*BrowserWindow) HasShadow

func (gbw *BrowserWindow) HasShadow() bool

HasShadow - Returns Boolean - Whether the window has a shadow.

On Windows and Linux always returns true.

func (*BrowserWindow) Hide

func (gbw *BrowserWindow) Hide()

Hide - Hides the window.

func (*BrowserWindow) HookWindowMessage

func (gbw *BrowserWindow) HookWindowMessage(message int, callback func([]interface{}) []interface{})

HookWindowMessage :

Hooks a windows message. The callback is called when the message is received in the WndProc.

func (*BrowserWindow) IsAlwaysOnTop

func (gbw *BrowserWindow) IsAlwaysOnTop() bool

IsAlwaysOnTop - Returns Boolean - Whether the window is always on top of other windows.

func (*BrowserWindow) IsClosable

func (gbw *BrowserWindow) IsClosable() bool

IsClosable :

Returns Boolean - Whether the window can be manually closed by user.

On Linux always returns true.

func (*BrowserWindow) IsDestroyed

func (gbw *BrowserWindow) IsDestroyed() bool

IsDestroyed - Returns Boolean - Whether the window is destroyed.

func (*BrowserWindow) IsDocumentEdited

func (gbw *BrowserWindow) IsDocumentEdited()

IsDocumentEdited - Returns Boolean - Whether the window's document has been edited.

func (*BrowserWindow) IsFocused

func (gbw *BrowserWindow) IsFocused() bool

IsFocused - Returns Boolean - Whether the window is focused.

func (*BrowserWindow) IsFullScreen

func (gbw *BrowserWindow) IsFullScreen() bool

IsFullScreen - Returns Boolean - Whether the window is in fullscreen mode.

func (*BrowserWindow) IsFullScreenable

func (gbw *BrowserWindow) IsFullScreenable() bool

IsFullScreenable :

Returns Boolean - Whether the maximize/zoom window button toggles fullscreen mode or maximizes the window.

func (*BrowserWindow) IsKiosk

func (gbw *BrowserWindow) IsKiosk() bool

IsKiosk - Returns Boolean - Whether the window is in kiosk mode.

func (*BrowserWindow) IsMaximised

func (gbw *BrowserWindow) IsMaximised() bool

IsMaximised - Returns Boolean - Whether the window is maximized.

func (*BrowserWindow) IsMaximizable

func (gbw *BrowserWindow) IsMaximizable() bool

IsMaximizable :

Returns Boolean - Whether the window can be manually maximized by user.

On Linux always returns true.

func (*BrowserWindow) IsMenuBarAutoHide

func (gbw *BrowserWindow) IsMenuBarAutoHide() bool

IsMenuBarAutoHide - Returns Boolean - Whether menu bar automatically hides itself.

func (*BrowserWindow) IsMenuBarVisible

func (gbw *BrowserWindow) IsMenuBarVisible() bool

IsMenuBarVisible - Returns Boolean - Whether the menu bar is visible.

func (*BrowserWindow) IsMinimizable

func (gbw *BrowserWindow) IsMinimizable() bool

IsMinimizable :

Returns Boolean - Whether the window can be manually minimized by user

On Linux always returns true.

func (*BrowserWindow) IsMinimized

func (gbw *BrowserWindow) IsMinimized() bool

IsMinimized - Returns Boolean - Whether the window is minimized.

func (*BrowserWindow) IsModal

func (gbw *BrowserWindow) IsModal() bool

IsModal - Returns Boolean - Whether current window is a modal window.

func (*BrowserWindow) IsMovable

func (gbw *BrowserWindow) IsMovable() bool

IsMovable :

Returns Boolean - Whether the window can be moved by user.

On Linux always returns true.

func (*BrowserWindow) IsNormal

func (gbw *BrowserWindow) IsNormal() bool

IsNormal - Returns Boolean - Whether the window is in normal state (not maximized, not minimized, not in fullscreen mode).

func (*BrowserWindow) IsResizable

func (gbw *BrowserWindow) IsResizable() bool

IsResizable - Returns Boolean - Whether the window can be manually resized by user.

func (*BrowserWindow) IsSimpleFullScreen

func (gbw *BrowserWindow) IsSimpleFullScreen() bool

IsSimpleFullScreen - Returns Boolean - Whether the window is in simple (pre-Lion) fullscreen mode.

func (*BrowserWindow) IsVisible

func (gbw *BrowserWindow) IsVisible() bool

IsVisible - Returns Boolean - Whether the window is visible to the user.

func (*BrowserWindow) IsVisibleOnAllWorkspaces

func (gbw *BrowserWindow) IsVisibleOnAllWorkspaces() bool

IsVisibleOnAllWorkspaces - Returns Boolean - Whether the window is visible on all workspaces.

func (*BrowserWindow) IsWindowMessageHooked

func (gbw *BrowserWindow) IsWindowMessageHooked(message int) bool

IsWindowMessageHooked - Returns Boolean - true or false depending on whether the message is hooked.

func (*BrowserWindow) LoadFile

func (gbw *BrowserWindow) LoadFile(filePath string, options interface{})

LoadFile :

filePath String

options Object (optional)

query Object (optional) - Passed to url.format().

search String (optional) - Passed to url.format().

hash String (optional) - Passed to url.format().

Same as webContents.loadFile, filePath should be a path to an HTML file relative to the root of your application. See the webContents docs for more information.

func (*BrowserWindow) LoadURL

func (gbw *BrowserWindow) LoadURL(url, options interface{})

LoadURL :

url String

options Object (optional){

httpReferrer (String | Referrer) (optional) An HTTP Referrer url.

userAgent String (optional) A user agent originating the request.

extraHeaders String (optional) Extra headers separated by "\n"

postData (UploadRawData[] | UploadFile[] | UploadBlob[]) (optional)

baseURLForDataURL String (optional) Base url (with trailing path separator) for files to be loaded by the data url. This is needed only if the specified url is a data url and needs to load other files.}

Same as webContents.loadURL(url[, options]).

The url can be a remote address (e.g. http://) or a path to a local HTML file using the file:// protocol.

To ensure that file URLs are properly formatted, it is recommended to use Node's url.format method:

 let url = require('url').format({
   protocol: 'file',
   slashes: true,
   pathname: require('path').join(__dirname, 'index.html')
 })

win.loadURL(url)

You can load a URL using a POST request with URL-encoded data by doing the following:

win.loadURL('http://localhost:8000/post', {
  postData: [{
    type: 'rawData',
    bytes: Buffer.from('hello=world')
  }],
  extraHeaders: 'Content-Type: application/x-www-form-urlencoded'
})

func (*BrowserWindow) Maximize

func (gbw *BrowserWindow) Maximize()

Maximize - Maximizes the window. This will also show (but not focus) the window if it isn't being displayed already.

func (*BrowserWindow) MergeAllWindows

func (gbw *BrowserWindow) MergeAllWindows()

MergeAllWindows - Merges all windows into one window with multiple tabs when native tabs are enabled and there is more than one open window.

func (*BrowserWindow) Minimize

func (gbw *BrowserWindow) Minimize()

Minimize - Minimizes the window. On some platforms the minimized window will be shown in the Dock.

func (*BrowserWindow) MoveTabToNewWindow

func (gbw *BrowserWindow) MoveTabToNewWindow()

MoveTabToNewWindow - Moves the current tab into a new window if native tabs are enabled and there is more than one tab in the current window.

func (*BrowserWindow) MoveTop

func (gbw *BrowserWindow) MoveTop()

MoveTop - Moves window to top(z-order) regardless of focus

func (*BrowserWindow) On

func (gbw *BrowserWindow) On(msg EventInterface, handler func(bin []byte))

On register handler for messages incoming from js frontend

func (*BrowserWindow) OpenDevTools

func (gbw *BrowserWindow) OpenDevTools()

OpenDevTools open the devtools view in this BrowserWindow

func (*BrowserWindow) PreviewFile

func (gbw *BrowserWindow) PreviewFile(path string, displayName ...string)

PreviewFile :

path String - The absolute path to the file to preview with QuickLook. This is important as Quick Look uses the file name and file extension on the path to determine the content type of the file to open.

displayName String (optional) - The name of the file to display on the Quick Look modal view. This is purely visual and does not affect the content type of the file. Defaults to path.

Uses Quick Look to preview a file at a given path.

func (*BrowserWindow) Reload

func (gbw *BrowserWindow) Reload()

Reload - Same as webContents.reload.

func (*BrowserWindow) Restore

func (gbw *BrowserWindow) Restore()

Restore - Restores the window from minimized state to its previous state.

func (*BrowserWindow) SelectNextTab

func (gbw *BrowserWindow) SelectNextTab()

SelectNextTab - Selects the next tab when native tabs are enabled and there are other tabs in the window.

func (*BrowserWindow) SelectPreviousTab

func (gbw *BrowserWindow) SelectPreviousTab()

SelectPreviousTab - Selects the previous tab when native tabs are enabled and there are other tabs in the window.

func (*BrowserWindow) Send

func (gbw *BrowserWindow) Send(msg EventInterface) (err error)

Send send message (with data) to js frontend

func (*BrowserWindow) SetAlwaysOnTop

func (gbw *BrowserWindow) SetAlwaysOnTop(flag bool, level string, relativeLevel ...int)

SetAlwaysOnTop :

flag Boolean

level String (optional) macOS - Values include normal, floating, torn-off-menu, modal-panel, main-menu, status, pop-up-menu, screen-saver, and dock (Deprecated). The default is floating. See the macOS docs for more details.

relativeLevel Integer (optional) macOS - The number of layers higher to set this window relative to the given level. The default is 0. Note that Apple discourages setting levels higher than 1 above screen-saver.

Sets whether the window should show always on top of other windows. After setting this, the window is still a normal window, not a toolbox window which can not be focused on.

func (*BrowserWindow) SetAppDetails

func (gbw *BrowserWindow) SetAppDetails(options interface{})

SetAppDetails :

options Object

appId String (optional) - Window's App User Model ID. It has to be set, otherwise the other options will have no effect.

appIconPath String (optional) - Window's Relaunch Icon.

appIconIndex Integer (optional) - Index of the icon in appIconPath. Ignored when appIconPath is not set. Default is 0.

relaunchCommand String (optional) - Window's Relaunch Command.

relaunchDisplayName String (optional) - Window's Relaunch Display Name.

Sets the properties for the window's taskbar button.

Note: relaunchCommand and relaunchDisplayName must always be set together. If one of those properties is not set, then neither will be used.

func (*BrowserWindow) SetAspectRatio

func (gbw *BrowserWindow) SetAspectRatio(aspectRatio float64, extraSize string)

SetAspectRatio :

aspectRatio Float - The aspect ratio to maintain for some portion of the content view.

extraSize Size - The extra size not to be included while maintaining the aspect ratio.

This will make a window maintain an aspect ratio. The extra size allows a developer to have space, specified in pixels, not included within the aspect ratio calculations. This API already takes into account the difference between a window's size and its content size.

Consider a normal window with an HD video player and associated controls. Perhaps there are 15 pixels of controls on the left edge, 25 pixels of controls on the right edge and 50 pixels of controls below the player. In order to maintain a 16:9 aspect ratio (standard aspect ratio for HD @1920x1080) within the player itself we would call this function with arguments of 16/9 and [ 40, 50 ]. The second argument doesn't care where the extra width and height are within the content view--only that they exist. Sum any extra width and height areas you have within the overall content view.

Calling this function with a value of 0 will remove any previously set aspect ratios.

func (*BrowserWindow) SetAutoHideCursor

func (gbw *BrowserWindow) SetAutoHideCursor(autoHide bool)

SetAutoHideCursor - Controls whether to hide cursor when typing.

func (*BrowserWindow) SetAutoHideMenuBar

func (gbw *BrowserWindow) SetAutoHideMenuBar(hide bool)

SetAutoHideMenuBar - Sets whether the window menu bar should hide itself automatically. Once set the menu bar will only show when users press the single Alt key.

If the menu bar is already visible, calling setAutoHideMenuBar(true) won't hide it immediately.

func (*BrowserWindow) SetBackgroundColor

func (gbw *BrowserWindow) SetBackgroundColor(backgroundColor string)

SetBackgroundColor :

backgroundColor String - Window's background color as a hexadecimal value, like #66CD00 or #FFF or #80FFFFFF (alpha is supported if transparent is true). Default is #FFF (white).

Sets the background color of the window.

func (*BrowserWindow) SetBounds

func (gbw *BrowserWindow) SetBounds(bounds Rectangle, animate ...bool)

SetBounds :

bounds Rectangle

animate Boolean (optional) macOS

Resizes and moves the window to the supplied bounds. Any properties that are not supplied will default to their current values.

func (*BrowserWindow) SetBrowserView

func (gbw *BrowserWindow) SetBrowserView(browserView interface{})

SetBrowserView - experimental

func (*BrowserWindow) SetClosable

func (gbw *BrowserWindow) SetClosable(closable bool)

SetClosable - Sets whether the window can be manually closed by user. On Linux does nothing.

func (*BrowserWindow) SetContentBounds

func (gbw *BrowserWindow) SetContentBounds(bounds Rectangle, animate ...bool)

SetContentBounds - Returns Rectangle - Contains the window bounds of the normal state

Note: whatever the current state of the window : maximized, minimized or in fullscreen, this function always returns the position and size of the window in normal state. In normal state, getBounds and getNormalBounds returns the same Rectangle.

func (*BrowserWindow) SetContentProtection

func (gbw *BrowserWindow) SetContentProtection(enable bool)

SetContentProtection - Prevents the window contents from being captured by other apps.

On macOS it sets the NSWindow's sharingType to NSWindowSharingNone. On Windows it calls SetWindowDisplayAffinity with WDA_MONITOR.

func (*BrowserWindow) SetContentSize

func (gbw *BrowserWindow) SetContentSize(width int, height int, animate ...bool)

SetContentSize - Resizes the window's client area (e.g. the web page) to width and height.

func (*BrowserWindow) SetDocumentEdited

func (gbw *BrowserWindow) SetDocumentEdited(edited bool)

SetDocumentEdited - Specifies whether the window’s document has been edited, and the icon in title bar will become gray when set to true.

func (*BrowserWindow) SetEnabled

func (gbw *BrowserWindow) SetEnabled(enable bool)

SetEnabled - Disable or enable the window.

func (*BrowserWindow) SetFocusable

func (gbw *BrowserWindow) SetFocusable(focusable bool)

SetFocusable - Changes whether the window can be focused.

func (*BrowserWindow) SetFullScreen

func (gbw *BrowserWindow) SetFullScreen(flag bool)

SetFullScreen - Sets whether the window should be in fullscreen mode.

func (*BrowserWindow) SetFullScreenable

func (gbw *BrowserWindow) SetFullScreenable(fullscreenable bool)

SetFullScreenable - Sets whether the maximize/zoom window button toggles fullscreen mode or maximizes the window.

func (*BrowserWindow) SetHasShadow

func (gbw *BrowserWindow) SetHasShadow(hsShadow bool)

SetHasShadow - Sets whether the window should have a shadow. On Windows and Linux does nothing.

func (*BrowserWindow) SetHeight

func (gbw *BrowserWindow) SetHeight(height int)

SetHeight sets the height of the electron window to requested size

func (*BrowserWindow) SetIcon

func (gbw *BrowserWindow) SetIcon(icon string)

SetIcon - Changes window icon.

func (*BrowserWindow) SetIgnoreMouseEvents

func (gbw *BrowserWindow) SetIgnoreMouseEvents(ignore bool, options ...interface{})

SetIgnoreMouseEvents - Makes the window ignore all mouse events.

All mouse events happened in this window will be passed to the window below this window, but if this window has focus, it will still receive keyboard events.

func (*BrowserWindow) SetKiosk

func (gbw *BrowserWindow) SetKiosk(flag bool)

SetKiosk - Enters or leaves the kiosk mode.

func (*BrowserWindow) SetMaximizable

func (gbw *BrowserWindow) SetMaximizable(maximizable bool)

SetMaximizable - Sets whether the window can be manually maximized by user. On Linux does nothing.

func (*BrowserWindow) SetMaximumSize

func (gbw *BrowserWindow) SetMaximumSize(width, height int)

SetMaximumSize - Sets the maximum size of window to width and height.

func (*BrowserWindow) SetMenu

func (gbw *BrowserWindow) SetMenu(menu string)

SetMenu - Sets the menu as the window's menu bar, setting it to null will remove the menu bar.

func (*BrowserWindow) SetMenuBarVisibility

func (gbw *BrowserWindow) SetMenuBarVisibility(visible bool)

SetMenuBarVisibility - Sets whether the menu bar should be visible. If the menu bar is auto-hide, users can still bring up the menu bar by pressing the single Alt key.

func (*BrowserWindow) SetMinimizable

func (gbw *BrowserWindow) SetMinimizable(minimizable bool)

SetMinimizable - Sets whether the window can be manually minimized by user. On Linux does nothing.

func (*BrowserWindow) SetMinimumSize

func (gbw *BrowserWindow) SetMinimumSize(width, height int)

SetMinimumSize - Sets the minimum size of window to width and height.

func (*BrowserWindow) SetMovable

func (gbw *BrowserWindow) SetMovable(movable bool)

SetMovable - Sets whether the window can be moved by user. On Linux does nothing.

func (*BrowserWindow) SetOpacity

func (gbw *BrowserWindow) SetOpacity(opacity float64)

SetOpacity - Sets the opacity of the window. On Linux does nothing.

func (*BrowserWindow) SetOverlayIcon

func (gbw *BrowserWindow) SetOverlayIcon(overlay string, description string)

SetOverlayIcon - Sets a 16 x 16 pixel overlay onto the current taskbar icon, usually used to convey some sort of application status or to passively notify the user.

func (*BrowserWindow) SetParentWindow

func (gbw *BrowserWindow) SetParentWindow(parent *BrowserWindow)

SetParentWindow - Sets parent as current window's parent window, passing null will turn current window into a top-level window.

func (*BrowserWindow) SetPosition

func (gbw *BrowserWindow) SetPosition(x, y int, animate ...bool)

SetPosition - Moves window to x and y.

func (*BrowserWindow) SetProgressBar

func (gbw *BrowserWindow) SetProgressBar(progress float64, options ...interface{})

SetProgressBar :

Sets progress value in progress bar. Valid range is [0, 1.0].

Remove progress bar when progress < 0; Change to indeterminate mode when progress > 1.

On Linux platform, only supports Unity desktop environment, you need to specify the *.desktop file name to desktopName field in package.json. By default, it will assume app.getName().desktop.

On Windows, a mode can be passed. Accepted values are none, normal, indeterminate, error, and paused. If you call setProgressBar without a mode set (but with a value within the valid range), normal will be assumed.

func (*BrowserWindow) SetRepresentedFilename

func (gbw *BrowserWindow) SetRepresentedFilename(filename string)

SetRepresentedFilename - Sets the pathname of the file the window represents, and the icon of the file will show in window's title bar.

func (*BrowserWindow) SetResizable

func (gbw *BrowserWindow) SetResizable(resizable bool)

SetResizable - Sets whether the window can be manually resized by user.

func (*BrowserWindow) SetShape

func (gbw *BrowserWindow) SetShape(rects []Rectangle)

SetShape :

Setting a window shape determines the area within the window where the system permits drawing and user interaction. Outside of the given region, no pixels will be drawn and no mouse events will be registered. Mouse events outside of the region will not be received by that window, but will fall through to whatever is behind the window.

func (*BrowserWindow) SetSheetOffset

func (gbw *BrowserWindow) SetSheetOffset(offsetY float64, offsetX ...float64)

SetSheetOffset :

offsetY Float

offsetX Float (optional)

Changes the attachment point for sheets on macOS. By default, sheets are attached just below the window frame, but you may want to display them beneath a HTML-rendered toolbar. For example:

func (*BrowserWindow) SetSimpleFullScreen

func (gbw *BrowserWindow) SetSimpleFullScreen(flag bool)

SetSimpleFullScreen - Enters or leaves simple fullscreen mode. Simple fullscreen mode emulates the native fullscreen behavior found in versions of Mac OS X prior to Lion (10.7).

func (*BrowserWindow) SetSize

func (gbw *BrowserWindow) SetSize(width int, height int, animate ...bool)

SetSize :

Resizes the window to width and height. If width or height are below any set minimum size constraints the window will snap to its minimum size.

func (*BrowserWindow) SetSkipTaskbar

func (gbw *BrowserWindow) SetSkipTaskbar(skip bool)

SetSkipTaskbar - Makes the window not show in the taskbar.

func (*BrowserWindow) SetThumbarButtons

func (gbw *BrowserWindow) SetThumbarButtons(buttons interface{}) bool

SetThumbarButtons :

Returns Boolean - Whether the buttons were added successfully

Add a thumbnail toolbar with a specified set of buttons to the thumbnail image of a window in a taskbar button layout. Returns a Boolean object indicates whether the thumbnail has been added successfully.

The number of buttons in thumbnail toolbar should be no greater than 7 due to the limited room. Once you setup the thumbnail toolbar, the toolbar cannot be removed due to the platform's limitation. But you can call the API with an empty array to clean the buttons.

The buttons is an array of Button objects:

Button Object

icon NativeImage - The icon showing in thumbnail toolbar.

click Function

tooltip String (optional) - The text of the button's tooltip.

flags String[] (optional) - Control specific states and behaviors of the button. By default, it is ['enabled'].

The flags is an array that can include following Strings:

enabled - The button is active and available to the user.

disabled - The button is disabled. It is present, but has a visual state indicating it will not respond to user action.

dismissonclick - When the button is clicked, the thumbnail window closes immediately.

nobackground - Do not draw a button border, use only the image.

hidden - The button is not shown to the user.

noninteractive - The button is enabled but not interactive; no pressed button state is drawn. This value is intended for instances where the button is used in a notification.

func (*BrowserWindow) SetThumbnailClip

func (gbw *BrowserWindow) SetThumbnailClip(region Rectangle)

SetThumbnailClip :

Sets the region of the window to show as the thumbnail image displayed when hovering over the window in the taskbar. You can reset the thumbnail to be the entire window by specifying an empty region: { x: 0, y: 0, width: 0, height: 0 }.

func (*BrowserWindow) SetThumbnailToolTip

func (gbw *BrowserWindow) SetThumbnailToolTip(toolTip string)

SetThumbnailToolTip - Sets the toolTip that is displayed when hovering over the window thumbnail in the taskbar.

func (*BrowserWindow) SetTitle

func (gbw *BrowserWindow) SetTitle(title string)

SetTitle - Changes the title of native window to title.

func (*BrowserWindow) SetTouchBar

func (gbw *BrowserWindow) SetTouchBar(touchBar interface{})

SetTouchBar - Sets the touchBar layout for the current window. Specifying null or undefined clears the touch bar. This method only has an effect if the machine has a touch bar and is running on macOS 10.12.1+.

Note: The TouchBar API is currently experimental and may change or be removed in future Electron releases.

func (*BrowserWindow) SetVibrancy

func (gbw *BrowserWindow) SetVibrancy(vibrancy string)

SetVibrancy - Adds a vibrancy effect to the browser window. Passing null or an empty string will remove the vibrancy effect on the window.

func (*BrowserWindow) SetVisibleOnAllWorkspaces

func (gbw *BrowserWindow) SetVisibleOnAllWorkspaces(visible bool, options ...interface{})

SetVisibleOnAllWorkspaces - Sets whether the window should be visible on all workspaces.

Note: This API does nothing on Windows.

func (*BrowserWindow) SetWidth

func (gbw *BrowserWindow) SetWidth(width int)

SetWidth sets the width of the electron window to requested size

func (*BrowserWindow) SetWindowButtonVisibility

func (gbw *BrowserWindow) SetWindowButtonVisibility(visible bool)

SetWindowButtonVisibility - Sets whether the window traffic light buttons should be visible.

This cannot be called when titleBarStyle is set to customButtonsOnHover.

func (*BrowserWindow) Show

func (gbw *BrowserWindow) Show()

Show - Shows and gives focus to the window.

func (*BrowserWindow) ShowDefinitionForSelection

func (gbw *BrowserWindow) ShowDefinitionForSelection()

ShowDefinitionForSelection - Same as webContents.showDefinitionForSelection().

func (*BrowserWindow) ShowInactive

func (gbw *BrowserWindow) ShowInactive()

ShowInactive - Shows the window but doesn't focus on it.

func (*BrowserWindow) Start

func (gbw *BrowserWindow) Start(forceInstall ...bool) (isdone chan bool, err error)

Start starts an Instance of gotronbrowserwindow

func (*BrowserWindow) ToggleTabBar

func (gbw *BrowserWindow) ToggleTabBar()

ToggleTabBar - Toggles the visibility of the tab bar if native tabs are enabled and there is only one tab in the current window.

func (*BrowserWindow) UnMaximize

func (gbw *BrowserWindow) UnMaximize()

UnMaximize - Unmaximizes the window.

func (*BrowserWindow) UnhookAllWindowMessages

func (gbw *BrowserWindow) UnhookAllWindowMessages()

UnhookAllWindowMessages - Unhooks all of the window messages.

func (*BrowserWindow) UnhookWindowMessage

func (gbw *BrowserWindow) UnhookWindowMessage(message int)

UnhookWindowMessage - Unhook the window message.

type Configuration

type Configuration struct {
	UIFolder     string
	AppDirectory string // Directory to search for a electron application
	Port         int
}

Configuration Backend Configuration returned by loadConfig

type Event added in v0.2.23

type Event struct {
	Event string `json:"event,omitempty"`
}

func (*Event) EventString added in v0.2.23

func (e *Event) EventString() string

type EventInterface added in v0.2.23

type EventInterface interface {
	EventString() string
}

type Rectangle

type Rectangle struct {
	X      int
	Y      int
	Width  int
	Height int
}

Rectangle basic rectangle object

type SocketEvent

type SocketEvent struct {
	Event string
	Data  interface{}
	ID    uuid.UUID
}

SocketEvent event

type WebPreferences

type WebPreferences struct {
	DevTools                    bool        `json:"devTools"`
	NodeIntegration             bool        `json:"nodeIntegration"`
	NodeIntegratonInWorker      bool        `json:"nodeIntegrationInWorker,omitempty"`
	Preload                     string      `json:"preload,omitempty"`
	Sandbox                     bool        `json:"sandbox,omitempty"` //Experimental
	EnableRemoteModule          bool        `json:"enableRemoteModule"`
	Session                     interface{} `json:"session,omitempty"` //TODO: Find out how this can be passed from go to electron
	Partition                   string      `json:"partition,omitempty"`
	Affinity                    string      `json:"affinity,omitempty"`
	ZoomFactor                  float64     `json:"zoomFactor,omitempty"`
	Javascript                  bool        `json:"javascript"`
	WebSecurity                 bool        `json:"webSecurity"`
	AllowRunningInsecureContent bool        `json:"allowRunningInsecureContent,omitempty"`
	Images                      bool        `json:"images"`
	TextAreasAreResizable       bool        `json:"textAreasAreResizable"`
	Webgl                       bool        `json:"webgl"`
	Webaudio                    bool        `json:"webaudio"`
	Plugins                     bool        `json:"plugins,omitempty"`
	ExperimentalFeatures        bool        `json:"experimentalFeatures,omitempty"`
	ScrollBounce                bool        `json:"scrollBounce,omitempty"`
	EnableBlinkFeatures         string      `json:"enableBlinkFeatures,omitempty"`
	DisableBlinkFeatures        string      `json:"disableBlinkFeatures,omitempty"`
	DefaultFontFamily           string      `json:"defaultFontFamily,omitempty"`
	DefaultFontSize             int         `json:"defaultFontSize,omitempty"`
	DefaultMonospaceFontSize    int         `json:"defaultMonospaceFontSize,omitempty"`
	MinimumFontSize             int         `json:"minimumFontSize,omitempty"`
	DefaultEncoding             int         `json:"defaultEncoding,omitempty"`
	BackgroundThrottling        bool        `json:"backgroundThrottling"`
	Offscreen                   bool        `json:"offscreen,omitempty"`
	ContextIsolation            bool        `json:"contextIsolation,omitempty"`
	NativeWindowOpen            bool        `json:"nativeWindowOpen,omitempty"`
	WebviewTag                  bool        `json:"webviewTag"`
	AdditionalArguments         []string    `json:"additionalArguments,omitempty"`
	SafeDialogs                 bool        `json:"safeDialogs,omitempty"`
	SafeDialogsMessage          string      `json:"safeDialogsMessage,omitempty"`
	NavigateOnDragDrop          bool        `json:"navigateOnDragDrop,omitempty"`
}

WebPreferences - webpreferences for electron browserwindow

type WindowOptions

type WindowOptions struct {
	Width                  int            `json:"width,omitempty"`
	Height                 int            `json:"height,omitempty"`
	X                      int            `json:"x,omitempty"`
	Y                      int            `json:"y,omitempty"`
	UseContentSize         bool           `json:"useContentSize,omitempty"`
	Center                 bool           `json:"center,omitempty"`
	MinWidth               int            `json:"minWidth,omitempty"`
	MinHeight              int            `json:"minHeight,omitempty"`
	MaxWidth               int            `json:"maxWidth,omitempty"`
	MaxHeight              int            `json:"maxHeight,omitempty"`
	Resizable              bool           `json:"resizable"`
	Movable                bool           `json:"movable"`
	Minimizable            bool           `json:"minimizable"`
	Maximizable            bool           `json:"maximizable"`
	Closable               bool           `json:"closable"`
	Focusable              bool           `json:"focusable"`
	AlwaysOnTop            bool           `json:"alwaysOnTop,omitempty"`
	FullScreen             bool           `json:"fullscreen,omitempty"`
	Fullscreenable         bool           `json:"fullscreenable"`
	SimpleFullscreen       bool           `json:"simpleFullscreen,omitempty"`
	SkipTaskbar            bool           `json:"skipTaskbar,omitempty"`
	Kiosk                  bool           `json:"kiosk,omitempty"`
	Title                  string         `json:"title,omitempty"`
	Icon                   string         `json:"icon,omitempty"`
	Show                   bool           `json:"show"`
	Frame                  bool           `json:"frame"`
	Parent                 interface{}    `json:"parent,omitempty"` // default is null, how to obtain parent windo handle?
	Modal                  bool           `json:"modal,omitempty"`
	AcceptFirstMouse       bool           `json:"acceptFirstMouse,omitempty"`
	DisableAutoHideCursor  bool           `json:"disableAutoHideCursor,omitempty"`
	AutoHideMenuBar        bool           `json:"autoHideMenuBar,omitempty"`
	EnableLargerThanScreen bool           `json:"enableLargerThanScreen,omitempty"`
	BackGroundColor        string         `json:"backgroundColo,omitempty"`
	HasShadow              bool           `json:"hasShadow"`
	Opacity                float64        `json:"opacity,omitempty"`
	DarkTheme              bool           `json:"darkTheme,omitempty"`
	TransParent            bool           `json:"transparent,omitempty"`
	Type                   string         `json:"type,omitempty"`
	TitleBarStyle          string         `json:"titleBarStyle,omitempty"`
	FullscreenWindowTitle  bool           `json:"fullscreenWindowTitle,omitempty"`
	ThickFrame             bool           `json:"thickFrame"`
	Vibrancy               string         `json:"vibrancy,omitempty"`
	ZoomToPageWidth        bool           `json:"zoomToPageWidth,omitempty"`
	TabbingIdentifier      string         `json:"tabbingIdentifier,omitempty"`
	WebPreferences         WebPreferences `json:"webPreferences"`
}

WindowOptions - all possible electron browserwindow options

Directories

Path Synopsis
cmd
gotron-builder/internal/application
package application proviedes build pipeline for application with gotron api.
package application proviedes build pipeline for application with gotron api.
internal

Jump to

Keyboard shortcuts

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