webapp

package module
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2020 License: MPL-2.0 Imports: 10 Imported by: 1

README

Framework for displaying a web view within a Go application

Currently supports macOS and Windows. Before this can be used, the CEF bindings must be installed. Follow the directions in the repository at https://github.com/richardwilkes/cef

An example use of this library can be found at https://github.com/richardwilkes/webapp-example

Documentation

Index

Constants

View Source
const (
	MenuIDAppMenu = int(cef.MenuIDUserFirst) + iota
	MenuIDFileMenu
	MenuIDEditMenu
	MenuIDWindowMenu
	MenuIDHelpMenu
	MenuIDServicesMenu
	MenuIDAboutItem
	MenuIDDevToolsItem
	MenuIDPreferencesItem
	MenuIDQuitItem
	MenuIDCutItem
	MenuIDCopyItem
	MenuIDPasteItem
	MenuIDDeleteItem
	MenuIDSelectAllItem
	MenuIDMinimizeItem
	MenuIDZoomItem
	MenuIDBringAllWindowsToFrontItem
	MenuIDCloseItem
	MenuIDHideItem
	MenuIDHideOthersItem
	MenuIDShowAllItem
	MenuIDUserBase = MenuIDAppMenu + 250
)

Pre-defined menu IDs. Apps should start their IDs at MenuIDUserBase.

Variables

View Source
var CheckQuitCallback = func() QuitResponse { return Now }

CheckQuitCallback is called when termination has been requested. Default returns Now.

View Source
var DidActivateCallback = func() {}

DidActivateCallback is called once the application is activated.

View Source
var DidDeactivateCallback = func() {}

DidDeactivateCallback is called once the application is deactivated.

View Source
var DidFinishStartupCallback = func() {}

DidFinishStartupCallback is called once application startup has completed.

View Source
var QuitAfterLastWindowClosedCallback = func() bool { return true }

QuitAfterLastWindowClosedCallback is called when the last window is closed to determine if the application should quit as a result. Default returns yes.

View Source
var QuittingCallback = func() {}

QuittingCallback is called when the app will in fact terminate.

View Source
var ThemeChangedCallback = func() {}

ThemeChangedCallback is called when the theme is changed.

View Source
var WillActivateCallback = func() {}

WillActivateCallback is called right before the application is activated.

View Source
var WillDeactivateCallback = func() {}

WillDeactivateCallback is called right before the application is deactivated.

View Source
var WillFinishStartupCallback = func() {}

WillFinishStartupCallback is called right before application startup has completed. This is a good point to create any windows your app wants to display.

Functions

func AllWindowsToFront

func AllWindowsToFront()

AllWindowsToFront attempts to bring all of the application's windows to the foreground.

func AttemptQuit

func AttemptQuit()

AttemptQuit initiates the termination sequence.

func Count

func Count() int

Count returns the number of windows that are open.

func Initialize

func Initialize(platformDriver Driver) (*cef.MainArgs, error)

Initialize the library. This should be called on the main OS thread as early as possible -- typically before parsing command-line arguments, as this may be a request to start a sub-process and not the primary application.

Note that starting goroutines may cause your code to start executing on a secondary thread, so either make this call prior to starting goroutines, or explicitly call runtime.LockOSThread() before doing so.

This function will not return if the executable is being started as a CEF sub-process.

func InvokeUITask

func InvokeUITask(task func())

InvokeUITask a task on the UI thread. The task is put into the system event queue and will be run at the next opportunity.

func InvokeUITaskAfter

func InvokeUITaskAfter(task func(), after time.Duration)

InvokeUITaskAfter schedules a task to be run on the UI thread after waiting for the specified duration.

func MayQuitNow

func MayQuitNow(quit bool)

MayQuitNow resumes the termination sequence that was delayed when Later is returned from CheckQuit. Passing in false for the quit parameter will cancel the termination sequence while true will allow it to proceed.

func MenuBarHeight() float64

MenuBarHeight returns the height of the MenuBar when displayed in a window.

func Start

func Start(args *cef.MainArgs, settings *cef.Settings, application *cef.App) error

Start the user interface. This and most other functions in this package should only be called from the main (UI) thread.

Types

type AppVisibilityController

type AppVisibilityController interface {
	HideApp()
	HideOtherApps()
	ShowAllApps()
}

AppVisibilityController defines optional APIs a platform can provide for manipulating application visibility.

type Display

type Display struct {
	Bounds        geom.Rect
	UsableBounds  geom.Rect
	ScalingFactor float64
	IsMain        bool
}

Display holds information about each available active display.

func Displays

func Displays() []*Display

Displays returns all displays.

func MainDisplay

