state

package
v2.17.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2026 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoActiveMedia          = errors.New("no active media")
	ErrActiveMediaChanged     = errors.New("active media changed")
	ErrRestoreInProgress      = errors.New("backup restore is in progress")
	ErrMediaLaunchInProgress  = errors.New("media launch is in progress")
	ErrRestoreRestartRequired = errors.New("backup restore restart is pending")
)
View Source
var ErrLaunchInProgress = errors.New("launch already in progress")

ErrLaunchInProgress is returned when a launch is attempted while another is in progress.

View Source
var ErrRunZapScriptDisabled = errors.New("run ZapScript is disabled")

ErrRunZapScriptDisabled is returned when ZapScript execution is attempted while the user has disabled it via settings.runZapScript. Every source (local scans, mappings, remote operations) is subject to this switch — there is no bypass.

Functions

This section is empty.

Types

type LauncherManager added in v2.7.0

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

LauncherManager manages the lifecycle of launcher contexts across the application. It provides thread-safe access to a shared context that gets canceled whenever a new launcher starts, allowing previous launcher cleanup routines to detect when they've been superseded and should skip their cleanup actions.

func NewLauncherManager added in v2.7.0

func NewLauncherManager() *LauncherManager

func (*LauncherManager) EndLaunch added in v2.8.0

func (lm *LauncherManager) EndLaunch()

EndLaunch releases the launch lock.

func (*LauncherManager) GetContext added in v2.7.0

func (lm *LauncherManager) GetContext() context.Context

GetContext returns the current launcher context. This context will be canceled when a new launcher starts.

func (*LauncherManager) NewContext added in v2.7.0

func (lm *LauncherManager) NewContext() context.Context

NewContext cancels the current launcher context and creates a new one. This should be called when starting a new launcher to invalidate any cleanup routines from previous launchers. Returns the newly created context.

func (*LauncherManager) TryStartLaunch added in v2.8.0

func (lm *LauncherManager) TryStartLaunch() error

TryStartLaunch attempts to acquire the launch lock. Returns ErrLaunchInProgress if a launch is already in progress.

type PendingLaunchOverride added in v2.13.0

type PendingLaunchOverride struct {
	CreatedAt  time.Time
	LauncherID string
	Source     tokens.Token
}

State holds the runtime state of the Zaparoo service.

LOCKING RULES: The mu mutex protects all mutable fields. To prevent deadlocks:

  • Never send to channels while holding the lock (notifications, callbacks)
  • Never call external methods (reader.OnMediaChange, hooks) while holding the lock
  • Pattern: lock → modify state → copy needed data → unlock → send notifications

See SetActiveCard, SetActiveMedia, SetReader, RemoveReader for examples.

type PendingWrite added in v2.13.0

type PendingWrite struct {
	CreatedAt time.Time
	Payload   string
	Source    tokens.Token
}

type State

type State struct {
	Notifications chan<- models.Notification
	// contains filtered or unexported fields
}

func NewState

func NewState(platform platforms.Platform, bootUUID string) (state *State, notificationCh <-chan models.Notification)

func (*State) AcquireMediaLaunch added in v2.16.0

func (s *State) AcquireMediaLaunch() (platforms.MediaLaunchAccess, error)

func (*State) AcquireMediaStop added in v2.16.1

func (s *State) AcquireMediaStop(ctx context.Context) (func(), error)

AcquireMediaStop waits for in-flight media launches, then prevents another launch from starting until the returned release function is called.

func (*State) AcquireRestoreAccess added in v2.16.0

func (s *State) AcquireRestoreAccess() (func(), error)

func (*State) AcquireUpdateMediaGate

func (s *State) AcquireUpdateMediaGate(ctx context.Context) (func(), error)

AcquireUpdateMediaGate waits for in-flight launches and ActiveMedia publications, then prevents either from starting until release. The updater holds this gate from its final safety check through restart cancellation.

func (*State) ActiveMedia

