app

package
v0.0.0-...-bedf5c0 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2024 License: MPL-2.0 Imports: 18 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Error

func Error(ctx context.Context, errs ...error)

Error calls Error on the application inside the context. It panics if the context does not have the application.

func Fatal

func Fatal(ctx context.Context, errs ...error)

Fatal is similar to Error, but calls Fatal instead.

func GTKWindowFromContext

func GTKWindowFromContext(ctx context.Context) *gtk.Window

GTKWindowFromContext returns the context's window. If the context does not have a window, then the active window is returned.

func Hook

func Hook(f func(*Application))

Hook adds a new hook callback to be called during construction of an Application. This function allows injecting initialization function calls such as Adwaita's without having to explicitly write it in main().

func IsActive

func IsActive(ctx context.Context) bool

IsActive returns true if any of the windows belonging to gotktrix is active.

func IsDevel

func IsDevel() bool

IsDevel returns true if the windows spawned using app will have the .devel class. This returns true if Go reports that vcs.modified is true.

func OpenURI

func OpenURI(ctx context.Context, uri string)

OpenURI opens the given URI using the system's default application.

func SetTitle

func SetTitle(ctx context.Context, title string)

SetTitle sets the main window's title.

func WithApplication

func WithApplication(ctx context.Context, app *Application) context.Context

WithApplication injects the given application instance into a context. The returned context will also be cancelled if the application shuts down.

func WithWindow

func WithWindow(ctx context.Context, win *Window) context.Context

WithWindow injects the given Window instance into a context. The returned context will be cancelled if the window is closed.

Types

type Application

type Application struct {
	*gtk.Application
	// contains filtered or unexported fields
}

Application describes the state of a Matrix application.

func FromContext

func FromContext(ctx context.Context) *Application

FromContext pulls the application from the given context. If the given context isn't derived from Application, then nil is returned.

func New

func New(ctx context.Context, appID, appName string) *Application

New creates a new Application.

func NewWithFlags

func NewWithFlags(ctx context.Context, appID, appName string, flags gio.ApplicationFlags) *Application

NewWithFlags creates a new Application with the given application flags.

func (*Application) AddActionCallbacks

func (app *Application) AddActionCallbacks(m map[string]gtkutil.ActionCallback)

AddActionCallbacks is the ActionCallback variant of AddActions.

func (*Application) AddActionShortcuts

func (app *Application) AddActionShortcuts(m map[string]string)

AddActionShortcuts binds accelerator strings to action strings.

func (*Application) AddActions

func (app *Application) AddActions(m map[string]func())

AddActions adds the given map of actions into the Application.

func (*Application) AddJSONActions

func (app *Application) AddJSONActions(m map[string]interface{})

AddJSONActions adds the given map of action functions with parameters into the Application. The value of the map is a function of type `func(T)`, where T is any type that is JSON-encoded using gtkutil.NewJSONVariant.

func (*Application) BaseID

func (app *Application) BaseID() string

BaseID returns the last part of the application ID.

func (*Application) CachePath

func (app *Application) CachePath(tails ...string) string

CacheDir returns the path to the cache directory of the application.

func (*Application) ConfigPath

func (app *Application) ConfigPath(tails ...string) string

ConfigPath returns the path to the configuration directory with the given tails appended. If the path fails, then the function panics.

func (*Application) Context

func (app *Application) Context() context.Context

Context returns the Application's context. This context contains the Application instance and will be cancelled on SIGINT once Run has been called. This method will panic if it's called before Run is called. Use it during initialization within signals.

func (*Application) Error

func (app *Application) Error(err ...error)

Error shows an error popup.

func (*Application) Fatal

func (app *Application) Fatal(err ...error)

Fatal shows a fatal error popup and closes the application afterwards.

func (*Application) ID

func (app *Application) ID() string

ID returns the application ID.

func (*Application) IDDot

func (app *Application) IDDot(parts ...string) string

IDDot creates a new application ID by joining all parts into the tail of the application ID. If no arguments are given, then the app ID is returned.

func (*Application) Name

func (app *Application) Name() string

Name returns the application name.

func (*Application) NewWindow

func (app *Application) NewWindow() *Window

NewWindow creates a new Window bounded to the Application instance.

func (*Application) Quit

func (app *Application) Quit()

Quit quits the application. The function is thread-safe.

func (*Application) Run

func (app *Application) Run(args []string) int

Run runs the application for as long as the context is alive. If a SIGINT is sent, then the application is stopped.

func (*Application) RunMain

func (app *Application) RunMain()

RunMain is a convenient function around Run that uses os.Args and os.Exit.

func (*Application) SuffixedTitle

func (app *Application) SuffixedTitle(title string) string

SuffixedTitle suffixes the title with the application name and returns the string.

type SingleStateKey

type SingleStateKey[StateT any] struct {
	// contains filtered or unexported fields
}

SingleStateKey defines a constant key for a state that only has one value.

func NewSingleStateKey

func NewSingleStateKey[StateT any](tails ...string) SingleStateKey[StateT]

NewSingleStateKey creates a new SingleStateKey with the given state type and the config path tails.

func (SingleStateKey[StateT]) Acquire

func (s SingleStateKey[StateT]) Acquire(ctx context.Context) *TypedSingleState[StateT]

type State deprecated

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

State implements an easy API for storing persistent state that components can use.

Deprecated: prefer StateKey, which is a type-safe wrapper around this.