func MainDisplay() *Display

MainDisplay returns the primary display.

type Driver

type Driver interface {
	PrepareForStart() error
	PrepareForEventLoop()
	RunEventLoop()
	OnPreKeyEvent(event *cef.KeyEvent, isKeyboardShortcut *int32) int32
	OnKeyEvent(event *cef.KeyEvent) int32

	AttemptQuit()
	MayQuitNow(quit bool)

	MenuBarForWindow(wnd *Window) (bar *MenuBar, isGlobal, isFirst bool)
	MenuBarMenuAtIndex(bar *MenuBar, index int) *Menu
	MenuBarInsert(bar *MenuBar, beforeIndex int, menu *Menu)
	MenuBarRemove(bar *MenuBar, index int)
	MenuBarCount(bar *MenuBar) int
	MenuBarHeightInWindow() float64

	MenuInit(menu *Menu)
	MenuItemAtIndex(menu *Menu, index int) *MenuItem
	MenuItemAtIndexSetTitle(menu *Menu, index int, title string)
	MenuInsertSeparator(menu *Menu, beforeIndex int)
	MenuInsertItem(menu *Menu, beforeIndex, id int, title string, key *keys.Key, keyModifiers keys.Modifiers, validator func() bool, handler func())
	MenuInsertMenu(menu *Menu, beforeIndex, id int, title string) *Menu
	MenuRemove(menu *Menu, index int)
	MenuCount(menu *Menu) int
	MenuDispose(menu *Menu)

	Displays() []*Display
	KeyWindow() *Window
	BringAllWindowsToFront()

	WindowInit(wnd *Window, style StyleMask, bounds geom.Rect, title string) error
	WindowBrowserParent(wnd *Window) unsafe.Pointer
	WindowClose(wnd *Window)
	WindowSetTitle(wnd *Window, title string)
	WindowBounds(wnd *Window) geom.Rect
	WindowSetBounds(wnd *Window, bounds geom.Rect)
	WindowContentSize(wnd *Window) geom.Size
	WindowToFront(wnd *Window)
	WindowMinimize(wnd *Window)
	WindowZoom(wnd *Window)
	WindowThemeIsDark(wnd *Window) bool
}

Driver defines the required functions each platform driver must provide.

func PlatformDriver

func PlatformDriver() Driver

PlatformDriver returns the underlying driver.

type Menu struct {
	PlatformData interface{}
	ID           int
	Title        string
}

Menu represents a set of menu items.

func NewMenu

func NewMenu(id int, title string) *Menu

NewMenu creates a new menu.

func (menu *Menu) Count() int

Count of menu items in this menu.

func (menu *Menu) Dispose()

Dispose releases any operating system resources associated with this menu.

func (menu *Menu) InsertItem(beforeIndex, id int, title string, key *keys.Key, keyModifiers keys.Modifiers, validator func() bool, handler func())

InsertItem inserts a menu item at the specified item index within this menu. Pass in a negative index to append to the end. Both 'validator' and 'handler' may be nil for default behavior.

func (menu *Menu) InsertMenu(beforeIndex, id int, title string) *Menu

InsertMenu inserts a new sub-menu at the specified item index within this menu. Pass in a negative index to append to the end.

func (menu *Menu) InsertSeparator(beforeIndex int)

InsertSeparator inserts a menu separator at the specified item index within this menu. Pass in a negative index to append to the end.

func (menu *Menu) Item(id int) *MenuItem

Item returns the menu item with the specified id anywhere in the menu and and its sub-menus.

func (menu *Menu) ItemAtIndex(index int) *MenuItem

ItemAtIndex returns the menu item at the specified index within the menu.

func (menu *Menu) Remove(index int)

Remove the menu item at the specified index from this menu.

func (menu *Menu) SetItemAtIndexTitle(index int, title string)

SetItemAtIndexTitle sets the title of the menu item at the specified index within the menu.

func (menu *Menu) SetItemTitle(id int, title string)

SetItemTitle sets the title of the menu item with the specified id anywhere in the menu and its sub-menus.

type MenuBar struct {
	PlatformData interface{}
}

MenuBar represents a set of menus.

func MenuBarForWindow(window *Window) (bar *MenuBar, isGlobal, isFirst bool)

MenuBarForWindow returns the menu bar for the given window. On macOS, the menu bar is a global entity and the same value will be returned for all windows. On macOS, you may pass nil for the window parameter. If isGlobal is true, the first time this function is called, isFirst will be true as well, allowing you to only initialize the global menu bar once.

func (bar *MenuBar) Count() int

Count of menus in this menu bar.

func (bar *MenuBar) IndexOf(menu *Menu) int