func (s *State) ActiveMedia() *models.ActiveMedia

func (*State) ActiveMediaReady added in v2.14.0

func (s *State) ActiveMediaReady() bool

func (*State) ActiveMediaReadyGeneration added in v2.14.0

func (s *State) ActiveMediaReadyGeneration() (uint64, bool)

func (*State) ActiveProfile added in v2.16.0

func (s *State) ActiveProfile() *models.ActiveProfile

ActiveProfile returns a copy of the device's active profile snapshot, or nil when no profile is active.

func (*State) AnyReaderWriteActive

func (s *State) AnyReaderWriteActive() bool

AnyReaderWriteActive reports whether any reader is part-way through writing a token.

ReaderWriteActive answers for one reader and defaults to the empty ID, which no production caller records under: writes are tracked per reader by Reader.ID(). A caller that wants to know whether the device is mid-write at all — the updater, before it restarts the service — has to ask about every reader, not about a reader that does not exist.

func (*State) BackgroundAutoPaused added in v2.15.0

func (s *State) BackgroundAutoPaused() bool

func (*State) BackgroundMedia added in v2.15.0

func (s *State) BackgroundMedia() *models.ActiveMedia

func (*State) BackupCoordinator added in v2.16.0

func (s *State) BackupCoordinator() *backupcoordinator.Coordinator

func (*State) BeginRestoreGate added in v2.16.0

func (s *State) BeginRestoreGate() (func(bool), error)

func (*State) BootUUID added in v2.7.0

func (s *State) BootUUID() string

func (*State) ClearPendingWrite added in v2.13.0

func (s *State) ClearPendingWrite()

func (*State) ConsumePendingLaunchOverride added in v2.13.0

func (s *State) ConsumePendingLaunchOverride() *PendingLaunchOverride

func (*State) ConsumePendingWrite added in v2.13.0

func (s *State) ConsumePendingWrite() *PendingWrite

func (*State) GetActiveCard

func (s *State) GetActiveCard() tokens.Token

func (*State) GetActivePlaylist

func (s *State) GetActivePlaylist() *playlists.Playlist

func (*State) GetBackgroundPlaylist added in v2.15.0

func (s *State) GetBackgroundPlaylist() *playlists.Playlist

func (*State) GetContext

func (s *State) GetContext() context.Context

func (*State) GetLastScanned

func (s *State) GetLastScanned() tokens.Token

func (*State) GetPendingLaunchOverride added in v2.13.0

func (s *State) GetPendingLaunchOverride() *PendingLaunchOverride

func (*State) GetPendingWrite added in v2.13.0

func (s *State) GetPendingWrite() *PendingWrite

func (*State) GetReader

func (s *State) GetReader(readerID string) (readers.Reader, bool)

GetReader returns the Reader for a given ReaderID.

func (*State) GetSoftwareToken

func (s *State) GetSoftwareToken() *tokens.Token

func (*State) GetWroteToken

func (s *State) GetWroteToken(readerIDs ...string) *tokens.Token

func (*State) Inbox added in v2.8.0

func (s *State) Inbox() *inbox.Service

Inbox returns the inbox service for adding system notifications.

func (*State) LauncherManager added in v2.7.0

func (s *State) LauncherManager() *LauncherManager

func (*State) ListReaders

func (s *State) ListReaders() []readers.Reader

ListReaders returns all registered Reader instances.

func (*State) MarkActiveMediaReady added in v2.14.0

func (s *State) MarkActiveMediaReady(gen uint64)

func (*State) MarkWrittenTagRemoved

func (s *State) MarkWrittenTagRemoved(readerIDs ...string)

func (*State) MediaDBRecoveryActive

func (s *State) MediaDBRecoveryActive() bool

MediaDBRecoveryActive reports whether automatic media database recovery is currently running.

func (*State) ReaderWriteActive

func (s *State) ReaderWriteActive(readerIDs ...string) bool

func (*State) RemoveReader

