app

package
v1.26.0 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2026 License: MIT Imports: 45 Imported by: 0

Documentation

Overview

Package app contains the main application logic for Neru.

This package orchestrates all components of the Neru application, serving as the central coordinator that manages state transitions, mode switching, and integration between various subsystems. The App struct is the heart of the application.

Index

Constants

View Source
const (
	ModeIdle   = domain.ModeIdle
	ModeHints  = domain.ModeHints
	ModeGrid   = domain.ModeGrid
	ModeScroll = domain.ModeScroll
)

Mode constants from domain package.

View Source
const (
	// MaxExecDisplayLength is the maximum length for executable display names.
	MaxExecDisplayLength = 30
	// SystrayQuitTimeout is the timeout for systray quit.
	SystrayQuitTimeout = 10 * time.Second
	// GCTickerInterval is the interval for garbage collection.
	GCTickerInterval = 5 * time.Minute

	// HighMemoryThreshold is the heap allocation threshold for triggering GC (100MB).
	HighMemoryThreshold = 100 * 1024 * 1024 // 100MB

	// LowMemoryThreshold is the normal heap allocation threshold (50MB).
	LowMemoryThreshold = 50 * 1024 * 1024 // 50MB

	// HighMemoryGCInterval is the GC interval when memory pressure is high.
	HighMemoryGCInterval = 1 * time.Minute // GC every 1 minute when high memory

	// LowMemoryGCInterval is the GC interval when memory pressure is normal.
	LowMemoryGCInterval = 5 * time.Minute // GC every 5 minutes when low memory

	// BytesPerMB is the number of bytes in a megabyte.
	BytesPerMB = 1024 * 1024
)

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	ConfigPath string
	// contains filtered or unexported fields
}

App represents the main application instance containing all state and dependencies.

func New

func New(opts ...Option) (*App, error)

New creates a new App instance with the provided options. It applies sensible defaults and allows customization through functional options.

func (*App) ActivateMode

func (a *App) ActivateMode(mode Mode)

ActivateMode activates the specified mode.

func (*App) CaptureInitialCursorPosition

func (a *App) CaptureInitialCursorPosition()

CaptureInitialCursorPosition captures the initial cursor position.

func (*App) Cleanup

func (a *App) Cleanup()

Cleanup cleans up resources.

func (*App) Config

func (a *App) Config() *config.Config

Config returns the application configuration.

func (*App) CurrentMode

func (a *App) CurrentMode() Mode

CurrentMode returns the current mode.

func (*App) DisableEventTap

func (a *App) DisableEventTap()

DisableEventTap disables the event tap.

func (*App) EnableEventTap

func (a *App) EnableEventTap()

EnableEventTap enables the event tap.

func (*App) EventTap

func (a *App) EventTap() ports.EventTapPort

EventTap returns the event tap.

func (*App) ExitMode

func (a *App) ExitMode()

ExitMode exits the current mode.

func (*App) GetConfigPath

func (a *App) GetConfigPath() string

GetConfigPath returns the config path.

func (*App) GetSystrayComponent added in v1.12.1

func (a *App) GetSystrayComponent() SystrayComponent

GetSystrayComponent returns the systray component.

func (*App) GridContext

func (a *App) GridContext() *grid.Context

GridContext returns the grid context.

func (*App) GridEnabled

func (a *App) GridEnabled() bool

GridEnabled returns true if grid is enabled.

func (*App) HandleKeyPress

func (a *App) HandleKeyPress(key string)

HandleKeyPress delegates key press handling to the mode handler.

func (*App) HintsContext

func (a *App) HintsContext() *hints.Context

HintsContext returns the hints context.

func (*App) HintsEnabled

func (a *App) HintsEnabled() bool

HintsEnabled returns true if hints are enabled.

func (*App) IsEnabled

func (a *App) IsEnabled() bool

IsEnabled returns the enabled state of the application.

func (*App) IsFocusedAppExcluded