IndexOf returns the index of the menu within this menu bar, or -1.

func (bar *MenuBar) InsertMenu(beforeIndex int, menu *Menu)

InsertMenu inserts a menu at the specified item index within this menu bar. Pass in a negative index to append to the end.

func (bar *MenuBar) Menu(id int) *Menu

Menu returns the menu with the specified id anywhere in the menu bar and its sub-menus.

func (bar *MenuBar) MenuAtIndex(index int) *Menu

MenuAtIndex returns the menu at the specified index within the menu bar.

func (bar *MenuBar) MenuItem(id int) *MenuItem

MenuItem returns the menu item with the specified id anywhere in the menu bar and its sub-menus.

func (bar *MenuBar) Remove(index int)

Remove the menu at the specified index from this menu bar.

type MenuItem struct {
	Owner   *Menu
	Index   int
	ID      int
	Title   string
	SubMenu *Menu
}

MenuItem holds information about menu items.

type QuitResponse

type QuitResponse int

QuitResponse is used to respond to requests for app termination.

const (
	Cancel QuitResponse = iota
	Now
	Later // Must make a call to MayQuitNow() at some point in the future.
)

Possible termination responses

type StyleMask

type StyleMask int

StyleMask controls the look and capabilities of a window.

const (
	TitledWindowMask StyleMask = 1 << iota
	ClosableWindowMask
	MinimizableWindowMask
	ResizableWindowMask
	BorderlessWindowMask = 0
	StdWindowMask        = TitledWindowMask | ClosableWindowMask | MinimizableWindowMask | ResizableWindowMask
)

Possible values for the StyleMask.

type Window

type Window struct {
	PlatformData interface{}
	Browser      *cef.Browser

	// MayCloseCallback is called when the user has requested that the window
	// be closed. Return true to permit it, false to cancel the operation.
	// Defaults to always returning true.
	MayCloseCallback func() bool
	// WillCloseCallback is called just prior to the window closing.
	WillCloseCallback func()
	// GainedFocus is called when the keyboard focus is gained on this window.
	GainedFocus func()
	// LostFocus is called when the keyboard focus is lost from this window.
	LostFocus func()
	// contains filtered or unexported fields
}

Window holds window information.

func KeyWindow

func KeyWindow() *Window

KeyWindow returns the window that currently has the keyboard focus, or nil if none of your application's windows has the keyboard focus.

func NewWindow

func NewWindow(style StyleMask, bounds geom.Rect, title, url string) (*Window, error)

NewWindow creates a new window with a webview as its content.

func Windows

func Windows() []*Window

Windows returns a slice containing the current set of open windows.

func (*Window) AttemptClose

func (window *Window) AttemptClose()

AttemptClose closes the window if permitted.

func (*Window) Bounds

func (window *Window) Bounds() geom.Rect

Bounds returns the boundaries in display coordinates of the frame of this window (i.e. the area that includes both the content and its border and window controls).

func (*Window) Closable

func (window *Window) Closable() bool

Closable returns true if the window was created with the ClosableWindowMask.

func (*Window) Dispose

func (window *Window) Dispose()

Dispose of the window.

func (*Window) Focused

func (window *Window) Focused() bool

Focused returns true if the window has the current keyboard focus.

func (*Window) Minimizable

func (window *Window) Minimizable() bool

Minimizable returns true if the window was created with the MinimizableWindowMask.

func (*Window) Minimize

func (window *Window) Minimize()

Minimize performs the platform's minimize function on the window.

func (*Window) Resizable

func (window *Window) Resizable() bool

Resizable returns true if the window was created with the ResizableWindowMask.

func (*Window) SetBounds

func (window *Window) SetBounds(bounds geom.Rect)

SetBounds sets the boundaries of the frame of this window.

func (*Window) SetTitle

func (window *Window) SetTitle(title string)

SetTitle sets the title of this window.

func (*Window) String

func (window *Window) String() string

func (*Window) ThemeIsDark added in v0.2.1

func (window *Window) ThemeIsDark() bool

ThemeIsDark returns true if the window theme is a dark one.

func (*Window) Title

func (window *Window) Title() string

Title returns the title of this window.

func (*Window) ToFront

func (window *Window) ToFront()

ToFront attempts to bring the window to the foreground and give it the keyboard focus.

func (*Window) ToggleDevTools

func (window *Window) ToggleDevTools()

ToggleDevTools toggles display of the Chrome development tools window.

func (*Window) WindowContentSize

func (window *Window) WindowContentSize() geom.Size

WindowContentSize returns the size of the windoe's content area.

func (*Window) Zoom

func (window *Window) Zoom()

Zoom performs the platform's zoom function on the window.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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