state

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package state owns the TrackerState type and the only valid way to read or write it. No other package may touch state.json directly.

Index

Constants

View Source
const MinSupportedYear = 2017

Variables

View Source
var (
	ErrCorruptState  = errors.New("state file is corrupt or unreadable")
	ErrNothingToUndo = errors.New("nothing to undo: already at the start of the journey")
)

Sentinel errors — callers use errors.Is / errors.As to distinguish them.

Functions

This section is empty.

Types

type Manager

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

Manager handles atomic reads and writes of TrackerState.

func NewManager

func NewManager(stateFile string) *Manager

NewManager creates a Manager for the given state file path.

func (*Manager) CompleteCurrentRace

func (m *Manager) CompleteCurrentRace(totalRounds int) (TrackerState, error)

CompleteCurrentRace advances the watch pointer to the next race. If current_round == totalRounds, it wraps to Round 1 of the next season. A snapshot is taken before the advance.

func (*Manager) InitSeason

func (m *Manager) InitSeason(year int, clearHighlights bool) (TrackerState, error)

InitSeason resets progress to Round 1 of year, preserving existing highlight URLs unless clearHighlights is true. A snapshot is taken so the operation can be undone.

func (*Manager) Load

func (m *Manager) Load() (TrackerState, error)

Load reads the state file, creating a default one if it does not exist.

func (*Manager) RemoveHighlightURL

func (m *Manager) RemoveHighlightURL(year, round int) (TrackerState, error)

RemoveHighlightURL deletes the URL for (year, round) if present.

func (*Manager) Save

func (m *Manager) Save(s TrackerState) error

Save atomically persists s to disk (write-to-temp then rename).

func (*Manager) SetHighlightURL

func (m *Manager) SetHighlightURL(year, round int, url string) (TrackerState, error)

SetHighlightURL stores a highlight URL for (year, round).

func (*Manager) SetProgress

func (m *Manager) SetProgress(year, round int) (TrackerState, error)

SetProgress manually repositions the watch pointer. A snapshot is taken.

func (*Manager) SetSpoilerSafe

func (m *Manager) SetSpoilerSafe(enabled bool) error

SetSpoilerSafe toggles spoiler-safe mode and persists the change. Pass true to re-enable spoiler-safe mode; false to activate Expert Mode.

func (*Manager) Undo

func (m *Manager) Undo() (TrackerState, error)

Undo restores the previous watch position from the undo snapshot. Returns ErrNothingToUndo if no snapshot is available.

type TrackerState

type TrackerState struct {
	CurrentYear  int                    `json:"current_year"`
	CurrentRound int                    `json:"current_round"`
	Highlights   map[int]map[int]string `json:"highlights"`
	UpdatedAtUTC time.Time              `json:"updated_at_utc"`

	// Undo checkpoint — nil when no prior state is available.
	PrevYear  *int `json:"prev_year,omitempty"`
	PrevRound *int `json:"prev_round,omitempty"`

	// SpoilerSafe controls whether future results are hidden.
	// nil (field absent in JSON) and &true both mean spoiler-safe mode is active,
	// which is the correct default for new users.  Explicitly set to &false to
	// enable Expert Mode.  We use *bool so the zero-value (false) is never
	// misinterpreted as "expert mode on" for users who have never touched the setting.
	SpoilerSafe *bool `json:"spoiler_safe,omitempty"`
}

TrackerState is the single source of truth for the user's watch progress. It is serialised as JSON at ~/.since17/state.json.

Undo slot: PrevYear / PrevRound store a single-level rollback checkpoint. They are populated before every mutation and cleared after a successful undo.

func Default

func Default() TrackerState

Default returns a brand-new TrackerState at the earliest supported season.

func (*TrackerState) HighlightURL

func (s *TrackerState) HighlightURL(year, round int) string

HighlightURL returns the stored highlight URL for (year, round), or "".

func (*TrackerState) IsSpoilerSafe

func (s *TrackerState) IsSpoilerSafe() bool

IsSpoilerSafe reports whether spoiler-safe mode is active. Returns true when the field is absent (nil) or explicitly set to true — so new users and users who have never run `config spoiler-safe` are safe by default.

func (*TrackerState) SetHighlightURL

func (s *TrackerState) SetHighlightURL(year, round int, url string)

SetHighlightURL stores url for (year, round), initialising the nested map if needed.

Jump to

Keyboard shortcuts

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