func (a *App) IsFocusedAppExcluded() bool

IsFocusedAppExcluded checks if the focused app is excluded.

func (*App) IsOverlayHiddenForScreenShare added in v1.19.0

func (a *App) IsOverlayHiddenForScreenShare() bool

IsOverlayHiddenForScreenShare returns whether the overlay is hidden from screen sharing.

func (*App) Logger

func (a *App) Logger() *zap.Logger

Logger returns the application logger.

func (*App) OffEnabledStateChanged added in v1.18.1

func (a *App) OffEnabledStateChanged(id uint64)

OffEnabledStateChanged unsubscribes a callback by ID.

func (*App) OffScreenShareStateChanged added in v1.19.0

func (a *App) OffScreenShareStateChanged(id uint64)

OffScreenShareStateChanged unsubscribes a callback by ID.

func (*App) OnEnabledStateChanged added in v1.12.1

func (a *App) OnEnabledStateChanged(callback func(bool)) uint64

OnEnabledStateChanged registers a callback for when the enabled state changes. Returns a subscription ID that can be used to unsubscribe later.

func (*App) OnScreenShareStateChanged added in v1.19.0

func (a *App) OnScreenShareStateChanged(callback func(bool)) uint64

OnScreenShareStateChanged registers a callback for when the screen share state changes.

func (*App) OverlayManager

func (a *App) OverlayManager() OverlayManager

OverlayManager returns the overlay manager.

func (*App) RecursiveGridEnabled added in v1.20.0

func (a *App) RecursiveGridEnabled() bool

RecursiveGridEnabled returns true if recursive-grid is enabled.

func (*App) ReloadConfig

func (a *App) ReloadConfig(ctx context.Context, configPath string) error

ReloadConfig reloads the configuration from the specified path. If validation fails, shows an alert and keeps the current config. Preserves the current app state (enabled/disabled, current mode).

func (*App) Renderer

func (a *App) Renderer() *ui.OverlayRenderer

Renderer returns the overlay renderer.

func (*App) Run

func (a *App) Run() error

Run starts the main application loop and initializes all subsystems.

func (*App) ScrollContext

func (a *App) ScrollContext() *scroll.Context

ScrollContext returns the scroll context.

func (*App) SetEnabled

func (a *App) SetEnabled(v bool)

SetEnabled sets the enabled state of the application.

func (*App) SetHintOverlayNeedsRefresh

func (a *App) SetHintOverlayNeedsRefresh(
	value bool,
)

SetHintOverlayNeedsRefresh sets the hint overlay needs refresh flag.

func (*App) SetModeGrid

func (a *App) SetModeGrid()

SetModeGrid switches the application to grid mode.

func (*App) SetModeHints

func (a *App) SetModeHints()

SetModeHints sets the mode to hints. SetModeHints switches the application to hints mode.

func (*App) SetModeIdle

func (a *App) SetModeIdle()

SetModeIdle switches the application to idle mode.

func (*App) SetModeRecursiveGrid added in v1.20.0

func (a *App) SetModeRecursiveGrid()

SetModeRecursiveGrid switches the application to recursive-grid mode.

func (*App) SetModeScroll added in v1.11.0

func (a *App) SetModeScroll()

SetModeScroll switches the application to scroll mode.

func (*App) SetOverlayHiddenForScreenShare added in v1.19.0

func (a *App) SetOverlayHiddenForScreenShare(hide bool)

SetOverlayHiddenForScreenShare sets whether the overlay should be hidden from screen sharing.

func (*App) Stop added in v1.11.0

func (a *App) Stop()

Stop gracefully stops the application.

func (*App) ToggleEnabled added in v1.21.4

func (a *App) ToggleEnabled()

ToggleEnabled atomically toggles the enabled state.

func (*App) ToggleOverlayHiddenForScreenShare added in v1.21.4

func (a *App) ToggleOverlayHiddenForScreenShare() bool

ToggleOverlayHiddenForScreenShare atomically toggles the screen share hidden state.