func AcquireState

func AcquireState(ctx context.Context, tails ...string) *State

AcquireState creates a new Config instance.

func (*State) Delete

func (s *State) Delete(key string)

Delete calls Set(key, nil).

func (*State) Each

func (s *State) Each(f func(key string, unmarshal func(interface{}) bool) (done bool))

Each loops over each key in the map.

func (*State) Exists

func (s *State) Exists(key string) bool

Exists returns true if key exists.

func (*State) ExistsAsync

func (s *State) ExistsAsync(key string, done func(exists bool))

func (*State) Get

func (s *State) Get(key string, dst interface{}) bool

Get gets the value of the key.

func (*State) GetAsync

func (s *State) GetAsync(key string, dst interface{}, done func())

GetAsync gets the value of the key asynchronously. The given callback may be immediately called if the value is already available, or it may be called later when the value is available. The callback is always called in the main thread.

func (*State) Set

func (s *State) Set(key string, val interface{})

Set sets the value of the key. If val = nil, then the key is deleted.

type StateKey

type StateKey[StateT any] struct {
	// contains filtered or unexported fields
}

StateKey defines a constant key for a state. It exposes a type-safe API to acquire, get and restore state.

func NewStateKey

func NewStateKey[StateT any](tails ...string) StateKey[StateT]

NewStateKey creates a new StateKey with the given state type and the config path tails.

func (StateKey[StateT]) Acquire

func (s StateKey[StateT]) Acquire(ctx context.Context) *TypedState[StateT]

type TypedSingleState

type TypedSingleState[StateT any] State

TypedSingleState is a type-safe wrapper around State that only has one value.

func (*TypedSingleState[StateT]) Delete

func (s *TypedSingleState[StateT]) Delete()

Delete deletes the key.

func (*TypedSingleState[StateT]) Exists

func (s *TypedSingleState[StateT]) Exists(f func(bool))

Exists returns true if key exists.

func (*TypedSingleState[StateT]) Get

func (s *TypedSingleState[StateT]) Get(f func(StateT))

Get gets the value of the key. If the key does not exist, it does not call f.

func (*TypedSingleState[StateT]) Set

func (s *TypedSingleState[StateT]) Set(value StateT)

Set sets the value of the key.

type TypedState

type TypedState[StateT any] State

TypedState is a type-safe wrapper around State.

func (*TypedState[StateT]) Delete

func (s *TypedState[StateT]) Delete(key string)

Delete deletes the key.

func (*TypedState[StateT]) Each

func (s *TypedState[StateT]) Each(f func(key string, value StateT) (done bool))

Each loops over each key in the map. It automatically unmarshals the value before calling f. To avoid this, use EachKey.

func (*TypedState[StateT]) EachKey

func (s *TypedState[StateT]) EachKey(f func(key string) (done bool))

EachKey loops over each key in the map.

func (*TypedState[StateT]) Exists

func (s *TypedState[StateT]) Exists(key string, f func(bool))

Exists returns true if key exists.

func (*TypedState[StateT]) Get

func (s *TypedState[StateT]) Get(key string, f func(StateT))

Get gets the value of the key. If the key does not exist, it does not call f.

func (*TypedState[StateT]) Set

func (s *TypedState[StateT]) Set(key string, value StateT)

Set sets the value of the key.

type Window

type Window struct {
	gtk.Window
	// contains filtered or unexported fields
}

Window wraps a gtk.ApplicationWindow.

func NewWindow

func NewWindow(app *Application) *Window

NewWindow creates a new Window bounded to the Application instance.

func WindowFromContext

func WindowFromContext(ctx context.Context) *Window

WindowFromContext returns the context's window.

func WrapWindow

func WrapWindow(app *Application, window *gtk.ApplicationWindow) *Window

WrapWindow wraps a gtk.ApplicationWindow into an app.Window.

func (*Window) Application

func (w *Window) Application() *Application

Application returns the Window's parent Application instance.

func (*Window) Error

func (w *Window) Error(err ...error)

Error shows an error popup.

func (*Window) Fatal

func (w *Window) Fatal(err ...error)

Fatal shows a fatal error popup and closes the window afterwards.

func (*Window) NewHeader

func (w *Window) NewHeader() *gtk.HeaderBar

NewHeader creates a new header and puts it into the application window.

func (*Window) NewWindowHandle

func (w *Window) NewWindowHandle() *gtk.WindowHandle

NewWindowHeader creates a new blank header.

func (*Window) NotifyChild

func (w *Window) NotifyChild(once bool, f func())

NotifyChild calls f if the main window's child is changed. If once is true, then f is never called again.

func (*Window) SetLoading

func (w *Window) SetLoading()

SetLoading shows a spinning circle. It disables the window. Note that this function crashes when the base gtk.Window comes from adw.Window.

func (*Window) SetSensitive

func (w *Window) SetSensitive(sensitive bool)

SetSensitive sets whether or not the application's window is enabled.

func (*Window) SetTitle

func (w *Window) SetTitle(title string)

SetTitle sets the application (and the main instance window)'s title.

Directories

Path Synopsis
Package notify provides an API to send declarative notifications as well as playing sounds when they're sent.
Package notify provides an API to send declarative notifications as well as playing sounds when they're sent.
Package prefs provides a publish-subscription API for global settinsg management.
Package prefs provides a publish-subscription API for global settinsg management.

Jump to

Keyboard shortcuts

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