func (s *State) RemoveReader(readerID string)

RemoveReader removes a reader by its ReaderID and closes it.

func (*State) RestartRequested added in v2.10.0

func (s *State) RestartRequested() bool

RestartRequested returns true if the service shutdown was triggered by a restart request (e.g. after applying an update).

func (*State) RestartService added in v2.10.0

func (s *State) RestartService()

RestartService signals the service to shut down and restart with the new binary. Used after applying an update for graceful restart instead of os.Exit.

func (*State) RunZapScriptEnabled

func (s *State) RunZapScriptEnabled() bool

func (*State) SetActiveCard

func (s *State) SetActiveCard(card tokens.Token)

func (*State) SetActiveMedia

func (s *State) SetActiveMedia(media *models.ActiveMedia)

func (*State) SetActivePlaylist

func (s *State) SetActivePlaylist(playlist *playlists.Playlist)

func (*State) SetActiveProfile added in v2.16.0

func (s *State) SetActiveProfile(profile *models.ActiveProfile)

SetActiveProfile sets or clears (nil) the device's active profile and broadcasts a profiles.active notification. The snapshot is stored by value internally so callers cannot mutate state through the pointer.

func (*State) SetBackgroundAutoPaused added in v2.15.0

func (s *State) SetBackgroundAutoPaused(v bool)

func (*State) SetBackgroundMedia added in v2.15.0

func (s *State) SetBackgroundMedia(media *models.ActiveMedia)

func (*State) SetBackgroundPlaylist added in v2.15.0

func (s *State) SetBackgroundPlaylist(playlist *playlists.Playlist)

func (*State) SetInbox added in v2.8.0

func (s *State) SetInbox(svc *inbox.Service)

SetInbox sets the inbox service. Called during service startup after database is ready.

func (*State) SetMediaDBRecoveryActive

func (s *State) SetMediaDBRecoveryActive(active bool)

SetMediaDBRecoveryActive records whether automatic media database recovery currently owns the recovery workflow.

func (*State) SetOnMediaStartHook

func (s *State) SetOnMediaStartHook(hook func(*models.ActiveMedia, uint64))

func (*State) SetOnMediaStopHook added in v2.15.0

func (s *State) SetOnMediaStopHook(hook func())

func (*State) SetPendingLaunchOverride added in v2.13.0

func (s *State) SetPendingLaunchOverride(pending *PendingLaunchOverride)

func (*State) SetPendingWrite added in v2.13.0

func (s *State) SetPendingWrite(pending *PendingWrite)

func (*State) SetReader

func (s *State) SetReader(reader readers.Reader)

SetReader registers a reader using its ReaderID as the key. If a reader with the same ReaderID exists, it is closed first.

func (*State) SetReaderWriteActive

func (s *State) SetReaderWriteActive(active bool, readerIDs ...string)

func (*State) SetRunZapScript

func (s *State) SetRunZapScript(run bool)

func (*State) SetSoftwareToken

func (s *State) SetSoftwareToken(token *tokens.Token)

func (*State) SetUIEvents added in v2.16.0

func (s *State) SetUIEvents(service *uievents.Service)

SetUIEvents stores the process-wide UI event service.

func (*State) SetWroteToken

func (s *State) SetWroteToken(token *tokens.Token)

func (*State) SetWroteTokenForReader

func (s *State) SetWroteTokenForReader(readerID string, token *tokens.Token)

func (*State) StopService

func (s *State) StopService()

func (*State) TryAcquireRestoreAccess added in v2.16.0

func (s *State) TryAcquireRestoreAccess() (func(), error)

func (*State) UIEvents added in v2.16.0

func (s *State) UIEvents() *uievents.Service

UIEvents returns the process-wide UI event service.

func (*State) WaitForActiveMediaReady added in v2.14.0

func (s *State) WaitForActiveMediaReady(ctx context.Context, expectedGen uint64) error

Jump to

Keyboard shortcuts

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