type ComponentCreationOptions added in v1.11.0

type ComponentCreationOptions struct {
	SkipIfDisabled bool   // Skip creation if component is disabled in config
	Required       bool   // Component is required (return error if creation fails)
	OverlayType    string // Type of overlay to create ("hints", "grid", "action", "scroll")
}

ComponentCreationOptions defines options for component creation.

type ComponentFactory added in v1.11.0

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

ComponentFactory provides standardized component creation patterns.

func NewComponentFactory added in v1.11.0

func NewComponentFactory(
	config *config.Config,
	logger *zap.Logger,
	overlayManager OverlayManager,
) *ComponentFactory

NewComponentFactory creates a new component factory.

func (*ComponentFactory) CreateGridComponent added in v1.11.0

func (f *ComponentFactory) CreateGridComponent(
	opts ComponentCreationOptions,
) (*components.GridComponent, error)

CreateGridComponent creates a grid component with standardized error handling.

func (*ComponentFactory) CreateHintsComponent added in v1.11.0

func (f *ComponentFactory) CreateHintsComponent(
	opts ComponentCreationOptions,
) (*components.HintsComponent, error)

CreateHintsComponent creates a hints component with standardized error handling.

func (*ComponentFactory) CreateModeIndicatorComponent added in v1.21.0

func (f *ComponentFactory) CreateModeIndicatorComponent(
	opts ComponentCreationOptions,
) (*components.ModeIndicatorComponent, error)

CreateModeIndicatorComponent creates the shared mode indicator overlay component.

func (*ComponentFactory) CreateRecursiveGridComponent added in v1.20.0

func (f *ComponentFactory) CreateRecursiveGridComponent(
	opts ComponentCreationOptions,
) (*components.RecursiveGridComponent, error)

CreateRecursiveGridComponent creates a recursive-grid component with standardized error handling.

func (*ComponentFactory) CreateScrollComponent added in v1.11.0

func (f *ComponentFactory) CreateScrollComponent(
	opts ComponentCreationOptions,
) (*components.ScrollComponent, error)

CreateScrollComponent creates a scroll component with standardized error handling. This component now only owns scroll context and key mappings; the visual mode indicator overlay is managed separately.

type HotkeyService

type HotkeyService interface {
	// Register registers a new hotkey with the given key string and callback.
	// Returns a HotkeyID that can be used to unregister the hotkey later.
	Register(keyString string, callback hotkeys.Callback) (hotkeys.HotkeyID, error)

	// UnregisterAll unregisters all registered hotkeys.
	UnregisterAll()
}

HotkeyService defines the interface for hotkey management. It provides methods for registering and unregistering global hotkeys.

type IPCController

type IPCController struct {
	// Services
	HintService   *services.HintService
	GridService   *services.GridService
	ActionService *services.ActionService
	ScrollService *services.ScrollService
	ConfigService *config.Service

	// State
	AppState *state.AppState

	// Infrastructure
	Logger *zap.Logger

	// Mode management
	Modes *modes.Handler

	// Reload callback for full app-level config reload
	ReloadConfig func(ctx context.Context, configPath string) error

	// Command Handlers map
	Handlers map[string]func(context.Context, ipc.Command) ipc.Response
	// contains filtered or unexported fields
}

IPCController handles IPC command routing and execution.

func NewIPCController

func NewIPCController(
	hintService *services.HintService,
	gridService *services.GridService,
	actionService *services.ActionService,
	scrollService *services.ScrollService,
	configService *config.Service,
	appState *state.AppState,
	config *config.Config,
	modesHandler *modes.Handler,
	reloadConfig func(ctx context.Context, configPath string) error,
	logger *zap.Logger,
) *IPCController

NewIPCController creates a new IPC controller with the given dependencies.

func (*IPCController) HandleCommand

func (c *IPCController) HandleCommand(ctx context.Context, command ipc.Command) ipc.Response

HandleCommand routes an IPC command to the appropriate handler.

