stopwatchapp

package
v0.0.0-...-ea70059 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2017 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package stopwatchapp contains utilities and functions for easy bootsrapping of an go GUI software

Index

Constants

View Source
const (
	EmbeddedIconPng  = "icons/app.png"  // linux
	EmbeddedIconIcns = "icons/app.icns" // mac
	EmbeddedIconIco  = "icons/app.ico"  // windows
)

Application icon embedded paths

View Source
const (
	WindowWidth  = 412
	WindowHeight = 732
)

Window size constants. These are both the minimum and default values for application window size.

View Source
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

View Source
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

View Source
const (
	Response = "response"
	Error    = "error"
	Event    = "event"
	Alert    = "alert"
)

Message types

View Source
const (
	BackendIdle = "idle"
)

Backend status strings

View Source
const EmbeddedUIPackageName = "ui/ui.asar"

EmbeddedUIPackageName is the embedded ui package path

View Source
const (
	ErrorOperationFailed = Key("failure")
)

Error keys

View Source
const (
	EventBackendStatusChanged = Key("backend.status")
)

Event keys

Variables

This section is empty.

Functions

func AstilectronVersion

func AstilectronVersion() string

AstilectronVersion returns bundled astilectron version

func Build

func Build() string

Build returns current build version

func DevTools

func DevTools() bool

DevTools returns if devtools should be enabled

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 EmbeddedUIPath

func EmbeddedUIPath() string

EmbeddedUIPath returns path to the UI package

func MustClose

func MustClose(f io.Closer)

MustClose closes given io.Closer or panics

func Name

func Name() string

Name returns the application name

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

func PersistentDataDir() (string, error)

PersistentDataDir returns an directory path for storing persistent data

func TmpDataDir

func TmpDataDir() (string, error)

TmpDataDir returns an directory path for placing temporary assets

func Unpack

func Unpack(src, dest string) error

Unpack unpacks an firmware bundle, writing files to destination directory.

func UnpackEmbeddedAssets

func UnpackEmbeddedAssets(toDir string, assetFn AssetRestoreFn) error

UnpackEmbeddedAssets unloads certain required files to given directory from the inmemory copy.

func UseTemp

func UseTemp() bool

UseTemp returns if temp should be user for assets

func Version

func Version() string

Version returns the app version

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) Bootstrap

func (a *App) Bootstrap() error

Bootstrap unpacks required assets and creates the application GUI window

func (*App) Busy

func (a *App) Busy() bool

Busy tells if application state is marked busy. This call is synchronized via mutex and is thread safe

func (*App) Send

func (a *App) Send(m *Message)

Send sends an message into queue for delivery to renderer.

func (*App) SetOpRunning

func (a *App) SetOpRunning(active bool) bool

SetOpRunning activates or disables run status. If return value is different than input value, then operation was refused

func (*App) SetWorkingDir

func (a *App) SetWorkingDir(dirname string)

SetWorkingDir sets directory where assets and database should be unloaded.

func (*App) Wait

func (a *App) Wait()

Wait waits until process has finished.

func (*App) WorkingDir

func (a *App) WorkingDir() string

WorkingDir returns current working dir. Attempts to resolve and create a working dir on first use if no dir is yet set.

type Asset

type Asset struct {
	*bytes.Reader
}

Asset is an embedded asset that implements io.ReadCloser

func NewAsset

func NewAsset(b []byte) *Asset

NewAsset returns an asset from given bytes

func (*Asset) Close

func (a *Asset) Close() error

Close method for completing io.Closer

type AssetRestoreFn

type AssetRestoreFn func(dir, name string) error

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) Get

func (d DataMap) Get(key string) (v interface{}, ok bool)

Get returns a value from the map by key

func (DataMap) GetBool

func (d DataMap) GetBool(key string) (v, ok bool)

GetBool returns a value from the map by key as a bool

func (DataMap) GetFloat64

func (d DataMap) GetFloat64(key string) (v float64, ok bool)

GetFloat64 returns a value from the map by key as a float64

func (DataMap) GetInt

func (d DataMap) GetInt(key string) (v int, ok bool)

GetInt returns a value from the map by key as a int

func (DataMap) GetString

func (d DataMap) GetString(key string) (v string, ok bool)

GetString returns a value from the map by key as a string

type Dimensions

type Dimensions struct {
	Height int
	Width  int
}

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 Key

type Key string

Key is a message key, which tells what the message purpose is.

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

func NewBackendStatus(status string) *Message

NewBackendStatus generates an new backend status event message

func NewError

func NewError(id string, err string) *Message

NewError returns an error message.

func NewEvent

func NewEvent(event Key, data interface{}) *Message

NewEvent returns an event message with given data.

func NewMessage

func NewMessage(id string, t Type, key Key, data interface{}) *Message

NewMessage returns an Message with given values

func NewResponse

func NewResponse(id string, key Key, data interface{}) *Message

NewResponse returns an response message with given data.

func (*Message) DataBool

func (m *Message) DataBool() (v bool, ok bool)

DataBool returns the data as bool if possible and if the value was a bool.

func (*Message) DataFloat64

func (m *Message) DataFloat64() (v float64, ok bool)

DataFloat64 returns the data as float64 if possible and truth value if data conversion worked

func (*Message) DataInt

func (m *Message) DataInt() (int, bool)

DataInt returns the data as int if possible and truth value if data conversion was possible.

func (*Message) DataMap

func (m *Message) DataMap() (DataMap, bool)

DataMap returns the data as DataMap if possible and truth value if data conversion worked

func (*Message) DataString

func (m *Message) DataString() (v string, ok bool)

DataString returns the data as string if possible and if the value was a string.

func (*Message) Into

func (m *Message) Into(tgt interface{}) error

Into attempts to coerce the message data into given interface value. Uses "json" tags for hinting.

func (Message) String

func (m Message) String() string

type MessageHandlerFn

type MessageHandlerFn func(*Message) (interface{}, error)

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

Jump to

Keyboard shortcuts

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