Documentation ¶
Overview ¶
Package stopwatchapp contains utilities and functions for easy bootsrapping of an go GUI software
Index ¶
- Constants
- func AstilectronVersion() string
- func Build() string
- func DevTools() bool
- func ElectronVersion() string
- func EmbeddedAstilectronPath() string
- func EmbeddedElectronPath() string
- func EmbeddedIconPath() string
- func EmbeddedResources() []string
- func EmbeddedUIMountPoint() string
- func EmbeddedUIPath() string
- func MustClose(f io.Closer)
- func Name() string
- func NewProvisioner(dest string, restoreFn AssetRestoreFn) astilectron.Provisioner
- func PersistentDataDir() (string, error)
- func TmpDataDir() (string, error)
- func Unpack(src, dest string) error
- func UnpackEmbeddedAssets(toDir string, assetFn AssetRestoreFn) error
- func UseTemp() bool
- func Version() string
- type App
- type Asset
- type AssetRestoreFn
- type BackendStatus
- type DataMap
- type Dimensions
- type GetAssetFunc
- type Key
- type Message
- func NewAlert(data interface{}) *Message
- func NewBackendStatus(status string) *Message
- func NewError(id string, err string) *Message
- func NewEvent(event Key, data interface{}) *Message
- func NewMessage(id string, t Type, key Key, data interface{}) *Message
- func NewResponse(id string, key Key, data interface{}) *Message
- func (m *Message) DataBool() (v bool, ok bool)
- func (m *Message) DataFloat64() (v float64, ok bool)
- func (m *Message) DataInt() (int, bool)
- func (m *Message) DataMap() (DataMap, bool)
- func (m *Message) DataString() (v string, ok bool)
- func (m *Message) Into(tgt interface{}) error
- func (m Message) String() string
- type MessageHandlerFn
- type Type
- type VendorVersions
- type VendorVersionsPackage
Constants ¶
const ( EmbeddedIconPng = "icons/app.png" // linux EmbeddedIconIcns = "icons/app.icns" // mac EmbeddedIconIco = "icons/app.ico" // windows )
Application icon embedded paths
const ( WindowWidth = 412 WindowHeight = 732 )
Window size constants. These are both the minimum and default values for application window size.
const ( RequestActiveTask = Key("get.active.task") RequestAppVersions = Key("get.versions") RequestOpenDatabase = Key("open.database") RequestAddTask = Key("add.task") RequestAddGroup = Key("add.group") RequestGetHistory = Key("get.history") RequestGetTask = Key("get.task") RequestGetUsage = Key("get.usage") RequestGroups = Key("get.groups") RequestGroupTasks = Key("get.group.tasks") RequestSetHistory = Key("set.history") RequestStartTask = Key("start.task") RequestStopTask = Key("stop.task") RequestTaskSlices = Key("get.task.slices") RequestUpdateGroup = Key("update.group") RequestUpdateTask = Key("update.task") RequestWindowClose = Key("window.close") RequestWindowMinimize = Key("window.minimize") )
Request keys
const ( EventNameProvisionAstilectronAlreadyProvisioned = "provision.astilectron.already.provisioned" EventNameProvisionAstilectronFinished = "provision.astilectron.finished" EventNameProvisionAstilectronMoved = "provision.astilectron.moved" EventNameProvisionAstilectronUnzipped = "provision.astilectron.unzipped" EventNameProvisionElectronAlreadyProvisioned = "provision.electron.already.provisioned" EventNameProvisionElectronFinished = "provision.electron.finished" EventNameProvisionElectronMoved = "provision.electron.moved" EventNameProvisionElectronUnzipped = "provision.electron.unzipped" )
Provision event names
const ( Response = "response" Error = "error" Event = "event" Alert = "alert" )
Message types
const (
BackendIdle = "idle"
)
Backend status strings
const EmbeddedUIPackageName = "ui/ui.asar"
EmbeddedUIPackageName is the embedded ui package path
const (
ErrorOperationFailed = Key("failure")
)
Error keys
const (
EventBackendStatusChanged = Key("backend.status")
)
Event keys
Variables ¶
This section is empty.
Functions ¶
func AstilectronVersion ¶
func AstilectronVersion() string
AstilectronVersion returns bundled astilectron version
func ElectronVersion ¶
func ElectronVersion() string
ElectronVersion returns bundled electron version
func EmbeddedAstilectronPath ¶
func EmbeddedAstilectronPath() string
EmbeddedAstilectronPath returns the embedded Astilectron package path
func EmbeddedElectronPath ¶
func EmbeddedElectronPath() string
EmbeddedElectronPath returns the embedded Electron package path
func EmbeddedIconPath ¶
func EmbeddedIconPath() string
EmbeddedIconPath returns the embedded path of application icon for current OS.
func EmbeddedResources ¶
func EmbeddedResources() []string
EmbeddedResources returns a list of resources that need to be unpacked
func EmbeddedUIMountPoint ¶
func EmbeddedUIMountPoint() string
EmbeddedUIMountPoint return the path to give for Electron to boot up the GUI
func NewProvisioner ¶
func NewProvisioner(dest string, restoreFn AssetRestoreFn) astilectron.Provisioner
NewProvisioner returns an initialized provisioner that will unpack the embedded vendor runtime resources to their correct locations.
func PersistentDataDir ¶
PersistentDataDir returns an directory path for storing persistent data
func TmpDataDir ¶
TmpDataDir returns an directory path for placing temporary assets
func UnpackEmbeddedAssets ¶
func UnpackEmbeddedAssets(toDir string, assetFn AssetRestoreFn) error
UnpackEmbeddedAssets unloads certain required files to given directory from the inmemory copy.
Types ¶
type App ¶
type App struct { Window *astilectron.Window // Main application window Renderer *astilectron.Astilectron // Renderer process handle // contains filtered or unexported fields }
App defines an GUI application and the required component handles
func New ¶
func New(dataFn astilectron.Disembedder, restoreFn AssetRestoreFn, msgFn MessageHandlerFn) *App
New returns a new initialized application ready for boostrapping.
func (*App) AssetReader ¶
func (a *App) AssetReader() GetAssetFunc
AssetReader returns an function for reading in-memory firmware asset as a io.Reader
func (*App) Busy ¶
Busy tells if application state is marked busy. This call is synchronized via mutex and is thread safe
func (*App) SetOpRunning ¶
SetOpRunning activates or disables run status. If return value is different than input value, then operation was refused
func (*App) SetWorkingDir ¶
SetWorkingDir sets directory where assets and database should be unloaded.
func (*App) WorkingDir ¶
WorkingDir returns current working dir. Attempts to resolve and create a working dir on first use if no dir is yet set.
type AssetRestoreFn ¶
AssetRestoreFn defines an accessor function type for restoring embedded assets to file system.
type BackendStatus ¶
type BackendStatus struct { // Status is the backend status Status string `json:"status"` }
BackendStatus indicates status of backend
type DataMap ¶
type DataMap map[string]interface{}
DataMap is an helper for interacting with map type message data
func (DataMap) GetFloat64 ¶
GetFloat64 returns a value from the map by key as a float64
type Dimensions ¶
Dimensions describes size in width and height in pixels.
func WindowSize ¶
func WindowSize() Dimensions
WindowSize returns the effective size to be used for new application window to get correct effective size (takes window chrome into account).
type GetAssetFunc ¶
type GetAssetFunc func(path string) (io.ReadCloser, error)
GetAssetFunc defines an interface function for retrieving data of a named file
type Message ¶
type Message struct { ID string `json:"id,omitempty"` // message ID, set by sender and replayed by responder. Key Key `json:"key,omitempty"` // message target, what is requested. Type Type `json:"type"` // type tells what kind of a message this is. Data interface{} `json:"data,omitempty"` // target data, will be parsed based on Target. }
Message describes an message sent by GUI to our Go process.
func NewAlert ¶
func NewAlert(data interface{}) *Message
NewAlert returns an alert message with given data
func NewBackendStatus ¶
NewBackendStatus generates an new backend status event message
func NewMessage ¶
NewMessage returns an Message with given values
func NewResponse ¶
NewResponse returns an response message with given data.
func (*Message) DataBool ¶
DataBool returns the data as bool if possible and if the value was a bool.
func (*Message) DataFloat64 ¶
DataFloat64 returns the data as float64 if possible and truth value if data conversion worked
func (*Message) DataInt ¶
DataInt returns the data as int if possible and truth value if data conversion was possible.
func (*Message) DataMap ¶
DataMap returns the data as DataMap if possible and truth value if data conversion worked
func (*Message) DataString ¶
DataString returns the data as string if possible and if the value was a string.
type MessageHandlerFn ¶
MessageHandlerFn defines an callback for incoming GUI messages
type Type ¶
type Type string
Type tells the type of the message, if it's a response, error or an event
type VendorVersions ¶
type VendorVersions struct { Astilectron *VendorVersionsPackage `json:"astilectron,omitempty"` Electron map[string]*VendorVersionsPackage `json:"electron,omitempty"` }
VendorVersions represents the provision status
func BundledVendorVersions ¶
func BundledVendorVersions() VendorVersions
BundledVendorVersions returns versions for vendored packages that are bundled in the binary
type VendorVersionsPackage ¶
type VendorVersionsPackage struct {
Version string `json:"version"`
}
VendorVersionsPackage represents the provision status of a package