func (*IPCController) UpdateConfig added in v1.24.0

func (c *IPCController) UpdateConfig(cfg *config.Config)

UpdateConfig updates the stored config.

type IPCControllerActions added in v1.14.0

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

IPCControllerActions handles action-related IPC commands.

func NewIPCControllerActions added in v1.14.0

func NewIPCControllerActions(
	actionService *services.ActionService,
	logger *zap.Logger,
) *IPCControllerActions

NewIPCControllerActions creates a new action command handler.

func (*IPCControllerActions) RegisterHandlers added in v1.14.0

func (h *IPCControllerActions) RegisterHandlers(
	handlers map[string]func(context.Context, ipc.Command) ipc.Response,
)

RegisterHandlers registers action command handlers.

type IPCControllerInfo added in v1.11.0

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

IPCControllerInfo handles info and config-related IPC commands.

func NewIPCControllerInfo added in v1.11.0

func NewIPCControllerInfo(
	configService *config.Service,
	appState *state.AppState,
	config *config.Config,
	modes *modes.Handler,
	hintService *services.HintService,
	gridService *services.GridService,
	actionService *services.ActionService,
	scrollService *services.ScrollService,
	reloadConfig func(ctx context.Context, configPath string) error,
	logger *zap.Logger,
) *IPCControllerInfo

NewIPCControllerInfo creates a new info/config command handler.

func (*IPCControllerInfo) RegisterHandlers added in v1.11.0

func (h *IPCControllerInfo) RegisterHandlers(
	handlers map[string]func(context.Context, ipc.Command) ipc.Response,
)

RegisterHandlers registers info/config command handlers.

func (*IPCControllerInfo) ResolveConfigPath added in v1.11.0

func (h *IPCControllerInfo) ResolveConfigPath() string

ResolveConfigPath determines the configuration file path for status reporting.

func (*IPCControllerInfo) UpdateConfig added in v1.24.0

func (h *IPCControllerInfo) UpdateConfig(cfg *config.Config)

UpdateConfig updates the stored config.

type IPCControllerLifecycle added in v1.11.0

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

IPCControllerLifecycle handles lifecycle-related IPC commands.

func NewIPCControllerLifecycle added in v1.11.0

func NewIPCControllerLifecycle(
	appState *state.AppState,
	modes *modes.Handler,
	logger *zap.Logger,
) *IPCControllerLifecycle

NewIPCControllerLifecycle creates a new lifecycle command handler.

func (*IPCControllerLifecycle) RegisterHandlers added in v1.11.0

func (h *IPCControllerLifecycle) RegisterHandlers(
	handlers map[string]func(context.Context, ipc.Command) ipc.Response,
)

RegisterHandlers registers lifecycle command handlers.

type IPCControllerModes added in v1.11.0

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

IPCControllerModes handles mode-related IPC commands.

func NewIPCControllerModes added in v1.11.0

func NewIPCControllerModes(modes *modes.Handler, logger *zap.Logger) *IPCControllerModes

NewIPCControllerModes creates a new mode command handler.

func (*IPCControllerModes) RegisterHandlers added in v1.11.0

func (h *IPCControllerModes) RegisterHandlers(
	handlers map[string]func(context.Context, ipc.Command) ipc.Response,
)

RegisterHandlers registers mode command handlers.

type IPCControllerOverlay added in v1.19.0

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

IPCControllerOverlay handles overlay-related IPC commands.

func NewIPCControllerOverlay added in v1.19.0

func NewIPCControllerOverlay(appState *state.AppState, logger *zap.Logger) *IPCControllerOverlay

NewIPCControllerOverlay creates a new overlay command handler.

func (*IPCControllerOverlay) RegisterHandlers added in v1.19.0

func (h *IPCControllerOverlay) RegisterHandlers(
	handlers map[string]func(context.Context, ipc.Command) ipc.Response,
)

RegisterHandlers registers overlay command handlers.

type Mode

type Mode = domain.Mode

Mode is the current mode of the application.

type ModeService added in v1.10.5

type ModeService interface {
	// Show activates the mode's overlay/interface.
	Show(ctx context.Context) error

	// Hide deactivates the mode's overlay/interface.
	Hide(ctx context.Context) error
}

ModeService defines the common interface for mode-specific services. This ensures grid, hints, and scroll services have identical APIs.

type Option added in v1.10.5

type Option func(*App) error

Option is a functional option for configuring an App instance.

func WithConfig added in v1.10.5

func WithConfig(cfg *config.Config) Option

WithConfig sets the application configuration. Note: cfg can be nil, in which case default configuration will be used.

func WithConfigPath added in v1.10.5

func WithConfigPath(path string) Option

WithConfigPath sets the configuration file path.

func WithEventTap added in v1.10.5

func WithEventTap(eventTap ports.EventTapPort) Option

WithEventTap sets the event tap implementation. Note: eventTap can be nil, will be initialized during app startup if not provided.

func WithHotkeyService added in v1.10.5

func WithHotkeyService(hotkeyService HotkeyService) Option

WithHotkeyService sets the hotkey service implementation. Note: hotkeyService can be nil, will be initialized during app startup if not provided.

func WithIPCServer added in v1.10.5

func WithIPCServer(ipcServer ports.IPCPort) Option

WithIPCServer sets the IPC server implementation. Note: ipcServer can be nil, will be initialized during app startup if not provided.

func WithLogger added in v1.10.5

func WithLogger(logger *zap.Logger) Option

WithLogger sets the application logger.

func WithOverlayManager added in v1.10.5

func WithOverlayManager(overlayManager OverlayManager) Option

WithOverlayManager sets the overlay manager implementation. Note: overlayManager can be nil, will be initialized during app startup if not provided.

func WithWatcher added in v1.10.5

func WithWatcher(watcher Watcher) Option

WithWatcher sets the app watcher implementation. Note: watcher can be nil, will be initialized during app startup if not provided.

type OverlayManager

type OverlayManager = overlay.ManagerInterface

OverlayManager defines the interface for overlay window management.

type SystrayComponent added in v1.12.1

type SystrayComponent interface {
	OnReady()
	OnExit()
	Close()
}

SystrayComponent defines the interface for systray functionality.

type Watcher

type Watcher interface {
	Start()
	Stop()
	OnActivate(callback appwatcher.AppCallback)
	OnDeactivate(callback appwatcher.AppCallback)
	OnTerminate(callback appwatcher.AppCallback)
	OnScreenParametersChanged(callback func())
}

Watcher defines the interface for application lifecycle monitoring.

Directories

Path Synopsis
Package components provides feature-specific implementations.
Package components provides feature-specific implementations.
grid
Package grid provides grid-based navigation functionality for Neru.
Package grid provides grid-based navigation functionality for Neru.
hints
Package hints provides accessibility tree-based hint generation and navigation.
Package hints provides accessibility tree-based hint generation and navigation.
modeindicator
Package modeindicator provides the mode indicator overlay component.
Package modeindicator provides the mode indicator overlay component.
overlayutil
Package overlayutil provides shared utilities for overlay management.
Package overlayutil provides shared utilities for overlay management.
recursivegrid
Package recursivegrid provides the recursivegrid component.
Package recursivegrid provides the recursivegrid component.
scroll
Package scroll provides Vim-style scrolling functionality for the Neru application.
Package scroll provides Vim-style scrolling functionality for the Neru application.
systray
Package systray provides system tray functionality for the Neru application.
Package systray provides system tray functionality for the Neru application.
Package modes implements the different operational modes for Neru.
Package modes implements the different operational modes for Neru.
Package services implements application use cases and orchestration logic.
Package services implements application use cases and orchestration logic.
modeindicator
Package modeindicator provides the mode indicator service.
Package modeindicator provides the mode indicator service.

Jump to

Keyboard shortcuts

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